World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#13832] improvement(authz): short-circuit list authorization for views, functions, filesets, topics and semantic models (#13833)
YangJie495e1e3dbd3c
diff --git a/server-common/src/main/java/org/apache/gravitino/server/authorization/MetadataAuthzHelper.java b/server-common/src/main/java/org/apache/gravitino/server/authorization/MetadataAuthzHelper.javaindex 1ab6537b0f..891a6ea0fa 100644--- a/server-common/src/main/java/org/apache/gravitino/server/authorization/MetadataAuthzHelper.java+++ b/server-common/src/main/java/org/apache/gravitino/server/authorization/MetadataAuthzHelper.java@@ -93,6 +93,7 @@ public class MetadataAuthzHelper {private static final String TABLE_PARENT_SCOPES = "METALAKE, CATALOG, SCHEMA";private static final String MODEL_PARENT_SCOPES = "METALAKE, CATALOG, SCHEMA";+ private static final String SCHEMA_OBJECT_PARENT_SCOPES = "METALAKE, CATALOG, SCHEMA";private static final String SCHEMA_PARENT_SCOPES = "METALAKE, CATALOG";private static final String METALAKE_ONLY_SCOPE = "METALAKE";private static final String CATALOG_PARENT_SCOPES = "METALAKE";@@ -105,58 +106,117 @@ public class MetadataAuthzHelper {*/private static final Map<Entity.EntityType, Map<String, List<ParentScopeAccessPath>>>LIST_SHORT_CIRCUITS =- Map.of(- Entity.EntityType.USER,- principalListPaths(- AuthorizationExpressionConstants.LOAD_USER_AUTHORIZATION_EXPRESSION,- Privilege.Name.MANAGE_USERS),- Entity.EntityType.GROUP,- principalListPaths(- AuthorizationExpressionConstants.LOAD_GROUP_AUTHORIZATION_EXPRESSION,- Privilege.Name.MANAGE_GROUPS),- Entity.EntityType.ROLE,- principalListPaths(- AuthorizationExpressionConstants.LOAD_ROLE_AUTHORIZATION_EXPRESSION,- Privilege.Name.MANAGE_GRANTS),- Entity.EntityType.TABLE,- Map.of(- AuthorizationExpressionConstants.FILTER_TABLE_AUTHORIZATION_EXPRESSION,- List.of(- parentOwnerPath(TABLE_PARENT_SCOPES),- parentPrivilegePath(Privilege.Name.SELECT_TABLE, TABLE_PARENT_SCOPES),- parentPrivilegePath(Privilege.Name.MODIFY_TABLE, TABLE_PARENT_SCOPES)),- AuthorizationExpressionConstants.LIST_TABLE_LIKE_AUTHORIZATION_EXPRESSION,- List.of(- parentOwnerPath(TABLE_PARENT_SCOPES),- tableLikeParentPrivilegePath(Privilege.Name.PROBE_TABLE_LIKE),- tableLikeParentPrivilegePath(Privilege.Name.SELECT_TABLE),- tableLikeParentPrivilegePath(Privilege.Name.MODIFY_TABLE),- tableLikeParentPrivilegePath(Privilege.Name.CREATE_TABLE),- tableLikeParentPrivilegePath(Privilege.Name.CREATE_VIEW))),- Entity.EntityType.MODEL,- Map.of(- AuthorizationExpressionConstants.FILTER_MODEL_AUTHORIZATION_EXPRESSION,- List.of(- parentOwnerPath(MODEL_PARENT_SCOPES),- parentPrivilegePath(Privilege.Name.USE_MODEL, MODEL_PARENT_SCOPES))),- Entity.EntityType.JOB_TEMPLATE,- Map.of(- AuthorizationExpressionConstants.LOAD_JOB_TEMPLATE_AUTHORIZATION_EXPRESSION,- List.of(- parentOwnerPath(METALAKE_ONLY_SCOPE),- parentPrivilegePath(Privilege.Name.USE_JOB_TEMPLATE, METALAKE_ONLY_SCOPE))),- Entity.EntityType.SCHEMA,- Map.of(- AuthorizationExpressionConstants.FILTER_SCHEMA_AUTHORIZATION_EXPRESSION,- List.of(- parentOwnerPath(SCHEMA_PARENT_SCOPES),- parentPrivilegePath(Privilege.Name.USE_SCHEMA, SCHEMA_PARENT_SCOPES))),- Entity.EntityType.CATALOG,- Map.of(- AuthorizationExpressionConstants.LOAD_CATALOG_AUTHORIZATION_EXPRESSION,- List.of(- parentOwnerPath(CATALOG_PARENT_SCOPES),- parentPrivilegePath(Privilege.Name.USE_CATALOG, CATALOG_PARENT_SCOPES))));+ Map.ofEntries(+ Map.entry(+ Entity.EntityType.USER,+ principalListPaths(+ AuthorizationExpressionConstants.LOAD_USER_AUTHORIZATION_EXPRESSION,+ Privilege.Name.MANAGE_USERS)),+ Map.entry(+ Entity.EntityType.GROUP,+ principalListPaths(+ AuthorizationExpressionConstants.LOAD_GROUP_AUTHORIZATION_EXPRESSION,+ Privilege.Name.MANAGE_GROUPS)),+ Map.entry(+ Entity.EntityType.ROLE,+ principalListPaths(+ AuthorizationExpressionConstants.LOAD_ROLE_AUTHORIZATION_EXPRESSION,+ Privilege.Name.MANAGE_GRANTS)),+ Map.entry(+ Entity.EntityType.TABLE,+ Map.of(+ AuthorizationExpressionConstants.FILTER_TABLE_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(TABLE_PARENT_SCOPES),+ parentPrivilegePath(Privilege.Name.SELECT_TABLE, TABLE_PARENT_SCOPES),+ parentPrivilegePath(Privilege.Name.MODIFY_TABLE, TABLE_PARENT_SCOPES)),+ AuthorizationExpressionConstants.LIST_TABLE_LIKE_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(TABLE_PARENT_SCOPES),+ tableLikeParentPrivilegePath(Privilege.Name.PROBE_TABLE_LIKE),+ tableLikeParentPrivilegePath(Privilege.Name.SELECT_TABLE),+ tableLikeParentPrivilegePath(Privilege.Name.MODIFY_TABLE),+ tableLikeParentPrivilegePath(Privilege.Name.CREATE_TABLE),+ tableLikeParentPrivilegePath(Privilege.Name.CREATE_VIEW)))),+ Map.entry(+ Entity.EntityType.MODEL,+ Map.of(+ AuthorizationExpressionConstants.FILTER_MODEL_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(MODEL_PARENT_SCOPES),+ parentPrivilegePath(Privilege.Name.USE_MODEL, MODEL_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.VIEW,+ Map.of(+ AuthorizationExpressionConstants.FILTER_VIEW_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.SELECT_VIEW, SCHEMA_OBJECT_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.FUNCTION,+ Map.of(+ AuthorizationExpressionConstants.FILTER_FUNCTION_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.EXECUTE_FUNCTION, SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.MODIFY_FUNCTION, SCHEMA_OBJECT_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.FILESET,+ Map.of(+ AuthorizationExpressionConstants.FILTER_FILESET_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.READ_FILESET, SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.WRITE_FILESET, SCHEMA_OBJECT_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.TOPIC,+ Map.of(+ AuthorizationExpressionConstants.FILTER_TOPICS_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.CONSUME_TOPIC, SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.PRODUCE_TOPIC, SCHEMA_OBJECT_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.SEMANTIC_MODEL,+ Map.of(+ AuthorizationExpressionConstants+ .FILTER_SEMANTIC_MODEL_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.USE_SEMANTIC_MODEL, SCHEMA_OBJECT_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.MODIFY_SEMANTIC_MODEL, SCHEMA_OBJECT_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.JOB_TEMPLATE,+ Map.of(+ AuthorizationExpressionConstants.LOAD_JOB_TEMPLATE_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(METALAKE_ONLY_SCOPE),+ parentPrivilegePath(+ Privilege.Name.USE_JOB_TEMPLATE, METALAKE_ONLY_SCOPE)))),+ Map.entry(+ Entity.EntityType.SCHEMA,+ Map.of(+ AuthorizationExpressionConstants.FILTER_SCHEMA_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(SCHEMA_PARENT_SCOPES),+ parentPrivilegePath(Privilege.Name.USE_SCHEMA, SCHEMA_PARENT_SCOPES)))),+ Map.entry(+ Entity.EntityType.CATALOG,+ Map.of(+ AuthorizationExpressionConstants.LOAD_CATALOG_AUTHORIZATION_EXPRESSION,+ List.of(+ parentOwnerPath(CATALOG_PARENT_SCOPES),+ parentPrivilegePath(+ Privilege.Name.USE_CATALOG, CATALOG_PARENT_SCOPES)))));/** A sufficient parent-scope access path and the deny privileges that can invalidate it. */private static final class ParentScopeAccessPath {diff --git a/server-common/src/test/java/org/apache/gravitino/server/authorization/TestMetadataAuthzHelper.java b/server-common/src/test/java/org/apache/gravitino/server/authorization/TestMetadataAuthzHelper.javaindex 82480170c4..b1336af95d 100644--- a/server-common/src/test/java/org/apache/gravitino/server/authorization/TestMetadataAuthzHelper.java+++ b/server-common/src/test/java/org/apache/gravitino/server/authorization/TestMetadataAuthzHelper.java@@ -521,6 +521,323 @@ public class TestMetadataAuthzHelper {}}+ /** A SELECT_VIEW grant on the schema makes every view visible without per-view checks. */+ @Test+ public void testListShortCircuitViewViaSchemaGrant() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.SELECT_VIEW);+ NameIdentifier[] identifiers = views(2000);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_VIEW_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.VIEW,+ identifiers);+ Assertions.assertArrayEquals(identifiers, filtered);+ verify(authorizer, never())+ .isOwner(+ any(),+ eq("testMetalake"),+ argThat(object -> object.type() == MetadataObject.Type.VIEW),+ any());+ });+ }++ /** A possible SELECT_VIEW deny disables the schema-grant path and each view is checked. */+ @Test+ public void testListShortCircuitViewFallsBackWhenDenyMayExist() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.SELECT_VIEW);+ when(authorizer.hasDenyPolicy(any(), eq("testMetalake"), anySet(), any())).thenReturn(true);+ when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))+ .thenAnswer(+ invocation -> {+ MetadataObject object = invocation.getArgument(2);+ return object.type() == MetadataObject.Type.VIEW && "v1".equals(object.name());+ });+ NameIdentifier[] identifiers = views(3);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_VIEW_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.VIEW,+ identifiers);+ Assertions.assertArrayEquals(+ new NameIdentifier[] {identifiers[0], identifiers[2]}, filtered);+ // The shortcut must gate on exactly the SELECT_VIEW deny; a wrong deny set here+ // would over-permit by keeping the shortcut alive under a real deny.+ verify(authorizer)+ .hasDenyPolicy(+ any(), eq("testMetalake"), eq(Set.of(Privilege.Name.SELECT_VIEW)), any());+ });+ }++ /**+ * An EXECUTE_FUNCTION grant on the schema makes every function visible without per-function+ * checks.+ */+ @Test+ public void testListShortCircuitFunctionViaSchemaGrant() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.EXECUTE_FUNCTION);+ NameIdentifier[] identifiers = functions(2000);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_FUNCTION_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.FUNCTION,+ identifiers);+ Assertions.assertArrayEquals(identifiers, filtered);+ verify(authorizer, never())+ .isOwner(+ any(),+ eq("testMetalake"),+ argThat(object -> object.type() == MetadataObject.Type.FUNCTION),+ any());+ });+ }++ /**+ * A possible MODIFY_FUNCTION deny disables the schema-grant path and each function is checked;+ * the MODIFY_FUNCTION path is the second parent-scope path of the function entry.+ */+ @Test+ public void testListShortCircuitFunctionFallsBackWhenDenyMayExist() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.MODIFY_FUNCTION);+ when(authorizer.hasDenyPolicy(any(), eq("testMetalake"), anySet(), any())).thenReturn(true);+ when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))+ .thenAnswer(+ invocation -> {+ MetadataObject object = invocation.getArgument(2);+ return object.type() == MetadataObject.Type.FUNCTION && "f1".equals(object.name());+ });+ NameIdentifier[] identifiers = functions(3);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_FUNCTION_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.FUNCTION,+ identifiers);+ Assertions.assertArrayEquals(+ new NameIdentifier[] {identifiers[0], identifiers[2]}, filtered);+ // The granted path gates on exactly the MODIFY_FUNCTION deny.+ verify(authorizer)+ .hasDenyPolicy(+ any(), eq("testMetalake"), eq(Set.of(Privilege.Name.MODIFY_FUNCTION)), any());+ });+ }++ /** A READ_FILESET grant on the schema makes every fileset visible without per-object checks. */+ @Test+ public void testListShortCircuitFilesetViaSchemaGrant() {+ EntityStore store = mock(EntityStore.class);+ SchemaDispatcher schemaDispatcher = mock(SchemaDispatcher.class);+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.READ_FILESET);+ NameIdentifier[] identifiers = filesets(2000);+ withPreloadEnv(+ store,+ schemaDispatcher,+ () ->+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_FILESET_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.FILESET,+ identifiers);+ Assertions.assertArrayEquals(identifiers, filtered);+ verify(authorizer, never())+ .isOwner(+ any(),+ eq("testMetalake"),+ argThat(object -> object.type() == MetadataObject.Type.FILESET),+ any());+ verifyNoInteractions(store, schemaDispatcher);+ }));+ }++ /**+ * A possible WRITE_FILESET deny disables the schema-grant path and each fileset is checked; the+ * WRITE_FILESET path is the second parent-scope path of the fileset entry.+ */+ @Test+ public void testListShortCircuitFilesetFallsBackWhenDenyMayExist() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.WRITE_FILESET);+ when(authorizer.hasDenyPolicy(any(), eq("testMetalake"), anySet(), any())).thenReturn(true);+ when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))+ .thenAnswer(+ invocation -> {+ MetadataObject object = invocation.getArgument(2);+ return object.type() == MetadataObject.Type.FILESET && "fs1".equals(object.name());+ });+ NameIdentifier[] identifiers = filesets(3);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_FILESET_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.FILESET,+ identifiers);+ Assertions.assertArrayEquals(+ new NameIdentifier[] {identifiers[0], identifiers[2]}, filtered);+ // The granted path gates on exactly the WRITE_FILESET deny.+ verify(authorizer)+ .hasDenyPolicy(+ any(), eq("testMetalake"), eq(Set.of(Privilege.Name.WRITE_FILESET)), any());+ });+ }++ /**+ * A USE_SEMANTIC_MODEL grant on the schema makes every semantic model visible without per-object+ * checks.+ */+ @Test+ public void testListShortCircuitSemanticModelViaSchemaGrant() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.USE_SEMANTIC_MODEL);+ NameIdentifier[] identifiers = semanticModels(2000);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_SEMANTIC_MODEL_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.SEMANTIC_MODEL,+ identifiers);+ Assertions.assertArrayEquals(identifiers, filtered);+ verify(authorizer, never())+ .isOwner(+ any(),+ eq("testMetalake"),+ argThat(object -> object.type() == MetadataObject.Type.SEMANTIC_MODEL),+ any());+ });+ }++ /**+ * A possible MODIFY_SEMANTIC_MODEL deny disables the schema-grant path and each semantic model is+ * checked; the MODIFY_SEMANTIC_MODEL path is the second parent-scope path of the entry.+ */+ @Test+ public void testListShortCircuitSemanticModelFallsBackWhenDenyMayExist() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.MODIFY_SEMANTIC_MODEL);+ when(authorizer.hasDenyPolicy(any(), eq("testMetalake"), anySet(), any())).thenReturn(true);+ when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))+ .thenAnswer(+ invocation -> {+ MetadataObject object = invocation.getArgument(2);+ return object.type() == MetadataObject.Type.SEMANTIC_MODEL+ && "sm1".equals(object.name());+ });+ NameIdentifier[] identifiers = semanticModels(3);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_SEMANTIC_MODEL_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.SEMANTIC_MODEL,+ identifiers);+ Assertions.assertArrayEquals(+ new NameIdentifier[] {identifiers[0], identifiers[2]}, filtered);+ // The granted path gates on exactly the MODIFY_SEMANTIC_MODEL deny.+ verify(authorizer)+ .hasDenyPolicy(+ any(),+ eq("testMetalake"),+ eq(Set.of(Privilege.Name.MODIFY_SEMANTIC_MODEL)),+ any());+ });+ }++ /** A CONSUME_TOPIC grant on the schema makes every topic visible without per-topic checks. */+ @Test+ public void testListShortCircuitTopicViaSchemaGrant() {+ EntityStore store = mock(EntityStore.class);+ SchemaDispatcher schemaDispatcher = mock(SchemaDispatcher.class);+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.CONSUME_TOPIC);+ NameIdentifier[] identifiers = topics(2000);+ withPreloadEnv(+ store,+ schemaDispatcher,+ () ->+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_TOPICS_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.TOPIC,+ identifiers);+ Assertions.assertArrayEquals(identifiers, filtered);+ verify(authorizer, never())+ .isOwner(+ any(),+ eq("testMetalake"),+ argThat(object -> object.type() == MetadataObject.Type.TOPIC),+ any());+ verifyNoInteractions(store, schemaDispatcher);+ }));+ }++ /**+ * A possible PRODUCE_TOPIC deny disables the schema-grant path and each topic is checked; the+ * PRODUCE_TOPIC path is the second parent-scope path of the topic entry.+ */+ @Test+ public void testListShortCircuitTopicFallsBackWhenDenyMayExist() {+ GravitinoAuthorizer authorizer =+ mockParentGrantAuthorizer(MetadataObject.Type.SCHEMA, Privilege.Name.PRODUCE_TOPIC);+ when(authorizer.hasDenyPolicy(any(), eq("testMetalake"), anySet(), any())).thenReturn(true);+ when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))+ .thenAnswer(+ invocation -> {+ MetadataObject object = invocation.getArgument(2);+ return object.type() == MetadataObject.Type.TOPIC && "t1".equals(object.name());+ });+ NameIdentifier[] identifiers = topics(3);+ withAuthorizer(+ authorizer,+ () -> {+ NameIdentifier[] filtered =+ MetadataAuthzHelper.filterByExpression(+ "testMetalake",+ AuthorizationExpressionConstants.FILTER_TOPICS_AUTHORIZATION_EXPRESSION,+ Entity.EntityType.TOPIC,+ identifiers);+ Assertions.assertArrayEquals(+ new NameIdentifier[] {identifiers[0], identifiers[2]}, filtered);+ // The granted path gates on exactly the PRODUCE_TOPIC deny.+ verify(authorizer)+ .hasDenyPolicy(+ any(), eq("testMetalake"), eq(Set.of(Privilege.Name.PRODUCE_TOPIC)), any());+ });+ }+/** A possible USE_MODEL deny disables the schema-grant path and each model is checked. */@Testpublic void testListShortCircuitModelFallsBackWhenDenyMayExist() {@@ -648,6 +965,37 @@ public class TestMetadataAuthzHelper {.toArray(NameIdentifier[]::new);}+ private static NameIdentifier[] views(int count) {+ return IntStream.range(0, count)+ .mapToObj(i -> NameIdentifierUtil.ofView("testMetalake", "testCatalog", "s1", "v" + i))+ .toArray(NameIdentifier[]::new);+ }++ private static NameIdentifier[] functions(int count) {+ return IntStream.range(0, count)+ .mapToObj(i -> NameIdentifierUtil.ofFunction("testMetalake", "testCatalog", "s1", "f" + i))+ .toArray(NameIdentifier[]::new);+ }++ private static NameIdentifier[] filesets(int count) {+ return IntStream.range(0, count)+ .mapToObj(i -> NameIdentifierUtil.ofFileset("testMetalake", "testCatalog", "s1", "fs" + i))+ .toArray(NameIdentifier[]::new);+ }++ private static NameIdentifier[] topics(int count) {+ return IntStream.range(0, count)+ .mapToObj(i -> NameIdentifierUtil.ofTopic("testMetalake", "testCatalog", "s1", "t" + i))+ .toArray(NameIdentifier[]::new);+ }++ private static NameIdentifier[] semanticModels(int count) {+ return IntStream.range(0, count)+ .mapToObj(+ i -> NameIdentifierUtil.ofSemanticModel("testMetalake", "testCatalog", "s1", "sm" + i))+ .toArray(NameIdentifier[]::new);+ }+/** A role expression without MANAGE_GRANTS must not inherit that list shortcut. */@Testpublic void testDifferentRoleExpressionDoesNotUseManagementGrant() {@@ -807,6 +1155,27 @@ public class TestMetadataAuthzHelper {return authorizer;}+ /**+ * Runs {@code body} with the entity cache enabled and the store and schema dispatcher that the+ * list preload uses replaced by the given mocks.+ */+ private void withPreloadEnv(EntityStore store, SchemaDispatcher schemaDispatcher, Runnable body) {+ when(schemaDispatcher.schemaExists(any())).thenReturn(true);+ when(gravitinoEnv.entityStore()).thenReturn(store);+ when(gravitinoEnv.internalSchemaDispatcher()).thenReturn(schemaDispatcher);+ when(gravitinoEnv.internalAccessControlDispatcher())+ .thenReturn(mock(AccessControlDispatcher.class));+ when(gravitinoEnv.cacheEnabled()).thenReturn(true);+ try {+ body.run();+ } finally {+ when(gravitinoEnv.cacheEnabled()).thenReturn(false);+ when(gravitinoEnv.entityStore()).thenReturn(null);+ when(gravitinoEnv.internalSchemaDispatcher()).thenReturn(null);+ when(gravitinoEnv.internalAccessControlDispatcher()).thenReturn(null);+ }+ }+@Testpublic void testListShortCircuitSchemaViaCatalogGrant() {makeCompletableFutureUseCurrentThread();