You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by su...@apache.org on 2026/09/08 19:30:39 UTC
(polaris) branch main updated: Update `CatalogHandler` and `PolarisAdminServier` to `authorize` using `AuthorizationIntent` (#5194)
This is an automated email from the ASF dual-hosted git repository.
sungwy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 0858f79035 Update `CatalogHandler` and `PolarisAdminServier` to `authorize` using `AuthorizationIntent` (#5194)
0858f79035 is described below
commit 0858f790357704d3da37c47e59c3c4f1076ea138
Author: Sung Yun <10...@users.noreply.github.com>
AuthorDate: Tue Sep 8 15:30:34 2026 -0400
Update `CatalogHandler` and `PolarisAdminServier` to `authorize` using `AuthorizationIntent` (#5194)
---
CHANGELOG.md | 8 +
.../extension/auth/opa/OpaPolarisAuthorizer.java | 118 +--------
.../auth/opa/OpaPolarisAuthorizerFactoryTest.java | 87 ++++---
.../auth/opa/OpaPolarisAuthorizerTest.java | 283 +++++++++++++--------
.../auth/ranger/RangerPolarisAuthorizer.java | 155 +++++++++--
.../auth/ranger/RangerPolarisAuthorizerTest.java | 250 +++++++++++++++++-
.../semanticmodel/SemanticModelCatalogHandler.java | 27 +-
.../AbstractSemanticModelCatalogHandlerTest.java | 2 +
.../SemanticModelCatalogHandlerAuthzTest.java | 3 +
.../polaris/core/auth/AuthorizationDecision.java | 7 +
.../polaris/core/auth/PolarisAuthorizer.java | 34 ---
.../polaris/core/auth/PolarisAuthorizerImpl.java | 46 ++--
.../core/auth/PolarisAuthorizerImplTest.java | 159 +++++++-----
.../polaris/service/admin/PolarisAdminService.java | 130 +++-------
.../service/catalog/common/CatalogHandler.java | 279 +++++++++-----------
.../catalog/iceberg/IcebergCatalogHandler.java | 129 +++++++---
.../catalog/policy/PolicyCatalogHandler.java | 62 ++---
.../service/admin/PolarisAdminServiceTest.java | 2 +
.../catalog/iceberg/IcebergCatalogHandlerTest.java | 101 ++++----
.../org/apache/polaris/service/TestServices.java | 2 +
20 files changed, 1101 insertions(+), 783 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c585983b1..65d674e482 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -71,6 +71,14 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
and a subsequent `bootstrap` would create a second, empty set of tables in the other schema.
Either remove the setting from the URL, or point it at the schema that already holds your
Polaris tables.
+- PolarisAuthorizer inputs now reflect the intent-based authorization SPI more directly. Resource
+ targets and parent paths no longer include Polaris's internal synthetic `ROOT` container. For
+ example, catalog targets now have empty parent paths, root-scoped operations such as
+ `LIST_CATALOGS` no longer include a synthetic `ROOT` target.
+- PolarisAuthorizer requests with multiple intents are now evaluated one intent at a time. OPA
+ deployments will observe this as separate OPA queries per intent, so existing Rego policies that
+ depend on the previous combined-intent input shape may need to be updated. Same applies to other
+ PolarisAuthorizer implementations.
- Internal JWTs minted before credentials-generation binding (tokens without the `polaris-cv` claim) can no longer be used as subject tokens in token exchange; they remain valid as bearer tokens until expiry. During a rolling upgrade, an old node may still mint claim-less tokens: exchanging such a token on any already-upgraded node fails with `invalid_grant`, so clients can see intermittent exchange failures until the last old node is gone; after that, rejection is consistent.
### New Features
diff --git a/extensions/auth/opa/src/main/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizer.java b/extensions/auth/opa/src/main/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizer.java
index 286b7665a6..3a90c549b2 100644
--- a/extensions/auth/opa/src/main/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizer.java
+++ b/extensions/auth/opa/src/main/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizer.java
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import java.util.UUID;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@@ -38,7 +37,6 @@ import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
-import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.polaris.core.auth.AuthorizationDecision;
import org.apache.polaris.core.auth.AuthorizationIntent;
import org.apache.polaris.core.auth.AuthorizationRequest;
@@ -55,9 +53,6 @@ import org.apache.polaris.core.auth.RoleAssignmentAuthorizationIntent;
import org.apache.polaris.core.auth.RootPrivilegeGrantAuthorizationIntent;
import org.apache.polaris.core.auth.SingleTargetAuthorizationIntent;
import org.apache.polaris.core.auth.TargetlessAuthorizationIntent;
-import org.apache.polaris.core.entity.PolarisBaseEntity;
-import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
-import org.apache.polaris.core.persistence.ResolvedPolarisEntity;
import org.apache.polaris.extension.auth.opa.model.ImmutableActor;
import org.apache.polaris.extension.auth.opa.model.ImmutableContext;
import org.apache.polaris.extension.auth.opa.model.ImmutableOpaAuthorizationInput;
@@ -177,74 +172,20 @@ class OpaPolarisAuthorizer implements PolarisAuthorizer {
queryOpa(
buildOpaAuthorizationInput(request.principal(), operation, targets, secondaries));
if (!allowed) {
- return AuthorizationDecision.deny(
- "OPA denied authorization for principal="
- + request.principal().getName()
- + " operation="
- + operation);
+ LOGGER.debug(
+ "OPA denied authorization for principal={} operation={} targets={} secondaries={} realm={} requestId={}",
+ request.principal().getName(),
+ operation,
+ targets,
+ secondaries,
+ realm,
+ requestId);
+ return AuthorizationDecision.deny("OPA denied authorization");
}
}
return AuthorizationDecision.allow();
}
- /**
- * Authorizes a single target and secondary entity for the given principal and operation.
- *
- * <p>Delegates to the multi-target version for consistency.
- *
- * @param polarisPrincipal the principal requesting authorization
- * @param activatedEntities the set of activated entities (roles, etc.)
- * @param authzOp the operation to authorize
- * @param target the main target entity
- * @param secondary the secondary entity (if any)
- * @throws ForbiddenException if authorization is denied by OPA
- */
- @Override
- public void authorizeOrThrow(
- @NonNull PolarisPrincipal polarisPrincipal,
- @NonNull Set<PolarisBaseEntity> activatedEntities,
- @NonNull PolarisAuthorizableOperation authzOp,
- @Nullable PolarisResolvedPathWrapper target,
- @Nullable PolarisResolvedPathWrapper secondary) {
- authorizeOrThrow(
- polarisPrincipal,
- activatedEntities,
- authzOp,
- target == null ? null : List.of(target),
- secondary == null ? null : List.of(secondary));
- }
-
- /**
- * Authorizes one or more target and secondary entities for the given principal and operation.
- *
- * <p>Sends the authorization context to OPA and throws if not allowed.
- *
- * @param polarisPrincipal the principal requesting authorization
- * @param activatedEntities the set of activated entities (roles, etc.)
- * @param authzOp the operation to authorize
- * @param targets the list of main target entities
- * @param secondaries the list of secondary entities (if any)
- * @throws ForbiddenException if authorization is denied by OPA
- */
- @Override
- public void authorizeOrThrow(
- @NonNull PolarisPrincipal polarisPrincipal,
- @NonNull Set<PolarisBaseEntity> activatedEntities,
- @NonNull PolarisAuthorizableOperation authzOp,
- @Nullable List<PolarisResolvedPathWrapper> targets,
- @Nullable List<PolarisResolvedPathWrapper> secondaries) {
- boolean allowed =
- queryOpa(
- buildOpaAuthorizationInput(
- polarisPrincipal,
- authzOp,
- toResourceEntitiesFromResolvedPaths(targets),
- toResourceEntitiesFromResolvedPaths(secondaries)));
- if (!allowed) {
- throw new ForbiddenException("OPA denied authorization");
- }
- }
-
/**
* Sends an authorization query to the OPA server and parses the response.
*
@@ -381,47 +322,6 @@ class OpaPolarisAuthorizer implements PolarisAuthorizer {
return builder.build();
}
- private ResourceEntity buildResourceEntity(PolarisResolvedPathWrapper path) {
- // Currently, authorizeOrThrow still evaluate through resolved paths, including
- // root-scoped operations that may surface a resolved ROOT leaf. Preserve that legacy
- // behavior for compatibility until those callers migrate to the intent-based flow.
- ResolvedPolarisEntity resolvedLeaf = path.getResolvedLeafEntity();
- PathSegment leaf =
- new PathSegment(resolvedLeaf.getEntity().getType(), resolvedLeaf.getEntity().getName());
- List<ResourceEntity> parents = new ArrayList<>();
- List<ResolvedPolarisEntity> resolvedParents = path.getResolvedParentPath();
- if (resolvedParents != null) {
- for (ResolvedPolarisEntity resolvedParent : resolvedParents) {
- parents.add(
- ImmutableResourceEntity.builder()
- .type(resolvedParent.getEntity().getType().name())
- .name(resolvedParent.getEntity().getName())
- .build());
- }
- }
- return ImmutableResourceEntity.builder()
- .type(leaf.entityType().name())
- .name(leaf.name())
- .parents(parents)
- .build();
- }
-
- @NonNull
- private List<ResourceEntity> toResourceEntitiesFromResolvedPaths(
- @Nullable List<PolarisResolvedPathWrapper> paths) {
- if (paths == null || paths.isEmpty()) {
- return List.of();
- }
-
- List<ResourceEntity> entities = new ArrayList<>();
- for (PolarisResolvedPathWrapper path : paths) {
- if (path != null && path.getResolvedLeafEntity() != null) {
- entities.add(buildResourceEntity(path));
- }
- }
- return entities;
- }
-
private List<ResourceEntity> toResourceEntitiesFromSecurable(
@Nullable PolarisSecurable securable) {
return securable == null ? List.of() : List.of(buildResourceEntity(securable));
diff --git a/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerFactoryTest.java b/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerFactoryTest.java
index f514205d89..865ee8babb 100644
--- a/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerFactoryTest.java
+++ b/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerFactoryTest.java
@@ -41,12 +41,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.polaris.core.auth.AuthorizationRequest;
+import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
import org.apache.polaris.core.auth.PolarisPrincipal;
+import org.apache.polaris.core.auth.TargetlessAuthorizationIntent;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.context.RealmContext;
-import org.apache.polaris.core.entity.PolarisBaseEntity;
-import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.extension.auth.opa.token.FileBearerTokenProvider;
import org.apache.polaris.nosql.async.java.JavaPoolAsyncExec;
import org.junit.jupiter.api.Test;
@@ -225,12 +227,15 @@ public class OpaPolarisAuthorizerFactoryTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- Set.of(),
- PolarisAuthorizableOperation.GET_CATALOG,
- (PolarisResolvedPathWrapper) null,
- (PolarisResolvedPathWrapper) null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new TargetlessAuthorizationIntent(
+ PolarisAuthorizableOperation.GET_CATALOG))))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
@@ -281,12 +286,15 @@ public class OpaPolarisAuthorizerFactoryTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- Set.of(),
- PolarisAuthorizableOperation.GET_CATALOG,
- (PolarisResolvedPathWrapper) null,
- (PolarisResolvedPathWrapper) null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new TargetlessAuthorizationIntent(
+ PolarisAuthorizableOperation.GET_CATALOG))))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
@@ -338,18 +346,18 @@ public class OpaPolarisAuthorizerFactoryTest {
PolarisPrincipal principal =
PolarisPrincipal.of("eve", Map.of("department", "finance"), Set.of("auditor"));
- PolarisResolvedPathWrapper target = new PolarisResolvedPathWrapper(List.of());
- PolarisResolvedPathWrapper secondary = new PolarisResolvedPathWrapper(List.of());
-
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- Set.<PolarisBaseEntity>of(),
- PolarisAuthorizableOperation.LOAD_VIEW,
- target,
- secondary));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new TargetlessAuthorizationIntent(
+ PolarisAuthorizableOperation.LOAD_VIEW))))
+ .throwIfDenied());
JsonNode root = JsonMapper.builder().build().readTree(capturedRequestBody[0]);
assertThat(root.at("/input/context/request_id").asText())
@@ -402,21 +410,21 @@ public class OpaPolarisAuthorizerFactoryTest {
RealmConfig realmConfig = mock(RealmConfig.class);
PolarisPrincipal principal =
PolarisPrincipal.of("eve", Map.of("department", "finance"), Set.of("auditor"));
- PolarisResolvedPathWrapper target = new PolarisResolvedPathWrapper(List.of());
- PolarisResolvedPathWrapper secondary = new PolarisResolvedPathWrapper(List.of());
-
// First "request": factory.create() is called fresh, as it would be for each incoming
// HTTP request via the @RequestScoped PolarisAuthorizer producer.
OpaPolarisAuthorizer firstAuthorizer = (OpaPolarisAuthorizer) factory.create(realmConfig);
assertThatNoException()
.isThrownBy(
() ->
- firstAuthorizer.authorizeOrThrow(
- principal,
- Set.<PolarisBaseEntity>of(),
- PolarisAuthorizableOperation.LOAD_VIEW,
- target,
- secondary));
+ firstAuthorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new TargetlessAuthorizationIntent(
+ PolarisAuthorizableOperation.LOAD_VIEW))))
+ .throwIfDenied());
JsonNode firstRoot = JsonMapper.builder().build().readTree(capturedRequestBody[0]);
assertThat(firstRoot.at("/input/context/request_id").asText()).isEqualTo("request-1");
@@ -426,12 +434,15 @@ public class OpaPolarisAuthorizerFactoryTest {
assertThatNoException()
.isThrownBy(
() ->
- secondAuthorizer.authorizeOrThrow(
- principal,
- Set.<PolarisBaseEntity>of(),
- PolarisAuthorizableOperation.LOAD_VIEW,
- target,
- secondary));
+ secondAuthorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new TargetlessAuthorizationIntent(
+ PolarisAuthorizableOperation.LOAD_VIEW))))
+ .throwIfDenied());
JsonNode secondRoot = JsonMapper.builder().build().readTree(capturedRequestBody[0]);
assertThat(secondRoot.at("/input/context/request_id").asText()).isEqualTo("request-2");
}
diff --git a/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerTest.java b/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerTest.java
index bab45c2751..9d0a396ee3 100644
--- a/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerTest.java
+++ b/extensions/auth/opa/src/test/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizerTest.java
@@ -51,6 +51,7 @@ import org.apache.hc.core5.http.io.HttpClientResponseHandler;
import org.apache.hc.core5.http.io.entity.HttpEntities;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.polaris.core.auth.AuthorizationDecision;
+import org.apache.polaris.core.auth.AuthorizationIntent;
import org.apache.polaris.core.auth.AuthorizationRequest;
import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PathSegment;
@@ -59,7 +60,7 @@ import org.apache.polaris.core.auth.PolarisPrincipal;
import org.apache.polaris.core.auth.PolarisSecurable;
import org.apache.polaris.core.auth.RenameAuthorizationIntent;
import org.apache.polaris.core.auth.SingleTargetAuthorizationIntent;
-import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.auth.TargetlessAuthorizationIntent;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.core.entity.PolarisEntityType;
@@ -98,19 +99,22 @@ public class OpaPolarisAuthorizerTest {
PolarisPrincipal principal =
PolarisPrincipal.of("eve", Map.of("department", "finance"), Set.of("auditor"));
- Set<PolarisBaseEntity> entities = Set.of();
PolarisResolvedPathWrapper target = new PolarisResolvedPathWrapper(List.of());
PolarisResolvedPathWrapper secondary = new PolarisResolvedPathWrapper(List.of());
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- entities,
- PolarisAuthorizableOperation.LOAD_VIEW,
- target,
- secondary));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.LOAD_VIEW,
+ List.of(target),
+ List.of(secondary))))
+ .throwIfDenied());
// Parse and verify JSON structure from captured request
ObjectMapper mapper = JsonMapper.builder().build();
@@ -199,17 +203,19 @@ public class OpaPolarisAuthorizerTest {
createResolvedEntity(tableEntity));
PolarisResolvedPathWrapper tablePath = new PolarisResolvedPathWrapper(resolvedPath);
- Set<PolarisBaseEntity> entities = Set.of(catalogEntity, namespaceEntity, tableEntity);
-
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- entities,
- PolarisAuthorizableOperation.LOAD_TABLE,
- tablePath,
- null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.LOAD_TABLE,
+ List.of(tablePath),
+ null)))
+ .throwIfDenied());
// Parse and verify the complete JSON structure
ObjectMapper mapper = JsonMapper.builder().build();
@@ -350,18 +356,19 @@ public class OpaPolarisAuthorizerTest {
createResolvedEntity(tableEntity));
PolarisResolvedPathWrapper tablePath = new PolarisResolvedPathWrapper(resolvedPath);
- Set<PolarisBaseEntity> entities =
- Set.of(catalogEntity, departmentEntity, teamEntity, tableEntity);
-
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- entities,
- PolarisAuthorizableOperation.LOAD_TABLE,
- tablePath,
- null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.LOAD_TABLE,
+ List.of(tablePath),
+ null)))
+ .throwIfDenied());
// Parse and verify the complete JSON structure
ObjectMapper mapper = JsonMapper.builder().build();
@@ -447,7 +454,7 @@ public class OpaPolarisAuthorizerTest {
}
@Test
- void authorizeOrThrowHandlesEmptyTargetsAndSecondaries() throws Exception {
+ void authorizeHandlesEmptyTargetsAndSecondaries() throws Exception {
HttpServer server = createServerWithAllowResponse();
try {
URI policyUri =
@@ -464,20 +471,22 @@ public class OpaPolarisAuthorizerTest {
PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("admin"));
- Set<PolarisBaseEntity> entities = Set.of();
-
PolarisResolvedPathWrapper target = new PolarisResolvedPathWrapper(List.of());
PolarisResolvedPathWrapper secondary = new PolarisResolvedPathWrapper(List.of());
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- entities,
- PolarisAuthorizableOperation.CREATE_CATALOG,
- target,
- secondary));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.CREATE_CATALOG,
+ List.of(target),
+ List.of(secondary))))
+ .throwIfDenied());
// Test multiple targets
PolarisResolvedPathWrapper target1 = new PolarisResolvedPathWrapper(List.of());
@@ -488,12 +497,14 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- entities,
- PolarisAuthorizableOperation.LOAD_VIEW,
- targets,
- secondaries));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.LOAD_VIEW, targets, secondaries)))
+ .throwIfDenied());
} finally {
server.stop(0);
}
@@ -553,8 +564,16 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() -> {
- authorizer.authorizeOrThrow(
- mockPrincipal, Collections.emptySet(), mockOperation, target, secondary);
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ mockPrincipal,
+ authorizationIntents(
+ mockOperation,
+ target == null ? null : List.of(target),
+ secondary == null ? null : List.of(secondary))))
+ .throwIfDenied();
});
}
@@ -601,8 +620,16 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() -> {
- authorizer.authorizeOrThrow(
- mockPrincipal, Collections.emptySet(), mockOperation, target, secondary);
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ mockPrincipal,
+ authorizationIntents(
+ mockOperation,
+ target == null ? null : List.of(target),
+ secondary == null ? null : List.of(secondary))))
+ .throwIfDenied();
});
}
@@ -708,13 +735,7 @@ public class OpaPolarisAuthorizerTest {
AuthorizationDecision decision = authorizer.authorize(authzState, request);
assertThat(decision.isAllowed()).isFalse();
- assertThat(decision.getMessage())
- .hasValueSatisfying(
- message ->
- assertThat(message)
- .contains("OPA denied authorization")
- .contains("operation=GET_CATALOG")
- .contains("principal=alice"));
+ assertThat(decision.getMessage()).hasValue("OPA denied authorization");
}
@Test
@@ -780,7 +801,7 @@ public class OpaPolarisAuthorizerTest {
}
@Test
- void authorizeResolvedCatalogTargetPreservesRootParent() throws Exception {
+ void authorizeCatalogTargetOmitsRootParent() throws Exception {
final String[] capturedRequestBody = new String[1];
HttpServer server = createServerWithRequestCapture(capturedRequestBody);
@@ -819,15 +840,20 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- PolarisPrincipal.of("root", Map.of(), Set.of("service_admin")),
- Set.of(),
- PolarisAuthorizableOperation.GET_CATALOG,
- new PolarisResolvedPathWrapper(
- List.of(
- createResolvedEntity(rootEntity),
- createResolvedEntity(catalogEntity))),
- null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ PolarisPrincipal.of("root", Map.of(), Set.of("service_admin")),
+ authorizationIntents(
+ PolarisAuthorizableOperation.GET_CATALOG,
+ List.of(
+ new PolarisResolvedPathWrapper(
+ List.of(
+ createResolvedEntity(rootEntity),
+ createResolvedEntity(catalogEntity)))),
+ null)))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
@@ -838,9 +864,7 @@ public class OpaPolarisAuthorizerTest {
{
"type": "CATALOG",
"name": "catalog-1",
- "parents": [
- {"type": "ROOT", "name": "root_container", "parents": []}
- ]
+ "parents": []
}
""");
assertThat(target).isEqualTo(expectedTarget);
@@ -850,11 +874,7 @@ public class OpaPolarisAuthorizerTest {
}
@Test
- void authorizeRootScopedOperationSerializesRootTarget() throws Exception {
- // Test to verify that ROOT scoped operation still works
- // After migrating to intent-based authorization, we will
- // exclude ROOT container from the OPA request's target
- // and this test should be updated to fail
+ void authorizeRootScopedOperationOmitsRootTarget() throws Exception {
final String[] capturedRequestBody = new String[1];
HttpServer server = createServerWithRequestCapture(capturedRequestBody);
@@ -884,26 +904,22 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- PolarisPrincipal.of("root", Map.of(), Set.of("service_admin")),
- Set.of(),
- PolarisAuthorizableOperation.LIST_CATALOGS,
- new PolarisResolvedPathWrapper(List.of(createResolvedEntity(rootEntity))),
- null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ PolarisPrincipal.of("root", Map.of(), Set.of("service_admin")),
+ authorizationIntents(
+ PolarisAuthorizableOperation.LIST_CATALOGS,
+ List.of(
+ new PolarisResolvedPathWrapper(
+ List.of(createResolvedEntity(rootEntity)))),
+ null)))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
- JsonNode target = root.path("input").path("resource").path("targets").get(0);
- JsonNode expectedTarget =
- mapper.readTree(
- """
- {
- "type": "ROOT",
- "name": "root_container",
- "parents": []
- }
- """);
- assertThat(target).isEqualTo(expectedTarget);
+ assertThat(root.path("input").path("resource").path("targets").isMissingNode()).isTrue();
} finally {
server.stop(0);
}
@@ -1145,12 +1161,14 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- Set.of(),
- PolarisAuthorizableOperation.GET_CATALOG,
- (PolarisResolvedPathWrapper) null,
- (PolarisResolvedPathWrapper) null));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.GET_CATALOG, null, null)))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
@@ -1222,12 +1240,16 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- Set.of(),
- PolarisAuthorizableOperation.LOAD_VIEW,
- target,
- secondary));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.LOAD_VIEW,
+ List.of(target),
+ List.of(secondary))))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
@@ -1263,12 +1285,16 @@ public class OpaPolarisAuthorizerTest {
assertThatNoException()
.isThrownBy(
() ->
- authorizer.authorizeOrThrow(
- principal,
- Set.of(),
- PolarisAuthorizableOperation.LOAD_VIEW,
- target,
- secondary));
+ authorizer
+ .authorize(
+ new AuthorizationState(mock(PolarisResolutionManifest.class)),
+ new AuthorizationRequest(
+ principal,
+ authorizationIntents(
+ PolarisAuthorizableOperation.LOAD_VIEW,
+ List.of(target),
+ List.of(secondary))))
+ .throwIfDenied());
ObjectMapper mapper = JsonMapper.builder().build();
JsonNode root = mapper.readTree(capturedRequestBody[0]);
@@ -1288,6 +1314,55 @@ public class OpaPolarisAuthorizerTest {
PolarisSecurable.of(new PathSegment(PolarisEntityType.CATALOG, "catalog-1")))));
}
+ private List<AuthorizationIntent> authorizationIntents(
+ PolarisAuthorizableOperation operation,
+ List<PolarisResolvedPathWrapper> targets,
+ List<PolarisResolvedPathWrapper> secondaries) {
+ List<PolarisSecurable> targetSecurables = toSecurables(targets);
+ List<PolarisSecurable> secondarySecurables = toSecurables(secondaries);
+ if (targetSecurables.isEmpty()) {
+ return List.of(new TargetlessAuthorizationIntent(operation));
+ }
+ if (targetSecurables.size() == 1 && secondarySecurables.size() == 1) {
+ return List.of(
+ new RenameAuthorizationIntent(
+ operation, targetSecurables.getFirst(), secondarySecurables.getFirst()));
+ }
+ return targetSecurables.stream()
+ .<AuthorizationIntent>map(target -> new SingleTargetAuthorizationIntent(operation, target))
+ .toList();
+ }
+
+ private List<PolarisSecurable> toSecurables(List<PolarisResolvedPathWrapper> paths) {
+ if (paths == null) {
+ return List.of();
+ }
+ List<PolarisSecurable> securables = new ArrayList<>();
+ for (PolarisResolvedPathWrapper path : paths) {
+ if (path != null
+ && path.getResolvedLeafEntity() != null
+ && path.getResolvedLeafEntity().getEntity().getType() != PolarisEntityType.ROOT) {
+ securables.add(toSecurable(path));
+ }
+ }
+ return securables;
+ }
+
+ private PolarisSecurable toSecurable(PolarisResolvedPathWrapper path) {
+ List<PathSegment> segments = new ArrayList<>();
+ if (path.getResolvedParentPath() != null) {
+ for (ResolvedPolarisEntity parent : path.getResolvedParentPath()) {
+ if (parent.getEntity().getType() != PolarisEntityType.ROOT) {
+ segments.add(new PathSegment(parent.getEntity().getType(), parent.getEntity().getName()));
+ }
+ }
+ }
+ ResolvedPolarisEntity leaf = path.getResolvedLeafEntity();
+ segments.add(new PathSegment(leaf.getEntity().getType(), leaf.getEntity().getName()));
+ return PolarisSecurable.of(
+ segments.getFirst(), segments.stream().skip(1).toArray(PathSegment[]::new));
+ }
+
private ResolvedPolarisEntity createResolvedEntity(PolarisEntity entity) {
return new ResolvedPolarisEntity(entity, List.of(), List.of());
}
diff --git a/extensions/auth/ranger/src/main/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizer.java b/extensions/auth/ranger/src/main/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizer.java
index 4be898f951..5e92b3e9bb 100644
--- a/extensions/auth/ranger/src/main/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizer.java
+++ b/extensions/auth/ranger/src/main/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizer.java
@@ -24,16 +24,29 @@ import java.util.List;
import java.util.Set;
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.polaris.core.auth.AuthorizationDecision;
+import org.apache.polaris.core.auth.AuthorizationIntent;
import org.apache.polaris.core.auth.AuthorizationPreConditions;
import org.apache.polaris.core.auth.AuthorizationRequest;
import org.apache.polaris.core.auth.AuthorizationState;
+import org.apache.polaris.core.auth.PathSegment;
import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.auth.PolarisPrincipal;
+import org.apache.polaris.core.auth.PolarisSecurable;
+import org.apache.polaris.core.auth.PolicyAttachmentAuthorizationIntent;
+import org.apache.polaris.core.auth.PrivilegeGrantAuthorizationIntent;
+import org.apache.polaris.core.auth.RenameAuthorizationIntent;
+import org.apache.polaris.core.auth.RoleAssignmentAuthorizationIntent;
+import org.apache.polaris.core.auth.RootPrivilegeGrantAuthorizationIntent;
+import org.apache.polaris.core.auth.SingleTargetAuthorizationIntent;
+import org.apache.polaris.core.auth.TargetlessAuthorizationIntent;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
+import org.apache.polaris.core.persistence.resolver.ResolvedPathKey;
import org.apache.polaris.extension.auth.ranger.utils.RangerUtils;
import org.apache.ranger.authz.api.RangerAuthzException;
import org.apache.ranger.authz.embedded.RangerEmbeddedAuthorizer;
@@ -90,26 +103,134 @@ public class RangerPolarisAuthorizer implements PolarisAuthorizer {
@Override
public @NonNull AuthorizationDecision authorize(
@NonNull AuthorizationState authzState, @NonNull AuthorizationRequest request) {
- throw new UnsupportedOperationException("authorize is not implemented yet");
+ PolarisResolutionManifest resolutionManifest = authzState.getResolutionManifest();
+ for (AuthorizationIntent intent : request.intents()) {
+ AuthorizationDecision decision =
+ authorizeIntent(request.principal(), resolutionManifest, intent);
+ if (!decision.isAllowed()) {
+ return decision;
+ }
+ }
+ return AuthorizationDecision.allow();
}
- @Override
- public void authorizeOrThrow(
- @NonNull PolarisPrincipal polarisPrincipal,
- @NonNull Set<PolarisBaseEntity> activatedEntities,
- @NonNull PolarisAuthorizableOperation authzOp,
- @Nullable PolarisResolvedPathWrapper target,
- @Nullable PolarisResolvedPathWrapper secondary) {
- authorizeOrThrow(
- polarisPrincipal,
- activatedEntities,
- authzOp,
- target == null ? null : List.of(target),
- secondary == null ? null : List.of(secondary));
+ private AuthorizationDecision authorizeIntent(
+ PolarisPrincipal polarisPrincipal,
+ PolarisResolutionManifest resolutionManifest,
+ AuthorizationIntent intent) {
+ RangerPolarisOperationSemantics semantics =
+ RangerPolarisOperationSemantics.forOperation(intent.getOperation());
+ if (semantics == null) {
+ return AuthorizationDecision.deny(
+ String.format(
+ RANGER_AUTH_FAILED_ERROR, polarisPrincipal.getName(), intent.getOperation().name()));
+ }
+ boolean prependRootContainer =
+ semantics.rooting() == RangerPolarisOperationSemantics.ResolvedPathRooting.ROOT;
+
+ try {
+ List<PolarisResolvedPathWrapper> resolvedTargets;
+ List<PolarisResolvedPathWrapper> resolvedSecondaries;
+ if (intent instanceof TargetlessAuthorizationIntent) {
+ resolvedTargets =
+ prependRootContainer
+ ? List.of(resolutionManifest.getResolvedRootContainerEntityAsPath())
+ : null;
+ resolvedSecondaries = null;
+ } else if (intent instanceof SingleTargetAuthorizationIntent singleTargetIntent) {
+ resolvedTargets =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, singleTargetIntent.target(), prependRootContainer));
+ resolvedSecondaries = null;
+ } else if (intent instanceof RenameAuthorizationIntent renameIntent) {
+ resolvedTargets =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, renameIntent.from(), prependRootContainer));
+ resolvedSecondaries =
+ List.of(
+ getResolvedSecurable(resolutionManifest, renameIntent.to(), prependRootContainer));
+ } else if (intent instanceof PolicyAttachmentAuthorizationIntent policyAttachmentIntent) {
+ resolvedTargets =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, policyAttachmentIntent.policy(), prependRootContainer));
+ resolvedSecondaries =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, policyAttachmentIntent.attachedTo(), prependRootContainer));
+ } else if (intent instanceof PrivilegeGrantAuthorizationIntent privilegeGrantIntent) {
+ resolvedTargets =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, privilegeGrantIntent.grantTarget(), prependRootContainer));
+ resolvedSecondaries =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, privilegeGrantIntent.grantee(), prependRootContainer));
+ } else if (intent instanceof RootPrivilegeGrantAuthorizationIntent rootPrivilegeGrantIntent) {
+ resolvedTargets = List.of(resolutionManifest.getResolvedRootContainerEntityAsPath());
+ resolvedSecondaries =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, rootPrivilegeGrantIntent.grantee(), prependRootContainer));
+ } else if (intent instanceof RoleAssignmentAuthorizationIntent roleAssignmentIntent) {
+ resolvedTargets =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, roleAssignmentIntent.role(), prependRootContainer));
+ resolvedSecondaries =
+ List.of(
+ getResolvedSecurable(
+ resolutionManifest, roleAssignmentIntent.assignee(), prependRootContainer));
+ } else {
+ throw new IllegalStateException("Unsupported authorization intent: " + intent.getClass());
+ }
+
+ authorizeRangerOrThrow(
+ polarisPrincipal,
+ resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
+ intent.getOperation(),
+ resolvedTargets,
+ resolvedSecondaries);
+ return AuthorizationDecision.allow();
+ } catch (ForbiddenException e) {
+ return AuthorizationDecision.deny(e.getMessage());
+ }
}
- @Override
- public void authorizeOrThrow(
+ private PolarisResolvedPathWrapper getResolvedSecurable(
+ PolarisResolutionManifest resolutionManifest,
+ PolarisSecurable securable,
+ boolean prependRootContainer) {
+ PolarisResolvedPathWrapper resolvedSecurable =
+ securable.getLeaf().entityType() == PolarisEntityType.CATALOG
+ ? resolutionManifest.getResolvedReferenceCatalogEntity(prependRootContainer)
+ : securable.getLeaf().entityType().isTopLevel()
+ ? resolutionManifest.getResolvedTopLevelEntity(
+ securable.getLeaf().name(), securable.getLeaf().entityType())
+ : resolutionManifest.getResolvedPath(
+ ResolvedPathKey.of(
+ getPathNamesWithinCatalog(securable), securable.getLeaf().entityType()),
+ prependRootContainer);
+ Preconditions.checkState(
+ resolvedSecurable != null,
+ "Resolved path for securable is null for entityType=%s leaf=%s parents=%s",
+ securable.getLeaf().entityType(),
+ securable.getLeaf(),
+ securable.getParents());
+ return resolvedSecurable;
+ }
+
+ private List<String> getPathNamesWithinCatalog(PolarisSecurable securable) {
+ return securable.getPathSegments().stream()
+ .filter(segment -> segment.entityType() != PolarisEntityType.CATALOG)
+ .map(PathSegment::name)
+ .toList();
+ }
+
+ private void authorizeRangerOrThrow(
@NonNull PolarisPrincipal polarisPrincipal,
@NonNull Set<PolarisBaseEntity> activatedEntities,
@NonNull PolarisAuthorizableOperation authzOp,
@@ -126,7 +247,7 @@ public class RangerPolarisAuthorizer implements PolarisAuthorizer {
if (LOG.isDebugEnabled()) {
LOG.debug(
- "authorizeOrThrow(principal={}, activatedEntities={}, authzOp={name: {}, targetPrivileges: {}, secondaryPrivileges: {}), targets={}, secondaries={}",
+ "authorizeRanger(principal={}, activatedEntities={}, authzOp={name: {}, targetPrivileges: {}, secondaryPrivileges: {}), targets={}, secondaries={}",
polarisPrincipal,
activatedEntities,
authzOp,
diff --git a/extensions/auth/ranger/src/test/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizerTest.java b/extensions/auth/ranger/src/test/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizerTest.java
index d35fee899f..ea88fab97d 100644
--- a/extensions/auth/ranger/src/test/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizerTest.java
+++ b/extensions/auth/ranger/src/test/java/org/apache/polaris/extension/auth/ranger/RangerPolarisAuthorizerTest.java
@@ -23,9 +23,14 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.polaris.extension.auth.ranger.RangerTestUtils.createConfig;
import static org.apache.polaris.extension.auth.ranger.RangerTestUtils.createRealmConfig;
import static org.apache.polaris.extension.auth.ranger.RangerTestUtils.createRealmContext;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -37,14 +42,34 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.exceptions.ForbiddenException;
+import org.apache.polaris.core.auth.AuthorizationDecision;
+import org.apache.polaris.core.auth.AuthorizationIntent;
+import org.apache.polaris.core.auth.AuthorizationRequest;
+import org.apache.polaris.core.auth.AuthorizationState;
+import org.apache.polaris.core.auth.PathSegment;
import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.auth.PolarisPrincipal;
+import org.apache.polaris.core.auth.PolarisSecurable;
+import org.apache.polaris.core.auth.PolicyAttachmentAuthorizationIntent;
+import org.apache.polaris.core.auth.PrivilegeGrantAuthorizationIntent;
+import org.apache.polaris.core.auth.RenameAuthorizationIntent;
+import org.apache.polaris.core.auth.RoleAssignmentAuthorizationIntent;
+import org.apache.polaris.core.auth.RootPrivilegeGrantAuthorizationIntent;
+import org.apache.polaris.core.auth.SingleTargetAuthorizationIntent;
+import org.apache.polaris.core.auth.TargetlessAuthorizationIntent;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
import org.apache.polaris.core.persistence.ResolvedPolarisEntity;
+import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
+import org.apache.polaris.core.persistence.resolver.ResolvedPathKey;
+import org.apache.ranger.authz.embedded.RangerEmbeddedAuthorizer;
+import org.apache.ranger.authz.model.RangerAuthzResult;
+import org.apache.ranger.authz.model.RangerMultiAuthzRequest;
+import org.apache.ranger.authz.model.RangerMultiAuthzResult;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DatabindException;
import tools.jackson.databind.DeserializationContext;
@@ -104,20 +129,110 @@ public class RangerPolarisAuthorizerTest {
runTests(authorizer, "/authz_tests/tests_authz_unsupported.json");
}
+ @Test
+ void authorizeUsesIntentResolvedTarget() throws Exception {
+ RangerEmbeddedAuthorizer embeddedAuthorizer = mock(RangerEmbeddedAuthorizer.class);
+ RangerPolarisAuthorizer authorizer =
+ new RangerPolarisAuthorizer(embeddedAuthorizer, "dev_polaris", createRealmConfig());
+ authorizer.setRealmContext(createRealmContext());
+ PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
+ PolarisResolvedPathWrapper tablePath =
+ resolvedPath(
+ PolarisEntityType.ROOT,
+ "root",
+ PolarisEntityType.CATALOG,
+ "catalog",
+ PolarisEntityType.NAMESPACE,
+ "ns",
+ PolarisEntityType.TABLE_LIKE,
+ "table");
+ PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Collections.emptySet());
+ AuthorizationRequest request =
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.LOAD_TABLE,
+ PolarisSecurable.of(
+ new PathSegment(PolarisEntityType.CATALOG, "catalog"),
+ new PathSegment(PolarisEntityType.NAMESPACE, "ns"),
+ new PathSegment(PolarisEntityType.TABLE_LIKE, "table")))));
+
+ when(manifest.getResolvedPath(
+ ResolvedPathKey.of(List.of("ns", "table"), PolarisEntityType.TABLE_LIKE), true))
+ .thenReturn(tablePath);
+ when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Collections.emptySet());
+ when(embeddedAuthorizer.authorize(
+ org.mockito.ArgumentMatchers.any(RangerMultiAuthzRequest.class)))
+ .thenReturn(rangerResult(RangerAuthzResult.AccessDecision.ALLOW));
+
+ AuthorizationDecision decision =
+ authorizer.authorize(new AuthorizationState(manifest), request);
+
+ assertThat(decision.isAllowed()).isTrue();
+ ArgumentCaptor<RangerMultiAuthzRequest> requestCaptor =
+ ArgumentCaptor.forClass(RangerMultiAuthzRequest.class);
+ verify(embeddedAuthorizer).authorize(requestCaptor.capture());
+ RangerMultiAuthzRequest rangerRequest = requestCaptor.getValue();
+ assertThat(rangerRequest.getUser().getName()).isEqualTo("alice");
+ assertThat(rangerRequest.getAccesses()).hasSize(1);
+ assertThat(rangerRequest.getAccesses().get(0).getAction()).isEqualTo("LOAD_TABLE");
+ assertThat(rangerRequest.getAccesses().get(0).getResource().getName())
+ .isEqualTo("table:POLARIS/catalog/ns/table");
+ }
+
+ @Test
+ void authorizeReturnsDenyDecisionWhenRangerDenies() throws Exception {
+ RangerEmbeddedAuthorizer embeddedAuthorizer = mock(RangerEmbeddedAuthorizer.class);
+ RangerPolarisAuthorizer authorizer =
+ new RangerPolarisAuthorizer(embeddedAuthorizer, "dev_polaris", createRealmConfig());
+ authorizer.setRealmContext(createRealmContext());
+ PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
+ PolarisResolvedPathWrapper catalogPath =
+ resolvedPath(PolarisEntityType.ROOT, "root", PolarisEntityType.CATALOG, "catalog");
+ PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Collections.emptySet());
+ AuthorizationRequest request =
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.GET_CATALOG,
+ PolarisSecurable.of(new PathSegment(PolarisEntityType.CATALOG, "catalog")))));
+
+ when(manifest.getResolvedReferenceCatalogEntity(true)).thenReturn(catalogPath);
+ when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Collections.emptySet());
+ when(embeddedAuthorizer.authorize(
+ org.mockito.ArgumentMatchers.any(RangerMultiAuthzRequest.class)))
+ .thenReturn(rangerResult(RangerAuthzResult.AccessDecision.DENY));
+
+ AuthorizationDecision decision =
+ authorizer.authorize(new AuthorizationState(manifest), request);
+
+ assertThat(decision.isAllowed()).isFalse();
+ assertThat(decision.getMessage().orElseThrow())
+ .contains("Principal 'alice' is not authorized for op 'GET_CATALOG'");
+ }
+
private void runTests(PolarisAuthorizer authorizer, String testFilename) throws Exception {
InputStream inStream = this.getClass().getResourceAsStream(testFilename);
InputStreamReader reader = new InputStreamReader(inStream, UTF_8);
TestSuite testSuite = getMapper().readValue(reader, TestSuite.class);
for (TestData test : testSuite.tests) {
+ PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
+ when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles())
+ .thenReturn(Collections.emptySet());
+ stubResolutionManifest(manifest, test.request.target);
+ stubResolutionManifest(manifest, test.request.secondary);
+ AuthorizationRequest request =
+ new AuthorizationRequest(
+ test.request.principal,
+ List.of(
+ authorizationIntent(
+ test.request.authzOp, test.request.target, test.request.secondary)));
if (test.result.isAllowed) {
try {
- authorizer.authorizeOrThrow(
- test.request.principal,
- Collections.emptySet(),
- test.request.authzOp,
- test.request.target,
- test.request.secondary);
+ authorizer.authorize(new AuthorizationState(manifest), request).throwIfDenied();
} catch (ForbiddenException excp) {
fail(
test.request.principal
@@ -133,13 +248,7 @@ public class RangerPolarisAuthorizerTest {
} else {
assertThrows(
ForbiddenException.class,
- () ->
- authorizer.authorizeOrThrow(
- test.request.principal,
- Collections.emptySet(),
- test.request.authzOp,
- test.request.target,
- test.request.secondary),
+ () -> authorizer.authorize(new AuthorizationState(manifest), request).throwIfDenied(),
() ->
test.request.principal
+ " should not be allowed to perform "
@@ -153,6 +262,100 @@ public class RangerPolarisAuthorizerTest {
}
}
+ private AuthorizationIntent authorizationIntent(
+ PolarisAuthorizableOperation operation,
+ PolarisResolvedPathWrapper target,
+ PolarisResolvedPathWrapper secondary) {
+ if (RangerPolarisOperationSemantics.forOperation(operation) == null) {
+ return new TargetlessAuthorizationIntent(operation);
+ }
+ if (target == null
+ || target.getResolvedLeafEntity().getEntity().getType() == PolarisEntityType.ROOT) {
+ if (secondary != null && operation.name().endsWith("_ROOT_GRANT_FROM_PRINCIPAL_ROLE")) {
+ return new RootPrivilegeGrantAuthorizationIntent(operation, toSecurable(secondary));
+ }
+ return new TargetlessAuthorizationIntent(operation);
+ }
+
+ PolarisSecurable targetSecurable = toSecurable(target);
+ if (secondary == null) {
+ return new SingleTargetAuthorizationIntent(operation, targetSecurable);
+ }
+
+ PolarisSecurable secondarySecurable = toSecurable(secondary);
+ String operationName = operation.name();
+ if (operationName.startsWith("RENAME_")) {
+ return new RenameAuthorizationIntent(operation, targetSecurable, secondarySecurable);
+ }
+ if (operationName.startsWith("ATTACH_POLICY_") || operationName.startsWith("DETACH_POLICY_")) {
+ return new PolicyAttachmentAuthorizationIntent(
+ operation, targetSecurable, secondarySecurable);
+ }
+ if (operationName.endsWith("_ROOT_GRANT_FROM_PRINCIPAL_ROLE")) {
+ return new RootPrivilegeGrantAuthorizationIntent(operation, secondarySecurable);
+ }
+ if (operationName.contains("_CATALOG_ROLE_TO_PRINCIPAL_ROLE")
+ || operationName.contains("_PRINCIPAL_ROLE")) {
+ return new RoleAssignmentAuthorizationIntent(operation, targetSecurable, secondarySecurable);
+ }
+ if (operationName.contains("_GRANT_")) {
+ return new PrivilegeGrantAuthorizationIntent(operation, targetSecurable, secondarySecurable);
+ }
+ return new RenameAuthorizationIntent(operation, targetSecurable, secondarySecurable);
+ }
+
+ private void stubResolutionManifest(
+ PolarisResolutionManifest manifest, PolarisResolvedPathWrapper resolvedPath) {
+ if (resolvedPath == null || resolvedPath.getResolvedLeafEntity() == null) {
+ return;
+ }
+ PolarisEntity leaf = resolvedPath.getResolvedLeafEntity().getEntity();
+ if (leaf.getType() == PolarisEntityType.ROOT) {
+ when(manifest.getResolvedRootContainerEntityAsPath()).thenReturn(resolvedPath);
+ } else if (leaf.getType() == PolarisEntityType.CATALOG) {
+ when(manifest.getResolvedReferenceCatalogEntity(org.mockito.ArgumentMatchers.anyBoolean()))
+ .thenReturn(resolvedPath);
+ } else if (leaf.getType().isTopLevel()) {
+ when(manifest.getResolvedTopLevelEntity(leaf.getName(), leaf.getType()))
+ .thenReturn(resolvedPath);
+ } else {
+ List<String> pathNamesWithinCatalog = new ArrayList<>();
+ List<ResolvedPolarisEntity> parentPath = resolvedPath.getResolvedParentPath();
+ if (parentPath != null) {
+ for (ResolvedPolarisEntity parent : parentPath) {
+ PolarisEntity parentEntity = parent.getEntity();
+ if (parentEntity.getType() != PolarisEntityType.ROOT
+ && parentEntity.getType() != PolarisEntityType.CATALOG) {
+ pathNamesWithinCatalog.add(parentEntity.getName());
+ }
+ }
+ }
+ pathNamesWithinCatalog.add(leaf.getName());
+ ResolvedPathKey key = ResolvedPathKey.of(pathNamesWithinCatalog, leaf.getType());
+ when(manifest.getResolvedPath(eq(key), org.mockito.ArgumentMatchers.anyBoolean()))
+ .thenReturn(resolvedPath);
+ }
+ }
+
+ private PolarisSecurable toSecurable(PolarisResolvedPathWrapper resolvedPath) {
+ List<PathSegment> segments = new ArrayList<>();
+ List<ResolvedPolarisEntity> parentPath = resolvedPath.getResolvedParentPath();
+ if (parentPath != null) {
+ for (ResolvedPolarisEntity parent : parentPath) {
+ PolarisEntity parentEntity = parent.getEntity();
+ if (parentEntity.getType() != PolarisEntityType.ROOT) {
+ segments.add(new PathSegment(parentEntity.getType(), parentEntity.getName()));
+ }
+ }
+ }
+ PolarisEntity leaf = resolvedPath.getResolvedLeafEntity().getEntity();
+ if (leaf.getType() != PolarisEntityType.ROOT) {
+ segments.add(new PathSegment(leaf.getType(), leaf.getName()));
+ }
+ return PolarisSecurable.of(
+ segments.getFirst(), segments.stream().skip(1).toArray(PathSegment[]::new));
+ }
+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonIgnoreProperties(ignoreUnknown = true)
private static class TestSuite {
@@ -191,6 +394,27 @@ public class RangerPolarisAuthorizerTest {
return JsonMapper.builder().addModule(serDeModule).build();
}
+ private static RangerMultiAuthzResult rangerResult(RangerAuthzResult.AccessDecision decision) {
+ RangerAuthzResult accessResult = new RangerAuthzResult();
+ accessResult.setDecision(decision);
+ RangerMultiAuthzResult result = new RangerMultiAuthzResult();
+ result.setDecision(decision);
+ result.setAccesses(List.of(accessResult));
+ return result;
+ }
+
+ private static PolarisResolvedPathWrapper resolvedPath(Object... typeAndNamePairs) {
+ List<ResolvedPolarisEntity> entities = new ArrayList<>(typeAndNamePairs.length / 2);
+ for (int i = 0; i < typeAndNamePairs.length; i += 2) {
+ PolarisEntityType type = (PolarisEntityType) typeAndNamePairs[i];
+ String name = (String) typeAndNamePairs[i + 1];
+ PolarisEntity entity = new PolarisEntity.Builder().setName(name).setType(type).build();
+ entities.add(
+ new ResolvedPolarisEntity(entity, Collections.emptyList(), Collections.emptyList()));
+ }
+ return new PolarisResolvedPathWrapper(entities);
+ }
+
static class PolarisPrincipalDeserializer extends ValueDeserializer<PolarisPrincipal> {
@Override
public PolarisPrincipal deserialize(JsonParser parser, DeserializationContext context) {
diff --git a/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandler.java b/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandler.java
index 0b990cc241..58f5b8661a 100644
--- a/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandler.java
+++ b/extensions/semantic-models/src/main/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandler.java
@@ -126,17 +126,16 @@ public abstract class SemanticModelCatalogHandler extends CatalogHandler {
PolarisCatalogHelpers.identifierToList(namespace, identifier.getName()),
PolarisEntityType.SEMANTIC_MODEL,
true /* optional */));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op,
+ PolarisSecurableMapper.semanticModel(
+ catalogName(), namespace, identifier.getName()))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op,
- PolarisSecurableMapper.semanticModel(
- catalogName(), namespace, identifier.getName())))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper target =
resolutionManifest.getResolvedPath(
@@ -146,13 +145,7 @@ public abstract class SemanticModelCatalogHandler extends CatalogHandler {
String.format("Semantic model does not exist: %s", identifier.getName()));
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
diff --git a/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/AbstractSemanticModelCatalogHandlerTest.java b/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/AbstractSemanticModelCatalogHandlerTest.java
index 111bffe3e0..e530bd5638 100644
--- a/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/AbstractSemanticModelCatalogHandlerTest.java
+++ b/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/AbstractSemanticModelCatalogHandlerTest.java
@@ -32,6 +32,7 @@ import org.apache.polaris.core.admin.model.CatalogProperties;
import org.apache.polaris.core.admin.model.CreateCatalogRequest;
import org.apache.polaris.core.admin.model.FileStorageConfigInfo;
import org.apache.polaris.core.admin.model.StorageConfigInfo;
+import org.apache.polaris.core.auth.AuthorizationDecision;
import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.service.TestServices;
@@ -99,6 +100,7 @@ abstract class AbstractSemanticModelCatalogHandlerTest {
})
.when(authorizer)
.resolveAuthorizationInputs(any(), any());
+ Mockito.when(authorizer.authorize(any(), any())).thenReturn(AuthorizationDecision.allow());
return handler(authorizer);
}
diff --git a/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandlerAuthzTest.java b/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandlerAuthzTest.java
index df38223b96..628b8a77ba 100644
--- a/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandlerAuthzTest.java
+++ b/extensions/semantic-models/src/test/java/org/apache/polaris/service/catalog/semanticmodel/SemanticModelCatalogHandlerAuthzTest.java
@@ -24,8 +24,10 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import org.apache.iceberg.exceptions.ForbiddenException;
+import org.apache.polaris.core.auth.AuthorizationDecision;
import org.apache.polaris.core.auth.AuthorizationRequest;
import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
@@ -110,6 +112,7 @@ class SemanticModelCatalogHandlerAuthzTest extends AbstractSemanticModelCatalogH
})
.when(authorizer)
.resolveAuthorizationInputs(any(), any());
+ when(authorizer.authorize(any(), any())).thenReturn(AuthorizationDecision.allow());
handler(authorizer).loadSemanticModel(identifier("m1"));
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/AuthorizationDecision.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/AuthorizationDecision.java
index 06125a7ce4..380429cef3 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/auth/AuthorizationDecision.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/AuthorizationDecision.java
@@ -19,6 +19,7 @@
package org.apache.polaris.core.auth;
import java.util.Optional;
+import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.polaris.immutables.PolarisImmutable;
import org.immutables.value.Value;
import org.jspecify.annotations.Nullable;
@@ -41,4 +42,10 @@ public interface AuthorizationDecision {
@Value.Parameter(order = 2)
Optional<String> getMessage();
+
+ default void throwIfDenied() {
+ if (!isAllowed()) {
+ throw new ForbiddenException("%s", getMessage().orElse("Authorization denied"));
+ }
+ }
}
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java
index fad800f298..87400b3de2 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java
@@ -18,13 +18,7 @@
*/
package org.apache.polaris.core.auth;
-import java.util.List;
-import java.util.Set;
-import org.apache.iceberg.exceptions.ForbiddenException;
-import org.apache.polaris.core.entity.PolarisBaseEntity;
-import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
import org.jspecify.annotations.NonNull;
-import org.jspecify.annotations.Nullable;
/** Interface for invoking authorization checks. */
public interface PolarisAuthorizer {
@@ -52,32 +46,4 @@ public interface PolarisAuthorizer {
*/
@NonNull AuthorizationDecision authorize(
@NonNull AuthorizationState authzState, @NonNull AuthorizationRequest request);
-
- /**
- * Convenience method that throws a {@link ForbiddenException} when authorization is denied.
- *
- * <p>Implementations should provide allow/deny decisions via {@link #authorize}.
- */
- default void authorizeOrThrow(
- @NonNull AuthorizationState authzState, @NonNull AuthorizationRequest request) {
- AuthorizationDecision decision = authorize(authzState, request);
- if (!decision.isAllowed()) {
- String message = decision.getMessage().orElse("Authorization denied");
- throw new ForbiddenException("%s", message);
- }
- }
-
- void authorizeOrThrow(
- @NonNull PolarisPrincipal polarisPrincipal,
- @NonNull Set<PolarisBaseEntity> activatedEntities,
- @NonNull PolarisAuthorizableOperation authzOp,
- @Nullable PolarisResolvedPathWrapper target,
- @Nullable PolarisResolvedPathWrapper secondary);
-
- void authorizeOrThrow(
- @NonNull PolarisPrincipal polarisPrincipal,
- @NonNull Set<PolarisBaseEntity> activatedEntities,
- @NonNull PolarisAuthorizableOperation authzOp,
- @Nullable List<PolarisResolvedPathWrapper> targets,
- @Nullable List<PolarisResolvedPathWrapper> secondaries);
}
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java
index a8fd1ce013..cdd81ecf24 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java
@@ -137,6 +137,7 @@ import org.apache.polaris.core.auth.RbacOperationSemantics.ResolvedPathRooting;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntityCore;
+import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.entity.PolarisGrantRecord;
import org.apache.polaris.core.entity.PolarisPrivilege;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
@@ -834,7 +835,7 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
} else {
throw new IllegalStateException("Unsupported authorization intent: " + intent.getClass());
}
- authorizeOrThrow(
+ authorizeRbacOrThrow(
polarisPrincipal,
resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
intent.getOperation(),
@@ -856,13 +857,15 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
PolarisSecurable securable,
boolean prependRootContainer) {
PolarisResolvedPathWrapper resolvedSecurable =
- securable.getLeaf().entityType().isTopLevel()
- ? resolutionManifest.getResolvedTopLevelEntity(
- securable.getLeaf().name(), securable.getLeaf().entityType())
- : resolutionManifest.getResolvedPath(
- ResolvedPathKey.of(
- getPathNamesWithinCatalog(securable), securable.getLeaf().entityType()),
- prependRootContainer);
+ securable.getLeaf().entityType() == PolarisEntityType.CATALOG
+ ? resolutionManifest.getResolvedReferenceCatalogEntity(prependRootContainer)
+ : securable.getLeaf().entityType().isTopLevel()
+ ? resolutionManifest.getResolvedTopLevelEntity(
+ securable.getLeaf().name(), securable.getLeaf().entityType())
+ : resolutionManifest.getResolvedPath(
+ ResolvedPathKey.of(
+ getPathNamesWithinCatalog(securable), securable.getLeaf().entityType()),
+ prependRootContainer);
Preconditions.checkState(
resolvedSecurable != null,
"Resolved path for securable is null for entityType=%s leaf=%s parents=%s",
@@ -876,9 +879,7 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
// Resolver path keys are scoped within the reference catalog, so the explicit catalog
// path segment is omitted from the PolarisSecurable path before lookup.
return securable.getPathSegments().stream()
- .filter(
- segment ->
- segment.entityType() != org.apache.polaris.core.entity.PolarisEntityType.CATALOG)
+ .filter(segment -> segment.entityType() != PolarisEntityType.CATALOG)
.map(PathSegment::name)
.toList();
}
@@ -902,23 +903,7 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
return false;
}
- @Override
- public void authorizeOrThrow(
- @NonNull PolarisPrincipal polarisPrincipal,
- @NonNull Set<PolarisBaseEntity> activatedEntities,
- @NonNull PolarisAuthorizableOperation authzOp,
- @Nullable PolarisResolvedPathWrapper target,
- @Nullable PolarisResolvedPathWrapper secondary) {
- authorizeOrThrow(
- polarisPrincipal,
- activatedEntities,
- authzOp,
- target == null ? null : List.of(target),
- secondary == null ? null : List.of(secondary));
- }
-
- @Override
- public void authorizeOrThrow(
+ private void authorizeRbacOrThrow(
@NonNull PolarisPrincipal polarisPrincipal,
@NonNull Set<PolarisBaseEntity> activatedEntities,
@NonNull PolarisAuthorizableOperation authzOp,
@@ -986,9 +971,8 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
/**
* Collects every required privilege the caller is missing for the operation, without
- * short-circuiting on the first failure. Used both by {@link #isAuthorized} (which only inspects
- * emptiness) and by {@link #authorizeOrThrow} to log the specific missing privileges and the
- * entities they were checked against (client-facing messages stay generic).
+ * short-circuiting on the first failure. Used by authorization checks to log the specific missing
+ * privileges and the entities they were checked against (client-facing messages stay generic).
*
* <p>The returned list groups target-side failures before secondary-side failures. Iteration
* order within each group follows {@link RbacOperationSemantics#targetPrivileges()} and {@link
diff --git a/polaris-core/src/test/java/org/apache/polaris/core/auth/PolarisAuthorizerImplTest.java b/polaris-core/src/test/java/org/apache/polaris/core/auth/PolarisAuthorizerImplTest.java
index 1b847d6df5..fbb03b3548 100644
--- a/polaris-core/src/test/java/org/apache/polaris/core/auth/PolarisAuthorizerImplTest.java
+++ b/polaris-core/src/test/java/org/apache/polaris/core/auth/PolarisAuthorizerImplTest.java
@@ -22,9 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -53,6 +51,14 @@ import org.mockito.ArgumentMatchers;
public class PolarisAuthorizerImplTest {
+ private static RealmConfig realmConfig() {
+ RealmConfig realmConfig = mock(RealmConfig.class);
+ when(realmConfig.getConfig(
+ FeatureConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING))
+ .thenReturn(false);
+ return realmConfig;
+ }
+
@ParameterizedTest
@EnumSource(PolarisPrivilege.class)
void subsumingPrivilegesOf(PolarisPrivilege privilege) {
@@ -67,7 +73,7 @@ public class PolarisAuthorizerImplTest {
@Test
void resolveAuthorizationInputsResolvesAll() {
- PolarisAuthorizerImpl authorizer = new PolarisAuthorizerImpl(mock(RealmConfig.class));
+ PolarisAuthorizerImpl authorizer = new PolarisAuthorizerImpl(realmConfig());
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("role"));
@@ -88,7 +94,7 @@ public class PolarisAuthorizerImplTest {
void authorizeUsesRootTargetForRootGrantRequestWithoutPrimaryTarget() {
// Verify that new authorize SPI call without primary target uses root_container
// for resolution and authorization
- PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(mock(RealmConfig.class)));
+ PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(realmConfig()));
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisResolvedPathWrapper rootWrapper = mock(PolarisResolvedPathWrapper.class);
@@ -99,9 +105,9 @@ public class PolarisAuthorizerImplTest {
when(manifest.getResolvedTopLevelEntity("analytics-admin", PolarisEntityType.PRINCIPAL_ROLE))
.thenReturn(principalRoleWrapper);
when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
- doNothing()
+ doReturn(List.of())
.when(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
any(PolarisPrincipal.class),
ArgumentMatchers.any(),
eq(PolarisAuthorizableOperation.ADD_ROOT_GRANT_TO_PRINCIPAL_ROLE),
@@ -121,7 +127,7 @@ public class PolarisAuthorizerImplTest {
assertThat(decision.isAllowed()).isTrue();
verify(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.ADD_ROOT_GRANT_TO_PRINCIPAL_ROLE),
@@ -133,7 +139,7 @@ public class PolarisAuthorizerImplTest {
void authorizeUsesRootTargetForListCatalogsRequestWithoutPrimaryTarget() {
// Verify that new authorize SPI call without primary target uses root_container
// for resolution and authorization
- PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(mock(RealmConfig.class)));
+ PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(realmConfig()));
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisResolvedPathWrapper rootWrapper = mock(PolarisResolvedPathWrapper.class);
@@ -141,9 +147,9 @@ public class PolarisAuthorizerImplTest {
when(manifest.getResolvedRootContainerEntityAsPath()).thenReturn(rootWrapper);
when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
- doNothing()
+ doReturn(List.of())
.when(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
any(PolarisPrincipal.class),
ArgumentMatchers.any(),
eq(PolarisAuthorizableOperation.LIST_CATALOGS),
@@ -159,7 +165,7 @@ public class PolarisAuthorizerImplTest {
assertThat(decision.isAllowed()).isTrue();
verify(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.LIST_CATALOGS),
@@ -171,7 +177,7 @@ public class PolarisAuthorizerImplTest {
void authorizeResolvesNamespaceTargetUsingCatalog() {
// Verify authorize call that includes Catalog name in the PolarisSecurable
// successfully resolves the correct namespace
- PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(mock(RealmConfig.class)));
+ PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(realmConfig()));
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisResolvedPathWrapper namespaceWrapper = mock(PolarisResolvedPathWrapper.class);
@@ -181,9 +187,9 @@ public class PolarisAuthorizerImplTest {
ResolvedPathKey.of(List.of("ns"), PolarisEntityType.NAMESPACE), true))
.thenReturn(namespaceWrapper);
when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
- doNothing()
+ doReturn(List.of())
.when(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
any(PolarisPrincipal.class),
ArgumentMatchers.any(),
eq(PolarisAuthorizableOperation.LIST_NAMESPACES),
@@ -206,7 +212,7 @@ public class PolarisAuthorizerImplTest {
verify(manifest)
.getResolvedPath(ResolvedPathKey.of(List.of("ns"), PolarisEntityType.NAMESPACE), true);
verify(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.LIST_NAMESPACES),
@@ -216,21 +222,19 @@ public class PolarisAuthorizerImplTest {
@Test
void authorizeSingleOperationMultiIntentRequestEvaluatesSequentially() {
- PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(mock(RealmConfig.class)));
+ PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(realmConfig()));
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisResolvedPathWrapper firstCatalogWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisResolvedPathWrapper secondCatalogWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("role"));
- when(manifest.getResolvedTopLevelEntity("catalog1", PolarisEntityType.CATALOG))
- .thenReturn(firstCatalogWrapper);
- when(manifest.getResolvedTopLevelEntity("catalog2", PolarisEntityType.CATALOG))
- .thenReturn(secondCatalogWrapper);
+ when(manifest.getResolvedReferenceCatalogEntity(true))
+ .thenReturn(firstCatalogWrapper, secondCatalogWrapper);
when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
- doNothing()
+ doReturn(List.of())
.when(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
any(PolarisPrincipal.class),
ArgumentMatchers.any(),
eq(PolarisAuthorizableOperation.GET_CATALOG),
@@ -254,14 +258,14 @@ public class PolarisAuthorizerImplTest {
assertThat(decision.isAllowed()).isTrue();
verify(authorizer, times(1))
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.GET_CATALOG),
eq(List.of(firstCatalogWrapper)),
eq(null));
verify(authorizer, times(1))
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.GET_CATALOG),
@@ -271,7 +275,7 @@ public class PolarisAuthorizerImplTest {
@Test
void authorizeUpdateTableMultiIntentRequestEvaluatesSequentially() {
- PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(mock(RealmConfig.class)));
+ PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(realmConfig()));
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisResolvedPathWrapper tableWrapper = mock(PolarisResolvedPathWrapper.class);
@@ -281,9 +285,9 @@ public class PolarisAuthorizerImplTest {
ResolvedPathKey.of(List.of("ns", "table"), PolarisEntityType.TABLE_LIKE), true))
.thenReturn(tableWrapper);
when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
- doNothing()
+ doReturn(List.of())
.when(authorizer)
- .authorizeOrThrow(
+ .findMissingPrivileges(
any(PolarisPrincipal.class),
ArgumentMatchers.any(),
any(PolarisAuthorizableOperation.class),
@@ -309,14 +313,14 @@ public class PolarisAuthorizerImplTest {
assertThat(decision.isAllowed()).isTrue();
verify(authorizer, times(1))
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.REMOVE_TABLE_PROPERTIES),
eq(List.of(tableWrapper)),
eq(null));
verify(authorizer, times(1))
- .authorizeOrThrow(
+ .findMissingPrivileges(
eq(principal),
eq(Set.of()),
eq(PolarisAuthorizableOperation.SET_TABLE_SNAPSHOT_REF),
@@ -336,18 +340,17 @@ public class PolarisAuthorizerImplTest {
@Test
void authorizeReturnsDenyDecision() {
- PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(mock(RealmConfig.class)));
+ PolarisAuthorizerImpl authorizer = spy(new PolarisAuthorizerImpl(realmConfig()));
PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
AuthorizationState authzState = new AuthorizationState(manifest);
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("role"));
- when(manifest.getResolvedTopLevelEntity("catalog", PolarisEntityType.CATALOG))
- .thenReturn(catalogWrapper);
+ when(manifest.getResolvedReferenceCatalogEntity(true)).thenReturn(catalogWrapper);
when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
- doThrow(new ForbiddenException("missing privilege"))
+ doReturn(false)
.when(authorizer)
- .authorizeOrThrow(
+ .isAuthorized(
any(PolarisPrincipal.class),
ArgumentMatchers.any(),
eq(PolarisAuthorizableOperation.GET_CATALOG),
@@ -365,24 +368,34 @@ public class PolarisAuthorizerImplTest {
AuthorizationDecision decision = authorizer.authorize(authzState, request);
assertThat(decision.isAllowed()).isFalse();
- assertThat(decision.getMessage()).hasValue("missing privilege");
+ assertThat(decision.getMessage().orElseThrow()).contains("is not authorized");
}
// ----- Tests for server-side missing privilege logging -----
@Test
- void authorizeOrThrowLogsMissingPrivilegeDetailsServerSide() {
+ void authorizeLogsMissingPrivilegeDetailsServerSide() {
PolarisAuthorizerImpl authorizer = new PolarisAuthorizerImpl(realmConfigWithDefaults());
+ PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("reader"));
PolarisResolvedPathWrapper namespace = resolvedPath(namespaceEntity("ns1"));
+ PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
+ when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
+ when(manifest.getResolvedPath(
+ eq(ResolvedPathKey.of(List.of("ns1"), PolarisEntityType.NAMESPACE)),
+ ArgumentMatchers.anyBoolean()))
+ .thenReturn(namespace);
+ AuthorizationRequest request =
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.CREATE_TABLE_DIRECT,
+ PolarisSecurable.of(
+ new PathSegment(PolarisEntityType.CATALOG, "catalog"),
+ new PathSegment(PolarisEntityType.NAMESPACE, "ns1")))));
assertThatThrownBy(
- () ->
- authorizer.authorizeOrThrow(
- PolarisPrincipal.of("alice", Map.of(), Set.of("reader")),
- Set.of(),
- PolarisAuthorizableOperation.CREATE_TABLE_DIRECT,
- List.of(namespace),
- null))
+ () -> authorizer.authorize(new AuthorizationState(manifest), request).throwIfDenied())
.isInstanceOf(ForbiddenException.class)
// Client-facing message is generic (no missing privilege details).
.hasMessage(
@@ -395,21 +408,31 @@ public class PolarisAuthorizerImplTest {
}
@Test
- void authorizeOrThrowLogsAllMissingTargetPrivilegesWithoutShortCircuit() {
+ void authorizeLogsAllMissingTargetPrivilegesWithoutShortCircuit() {
// CREATE_TABLE_DIRECT_WITH_WRITE_DELEGATION requires both TABLE_CREATE and TABLE_WRITE_DATA
// on the target namespace. With no grants at all, both should be logged server-side but NOT
// exposed in the client-facing exception.
PolarisAuthorizerImpl authorizer = new PolarisAuthorizerImpl(realmConfigWithDefaults());
+ PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("reader"));
PolarisResolvedPathWrapper namespace = resolvedPath(namespaceEntity("ns1"));
+ PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
+ when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
+ when(manifest.getResolvedPath(
+ eq(ResolvedPathKey.of(List.of("ns1"), PolarisEntityType.NAMESPACE)),
+ ArgumentMatchers.anyBoolean()))
+ .thenReturn(namespace);
+ AuthorizationRequest request =
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.CREATE_TABLE_DIRECT_WITH_WRITE_DELEGATION,
+ PolarisSecurable.of(
+ new PathSegment(PolarisEntityType.CATALOG, "catalog"),
+ new PathSegment(PolarisEntityType.NAMESPACE, "ns1")))));
assertThatThrownBy(
- () ->
- authorizer.authorizeOrThrow(
- PolarisPrincipal.of("alice", Map.of(), Set.of("reader")),
- Set.of(),
- PolarisAuthorizableOperation.CREATE_TABLE_DIRECT_WITH_WRITE_DELEGATION,
- List.of(namespace),
- null))
+ () -> authorizer.authorize(new AuthorizationState(manifest), request).throwIfDenied())
.isInstanceOf(ForbiddenException.class)
// Generic client message.
.hasMessage(
@@ -421,22 +444,40 @@ public class PolarisAuthorizerImplTest {
}
@Test
- void authorizeOrThrowLogsSecondaryMissingPrivilegeServerSide() {
+ void authorizeLogsSecondaryMissingPrivilegeServerSide() {
// RENAME_TABLE: target privilege TABLE_DROP on the existing table; secondary privileges
// TABLE_LIST and TABLE_CREATE on the destination namespace. Secondary details must NOT
// appear in the client-facing exception.
PolarisAuthorizerImpl authorizer = new PolarisAuthorizerImpl(realmConfigWithDefaults());
+ PolarisPrincipal principal = PolarisPrincipal.of("alice", Map.of(), Set.of("reader"));
PolarisResolvedPathWrapper srcTable = resolvedPath(tableEntity("src_t"));
PolarisResolvedPathWrapper dstNamespace = resolvedPath(namespaceEntity("dst_ns"));
+ PolarisResolutionManifest manifest = mock(PolarisResolutionManifest.class);
+ when(manifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
+ when(manifest.getResolvedPath(
+ eq(ResolvedPathKey.of(List.of("namespace", "src_t"), PolarisEntityType.TABLE_LIKE)),
+ ArgumentMatchers.anyBoolean()))
+ .thenReturn(srcTable);
+ when(manifest.getResolvedPath(
+ eq(ResolvedPathKey.of(List.of("dst_ns"), PolarisEntityType.NAMESPACE)),
+ ArgumentMatchers.anyBoolean()))
+ .thenReturn(dstNamespace);
+ AuthorizationRequest request =
+ new AuthorizationRequest(
+ principal,
+ List.of(
+ new RenameAuthorizationIntent(
+ PolarisAuthorizableOperation.RENAME_TABLE,
+ PolarisSecurable.of(
+ new PathSegment(PolarisEntityType.CATALOG, "catalog"),
+ new PathSegment(PolarisEntityType.NAMESPACE, "namespace"),
+ new PathSegment(PolarisEntityType.TABLE_LIKE, "src_t")),
+ PolarisSecurable.of(
+ new PathSegment(PolarisEntityType.CATALOG, "catalog"),
+ new PathSegment(PolarisEntityType.NAMESPACE, "dst_ns")))));
assertThatThrownBy(
- () ->
- authorizer.authorizeOrThrow(
- PolarisPrincipal.of("alice", Map.of(), Set.of("reader")),
- Set.of(),
- PolarisAuthorizableOperation.RENAME_TABLE,
- List.of(srcTable),
- List.of(dstNamespace)))
+ () -> authorizer.authorize(new AuthorizationState(manifest), request).throwIfDenied())
.isInstanceOf(ForbiddenException.class)
// Generic client message.
.hasMessage(
diff --git a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java
index d27469a4f6..7c3d6fab94 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java
@@ -239,17 +239,12 @@ public class PolarisAdminService {
private void authorizeBasicRootOperationOrThrow(PolarisAuthorizableOperation op) {
PolarisResolutionManifest resolutionManifest = newResolutionManifest(null);
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(polarisPrincipal, List.of(new TargetlessAuthorizationIntent(op))));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(polarisPrincipal, List.of(new TargetlessAuthorizationIntent(op)));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper rootContainerWrapper =
resolutionManifest.getResolvedRootContainerEntityAsPath();
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedPrincipalRoleEntities(),
- op,
- rootContainerWrapper,
- null /* secondary */);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
}
private PolarisResolutionManifest authorizeBasicTopLevelEntityOperationOrThrow(
@@ -268,13 +263,13 @@ public class PolarisAdminService {
PolarisResolutionManifest resolutionManifest = newResolutionManifest(referenceCatalogName);
resolutionManifest.addTopLevelName(topLevelEntityName, entityType, false /* isOptional */);
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new SingleTargetAuthorizationIntent(
- op, PolarisSecurable.of(new PathSegment(entityType, topLevelEntityName))))));
+ op, PolarisSecurable.of(new PathSegment(entityType, topLevelEntityName)))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
throw new NotFoundException(
@@ -290,12 +285,7 @@ public class PolarisAdminService {
.addKeyValue(StructuredLogKeys.PRINCIPAL_NAME, topLevelEntityName)
.log("Allowing rotate own credentials");
} else {
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- topLevelEntityWrapper,
- null /* secondary */);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
}
return resolutionManifest;
}
@@ -328,24 +318,19 @@ public class PolarisAdminService {
PolarisResolutionManifest resolutionManifest = newResolutionManifest(catalogName);
resolutionManifest.addPath(new ResolverPath(ResolvedPathKey.ofCatalogRole(catalogRoleName)));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new SingleTargetAuthorizationIntent(
- op, PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName)))));
+ op, PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper target =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofCatalogRole(catalogRoleName), true);
if (target == null) {
throw new NotFoundException("CatalogRole does not exist: %s", catalogRoleName);
}
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -355,15 +340,15 @@ public class PolarisAdminService {
resolutionManifest.addTopLevelName(
principalRoleName, PolarisEntityType.PRINCIPAL_ROLE, false /* isOptional */);
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new RootPrivilegeGrantAuthorizationIntent(
op,
PolarisSecurable.of(
- new PathSegment(PolarisEntityType.PRINCIPAL_ROLE, principalRoleName))))));
+ new PathSegment(PolarisEntityType.PRINCIPAL_ROLE, principalRoleName)))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -378,12 +363,7 @@ public class PolarisAdminService {
resolutionManifest.getResolvedTopLevelEntity(
principalRoleName, PolarisEntityType.PRINCIPAL_ROLE);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- rootContainerWrapper,
- principalRoleWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -395,8 +375,7 @@ public class PolarisAdminService {
resolutionManifest.addTopLevelName(
principalName, PolarisEntityType.PRINCIPAL, false /* isOptional */);
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
@@ -405,7 +384,8 @@ public class PolarisAdminService {
PolarisSecurable.of(
new PathSegment(PolarisEntityType.PRINCIPAL_ROLE, principalRoleName)),
PolarisSecurable.of(
- new PathSegment(PolarisEntityType.PRINCIPAL, principalName))))));
+ new PathSegment(PolarisEntityType.PRINCIPAL, principalName)))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -420,12 +400,7 @@ public class PolarisAdminService {
PolarisResolvedPathWrapper principalWrapper =
resolutionManifest.getResolvedTopLevelEntity(principalName, PolarisEntityType.PRINCIPAL);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- principalRoleWrapper,
- principalWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -439,8 +414,7 @@ public class PolarisAdminService {
resolutionManifest.addTopLevelName(
principalRoleName, PolarisEntityType.PRINCIPAL_ROLE, false /* isOptional */);
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
@@ -448,7 +422,8 @@ public class PolarisAdminService {
op,
PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName),
PolarisSecurable.of(
- new PathSegment(PolarisEntityType.PRINCIPAL_ROLE, principalRoleName))))));
+ new PathSegment(PolarisEntityType.PRINCIPAL_ROLE, principalRoleName)))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -467,12 +442,7 @@ public class PolarisAdminService {
PolarisResolvedPathWrapper catalogRoleWrapper =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofCatalogRole(catalogRoleName), true);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- catalogRoleWrapper,
- principalRoleWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -483,15 +453,15 @@ public class PolarisAdminService {
catalogName, PolarisEntityType.CATALOG, false /* isOptional */);
resolutionManifest.addPath(new ResolverPath(ResolvedPathKey.ofCatalogRole(catalogRoleName)));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new PrivilegeGrantAuthorizationIntent(
op,
PolarisSecurable.of(new PathSegment(PolarisEntityType.CATALOG, catalogName)),
- PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName)))));
+ PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -504,12 +474,7 @@ public class PolarisAdminService {
resolutionManifest.getResolvedTopLevelEntity(catalogName, PolarisEntityType.CATALOG);
PolarisResolvedPathWrapper catalogRoleWrapper =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofCatalogRole(catalogRoleName), true);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- catalogWrapper,
- catalogRoleWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -523,15 +488,15 @@ public class PolarisAdminService {
new ResolverPath(Arrays.asList(namespace.levels()), PolarisEntityType.NAMESPACE));
resolutionManifest.addPath(new ResolverPath(ResolvedPathKey.ofCatalogRole(catalogRoleName)));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new PrivilegeGrantAuthorizationIntent(
op,
PolarisSecurableMapper.namespace(catalogName, namespace),
- PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName)))));
+ PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -550,12 +515,7 @@ public class PolarisAdminService {
PolarisResolvedPathWrapper catalogRoleWrapper =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofCatalogRole(catalogRoleName), true);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- namespaceWrapper,
- catalogRoleWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -574,15 +534,15 @@ public class PolarisAdminService {
PolarisCatalogHelpers.tableIdentifierToList(identifier), PolarisEntityType.TABLE_LIKE));
resolutionManifest.addPath(new ResolverPath(ResolvedPathKey.ofCatalogRole(catalogRoleName)));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new PrivilegeGrantAuthorizationIntent(
op,
PolarisSecurableMapper.tableLike(catalogName, identifier),
- PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName)))));
+ PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
@@ -610,12 +570,7 @@ public class PolarisAdminService {
PolarisResolvedPathWrapper catalogRoleWrapper =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofCatalogRole(catalogRoleName), true);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- tableLikeWrapper,
- catalogRoleWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
@@ -631,15 +586,15 @@ public class PolarisAdminService {
PolarisEntityType.POLICY));
resolutionManifest.addPath(new ResolverPath(ResolvedPathKey.ofCatalogRole(catalogRoleName)));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer.resolveAuthorizationInputs(
- authorizationState,
+ AuthorizationRequest authorizationRequest =
new AuthorizationRequest(
polarisPrincipal,
List.of(
new PrivilegeGrantAuthorizationIntent(
op,
PolarisSecurableMapper.policy(catalogName, identifier),
- PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName)))));
+ PolarisSecurableMapper.catalogRole(catalogName, catalogRoleName))));
+ authorizer.resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.ENTITY_COULD_NOT_BE_RESOLVED) {
throw new NotFoundException("Catalog not found: %s", catalogName);
@@ -657,12 +612,7 @@ public class PolarisAdminService {
PolarisResolvedPathWrapper catalogRoleWrapper =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofCatalogRole(catalogRoleName), true);
- authorizer.authorizeOrThrow(
- polarisPrincipal,
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- policyWrapper,
- catalogRoleWrapper);
+ authorizer.authorize(authorizationState, authorizationRequest).throwIfDenied();
return resolutionManifest;
}
diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/common/CatalogHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/common/CatalogHandler.java
index 2995bdba7e..ddae7a870f 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/common/CatalogHandler.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/common/CatalogHandler.java
@@ -27,7 +27,6 @@ import static org.apache.polaris.service.catalog.common.ExceptionUtils.notFoundE
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
-import java.util.Optional;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.AlreadyExistsException;
@@ -137,30 +136,23 @@ public abstract class CatalogHandler {
}
}
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op,
+ namespace.isEmpty()
+ ? PolarisSecurableMapper.catalog(catalogName())
+ : PolarisSecurableMapper.namespace(catalogName(), namespace))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op,
- namespace.isEmpty()
- ? PolarisSecurableMapper.catalog(catalogName())
- : PolarisSecurableMapper.namespace(catalogName(), namespace)))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper target =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofNamespace(namespace), true);
if (target == null) {
throw noSuchNamespaceException(namespace);
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
@@ -180,30 +172,23 @@ public abstract class CatalogHandler {
resolutionManifest.addPassthroughPath(
new ResolverPath(
Arrays.asList(namespace.levels()), PolarisEntityType.NAMESPACE, true /* optional */));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op,
+ parentNamespace.isEmpty()
+ ? PolarisSecurableMapper.catalog(catalogName())
+ : PolarisSecurableMapper.namespace(catalogName(), parentNamespace))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op,
- parentNamespace.isEmpty()
- ? PolarisSecurableMapper.catalog(catalogName())
- : PolarisSecurableMapper.namespace(catalogName(), parentNamespace)))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper target =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofNamespace(parentNamespace), true);
if (target == null) {
throw noSuchNamespaceException(parentNamespace);
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
@@ -225,39 +210,35 @@ public abstract class CatalogHandler {
PolarisCatalogHelpers.tableIdentifierToList(identifier),
PolarisEntityType.TABLE_LIKE,
true /* optional */));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op, PolarisSecurableMapper.namespace(catalogName(), namespace))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op, PolarisSecurableMapper.namespace(catalogName(), namespace)))));
- authorizeResolvedCreateTableLikeUnderNamespaceOperationOrThrow(op, identifier);
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
+ authorizeResolvedCreateTableLikeUnderNamespaceOperationOrThrow(
+ authorizationState, authorizationRequest, identifier);
}
protected void authorizeResolvedCreateTableLikeUnderNamespaceOperationOrThrow(
- PolarisAuthorizableOperation op, TableIdentifier identifier) {
+ AuthorizationState authorizationState,
+ AuthorizationRequest authorizationRequest,
+ TableIdentifier identifier) {
if (resolutionManifest == null) {
throw new IllegalStateException(
"Resolved authorization requires resolveAuthorizationInputs to run first");
}
- Namespace namespace = identifier.namespace();
PolarisResolvedPathWrapper target =
- resolutionManifest.getResolvedPath(ResolvedPathKey.ofNamespace(namespace), true);
+ resolutionManifest.getResolvedPath(
+ ResolvedPathKey.ofNamespace(identifier.namespace()), true);
if (target == null) {
- throw noSuchNamespaceException(namespace);
+ throw noSuchNamespaceException(identifier.namespace());
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
@@ -280,22 +261,35 @@ public abstract class CatalogHandler {
PolarisCatalogHelpers.tableIdentifierToList(identifier),
PolarisEntityType.TABLE_LIKE,
true /* optional */));
+ AuthorizationRequest overwriteRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ overwriteOp, PolarisSecurableMapper.tableLike(catalogName(), identifier))));
+ AuthorizationRequest fallbackRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ fallbackOp, PolarisSecurableMapper.namespace(catalogName(), namespace))));
+ // Resolve every intent that may be authorized from this shared AuthorizationState. A
+ // request-selective authorizer may use the operation, not just the target securable, to decide
+ // what inputs to resolve.
+ AuthorizationRequest resolutionRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(overwriteRequest.intents().getFirst(), fallbackRequest.intents().getFirst()));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- overwriteOp,
- PolarisSecurableMapper.tableLike(catalogName(), identifier)))));
- authorizeResolvedRegisterTableOverwriteOrThrow(overwriteOp, fallbackOp, identifier);
+ authorizer().resolveAuthorizationInputs(authorizationState, resolutionRequest);
+ authorizeResolvedRegisterTableOverwriteOrThrow(
+ authorizationState, overwriteRequest, fallbackRequest, identifier);
}
protected void authorizeResolvedRegisterTableOverwriteOrThrow(
- PolarisAuthorizableOperation overwriteOp,
- PolarisAuthorizableOperation fallbackOp,
+ AuthorizationState authorizationState,
+ AuthorizationRequest overwriteRequest,
+ AuthorizationRequest fallbackRequest,
TableIdentifier identifier) {
if (resolutionManifest == null) {
throw new IllegalStateException(
@@ -319,26 +313,14 @@ public abstract class CatalogHandler {
ResolvedPathKey.ofTableLike(identifier), PolarisEntitySubType.ICEBERG_TABLE, true);
if (tableTarget != null) {
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- overwriteOp,
- tableTarget,
- null /* secondary */);
+ authorizer().authorize(authorizationState, overwriteRequest).throwIfDenied();
} else {
PolarisResolvedPathWrapper namespaceTarget =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofNamespace(namespace), true);
if (namespaceTarget == null) {
throw noSuchNamespaceException(namespace);
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- fallbackOp, // normal register-table operation
- namespaceTarget,
- null /* secondary */);
+ authorizer().authorize(authorizationState, fallbackRequest).throwIfDenied();
}
initializeCatalog();
@@ -363,22 +345,25 @@ public abstract class CatalogHandler {
}
protected void resolveBasicTableLikeTargetOrThrow(
- PolarisAuthorizableOperation op, TableIdentifier identifier) {
+ AuthorizationState authorizationState,
+ PolarisAuthorizableOperation op,
+ TableIdentifier identifier) {
ensureResolutionManifestForTable(identifier);
- AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op, PolarisSecurableMapper.tableLike(catalogName(), identifier)))));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op, PolarisSecurableMapper.tableLike(catalogName(), identifier))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
}
protected void authorizeResolvedBasicTableLikeOperationOrThrow(
- PolarisAuthorizableOperation op, PolarisEntitySubType subType, TableIdentifier identifier) {
+ AuthorizationState authorizationState,
+ PolarisAuthorizableOperation op,
+ PolarisEntitySubType subType,
+ TableIdentifier identifier) {
PolarisResolvedPathWrapper target =
resolutionManifest.getResolvedPath(ResolvedPathKey.ofTableLike(identifier), subType, true);
if (target == null) {
@@ -386,23 +371,28 @@ public abstract class CatalogHandler {
}
authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ .authorize(
+ authorizationState,
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op, PolarisSecurableMapper.tableLike(catalogName(), identifier)))))
+ .throwIfDenied();
initializeCatalog();
}
protected void resolveAndAuthorizeBasicTableLikeOperationOrThrow(
PolarisAuthorizableOperation op, PolarisEntitySubType subType, TableIdentifier identifier) {
- resolveBasicTableLikeTargetOrThrow(op, identifier);
- authorizeResolvedBasicTableLikeOperationOrThrow(op, subType, identifier);
+ ensureResolutionManifestForTable(identifier);
+ AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
+ resolveBasicTableLikeTargetOrThrow(authorizationState, op, identifier);
+ authorizeResolvedBasicTableLikeOperationOrThrow(authorizationState, op, subType, identifier);
}
protected void authorizeBasicTableLikeOperationsOrThrow(
+ AuthorizationState authorizationState,
EnumSet<PolarisAuthorizableOperation> ops,
PolarisEntitySubType subType,
TableIdentifier identifier) {
@@ -417,13 +407,13 @@ public abstract class CatalogHandler {
}
for (PolarisAuthorizableOperation op : ops) {
- authorizer()
- .authorizeOrThrow(
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op, PolarisSecurableMapper.tableLike(catalogName(), identifier))));
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
}
initializeCatalog();
@@ -441,17 +431,15 @@ public abstract class CatalogHandler {
PolarisCatalogHelpers.tableIdentifierToList(identifier),
PolarisEntityType.TABLE_LIKE)));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ ids.stream()
+ .map(identifier -> PolarisSecurableMapper.tableLike(catalogName(), identifier))
+ .<AuthorizationIntent>map(target -> new SingleTargetAuthorizationIntent(op, target))
+ .toList());
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- ids.stream()
- .map(identifier -> PolarisSecurableMapper.tableLike(catalogName(), identifier))
- .<AuthorizationIntent>map(
- target -> new SingleTargetAuthorizationIntent(op, target))
- .toList()));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
// If one of the paths failed to resolve, throw exception based on the one that
@@ -463,23 +451,13 @@ public abstract class CatalogHandler {
throw notFoundExceptionForTableLikeEntity(identifier, subType);
}
- List<PolarisResolvedPathWrapper> targets =
- ids.stream()
- .map(
- identifier ->
- Optional.ofNullable(
- resolutionManifest.getResolvedPath(
- ResolvedPathKey.ofTableLike(identifier), subType, true))
- .orElseThrow(
- () -> notFoundExceptionForTableLikeEntity(identifier, subType)))
- .toList();
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- targets,
- null /* secondaries */);
+ for (TableIdentifier identifier : ids) {
+ if (resolutionManifest.getResolvedPath(ResolvedPathKey.ofTableLike(identifier), subType, true)
+ == null) {
+ throw notFoundExceptionForTableLikeEntity(identifier, subType);
+ }
+ }
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
@@ -501,17 +479,16 @@ public abstract class CatalogHandler {
PolarisCatalogHelpers.tableIdentifierToList(dst),
PolarisEntityType.TABLE_LIKE,
true /* optional */));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new RenameAuthorizationIntent(
+ op,
+ PolarisSecurableMapper.tableLike(catalogName(), src),
+ PolarisSecurableMapper.namespace(catalogName(), dst.namespace()))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new RenameAuthorizationIntent(
- op,
- PolarisSecurableMapper.tableLike(catalogName(), src),
- PolarisSecurableMapper.tableLike(catalogName(), dst)))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
ResolverStatus status = resolutionManifest.getPrimaryResolverStatusOrThrow();
if (status.getStatus() == ResolverStatus.StatusEnum.PATH_COULD_NOT_BE_FULLY_RESOLVED
&& status.getFailedToResolvePath().lastEntityType() == PolarisEntityType.NAMESPACE) {
@@ -543,17 +520,7 @@ public abstract class CatalogHandler {
break;
}
- PolarisResolvedPathWrapper target =
- resolutionManifest.getResolvedPath(ResolvedPathKey.ofTableLike(src), subType, true);
- PolarisResolvedPathWrapper secondary =
- resolutionManifest.getResolvedPath(ResolvedPathKey.ofNamespace(dst.namespace()), true);
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- secondary);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java
index 645ffad66c..dfc861b9a0 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java
@@ -935,18 +935,20 @@ public abstract class IcebergCatalogHandler extends CatalogHandler implements Au
PolarisAuthorizableOperation write =
PolarisAuthorizableOperation.LOAD_TABLE_WITH_WRITE_DELEGATION;
- resolveBasicTableLikeTargetOrThrow(write, tableIdentifier);
+ ensureResolutionManifestForTable(tableIdentifier);
+ AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
+ resolveBasicTableLikeTargetOrThrow(authorizationState, write, tableIdentifier);
Set<PolarisStorageActions> actionsRequested =
new HashSet<>(Set.of(PolarisStorageActions.READ, PolarisStorageActions.LIST));
try {
authorizeResolvedBasicTableLikeOperationOrThrow(
- write, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
+ authorizationState, write, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
actionsRequested.add(PolarisStorageActions.WRITE);
} catch (ForbiddenException e) {
// Reuse the already-resolved table view for the read-delegation fallback.
authorizeResolvedBasicTableLikeOperationOrThrow(
- read, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
+ authorizationState, read, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
}
return actionsRequested;
@@ -986,40 +988,98 @@ public abstract class IcebergCatalogHandler extends CatalogHandler implements Au
PolarisEntityType.TABLE_LIKE,
true /* optional */));
- // Resolve once for the shared table target before auth fallback. Today resolution depends on
- // the principal and target, not the register-table operation, so either delegation op is
- // sufficient for building the manifest.
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- PolarisAuthorizableOperation.REGISTER_TABLE_WITH_READ_DELEGATION,
- PolarisSecurableMapper.tableLike(catalogName(), tableIdentifier)))));
- try {
- if (overwrite) {
+ if (overwrite) {
+ AuthorizationRequest writeOverwriteRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE_WITH_WRITE_DELEGATION,
+ PolarisSecurableMapper.tableLike(catalogName(), tableIdentifier))));
+ AuthorizationRequest writeFallbackRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION,
+ PolarisSecurableMapper.namespace(
+ catalogName(), tableIdentifier.namespace()))));
+ AuthorizationRequest readOverwriteRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE_WITH_READ_DELEGATION,
+ PolarisSecurableMapper.tableLike(catalogName(), tableIdentifier))));
+ AuthorizationRequest readFallbackRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_READ_DELEGATION,
+ PolarisSecurableMapper.namespace(
+ catalogName(), tableIdentifier.namespace()))));
+
+ // Resolve every write/read and overwrite/fallback intent that may be authorized from this
+ // shared AuthorizationState. A request-selective authorizer may use the operation, not just
+ // the target securable, to decide what inputs to resolve.
+ authorizer()
+ .resolveAuthorizationInputs(
+ authorizationState,
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ writeOverwriteRequest.intents().getFirst(),
+ writeFallbackRequest.intents().getFirst(),
+ readOverwriteRequest.intents().getFirst(),
+ readFallbackRequest.intents().getFirst())));
+
+ try {
authorizeResolvedRegisterTableOverwriteOrThrow(
- PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE_WITH_WRITE_DELEGATION,
- PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION,
- tableIdentifier);
- } else {
- authorizeResolvedCreateTableLikeUnderNamespaceOperationOrThrow(
- PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION, tableIdentifier);
- }
- actionsRequested.add(PolarisStorageActions.WRITE);
- } catch (ForbiddenException e) {
- if (overwrite) {
+ authorizationState, writeOverwriteRequest, writeFallbackRequest, tableIdentifier);
+ actionsRequested.add(PolarisStorageActions.WRITE);
+ } catch (ForbiddenException e) {
authorizeResolvedRegisterTableOverwriteOrThrow(
- PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE_WITH_READ_DELEGATION,
- PolarisAuthorizableOperation.REGISTER_TABLE_WITH_READ_DELEGATION,
- tableIdentifier);
- } else {
+ authorizationState, readOverwriteRequest, readFallbackRequest, tableIdentifier);
+ }
+ } else {
+ AuthorizationRequest writeCreateRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION,
+ PolarisSecurableMapper.namespace(
+ catalogName(), tableIdentifier.namespace()))));
+ AuthorizationRequest readCreateRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_READ_DELEGATION,
+ PolarisSecurableMapper.namespace(
+ catalogName(), tableIdentifier.namespace()))));
+
+ // Resolve both delegation intents before authorization so the read fallback can reuse the
+ // same AuthorizationState without assuming operation-independent resolution.
+ authorizer()
+ .resolveAuthorizationInputs(
+ authorizationState,
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ writeCreateRequest.intents().getFirst(),
+ readCreateRequest.intents().getFirst())));
+
+ try {
authorizeResolvedCreateTableLikeUnderNamespaceOperationOrThrow(
- PolarisAuthorizableOperation.REGISTER_TABLE_WITH_READ_DELEGATION, tableIdentifier);
+ authorizationState, writeCreateRequest, tableIdentifier);
+ actionsRequested.add(PolarisStorageActions.WRITE);
+ } catch (ForbiddenException e) {
+ authorizeResolvedCreateTableLikeUnderNamespaceOperationOrThrow(
+ authorizationState, readCreateRequest, tableIdentifier);
}
}
@@ -1230,7 +1290,10 @@ public abstract class IcebergCatalogHandler extends CatalogHandler implements Au
getUpdateTableAuthorizableOperations(request, getResolvedCatalogEntity());
authorizeBasicTableLikeOperationsOrThrow(
- authorizableOperations, PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier);
+ authorizationState,
+ authorizableOperations,
+ PolarisEntitySubType.ICEBERG_TABLE,
+ tableIdentifier);
CatalogEntity catalog = getResolvedCatalogEntity();
if (catalog.isStaticFacade()) {
diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalogHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalogHandler.java
index e731289dd1..1bb6d0a0f8 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalogHandler.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalogHandler.java
@@ -149,15 +149,14 @@ public abstract class PolicyCatalogHandler extends CatalogHandler {
PolarisCatalogHelpers.identifierToList(identifier.namespace(), identifier.name()),
PolarisEntityType.POLICY,
true /* optional */));
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op, PolarisSecurableMapper.policy(catalogName(), identifier))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op, PolarisSecurableMapper.policy(catalogName(), identifier)))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper target =
resolutionManifest.getResolvedPath(
@@ -166,13 +165,7 @@ public abstract class PolicyCatalogHandler extends CatalogHandler {
throw new NoSuchPolicyException(String.format("Policy does not exist: %s", identifier));
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- target,
- null /* secondary */);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
@@ -202,28 +195,21 @@ public abstract class PolicyCatalogHandler extends CatalogHandler {
private void authorizeBasicCatalogOperationOrThrow(PolarisAuthorizableOperation op) {
resolutionManifest = newResolutionManifest();
+ AuthorizationRequest authorizationRequest =
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new SingleTargetAuthorizationIntent(
+ op, PolarisSecurableMapper.catalog(catalogName()))));
AuthorizationState authorizationState = new AuthorizationState(resolutionManifest);
- authorizer()
- .resolveAuthorizationInputs(
- authorizationState,
- new AuthorizationRequest(
- polarisPrincipal(),
- List.of(
- new SingleTargetAuthorizationIntent(
- op, PolarisSecurableMapper.catalog(catalogName())))));
+ authorizer().resolveAuthorizationInputs(authorizationState, authorizationRequest);
PolarisResolvedPathWrapper targetCatalog =
resolutionManifest.getResolvedReferenceCatalogEntity();
if (targetCatalog == null) {
throw new NotFoundException("Catalog not found");
}
- authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- targetCatalog,
- null);
+ authorizer().authorize(authorizationState, authorizationRequest).throwIfDenied();
initializeCatalog();
}
@@ -287,12 +273,16 @@ public abstract class PolicyCatalogHandler extends CatalogHandler {
determinePolicyMappingOperation(target, targetWrapper, isAttach);
authorizer()
- .authorizeOrThrow(
- polarisPrincipal(),
- resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(),
- op,
- policyWrapper,
- targetWrapper);
+ .authorize(
+ authorizationState,
+ new AuthorizationRequest(
+ polarisPrincipal(),
+ List.of(
+ new PolicyAttachmentAuthorizationIntent(
+ op,
+ PolarisSecurableMapper.policy(catalogName(), identifier),
+ PolarisSecurableMapper.policyAttachmentTarget(catalogName(), target)))))
+ .throwIfDenied();
initializeCatalog();
}
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java
index 66d938239e..0ea5a0fbaa 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java
@@ -50,6 +50,7 @@ import org.apache.polaris.core.admin.model.ExternalCatalog;
import org.apache.polaris.core.admin.model.IcebergRestConnectionConfigInfo;
import org.apache.polaris.core.admin.model.OAuthClientCredentialsParameters;
import org.apache.polaris.core.admin.model.StorageConfigInfo;
+import org.apache.polaris.core.auth.AuthorizationDecision;
import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.auth.PolarisPrincipal;
@@ -133,6 +134,7 @@ public class PolarisAdminServiceTest {
})
.when(authorizer)
.resolveAuthorizationInputs(any(), any());
+ when(authorizer.authorize(any(), any())).thenReturn(AuthorizationDecision.allow());
adminService =
new PolarisAdminService(
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerTest.java
index 0d84acf224..a2d54d7bd6 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerTest.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerTest.java
@@ -23,9 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -48,7 +47,6 @@ import org.apache.iceberg.TableOperations;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
-import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.iceberg.rest.credentials.Credential;
import org.apache.iceberg.rest.requests.ImmutableRegisterTableRequest;
import org.apache.iceberg.rest.requests.RegisterTableRequest;
@@ -57,6 +55,7 @@ import org.apache.iceberg.rest.responses.ImmutableLoadCredentialsResponse;
import org.apache.iceberg.rest.responses.LoadTableResponse;
import org.apache.iceberg.types.Types;
import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.auth.AuthorizationDecision;
import org.apache.polaris.core.auth.AuthorizationRequest;
import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
@@ -144,6 +143,7 @@ class IcebergCatalogHandlerTest {
when(resolutionManifest.getResolvedPath(any(), any())).thenReturn(resolvedPath);
when(resolutionManifest.getResolvedPath(any())).thenReturn(resolvedPath);
when(resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles()).thenReturn(Set.of());
+ when(authorizer.authorize(any(), any())).thenReturn(AuthorizationDecision.allow());
// initializeCatalog() reads the resolved catalog entity to decide federated vs. local.
// Return a CatalogEntity without a connection config so we take the local-catalog path.
@@ -208,6 +208,12 @@ class IcebergCatalogHandlerTest {
return table;
}
+ private static boolean hasOperation(
+ AuthorizationRequest request, PolarisAuthorizableOperation operation) {
+ return request != null
+ && request.intents().stream().anyMatch(intent -> intent.getOperation().equals(operation));
+ }
+
@SuppressWarnings({"unchecked", "rawtypes"})
private void assertVendedActions(PolarisStorageActions... actions) {
ArgumentCaptor<Set<PolarisStorageActions>> actionsCaptor =
@@ -243,17 +249,17 @@ class IcebergCatalogHandlerTest {
Catalog catalog = mockRegisterTableCatalog(false);
when(accessDelegationModeResolver.resolve(eq(EnumSet.of(VENDED_CREDENTIALS)), any()))
.thenReturn(Optional.of(VENDED_CREDENTIALS));
- doThrow(new ForbiddenException("write delegation denied"))
- .when(authorizer)
- .authorizeOrThrow(
- any(),
- any(),
- eq(PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION),
- nullable(PolarisResolvedPathWrapper.class),
- nullable(PolarisResolvedPathWrapper.class));
@SuppressWarnings("resource")
IcebergCatalogHandler handler = newHandler();
+ when(authorizer.authorize(
+ any(),
+ argThat(
+ request ->
+ hasOperation(
+ request,
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION))))
+ .thenReturn(AuthorizationDecision.deny("write delegation denied"));
LoadTableResponse response =
handler.registerTable(
@@ -290,17 +296,17 @@ class IcebergCatalogHandlerTest {
when(catalogEntity.isExternal()).thenReturn(false);
when(accessDelegationModeResolver.resolve(eq(EnumSet.of(VENDED_CREDENTIALS)), any()))
.thenReturn(Optional.of(VENDED_CREDENTIALS));
- doThrow(new ForbiddenException("write delegation denied"))
- .when(authorizer)
- .authorizeOrThrow(
- any(),
- any(),
- eq(PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION),
- nullable(PolarisResolvedPathWrapper.class),
- nullable(PolarisResolvedPathWrapper.class));
@SuppressWarnings("resource")
IcebergCatalogHandler handler = newHandler();
+ when(authorizer.authorize(
+ any(),
+ argThat(
+ request ->
+ hasOperation(
+ request,
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION))))
+ .thenReturn(AuthorizationDecision.deny("write delegation denied"));
when(resolutionManifest.getResolvedPath(
eq(ResolvedPathKey.ofTableLike(TABLE2)),
eq(PolarisEntitySubType.ICEBERG_TABLE),
@@ -314,6 +320,18 @@ class IcebergCatalogHandlerTest {
verify(catalog).registerTable(TABLE2, TABLE_LOCATION, true);
assertThat(response.credentials()).hasSize(1);
assertVendedActions(PolarisStorageActions.READ, PolarisStorageActions.LIST);
+ ArgumentCaptor<AuthorizationRequest> resolveRequestCaptor =
+ ArgumentCaptor.forClass(AuthorizationRequest.class);
+ verify(authorizer).resolveAuthorizationInputs(any(), resolveRequestCaptor.capture());
+ assertThat(
+ resolveRequestCaptor.getValue().intents().stream()
+ .map(intent -> intent.getOperation())
+ .toList())
+ .containsExactly(
+ PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE_WITH_WRITE_DELEGATION,
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_WRITE_DELEGATION,
+ PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE_WITH_READ_DELEGATION,
+ PolarisAuthorizableOperation.REGISTER_TABLE_WITH_READ_DELEGATION);
}
@Test
@@ -323,24 +341,23 @@ class IcebergCatalogHandlerTest {
when(catalog.loadTable(TABLE2)).thenReturn(table);
when(accessDelegationModeResolver.resolve(any(), any()))
.thenReturn(Optional.of(VENDED_CREDENTIALS));
- doThrow(new ForbiddenException("write delegation denied"))
- .when(authorizer)
- .authorizeOrThrow(
- any(),
- any(),
- eq(PolarisAuthorizableOperation.LOAD_TABLE_WITH_WRITE_DELEGATION),
- nullable(PolarisResolvedPathWrapper.class),
- nullable(PolarisResolvedPathWrapper.class));
@SuppressWarnings("unchecked")
ArgumentCaptor<AuthorizationRequest> requestCaptor =
ArgumentCaptor.forClass(AuthorizationRequest.class);
ArgumentCaptor<AuthorizationState> stateCaptor =
ArgumentCaptor.forClass(AuthorizationState.class);
- ArgumentCaptor<PolarisAuthorizableOperation> operationCaptor =
- ArgumentCaptor.forClass(PolarisAuthorizableOperation.class);
+ ArgumentCaptor<AuthorizationRequest> authorizeRequestCaptor =
+ ArgumentCaptor.forClass(AuthorizationRequest.class);
@SuppressWarnings("resource")
IcebergCatalogHandler handler = newHandler();
+ when(authorizer.authorize(
+ any(),
+ argThat(
+ request ->
+ hasOperation(
+ request, PolarisAuthorizableOperation.LOAD_TABLE_WITH_WRITE_DELEGATION))))
+ .thenReturn(AuthorizationDecision.deny("write delegation denied"));
handler.loadCredentials(TABLE2, Optional.empty());
@@ -349,13 +366,11 @@ class IcebergCatalogHandlerTest {
assertThat(requestCaptor.getValue().intents().getFirst().getOperation())
.isEqualTo(PolarisAuthorizableOperation.LOAD_TABLE_WITH_WRITE_DELEGATION);
verify(authorizer, org.mockito.Mockito.times(2))
- .authorizeOrThrow(
- any(),
- any(),
- operationCaptor.capture(),
- nullable(PolarisResolvedPathWrapper.class),
- nullable(PolarisResolvedPathWrapper.class));
- assertThat(operationCaptor.getAllValues())
+ .authorize(any(), authorizeRequestCaptor.capture());
+ assertThat(
+ authorizeRequestCaptor.getAllValues().stream()
+ .map(request -> request.intents().getFirst().getOperation())
+ .toList())
.containsExactly(
PolarisAuthorizableOperation.LOAD_TABLE_WITH_WRITE_DELEGATION,
PolarisAuthorizableOperation.LOAD_TABLE_WITH_READ_DELEGATION);
@@ -379,8 +394,8 @@ class IcebergCatalogHandlerTest {
ArgumentCaptor.forClass(AuthorizationRequest.class);
ArgumentCaptor<AuthorizationState> stateCaptor =
ArgumentCaptor.forClass(AuthorizationState.class);
- ArgumentCaptor<PolarisAuthorizableOperation> operationCaptor =
- ArgumentCaptor.forClass(PolarisAuthorizableOperation.class);
+ ArgumentCaptor<AuthorizationRequest> authorizeRequestCaptor =
+ ArgumentCaptor.forClass(AuthorizationRequest.class);
@SuppressWarnings("resource")
IcebergCatalogHandler handler = newHandler();
@@ -391,14 +406,8 @@ class IcebergCatalogHandlerTest {
assertThat(stateCaptor.getValue().getResolutionManifest()).isSameAs(resolutionManifest);
assertThat(requestCaptor.getValue().intents().getFirst().getOperation())
.isEqualTo(PolarisAuthorizableOperation.UPDATE_TABLE);
- verify(authorizer)
- .authorizeOrThrow(
- any(),
- any(),
- operationCaptor.capture(),
- nullable(PolarisResolvedPathWrapper.class),
- nullable(PolarisResolvedPathWrapper.class));
- assertThat(operationCaptor.getValue())
+ verify(authorizer).authorize(any(), authorizeRequestCaptor.capture());
+ assertThat(authorizeRequestCaptor.getValue().intents().getFirst().getOperation())
.isEqualTo(PolarisAuthorizableOperation.SET_TABLE_PROPERTIES);
}
diff --git a/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java b/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java
index 3e2e2532e8..58df264422 100644
--- a/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java
+++ b/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java
@@ -41,6 +41,7 @@ import java.util.stream.Stream;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.auth.AuthorizationDecision;
import org.apache.polaris.core.auth.AuthorizationState;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.auth.PolarisPrincipal;
@@ -254,6 +255,7 @@ public record TestServices(
})
.when(authorizer)
.resolveAuthorizationInputs(any(), any());
+ Mockito.when(authorizer.authorize(any(), any())).thenReturn(AuthorizationDecision.allow());
// Application level
StorageCredentialCacheConfig storageCredentialCacheConfig = () -> 10_000;