Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# A listing filters its rows in SQL compiled from the caller's policies, and checks rows one at a time only where SQL cannot decide them

- **Status:** Accepted
- **Revisions:** v1 2026-11-13 (initial); v2 2026-12-02 (team subtree limit)
- **Revisions:** v1 2026-11-13 (initial); v2 2026-12-02 (team subtree limit); v3 2026-12-07
(custom list and aggregate endpoints carry the scope, the services overview first)
- **Deciders:** OpenMetadata maintainers
- **Guard:** `RowFilterDifferentialIT`, `ListRowPolicyConditionsIT`, `ListRowAuthorizationIT`,
`RowFilterCompilerTest`, `SqlRowFilterRendererTest`, `ListFilterAccessScopeTest`,
`ListingConditionGuardTest`, `ListCountCacheTest`
`ListingConditionGuardTest`, `ListCountCacheTest`, `ServicesOverviewResourceIT`
- **Related:** `docs/plans/2026-11-09-list-access-scope-design.md`;
supersedes ADR:2026-11-03-a-listing-returns-only-rows-the-caller-may-read;
ADR:2026-11-03-search-applies-the-same-access-rules-as-entity-reads
Expand Down Expand Up @@ -55,6 +56,13 @@ conditional allow such as `ViewAll` with `isOwner()` answers 403 to the whole li
users, and a deleted team brings no deny rules. An item read of a stored procedure or an API
endpoint loads its parent with only the parent's live owners, as a table's read and every listing
do.
- A custom list or aggregate endpoint over a listed type, which reads its rows without
`EntityResource`, carries the same scope: it asks `listScope` once per type, admits the type on
the entry rule above, and computes every number it returns (counts, per-bucket counts, totals)
with a query that carries the scope. Where the scope is inexact, it checks a bounded candidate set
one row at a time (`ViewPermissionFilter.retainPermittedIds`) and counts the rows that pass. A type
with more candidates than the bound is left out of the response rather than counted from part of
its rows. `GET /v1/services/overview` is the first such endpoint (bound: 10,000 candidates).
- `TeamPolicySnapshot` keeps the snapshots of the last 4 policy generations, each for
`SubjectCache.POLICIES_TTL` (2 minutes). A team or policy change made on another server is then
seen within the bound the compiled policies already have. A snapshot keeps at most 256 team
Expand All @@ -71,8 +79,9 @@ conditional allow such as `ViewAll` with `isOwner()` answers 403 to the whole li
- A scoped count runs its correlated conditions on every page, uncached. Each team that holds a deny
policy adds an owner subquery. Their cost was not measured.
- An `Authorizer` that does not override `listScope` checks every row of every page.
- Search-backed lists, `/history`, time-series lists, custom list endpoints, MCP tools and filters
built outside `EntityResource` keep their current checks. A list filter can still be built
- Search-backed lists, `/history`, time-series lists, MCP tools, filters built outside
`EntityResource` and the custom list endpoints not yet moved onto the scope keep their current
checks. A list filter can still be built
without a scope. The later steps of `docs/plans/2026-11-09-list-access-scope-design.md` cover
them.
- Revisit the 2,000-team limit, the 4 generations and the 256 subtrees if a tenant's team graph or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.schema.EntityInterface;
import org.openmetadata.schema.api.policies.CreatePolicy;
import org.openmetadata.schema.api.services.CreateDriveService;
import org.openmetadata.schema.api.teams.CreateRole;
import org.openmetadata.schema.entity.policies.Policy;
import org.openmetadata.schema.entity.policies.accessControl.Rule;
import org.openmetadata.schema.entity.services.DriveService;
import org.openmetadata.schema.entity.teams.Role;
import org.openmetadata.schema.services.connections.drive.GoogleDriveConnection;
import org.openmetadata.schema.type.DriveConnection;
import org.openmetadata.schema.type.MetadataOperation;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.exceptions.ForbiddenException;
import org.openmetadata.sdk.network.HttpMethod;
import org.openmetadata.service.Entity;
import org.openmetadata.service.jdbi3.ServicesOverviewRepository;
import org.openmetadata.service.security.listaccess.ListAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -98,6 +103,10 @@ public class RowFilterDifferentialIT {
private static final Set<String> NOTHING_TO_REFUSE =
Set.of(Entity.USER + "/" + Scenario.TEAM_OUTSIDER, Entity.USER + "/" + Scenario.NO_OWNER);

private static final String OVERVIEW_PATH = "/v1/services/overview";
private static final int OVERVIEW_PAGE_SIZE = 100;
private static final int SMALL_ROW_CHECK_WINDOW = 2;

private static final String ORGANIZATION_POLICY = "OrganizationPolicy";
private static final String ORGANIZATION_VIEW_RULE = "OrganizationPolicy-ViewAll-Rule";
private static final String DATA_CONSUMER_POLICY = "DataConsumerPolicy";
Expand Down Expand Up @@ -299,6 +308,135 @@ void aCallerWhoOwnsNothingGetsAnEmptyListingRatherThanARefusal() throws Exceptio
});
}

static Stream<Arguments> overviewCases() {
return serviceTypes()
.flatMap(type -> Stream.of(Scenario.values()).map(rule -> Arguments.of(type, rule)));
}

static Stream<String> serviceTypes() {
return new TreeSet<>(ListAccess.coveredTypes())
.stream().filter(Entity.getServiceEntityTypes()::contains);
}

/** The services overview names and counts exactly the services the same caller can open. */
@ParameterizedTest(name = "{0} {1}")
@MethodSource("overviewCases")
void theServicesOverviewShowsExactlyTheServicesItsItemEndpointsRead(String type, Scenario rule)
throws Exception {
Caller caller = fixture.callers.get(rule);
if (rule == Scenario.OWNER_ALLOWED) {
withTheOwnerRuleAsTheOnlyViewGrant(() -> compareOverviewWithItemReads(type, caller));
} else {
compareOverviewWithItemReads(type, caller);
}
}

/**
* A type whose rows are checked one by one, with more candidates than the row-check window, is
* left out of the overview, counts included, rather than counted from part of its rows.
*/
@Test
void aRowCheckedTypeWithMoreCandidatesThanTheWindowIsLeftOutOfTheOverview() throws Exception {
Caller caller = fixture.driveDomainCaller();
for (int i = 0; i <= SMALL_ROW_CHECK_WINDOW; i++) {
fixture.driveService("overflow" + i);
}
String query =
OVERVIEW_PATH
+ "?limit=1000&entityType="
+ Entity.DATABASE_SERVICE
+ "&entityType="
+ Entity.DRIVE_SERVICE;
assertTrue(get(caller.client(), query).path("counts").has(Entity.DRIVE_SERVICE));

int previous = ServicesOverviewRepository.setRowCheckWindowForTesting(SMALL_ROW_CHECK_WINDOW);
try {
JsonNode overview = get(caller.client(), query);

assertFalse(overview.path("counts").has(Entity.DRIVE_SERVICE), "counts");
assertFalse(
overview.path("serviceTypeCounts").has(Entity.DRIVE_SERVICE), "serviceTypeCounts");
overview
.path("data")
.forEach(
row -> assertFalse(Entity.DRIVE_SERVICE.equals(row.path("entityType").asText())));
assertTrue(overview.path("counts").has(Entity.DATABASE_SERVICE), "other types stay");
} finally {
ServicesOverviewRepository.setRowCheckWindowForTesting(previous);
}
}

/**
* A caller whose only view grant is an Allow on {@code hasDomain()} sees, in the overview, the
* services of its domain and those with no domain, with counts to match.
*/
@ParameterizedTest(name = "{0}")
@MethodSource("serviceTypes")
void aDomainAllowOnlyCallerSeesInTheOverviewTheServicesItCanOpen(String type) throws Exception {
withTheOwnerRuleAsTheOnlyViewGrant(
() -> compareOverviewWithItemReads(type, fixture.domainAllowed));
}

private static void compareOverviewWithItemReads(String type, Caller caller) throws Exception {
String collection = COLLECTIONS.get(type);
Set<String> readable = rowsReadAs(caller, collection, adminListing(collection));
Overview overview = overviewAll(caller, type, "", UNIVERSE_PAGE_SIZE);

assertFalse(mine(type, readable).isEmpty(), type + " has no row " + caller.name() + " reads");
assertEquals(new TreeSet<>(readable), new TreeSet<>(overview.names()), "data");
assertEquals(readable.size(), overview.names().size(), "a service came back on two pages");
assertEquals(Set.of(readable.size()), new HashSet<>(overview.totals()), "paging.total");
assertEquals(readable.size(), overview.count(), "counts");
assertEquals(readable.size(), overview.connectorCount(), "serviceTypeCounts");
assertEquals(readable.size(), overview.healthCount(), "healthCounts");
assertEquals(
overview.names().reversed(),
overviewAll(caller, type, "&sortOrder=desc", UNIVERSE_PAGE_SIZE).names(),
"desc");
assertEquals(
overview.names(), overviewAll(caller, type, "", OVERVIEW_PAGE_SIZE).names(), "paging");
}

/** What the overview returned for one service type, walked page by page. */
private record Overview(
List<String> names, List<Integer> totals, int count, int connectorCount, int healthCount) {}

private static Overview overviewAll(Caller caller, String type, String query, int pageSize)
throws Exception {
List<String> names = new ArrayList<>();
List<Integer> totals = new ArrayList<>();
JsonNode page;
do {
page =
get(
caller.client(),
OVERVIEW_PATH
+ "?includeHealth=true&limit="
+ pageSize
+ "&offset="
+ names.size()
+ "&entityType="
+ type
+ query);
page.path("data").forEach(row -> names.add(row.path("fullyQualifiedName").asText()));
totals.add(page.path("paging").path("total").asInt(-1));
} while (page.path("data").size() == pageSize);
return new Overview(
names,
totals,
page.path("counts").path(type).asInt(-1),
sum(page.path("serviceTypeCounts").path(type)),
sum(page.path("healthCounts").path(type)));
}

private static int sum(JsonNode counts) {
int total = 0;
for (JsonNode value : counts) {
total += value.asInt();
}
return total;
}

private static void compareListingWithItemReads(String type, Scenario rule) throws Exception {
assertTrue(fixture.rowsByType.containsKey(type), "no fixture for declared type " + type);
assertFalse(fixture.rowsByType.get(type).isEmpty(), "no rows in the fixture of " + type);
Expand Down Expand Up @@ -501,6 +639,7 @@ private static final class Fixture {
private Ref otherUser;
private Ref leaver;
private Caller nobody;
private Caller domainAllowed;
private String domain;
private String subDomain;
private String otherDomain;
Expand Down Expand Up @@ -536,6 +675,7 @@ Fixture build() {
callers.put(
Scenario.OWNER_ALLOWED, caller(user("allowed", List.of(callerTeam.id()), null, null)));
nobody = caller(user("nobody", List.of(), null, null));
domainAllowed = caller(user("domainAllowed", List.of(), domain, domainAllowRole()));
rootTypes();
databaseChain();
siblingServices();
Expand Down Expand Up @@ -829,15 +969,75 @@ private Policy denyPolicy(String name, String condition) {
.withOperations(List.of(MetadataOperation.ALL))
.withEffect(Rule.Effect.DENY)
.withCondition(condition);
return policy(name, deny);
}

private Policy policy(String name, Rule rule) {
return ns.trackRoot(
Entity.POLICY,
admin
.policies()
.create(
new CreatePolicy()
.withName(ns.prefix(name))
.withDescription("Refuses the rows the condition names")
.withRules(List.of(deny))));
.withDescription("Decides the rows the condition names")
.withRules(List.of(rule))));
}

/** Grants view on the rows of the caller's domain and on rows with no domain, nothing else. */
private Role domainAllowRole() {
return roleWith(
"domainAllow",
new Rule()
.withName("allowDomain")
.withResources(new ArrayList<>(TYPES))
.withOperations(List.of(MetadataOperation.VIEW_ALL))
.withEffect(Rule.Effect.ALLOW)
.withCondition("hasDomain()"));
}

private Role roleWith(String name, Rule rule) {
Policy policy = policy(name + "Policy", rule);
return ns.trackRoot(
Entity.ROLE,
admin
.roles()
.create(
new CreateRole()
.withName(ns.prefix(name + "Role"))
.withDescription("Decides the rows the condition names")
.withPolicies(List.of(policy.getFullyQualifiedName()))));
}

/**
* A caller in the fixture's domain refused drive services outside it. Drive services have no
* declared row storage, so the overview checks each of them for this caller.
*/
private Caller driveDomainCaller() {
Role role =
roleWith(
"driveDomain",
new Rule()
.withName("denyOutsideDomain")
.withResources(List.of(Entity.DRIVE_SERVICE))
.withOperations(List.of(MetadataOperation.ALL))
.withEffect(Rule.Effect.DENY)
.withCondition("!hasDomain()"));
return caller(user("driveDomain", List.of(), domain, role));
}

private void driveService(String label) {
CreateDriveService request =
new CreateDriveService()
.withName(ns.prefix(label + "_" + suffix))
.withServiceType(CreateDriveService.DriveServiceType.GoogleDrive)
.withConnection(new DriveConnection().withConfig(new GoogleDriveConnection()))
.withDomains(List.of(domain));
DriveService created =
admin
.getHttpClient()
.execute(HttpMethod.POST, "/v1/services/driveServices", request, DriveService.class);
ns.trackRoot(Entity.DRIVE_SERVICE, created.getId());
}

private Role role(Scenario scenario) {
Expand Down
Loading
Loading