You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by yu...@apache.org on 2026/06/23 12:57:45 UTC

(gravitino) branch improvement-list-authz-schema-short-circuit-11775 created (now 415bd4297f)

This is an automated email from the ASF dual-hosted git repository.

yuqi1129 pushed a change to branch improvement-list-authz-schema-short-circuit-11775
in repository https://gitbox.apache.org/repos/asf/gravitino.git


      at 415bd4297f [#11775] improvement(authz): short-circuit list authorization via parent-scope grant

This branch includes the following new commits:

     new 415bd4297f [#11775] improvement(authz): short-circuit list authorization via parent-scope grant

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(gravitino) 01/01: [#11775] improvement(authz): short-circuit list authorization via parent-scope grant

Posted by yu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

yuqi1129 pushed a commit to branch improvement-list-authz-schema-short-circuit-11775
in repository https://gitbox.apache.org/repos/asf/gravitino.git

commit 415bd4297f9af54fd4de353937a23c1277366d10
Author: yuqi <yu...@datastrato.com>
AuthorDate: Tue Jun 23 20:57:29 2026 +0800

    [#11775] improvement(authz): short-circuit list authorization via parent-scope grant
    
    When authorization is enabled, list operations (listTables/listSchemas/listCatalogs
    on both Gravitino REST and Iceberg REST) ran one per-object permission check per
    result, causing an N+1 explosion (e.g. ~10k tables took ~134s vs ~4s with auth off).
    
    Evaluate the ancestor-only portion of the filter expression once per list request:
    when a privilege is granted (or the object is owned) at a parent scope
    (metalake/catalog/schema) every child is visible unless an object-level deny
    overrides it. A new GravitinoAuthorizer#hasDenyPolicyOnType gate (in-memory scan of
    the user's deny policies in JcasbinAuthorizer; conservative default of true) makes the
    short-circuit safe, falling back to per-object filtering only when a deny may exist.
---
 .../authorization/GravitinoAuthorizer.java         |  30 ++++
 .../server/authorization/MetadataAuthzHelper.java  |  92 ++++++++++
 .../AuthorizationExpressionConstants.java          |  38 ++++
 .../authorization/jcasbin/JcasbinAuthorizer.java   |  35 ++++
 .../authorization/TestMetadataAuthzHelper.java     | 197 +++++++++++++++++++++
 .../jcasbin/TestJcasbinAuthorizer.java             |  51 ++++++
 6 files changed, 443 insertions(+)

diff --git a/core/src/main/java/org/apache/gravitino/authorization/GravitinoAuthorizer.java b/core/src/main/java/org/apache/gravitino/authorization/GravitinoAuthorizer.java
index f072c15684..38258e8dc4 100644
--- a/core/src/main/java/org/apache/gravitino/authorization/GravitinoAuthorizer.java
+++ b/core/src/main/java/org/apache/gravitino/authorization/GravitinoAuthorizer.java
@@ -19,6 +19,7 @@ package org.apache.gravitino.authorization;
 
 import java.io.Closeable;
 import java.security.Principal;
+import java.util.Set;
 import javax.annotation.Nullable;
 import org.apache.gravitino.Entity;
 import org.apache.gravitino.GravitinoEnv;
@@ -107,6 +108,35 @@ public interface GravitinoAuthorizer extends Closeable {
    */
   boolean isMetalakeUser(String metalake, AuthorizationRequestContext requestContext);
 
+  /**
+   * Determines whether the given principal may have any {@code DENY} privilege policy, for any of
+   * the given privileges, granted directly on metadata objects of {@code type} within the metalake.
+   *
+   * <p>This supports list-authorization short-circuiting: when a privilege is granted at a parent
+   * scope (metalake, catalog or schema), every child object of {@code type} is visible
+   * <em>unless</em> an object-level {@code DENY} overrides it. A {@code false} return therefore
+   * lets the caller skip per-object authorization for the whole list and return every identifier; a
+   * {@code true} return forces the caller to fall back to per-object authorization.
+   *
+   * <p>The default implementation conservatively returns {@code true} so that authorizers which
+   * cannot answer the question never enable an unsafe short-circuit.
+   *
+   * @param principal the user principal
+   * @param metalake the metalake
+   * @param type the metadata type of the listed objects (for example {@code TABLE}, {@code SCHEMA})
+   * @param privileges the privileges whose object-level denies would affect visibility
+   * @param requestContext authorization request context
+   * @return whether an object-level deny for the given privileges and type may exist
+   */
+  default boolean hasDenyPolicyOnType(
+      Principal principal,
+      String metalake,
+      Entity.EntityType type,
+      Set<Privilege.Name> privileges,
+      AuthorizationRequestContext requestContext) {
+    return true;
+  }
+
   /**
    * Determine whether the user can set owner
    *
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.java
index b63251fd96..a587c4c41d 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
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
@@ -42,6 +43,7 @@ import org.apache.gravitino.Namespace;
 import org.apache.gravitino.SupportsRelationOperations;
 import org.apache.gravitino.authorization.AuthorizationRequestContext;
 import org.apache.gravitino.authorization.GravitinoAuthorizer;
+import org.apache.gravitino.authorization.Privilege;
 import org.apache.gravitino.dto.tag.MetadataObjectDTO;
 import org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConstants;
 import org.apache.gravitino.server.authorization.expression.AuthorizationExpressionEvaluator;
@@ -87,6 +89,43 @@ public class MetadataAuthzHelper {
   private static final List<Entity.EntityType> REQUIRE_SCHEMA_EXISTS =
       Arrays.asList(Entity.EntityType.TABLE, Entity.EntityType.TOPIC);
 
+  /**
+   * Registry of list-authorization short-circuits keyed by the listed object's entity type. Each
+   * entry pairs the per-object filter expression it applies to with the parent-scope expression to
+   * evaluate once and the privileges whose object-level denies would defeat the short-circuit.
+   */
+  private static final Map<Entity.EntityType, ListShortCircuit> LIST_SHORT_CIRCUITS =
+      Map.of(
+          Entity.EntityType.TABLE,
+          new ListShortCircuit(
+              AuthorizationExpressionConstants.FILTER_TABLE_AUTHORIZATION_EXPRESSION,
+              AuthorizationExpressionConstants.TABLE_LIST_PARENT_SCOPE_AUTHORIZATION_EXPRESSION,
+              Set.of(Privilege.Name.SELECT_TABLE, Privilege.Name.MODIFY_TABLE)),
+          Entity.EntityType.SCHEMA,
+          new ListShortCircuit(
+              AuthorizationExpressionConstants.FILTER_SCHEMA_AUTHORIZATION_EXPRESSION,
+              AuthorizationExpressionConstants.SCHEMA_LIST_PARENT_SCOPE_AUTHORIZATION_EXPRESSION,
+              Set.of(Privilege.Name.USE_SCHEMA)),
+          Entity.EntityType.CATALOG,
+          new ListShortCircuit(
+              AuthorizationExpressionConstants.LOAD_CATALOG_AUTHORIZATION_EXPRESSION,
+              AuthorizationExpressionConstants.CATALOG_LIST_PARENT_SCOPE_AUTHORIZATION_EXPRESSION,
+              Set.of(Privilege.Name.USE_CATALOG)));
+
+  /** Immutable description of a single list-authorization short-circuit. */
+  private static final class ListShortCircuit {
+    private final String filterExpression;
+    private final String parentScopeExpression;
+    private final Set<Privilege.Name> denyPrivileges;
+
+    private ListShortCircuit(
+        String filterExpression, String parentScopeExpression, Set<Privilege.Name> denyPrivileges) {
+      this.filterExpression = filterExpression;
+      this.parentScopeExpression = parentScopeExpression;
+      this.denyPrivileges = denyPrivileges;
+    }
+  }
+
   private MetadataAuthzHelper() {}
 
   public static Metalake[] filterMetalakes(Metalake[] metalakes, String expression) {
@@ -167,11 +206,64 @@ public class MetadataAuthzHelper {
       String expression,
       Entity.EntityType entityType,
       NameIdentifier[] nameIdentifiers) {
+    if (enableAuthorization()
+        && nameIdentifiers.length > 0
+        && allVisibleViaParentScope(metalake, expression, entityType, nameIdentifiers)) {
+      // A privilege granted at a parent scope (metalake/catalog/schema) makes every object in the
+      // list visible, and no object-level deny exists, so the per-object authorization loop is
+      // skipped entirely. See AuthorizationExpressionConstants.*_LIST_PARENT_SCOPE_*.
+      return nameIdentifiers;
+    }
     preloadToCache(entityType, nameIdentifiers);
     preloadOwner(entityType, nameIdentifiers);
     return filterByExpression(metalake, expression, entityType, nameIdentifiers, e -> e);
   }
 
+  /**
+   * Attempts the list-authorization short-circuit: when the listed objects all share one parent and
+   * the matching filter expression is granted at a parent scope, the whole list is visible unless
+   * an object-level deny may exist. Returns {@code true} only when it is safe to return every
+   * identifier without per-object authorization.
+   */
+  private static boolean allVisibleViaParentScope(
+      String metalake,
+      String expression,
+      Entity.EntityType entityType,
+      NameIdentifier[] nameIdentifiers) {
+    ListShortCircuit spec = LIST_SHORT_CIRCUITS.get(entityType);
+    if (spec == null || !spec.filterExpression.equals(expression)) {
+      return false;
+    }
+
+    // The short-circuit reasons about a single parent scope, so every identifier must share it.
+    Namespace parent = nameIdentifiers[0].namespace();
+    for (NameIdentifier ident : nameIdentifiers) {
+      if (!ident.namespace().equals(parent)) {
+        return false;
+      }
+    }
+
+    Principal principal = PrincipalUtils.getCurrentPrincipal();
+    GravitinoAuthorizer authorizer =
+        GravitinoAuthorizerProvider.getInstance().getGravitinoAuthorizer();
+    AuthorizationRequestContext requestContext = new AuthorizationRequestContext();
+    requestContext.setOriginalAuthorizationExpression(spec.parentScopeExpression);
+    Map<Entity.EntityType, NameIdentifier> metadataNames =
+        NameIdentifierUtil.splitNameIdentifier(metalake, entityType, nameIdentifiers[0]);
+
+    boolean parentGrantsAccess =
+        new AuthorizationExpressionEvaluator(spec.parentScopeExpression, authorizer)
+            .evaluate(metadataNames, requestContext, principal, Optional.empty());
+    if (!parentGrantsAccess) {
+      return false;
+    }
+
+    // Parent scope grants access to every object; the only thing that can still hide one is an
+    // object-level deny, so the short-circuit is only safe when no such deny may exist.
+    return !authorizer.hasDenyPolicyOnType(
+        principal, metalake, entityType, spec.denyPrivileges, requestContext);
+  }
+
   /**
    * Call {@link AuthorizationExpressionEvaluator} to check access
    *
diff --git a/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java b/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java
index 122bdfcd01..5ce0613810 100644
--- a/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java
+++ b/server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConstants.java
@@ -166,6 +166,44 @@ public class AuthorizationExpressionConstants {
                   ANY_MODIFY_TABLE
                   """;
 
+  /**
+   * Parent-scope expression used to short-circuit table-list authorization. It is the ancestor-only
+   * portion of {@link #FILTER_TABLE_AUTHORIZATION_EXPRESSION}: ownership of, or a SELECT/MODIFY
+   * grant at, the metalake/catalog/schema scope means every table in the schema is visible unless a
+   * table-level deny overrides it. Evaluated once per list request instead of once per table.
+   */
+  public static final String TABLE_LIST_PARENT_SCOPE_AUTHORIZATION_EXPRESSION =
+      """
+              ANY(OWNER, METALAKE, CATALOG, SCHEMA) ||
+              (ANY(SELECT_TABLE, METALAKE, CATALOG, SCHEMA)
+                  && !ANY(DENY_SELECT_TABLE, METALAKE, CATALOG, SCHEMA)) ||
+              (ANY(MODIFY_TABLE, METALAKE, CATALOG, SCHEMA)
+                  && !ANY(DENY_MODIFY_TABLE, METALAKE, CATALOG, SCHEMA))
+              """;
+
+  /**
+   * Parent-scope expression used to short-circuit schema-list authorization. Ancestor-only portion
+   * of {@link #FILTER_SCHEMA_AUTHORIZATION_EXPRESSION}: ownership of, or a USE_SCHEMA grant at, the
+   * metalake/catalog scope means every schema in the catalog is visible unless a schema-level deny
+   * overrides it.
+   */
+  public static final String SCHEMA_LIST_PARENT_SCOPE_AUTHORIZATION_EXPRESSION =
+      """
+              ANY(OWNER, METALAKE, CATALOG) ||
+              (ANY(USE_SCHEMA, METALAKE, CATALOG) && !ANY(DENY_USE_SCHEMA, METALAKE, CATALOG))
+              """;
+
+  /**
+   * Parent-scope expression used to short-circuit catalog-list authorization. Ancestor-only portion
+   * of {@link #LOAD_CATALOG_AUTHORIZATION_EXPRESSION}: metalake ownership, or a USE_CATALOG grant
+   * at the metalake scope, means every catalog is visible unless a catalog-level deny overrides it.
+   */
+  public static final String CATALOG_LIST_PARENT_SCOPE_AUTHORIZATION_EXPRESSION =
+      """
+              METALAKE::OWNER ||
+              (ANY(USE_CATALOG, METALAKE) && !ANY(DENY_USE_CATALOG, METALAKE))
+              """;
+
   public static final String FILTER_VIEW_AUTHORIZATION_EXPRESSION =
       """
                   ANY(OWNER, METALAKE, CATALOG, SCHEMA, VIEW) ||
diff --git a/server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java b/server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java
index 347900e606..8a03e22086 100644
--- a/server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java
+++ b/server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java
@@ -363,6 +363,41 @@ public class JcasbinAuthorizer implements GravitinoAuthorizer {
     return loadUserInfo(metalake, currentUserName, requestContext).isPresent();
   }
 
+  @Override
+  public boolean hasDenyPolicyOnType(
+      Principal principal,
+      String metalake,
+      Entity.EntityType type,
+      Set<Privilege.Name> privileges,
+      AuthorizationRequestContext requestContext) {
+    Optional<UserUpdatedAt> userInfoOpt =
+        loadUserInfo(metalake, principal.getName(), requestContext);
+    if (!userInfoOpt.isPresent()) {
+      // An unknown user holds no roles and therefore no deny policies.
+      return false;
+    }
+    UserUpdatedAt userInfo = userInfoOpt.get();
+    long userId = userInfo.getUserId();
+    // Bind the user's (direct + group-inherited) roles into the enforcers so the in-memory scan
+    // below sees every policy the user can carry. Idempotent within a request.
+    loadRolePrivilege(metalake, principal.getName(), userId, userInfo, requestContext);
+
+    Set<String> privilegeNames = privileges.stream().map(Enum::name).collect(Collectors.toSet());
+    String typeName = type.name();
+    String userIdStr = String.valueOf(userId);
+    // p-row layout: [sub(roleId), metadataType, metadataId, act(privilege), eft]. Filtering by
+    // (roleId, metadataType) keeps the scan bounded by the user's role/policy count, never by the
+    // number of listed objects.
+    for (String roleId : denyEnforcer.getRolesForUser(userIdStr)) {
+      for (List<String> policy : denyEnforcer.getFilteredNamedPolicy("p", 0, roleId, typeName)) {
+        if (policy.size() > 3 && privilegeNames.contains(policy.get(3))) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
   @Override
   public boolean isSelf(
       Entity.EntityType type,
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.java
index 81e7d858ca..99502ab6c7 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
@@ -18,12 +18,15 @@
 package org.apache.gravitino.server.authorization;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anySet;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.mockStatic;
 import static org.mockito.Mockito.when;
 
 import java.lang.reflect.Field;
+import java.util.Arrays;
 import java.util.concurrent.Executor;
 import org.apache.gravitino.Config;
 import org.apache.gravitino.Configs;
@@ -32,7 +35,10 @@ import org.apache.gravitino.GravitinoEnv;
 import org.apache.gravitino.MetadataObject;
 import org.apache.gravitino.NameIdentifier;
 import org.apache.gravitino.UserPrincipal;
+import org.apache.gravitino.authorization.GravitinoAuthorizer;
+import org.apache.gravitino.authorization.Privilege;
 import org.apache.gravitino.dto.tag.MetadataObjectDTO;
+import org.apache.gravitino.server.authorization.expression.AuthorizationExpressionConstants;
 import org.apache.gravitino.utils.NameIdentifierUtil;
 import org.apache.gravitino.utils.PrincipalUtils;
 import org.junit.jupiter.api.AfterAll;
@@ -190,6 +196,197 @@ public class TestMetadataAuthzHelper {
     }
   }
 
+  /**
+   * Builds three table identifiers under the same schema, where a parent (schema) level
+   * SELECT_TABLE grant exists and the middle table additionally carries a table-level deny. The
+   * deny gate is controlled separately so each branch of the list short-circuit can be exercised.
+   */
+  private GravitinoAuthorizer mockTableListAuthorizer(boolean owner, boolean denyGate) {
+    GravitinoAuthorizer authorizer = mock(GravitinoAuthorizer.class);
+    // Parent-scope SELECT_TABLE grant at the schema level (applies to every table in the schema).
+    lenient()
+        .when(authorizer.authorize(any(), eq("testMetalake"), any(), any(), any()))
+        .thenAnswer(
+            invocation -> {
+              MetadataObject object = invocation.getArgument(2);
+              Privilege.Name privilege = invocation.getArgument(3);
+              return object.type() == MetadataObject.Type.SCHEMA
+                  && privilege == Privilege.Name.SELECT_TABLE;
+            });
+    // The middle table (t2) has a table-level deny on SELECT_TABLE.
+    lenient()
+        .when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))
+        .thenAnswer(
+            invocation -> {
+              MetadataObject object = invocation.getArgument(2);
+              Privilege.Name privilege = invocation.getArgument(3);
+              return object.type() == MetadataObject.Type.TABLE
+                  && "t2".equals(object.name())
+                  && privilege == Privilege.Name.SELECT_TABLE;
+            });
+    lenient().when(authorizer.isOwner(any(), eq("testMetalake"), any(), any())).thenReturn(owner);
+    lenient()
+        .when(authorizer.hasDenyPolicyOnType(any(), eq("testMetalake"), any(), anySet(), any()))
+        .thenReturn(denyGate);
+    return authorizer;
+  }
+
+  /**
+   * Builds an authorizer that grants {@code grantPrivilege} at a single ancestor scope ({@code
+   * grantType}) and reports no object-level deny, so a list of children under that ancestor is
+   * fully visible via the parent-scope short-circuit.
+   */
+  private GravitinoAuthorizer mockParentGrantAuthorizer(
+      MetadataObject.Type grantType, Privilege.Name grantPrivilege) {
+    GravitinoAuthorizer authorizer = mock(GravitinoAuthorizer.class);
+    lenient()
+        .when(authorizer.authorize(any(), eq("testMetalake"), any(), any(), any()))
+        .thenAnswer(
+            invocation -> {
+              MetadataObject object = invocation.getArgument(2);
+              Privilege.Name privilege = invocation.getArgument(3);
+              return object.type() == grantType && privilege == grantPrivilege;
+            });
+    lenient()
+        .when(authorizer.deny(any(), eq("testMetalake"), any(), any(), any()))
+        .thenReturn(false);
+    lenient().when(authorizer.isOwner(any(), eq("testMetalake"), any(), any())).thenReturn(false);
+    lenient()
+        .when(authorizer.hasDenyPolicyOnType(any(), eq("testMetalake"), any(), anySet(), any()))
+        .thenReturn(false);
+    return authorizer;
+  }
+
+  @Test
+  public void testListShortCircuitSchemaViaCatalogGrant() {
+    makeCompletableFutureUseCurrentThread();
+    try (MockedStatic<PrincipalUtils> principalUtilsMocked = mockStatic(PrincipalUtils.class);
+        MockedStatic<GravitinoAuthorizerProvider> mockStatic =
+            mockStatic(GravitinoAuthorizerProvider.class)) {
+      principalUtilsMocked
+          .when(PrincipalUtils::getCurrentPrincipal)
+          .thenReturn(new UserPrincipal("tester"));
+      principalUtilsMocked.when(() -> PrincipalUtils.doAs(any(), any())).thenCallRealMethod();
+      GravitinoAuthorizerProvider mockedProvider = mock(GravitinoAuthorizerProvider.class);
+      mockStatic.when(GravitinoAuthorizerProvider::getInstance).thenReturn(mockedProvider);
+      GravitinoAuthorizer authorizer =
+          mockParentGrantAuthorizer(MetadataObject.Type.CATALOG, Privilege.Name.USE_SCHEMA);
+      when(mockedProvider.getGravitinoAuthorizer()).thenReturn(authorizer);
+
+      NameIdentifier[] schemas =
+          new NameIdentifier[] {
+            NameIdentifierUtil.ofSchema("testMetalake", "testCatalog", "s1"),
+            NameIdentifierUtil.ofSchema("testMetalake", "testCatalog", "s2")
+          };
+      NameIdentifier[] filtered =
+          MetadataAuthzHelper.filterByExpression(
+              "testMetalake",
+              AuthorizationExpressionConstants.FILTER_SCHEMA_AUTHORIZATION_EXPRESSION,
+              Entity.EntityType.SCHEMA,
+              schemas);
+
+      Assertions.assertEquals(2, filtered.length);
+    }
+  }
+
+  @Test
+  public void testListShortCircuitCatalogViaMetalakeGrant() {
+    makeCompletableFutureUseCurrentThread();
+    try (MockedStatic<PrincipalUtils> principalUtilsMocked = mockStatic(PrincipalUtils.class);
+        MockedStatic<GravitinoAuthorizerProvider> mockStatic =
+            mockStatic(GravitinoAuthorizerProvider.class)) {
+      principalUtilsMocked
+          .when(PrincipalUtils::getCurrentPrincipal)
+          .thenReturn(new UserPrincipal("tester"));
+      principalUtilsMocked.when(() -> PrincipalUtils.doAs(any(), any())).thenCallRealMethod();
+      GravitinoAuthorizerProvider mockedProvider = mock(GravitinoAuthorizerProvider.class);
+      mockStatic.when(GravitinoAuthorizerProvider::getInstance).thenReturn(mockedProvider);
+      GravitinoAuthorizer authorizer =
+          mockParentGrantAuthorizer(MetadataObject.Type.METALAKE, Privilege.Name.USE_CATALOG);
+      when(mockedProvider.getGravitinoAuthorizer()).thenReturn(authorizer);
+
+      NameIdentifier[] catalogs =
+          new NameIdentifier[] {
+            NameIdentifierUtil.ofCatalog("testMetalake", "c1"),
+            NameIdentifierUtil.ofCatalog("testMetalake", "c2")
+          };
+      NameIdentifier[] filtered =
+          MetadataAuthzHelper.filterByExpression(
+              "testMetalake",
+              AuthorizationExpressionConstants.LOAD_CATALOG_AUTHORIZATION_EXPRESSION,
+              Entity.EntityType.CATALOG,
+              catalogs);
+
+      Assertions.assertEquals(2, filtered.length);
+    }
+  }
+
+  private static NameIdentifier[] threeTables() {
+    return new NameIdentifier[] {
+      NameIdentifierUtil.ofTable("testMetalake", "testCatalog", "testSchema", "t1"),
+      NameIdentifierUtil.ofTable("testMetalake", "testCatalog", "testSchema", "t2"),
+      NameIdentifierUtil.ofTable("testMetalake", "testCatalog", "testSchema", "t3")
+    };
+  }
+
+  @Test
+  public void testListShortCircuitParentGrantWithoutDenyReturnsAll() {
+    makeCompletableFutureUseCurrentThread();
+    try (MockedStatic<PrincipalUtils> principalUtilsMocked = mockStatic(PrincipalUtils.class);
+        MockedStatic<GravitinoAuthorizerProvider> mockStatic =
+            mockStatic(GravitinoAuthorizerProvider.class)) {
+      principalUtilsMocked
+          .when(PrincipalUtils::getCurrentPrincipal)
+          .thenReturn(new UserPrincipal("tester"));
+      principalUtilsMocked.when(() -> PrincipalUtils.doAs(any(), any())).thenCallRealMethod();
+      GravitinoAuthorizerProvider mockedProvider = mock(GravitinoAuthorizerProvider.class);
+      mockStatic.when(GravitinoAuthorizerProvider::getInstance).thenReturn(mockedProvider);
+      GravitinoAuthorizer authorizer = mockTableListAuthorizer(false, false);
+      when(mockedProvider.getGravitinoAuthorizer()).thenReturn(authorizer);
+
+      NameIdentifier[] filtered =
+          MetadataAuthzHelper.filterByExpression(
+              "testMetalake",
+              AuthorizationExpressionConstants.FILTER_TABLE_AUTHORIZATION_EXPRESSION,
+              Entity.EntityType.TABLE,
+              threeTables());
+
+      // The schema-level grant covers every table and no object-level deny is reported, so the
+      // whole list is returned without consulting the per-table deny on t2.
+      Assertions.assertEquals(3, filtered.length);
+    }
+  }
+
+  @Test
+  public void testListShortCircuitFallsBackWhenDenyMayExist() {
+    makeCompletableFutureUseCurrentThread();
+    try (MockedStatic<PrincipalUtils> principalUtilsMocked = mockStatic(PrincipalUtils.class);
+        MockedStatic<GravitinoAuthorizerProvider> mockStatic =
+            mockStatic(GravitinoAuthorizerProvider.class)) {
+      principalUtilsMocked
+          .when(PrincipalUtils::getCurrentPrincipal)
+          .thenReturn(new UserPrincipal("tester"));
+      principalUtilsMocked.when(() -> PrincipalUtils.doAs(any(), any())).thenCallRealMethod();
+      GravitinoAuthorizerProvider mockedProvider = mock(GravitinoAuthorizerProvider.class);
+      mockStatic.when(GravitinoAuthorizerProvider::getInstance).thenReturn(mockedProvider);
+      GravitinoAuthorizer authorizer = mockTableListAuthorizer(false, true);
+      when(mockedProvider.getGravitinoAuthorizer()).thenReturn(authorizer);
+
+      NameIdentifier[] filtered =
+          MetadataAuthzHelper.filterByExpression(
+              "testMetalake",
+              AuthorizationExpressionConstants.FILTER_TABLE_AUTHORIZATION_EXPRESSION,
+              Entity.EntityType.TABLE,
+              threeTables());
+
+      // A deny may exist, so the short-circuit is disabled and per-table filtering excludes t2.
+      Assertions.assertEquals(2, filtered.length);
+      Assertions.assertTrue(
+          Arrays.stream(filtered).noneMatch(id -> "t2".equals(id.name())),
+          "t2 must be filtered out by its table-level deny");
+    }
+  }
+
   private static void makeCompletableFutureUseCurrentThread() {
     try {
       Executor currentThread = Runnable::run;
diff --git a/server-common/src/test/java/org/apache/gravitino/server/authorization/jcasbin/TestJcasbinAuthorizer.java b/server-common/src/test/java/org/apache/gravitino/server/authorization/jcasbin/TestJcasbinAuthorizer.java
index 5f28bfc7dd..263cac06d3 100644
--- a/server-common/src/test/java/org/apache/gravitino/server/authorization/jcasbin/TestJcasbinAuthorizer.java
+++ b/server-common/src/test/java/org/apache/gravitino/server/authorization/jcasbin/TestJcasbinAuthorizer.java
@@ -17,6 +17,7 @@
 
 package org.apache.gravitino.server.authorization.jcasbin;
 
+import static org.apache.gravitino.authorization.Privilege.Name.SELECT_TABLE;
 import static org.apache.gravitino.authorization.Privilege.Name.USE_CATALOG;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -37,6 +38,7 @@ import static org.mockito.Mockito.when;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -460,6 +462,55 @@ public class TestJcasbinAuthorizer {
     assertFalse(doAuthorize(currentPrincipal));
   }
 
+  @Test
+  public void testHasDenyPolicyOnType() throws Exception {
+    makeCompletableFutureUseCurrentThread(jcasbinAuthorizer);
+    Principal currentPrincipal = PrincipalUtils.getCurrentPrincipal();
+
+    // With no roles assigned, the user can hold no deny policy of any type.
+    assertFalse(
+        jcasbinAuthorizer.hasDenyPolicyOnType(
+            currentPrincipal,
+            METALAKE,
+            Entity.EntityType.CATALOG,
+            ImmutableSet.of(USE_CATALOG),
+            new AuthorizationRequestContext()));
+
+    // Assign a role that DENIES USE_CATALOG on a catalog.
+    mockRoleInStore(DENY_ROLE_ID, "denyRole", ImmutableList.of(getDenySecurableObject()));
+    when(roleMetaMapper.listRolesByUserId(eq(USER_ID)))
+        .thenReturn(ImmutableList.of(buildRolePO(DENY_ROLE_ID, "denyRole")));
+    when(userMetaMapper.getUserUpdatedAt(eq(METALAKE), eq(USERNAME)))
+        .thenReturn(new UserUpdatedAt(USER_ID, nextUserVersion()));
+
+    // The catalog-level deny is detected for the matching type and privilege.
+    assertTrue(
+        jcasbinAuthorizer.hasDenyPolicyOnType(
+            currentPrincipal,
+            METALAKE,
+            Entity.EntityType.CATALOG,
+            ImmutableSet.of(USE_CATALOG),
+            new AuthorizationRequestContext()));
+
+    // A deny on CATALOG must not be reported when querying a different metadata type.
+    assertFalse(
+        jcasbinAuthorizer.hasDenyPolicyOnType(
+            currentPrincipal,
+            METALAKE,
+            Entity.EntityType.TABLE,
+            ImmutableSet.of(SELECT_TABLE),
+            new AuthorizationRequestContext()));
+
+    // A deny on USE_CATALOG must not be reported when querying a different privilege.
+    assertFalse(
+        jcasbinAuthorizer.hasDenyPolicyOnType(
+            currentPrincipal,
+            METALAKE,
+            Entity.EntityType.CATALOG,
+            ImmutableSet.of(SELECT_TABLE),
+            new AuthorizationRequestContext()));
+  }
+
   @Test
   public void testUserRoleCacheDoesNotReuseRolesAfterUsernameRecreate() throws Exception {
     makeCompletableFutureUseCurrentThread(jcasbinAuthorizer);