jbonofre commented on code in PR #3999:
URL: https://github.com/apache/polaris/pull/3999#discussion_r2937076921
##########
polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java:
##########
@@ -747,15 +755,75 @@ public PolarisAuthorizerImpl(RealmConfig realmConfig) {
@Override
public void resolveAuthorizationInputs(
@Nonnull AuthorizationState authzState, @Nonnull AuthorizationRequest
request) {
- throw new UnsupportedOperationException(
- "resolveAuthorizationInputs is not implemented yet for
PolarisAuthorizerImpl");
+ PolarisResolutionManifest resolutionManifest =
authzState.getResolutionManifest();
+ resolutionManifest.resolveAll();
}
@Override
+ @Nonnull
public AuthorizationDecision authorize(
@Nonnull AuthorizationState authzState, @Nonnull AuthorizationRequest
request) {
- throw new UnsupportedOperationException(
- "authorize is not implemented yet for PolarisAuthorizerImpl");
+ PolarisResolutionManifest resolutionManifest =
authzState.getResolutionManifest();
+ RbacOperationSemantics semantics =
RbacOperationSemantics.forOperation(request.getOperation());
+ // Delegate to legacy authorizeOrThrow() to preserve existing RBAC
privilege
+ // evaluation semantics. A later cleanup can refactor internals to a
+ // decision-first approach and remove this exception-to-decision
adaptation.
+ try {
+ List<PolarisResolvedPathWrapper> resolvedSecondaries =
+ !semantics.hasSecondaryPrivileges() ||
request.getSecondaries().isEmpty()
+ ? null
+ : getResolvedSecurables(
+ resolutionManifest, semantics, request.getSecondaries(),
TargetType.SECONDARY);
+ authorizeOrThrow(
+ request.getPrincipal(),
+ resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
+ request.getOperation(),
+ getResolvedSecurables(
+ resolutionManifest, semantics, request.getTargets(),
TargetType.TARGET),
+ resolvedSecondaries);
+ return AuthorizationDecision.allow();
+ } catch (ForbiddenException e) {
+ return AuthorizationDecision.deny(e.getMessage());
+ }
+ }
+
+ private List<PolarisResolvedPathWrapper> getResolvedSecurables(
+ PolarisResolutionManifest resolutionManifest,
+ RbacOperationSemantics semantics,
+ List<PolarisSecurable> securables,
+ TargetType targetType) {
+ boolean prependRootContainer =
+ switch (targetType) {
+ case TARGET -> semantics.targetScope() == PathEvaluationScope.ROOT;
Review Comment:
I'm a bit confused here. Every operation uses `PathEvaluationScope.ROOT`
except the policy attach/detach operations which use `CATALOG`.
Is this correct for catalog-scoped operations like `LIST_NAMESPACES`,
`LIST_TABLES`, ...
These operations semantically happen within a catalog context. If the
existing `authorizeOrThrow` callers already prepend the root container
themselves, then `ROOT` make sense for backward compatibility. Maybe worth to
add a comment here to clarify.
--
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]