Copilot commented on code in PR #14993:
URL: https://github.com/apache/gravitino/pull/14993#discussion_r4603095085
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -467,6 +484,46 @@ public boolean deny(
return result;
}
+ /** {@inheritDoc} */
+ @Override
+ public Optional<ResolvedTagPolicy> matchTagPolicy(
+ Principal principal,
+ String metalake,
+ MetadataObject target,
+ Privilege.Name privilege,
+ AuthorizationRequestContext requestContext) {
+ if (tagPolicyResolver == null
+ || !AccessControlContent.PERMITTED_PRIVILEGES.contains(privilege)
+ || requestContext.getActiveRoles().isNone()) {
+ return Optional.empty();
+ }
+ if (prefetchUserAndGroupInfo(
+ metalake, principal.getName(), principalGroupNames(principal),
requestContext)
+ .isEmpty()) {
+ return Optional.empty();
+ }
+ ActiveRoles activeRoles = requestContext.getActiveRoles();
+ Set<String> roleNames =
+ requestContext.getPrefetchedRoleVersions().values().stream()
+ .map(RoleUpdatedAt::getRoleName)
+ .filter(name -> activeRoles.isAll() ||
activeRoles.roleNames().contains(name))
+ .collect(Collectors.toSet());
+ if (roleNames.isEmpty()
+ || !requestContext.hasEnabledAccessPolicies(
+ metalake, () -> hasEnabledAccessPolicies(metalake))) {
+ return Optional.empty();
+ }
+ String rawKey = JcasbinAuthorizationCacheKeys.metadataIdCacheKey(metalake,
target);
+ MetadataObject canonicalTarget =
+ requestContext.computeNormalizedMetadataObjectIfAbsent(
+ rawKey,
+ NameIdentifierUtil.getCatalogIdentifier(
+ MetadataObjectUtil.toEntityIdent(metalake, target)),
+ ignored -> MetadataIdConverter.normalizeMetadataObject(target,
metalake));
Review Comment:
With tag authorization enabled, an active role and an enabled access policy,
a target under a missing or concurrently dropped catalog can throw
`NoSuchCatalogException` here after an RBAC miss, turning a normal denial into
an authorization error. Catch normalization's `NotFoundException` and return
`Optional.empty()`, as `JcasbinAuthorizationLookups.resolveMetadataIdResult`
does, while preserving actual read failures. Add an enabled-feature regression
test for a missing catalog.
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/expression/AuthorizationExpressionConverter.java:
##########
@@ -406,4 +410,36 @@ public static String replaceAnyPrivilege(String
expression) {
"authorizer.hasMetadataPrivilegePermission(p_metalake,p_type,p_fullName,authorizationContext)");
return expression;
}
+
+ /**
+ * Routes tag-conferrable {@code ANY_*} checks through the RBAC and
tag-policy adapter.
+ *
+ * @param expression the authorization expression
+ * @return the expression with supported privilege checks routed through the
adapter
+ */
+ private static String replaceTagPrivilegeChecks(String expression) {
+ for (Privilege.Name privilege : AccessControlContent.PERMITTED_PRIVILEGES)
{
+ MetadataObject.Type type =
+ switch (privilege) {
+ case SELECT_TABLE, MODIFY_TABLE, PROBE_TABLE_LIKE ->
MetadataObject.Type.TABLE;
+ case SELECT_VIEW -> MetadataObject.Type.VIEW;
+ case READ_FILESET, WRITE_FILESET -> MetadataObject.Type.FILESET;
+ case CONSUME_TOPIC, PRODUCE_TOPIC -> MetadataObject.Type.TOPIC;
+ case USE_MODEL -> MetadataObject.Type.MODEL;
+ case EXECUTE_FUNCTION -> MetadataObject.Type.FUNCTION;
+ case USE_SEMANTIC_MODEL -> MetadataObject.Type.SEMANTIC_MODEL;
+ default -> throw new IllegalArgumentException(
+ "Missing tag privilege scope: " + privilege);
+ };
+ expression =
+ expression.replace(
+ "ANY_" + privilege.name(),
+
"tagAuthorization.authorize(principal,METALAKE_NAME,{METALAKE,CATALOG,SCHEMA,"
+ + type
Review Comment:
Native `ViewOperations.loadView` supplies `VIEW`, but this mapping makes
`ANY_PROBE_TABLE_LIKE` pass the absent `TABLE` as its target, so the adapter
skips tag matching. A caller with traversal privileges and a matching inherited
probe policy therefore receives 403 instead of 404 for an absent view. Select
the available table/view target for this privilege and add a native-view probe
regression test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]