Repository navigation
Services overview counts and lists only the services the caller may read - #39897
sonika-shah wants to merge 6 commits into
Conversation
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.
| 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) { |
There was a problem hiding this comment.
⚠️ 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 👍 / 👎
| Map<String, TypeAccess> access = accessByType(securityContext, requested, scopes); | ||
| ServicesOverviewRequest r = requested.restrictedTo(access.keySet()); |
There was a problem hiding this comment.
💡 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 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
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/overviewis 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,totalandpaging.total. A caller with no view grant on any service type still gets 403.What changed
ServicesOverviewResource: resolves the caller'sCallerScopeonce per service type. A type is included when that scope authorizes its listing, or when the check on the type passes, asEntityResource.authorizeListingdecides. The scopes are passed to the repository.ServicesOverviewRepository:ViewPermissionFilter.retainPermittedIds: the one place that loads authorization copies and checks them.EntityResourceand the overview both call it.ServicesOverviewResourceIT.ServicesOverviewResourceIT, and item-read parity for the overview inRowFilterDifferentialIT.Type of change:
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:PII.SensitiveThe caller's item GETs are the reference. For each role, the overview must list exactly those services, and
counts,serviceTypeCounts,healthCounts,totalandpaging.totalmust agree with them. This is checked under:q=serviceType=health=notRundomain=<other>include=deletedinclude=allsortOrder=descRoles:
!hasDomain()deny:DomainOnlyAccessRoleDeny noOwner()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 itsScenarioenum:!isOwner()!hasDomain()!matchTeam()denynoOwner()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
openmetadata-integration-tests/for new/changed API endpoints.openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ServicesOverviewResourceIT.java,openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/RowFilterDifferentialIT.javaRun locally on commit cb83761:
mysql-elasticsearch: ServicesOverviewResourceIT 40/40, RowFilterDifferentialIT 215/215postgres-opensearch: ServicesOverviewResourceIT 40/40, RowFilterDifferentialIT 215/215With the service code reset to
main, the domain-scoped tests added in the first commit fail.Not run locally: the other classes
make java_affectedselects. The merge queue runs them.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
None beyond the ITs above.
UI screen recording:
Not applicable: backend-only fix.
Checklist:
Fixes <issue-number>: <short explanation>(no issue yet)Fixes #<issue-number>above. (no issue yet)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).total. For non-admins, totals become caller-scoped.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.
RowStoragesget an exact scope for owner, domain and team conditions: database, dashboard, pipeline, messaging, ML model, storage, search and API services.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.Follow-ups (not in this PR).
RowStoragesfor drive, LLM, MCP, metadata and security services, so their domain and owner conditions become exact./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./assets/countsendpoints of domains, data products, glossary terms, tags and teams, and/testSuites/executionSummary, build unscoped key sets.GET /v1/domains/hierarchyauthorizes on the type and lists unscoped. Scoping it needs a choice first: the endpoint has always required only ViewBasic, but it returnsparent, 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.