Skip to content

Services overview counts and lists only the services the caller may read - #39897

Draft
sonika-shah wants to merge 6 commits into
mainfrom
fix/services-overview-row-access
Draft

sonika-shah wants to merge 6 commits into
mainfrom
fix/services-overview-row-access

Conversation

@sonika-shah

Copy link
Copy Markdown
Collaborator

Describe your changes:

Related to #30717 (the services overview API). No issue is open for this change yet; the PR stays a draft until one is linked.

Summary. GET /v1/services/overview is the API behind the Connections page in AI mode. It now counts and lists only the services the caller may read, and it decides which service types to include using the same rule as each type's own list endpoint. Every number in the response comes from the rows the caller can open: data, counts, serviceTypeCounts, healthCounts, total and paging.total. A caller with no view grant on any service type still gets 403.

What changed

  • ServicesOverviewResource: resolves the caller's CallerScope once per service type. A type is included when that scope authorizes its listing, or when the check on the type passes, as EntityResource.authorizeListing decides. The scopes are passed to the repository.
  • ServicesOverviewRepository:
    • Every count, key-scan and list query of a type carries the caller's scope.
    • Where the scope is inexact, each candidate is checked as the service's GET checks it, and the type's counts, health and list come from the rows that pass.
    • A type with more than 10,000 candidates to check is left out, with a warning, rather than counted from part of its rows.
  • ViewPermissionFilter.retainPermittedIds: the one place that loads authorization copies and checks them. EntityResource and the overview both call it.
  • ADR 2026-11-13, revision v3: custom list and aggregate endpoints carry the scope, and the overview is the first. Its Guard list now includes ServicesOverviewResourceIT.
  • ITs: a role matrix in ServicesOverviewResourceIT, and item-read parity for the overview in RowFilterDifferentialIT.

Type of change:

  • Bug fix

High-level design:

ADR:2026-11-13-a-listing-filters-its-rows-in-sql-compiled-from-the-callers-policies, revised in this PR (v3). It states the rule for custom list and aggregate endpoints: an aggregate is computed by a query that carries the scope; if the scope is inexact, a bounded set of candidates is checked row by row, or the number is omitted.

Tests:

Which test layer and why

Java ITs. The change is what the API returns to a given caller, and checking that needs real policies, domains, teams and SQL on both engines.

Use cases covered

In ServicesOverviewResourceIT, each role runs against its own estate of eight database services:

  • in the home domain
  • in its sub-domain
  • in another domain
  • in no domain
  • team-owned
  • tagged PII.Sensitive
  • two soft-deleted

The caller's item GETs are the reference. For each role, the overview must list exactly those services, and counts, serviceTypeCounts, healthCounts, total and paging.total must agree with them. This is checked under:

  • q=
  • serviceType=
  • health=notRun
  • domain=<other>
  • include=deleted
  • include=all
  • sortOrder=desc
  • offset paging

Roles:

  • admin
  • unconditional view grant
  • !hasDomain() deny:
    • home-domain user (sees the sub-domain and the no-domain service)
    • sub-domain user (does not see the parent's services)
    • two-domain user
    • no-domain user
  • DomainOnlyAccessRole
  • an explicit Deny overriding an Allow in the same policy
  • Deny noOwner()
  • a tag-condition Deny (an inexact scope, so rows are checked one by one)
  • two roles that each scope a different service type
  • drive services under a domain deny (no declared row storage, so rows are checked one by one)
  • no grant: 403

In RowFilterDifferentialIT (@Isolated, reusing its fixture), the overview is compared with item reads for each of the 8 declared service types under every scenario in its Scenario enum:

  • !isOwner()
  • !hasDomain()
  • team member and team outsider under a team-attached !matchTeam() deny
  • noOwner()
  • isOwner() as the only view grant (seeded view rules withdrawn)

It also covers a hasDomain() Allow as the only view grant. Each case asserts data, counts, serviceTypeCounts, healthCounts, paging.total, descending order and offset paging. One more test lowers the row-check window through a test hook and checks that a row-checked type with more candidates is left out of counts and data, while the other types stay.

Unit tests

No new unit test. The changed behaviour is authorization against real policies and SQL, which the ITs cover. The existing unit tests of the touched code ran green on the PR head: ServicesOverviewMergeTest, ColumnFieldAccessTest, CallerScopeTest, ListFilterAccessScopeTest, PolicyPushdownTest, SqlRowFilterRendererTest, AuditReportAccessTest, ListingConditionGuardTest, ListCountCacheTest, RowFilterCompilerTest (74/74).

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ServicesOverviewResourceIT.java, openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/RowFilterDifferentialIT.java

Run locally on commit cb83761:

  • mysql-elasticsearch: ServicesOverviewResourceIT 40/40, RowFilterDifferentialIT 215/215
  • postgres-opensearch: ServicesOverviewResourceIT 40/40, RowFilterDifferentialIT 215/215

With the service code reset to main, the domain-scoped tests added in the first commit fail.

Not run locally: the other classes make java_affected selects. The merge queue runs them.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

None beyond the ITs above.

UI screen recording:

Not applicable: backend-only fix.

Checklist:

  • I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.
  • My PR title is Fixes <issue-number>: <short explanation> (no issue yet)
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above. (no issue yet)
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable.
  • For a UI feature or feature task: not applicable.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review against REVIEW.md. The first commit was reviewed with no 🔴; the follow-up commits address that review's points (entry rule, window truncation, duplicated row check).
    • Placement: the OM Connections page, and the Collate onboarding probe that reads total. For non-admins, totals become caller-scoped.
    • Trade-off: the row-by-row check runs only for non-admins on types whose scope SQL cannot decide, capped at 10,000 candidates per type.
  • Decision check: ADR 2026-11-13 revised (v3) in this PR.
Details

Before this change. The overview checked VIEW_BASIC on each service type and then counted and listed every service of a type that passed. Its numbers therefore did not follow the row conditions (owner, domain, team, tag) that the type's own list endpoint applies, in either direction.

Exact vs inexact scope.

  • The eight service types declared in RowStorages get an exact scope for owner, domain and team conditions: database, dashboard, pipeline, messaging, ML model, storage, search and API services.
  • Metadata, security, drive, LLM and MCP services are not declared, so those conditions are inexact for them. So are tag conditions on any type. Inexact types get the row-by-row check.

Pre-existing, not changed here.

  • domain= is resolved by name before any authorization, so an unknown name answers 404 while a known one answers 200. That reveals whether a domain name exists.
  • Health is derived from a service's ingestion pipelines whether or not the caller may view those pipelines.

Follow-ups (not in this PR).

  • Declare RowStorages for drive, LLM, MCP, metadata and security services, so their domain and owner conditions become exact.
  • Incident lists (/testCaseIncidentStatus, /incidentGroups, /stateId/{id}) authorize on an empty context and read unscoped SQL. Their rows are authorized through the tested table, which needs its own design.
  • The /assets/counts endpoints of domains, data products, glossary terms, tags and teams, and /testSuites/executionSummary, build unscoped key sets.
  • GET /v1/domains/hierarchy authorizes on the type and lists unscoped. Scoping it needs a choice first: the endpoint has always required only ViewBasic, but it returns parent, which no field mapping covers, so a scope compiled from its fields asks for ViewAll. That is left to its own PR.

Timing. Not measured at scale. The row-by-row check runs only for non-admin callers on types whose scope is inexact, and stops at 10,000 candidates per type.

Each service type's queries now carry the caller's compiled list scope, as the type's own list endpoint does. Where SQL cannot decide a row, candidates are checked as the service's own GET checks them, and the type is counted from the rows that pass.
The services overview and EntityResource each loaded authorization copies of a row set and ran retainPermitted on them. Both now call ViewPermissionFilter.retainPermittedIds.
A service type is listed when the caller's compiled scope authorizes its listing, or the check on the type allows it, as EntityResource.authorizeListing decides. The scope is resolved once in the resource and handed to the repository.
A type whose rows are checked one by one is scanned to one row past the window. If there are more candidates than the window, the type is left out of the counts and the list, with a warning, instead of being counted from part of its rows. The type's list is built from the rows already checked, so sort order and connector filters do not need a second scan.
ServicesOverviewResourceIT checks, per role, that the overview lists exactly the services the caller's GETs read and that every count agrees with them, under each filter, sort and page. RowFilterDifferentialIT compares the overview with item reads for every declared service type and scenario, and covers the row-check window.
Comment on lines +181 to +195
private Map<String, TypeAccess> accessByType(
SecurityContext securityContext, ServicesOverviewRequest r, Map<String, CallerScope> scopes) {
Map<String, TypeAccess> access = new LinkedHashMap<>();
for (String entityType : r.entityTypes()) {
typeAccess(securityContext, r, entityType, scopes.get(entityType))
.ifPresent(typeAccess -> access.put(entityType, typeAccess));
}
return access;
}

private Optional<TypeAccess> typeAccess(
SecurityContext securityContext,
ServicesOverviewRequest r,
String entityType,
CallerScope scope) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance: Inexact types load and authorize up to 10,001 rows on every request

accessByType runs rowCheckedAccess for every type in the universe (r.entityTypes()), not just the listed ones. Each row-checked type scans up to window + 1 keys, deserializes up to 10,000 entities with their authorization fields through retainPermittedIds, and calls authorize on each one. None of this is cached and none of it is bounded by limit.

The Connections page calls this endpoint on every load with includeHealth. So a non-admin with one tag condition on database services, or any caller of the drive/LLM/MCP/metadata/security types, which have no row storage, pays this cost on every page view and every pagination click. The cost can repeat across up to 13 types. The description says performance at scale was not measured.

Suggested fix: compute the per-type TypeAccess once per caller and policy generation and reuse it, for example with a short-TTL cache keyed like PolicyPushdownCache. Alternatively, set a much smaller per-request bound for the per-row path.

Was this helpful? React with 👍 / 👎

Comment on lines +107 to +108
Map<String, TypeAccess> access = accessByType(securityContext, requested, scopes);
ServicesOverviewRequest r = requested.restrictedTo(access.keySet());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: A type left out for size looks the same as an unauthorized one

If a row-checked type has more candidates than the window, rowCheckedAccess drops it and logs a WARN on the server only. The response is then identical to one for a type the caller may not view, and the client cannot tell the two apart. If every requested type overflows, requested.restrictedTo(access.keySet()) is empty and the caller gets a 200 with zero counts and no data. The resource's 403 check runs before this step and never sees it.

As a result, a permitted caller is told they have no services, with nothing in the response to suggest narrowing with q or domain. Suggested fix: report the omitted types in the response, for example with an omittedTypes/truncated field added to the ServicesOverview schema. At minimum, fail with a clear 4xx when nothing is left to count.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 🔴 High risk 0 closed / 2 findings

Scoping service overview counts and rows to caller permissions changes authorization; faulty filtering could expose services or hide permitted services.

Adds per-caller scoping to the services overview so counts, lists and health reflect only the services the caller may read, with the same rule applied as each type's list endpoint. Changes are requested before merge: the row-by-row authorization path runs uncached on every request for non-admin callers on inexact types, with cost up to 10,000 rows per type across up to 13 types, and types left out for size are indistinguishable in the response from types the caller cannot view, so a permitted caller can receive a 200 with zero counts and no signal to narrow their query.

⚠️ Performance: Inexact types load and authorize up to 10,001 rows on every request

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServicesOverviewRepository.java:181-195 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/ViewPermissionFilter.java:115-127

accessByType runs rowCheckedAccess for every type in the universe (r.entityTypes()), not just the listed ones. Each row-checked type scans up to window + 1 keys, deserializes up to 10,000 entities with their authorization fields through retainPermittedIds, and calls authorize on each one. None of this is cached and none of it is bounded by limit.

The Connections page calls this endpoint on every load with includeHealth. So a non-admin with one tag condition on database services, or any caller of the drive/LLM/MCP/metadata/security types, which have no row storage, pays this cost on every page view and every pagination click. The cost can repeat across up to 13 types. The description says performance at scale was not measured.

Suggested fix: compute the per-type TypeAccess once per caller and policy generation and reuse it, for example with a short-TTL cache keyed like PolicyPushdownCache. Alternatively, set a much smaller per-request bound for the per-row path.

💡 Edge Case: A type left out for size looks the same as an unauthorized one

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServicesOverviewRepository.java:107-108 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ServicesOverviewRepository.java:206-220 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/services/ServicesOverviewResource.java:167-172

If a row-checked type has more candidates than the window, rowCheckedAccess drops it and logs a WARN on the server only. The response is then identical to one for a type the caller may not view, and the client cannot tell the two apart. If every requested type overflows, requested.restrictedTo(access.keySet()) is empty and the caller gets a 200 with zero counts and no data. The resource's 403 check runs before this step and never sees it.

As a result, a permitted caller is told they have no services, with nothing in the response to suggest narrowing with q or domain. Suggested fix: report the omitted types in the response, for example with an omittedTypes/truncated field added to the ServicesOverview schema. At minimum, fail with a clear 4xx when nothing is left to count.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant