adutra commented on code in PR #3999: URL: https://github.com/apache/polaris/pull/3999#discussion_r2940192496
########## polaris-core/src/main/java/org/apache/polaris/core/auth/RbacOperationSemantics.java: ########## @@ -0,0 +1,713 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.core.auth; + +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ATTACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_DETACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_ATTACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_DETACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_ATTACH; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_DETACH; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_READ; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_WRITE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_MANAGE_GRANTS_FOR_GRANTEE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_RESET_CREDENTIALS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_MANAGE_GRANTS_FOR_GRANTEE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROTATE_CREDENTIALS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.SERVICE_MANAGE_ACCESS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_PARTITION_SPEC; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_SCHEMA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_SNAPSHOT; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_SORT_ORDER; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ASSIGN_UUID; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ATTACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_DETACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_READ_DATA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_PARTITION_SPECS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_SNAPSHOTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_SNAPSHOT_REF; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_STATISTICS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_CURRENT_SCHEMA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_DEFAULT_SORT_ORDER; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_LOCATION; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_SNAPSHOT_REF; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_STATISTICS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_UPGRADE_FORMAT_VERSION; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_WRITE_DATA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_WRITE_PROPERTIES; + +import com.google.common.base.Preconditions; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.List; +import org.apache.polaris.core.entity.PolarisPrivilege; + +/** Polaris RBAC-specific interpretation of an authorizable operation. */ +record RbacOperationSemantics( + EnumSet<PolarisPrivilege> targetPrivileges, + EnumSet<PolarisPrivilege> secondaryPrivileges, + ResolvedPathRooting targetScope, + ResolvedPathRooting secondaryScope) { + + private RbacOperationSemantics( Review Comment: Not sure we need this constructor, why don't you update `RBAC_SEMANTICS_BY_OPERATION` using `EnumSet` as below: ```java RBAC_SEMANTICS_BY_OPERATION.put( PolarisAuthorizableOperation.LIST_NAMESPACES, new RbacOperationSemantics(EnumSet.of(NAMESPACE_LIST), null, ResolvedPathRooting.ROOT, null)); ``` ########## polaris-core/src/main/java/org/apache/polaris/core/auth/RbacOperationSemantics.java: ########## @@ -0,0 +1,713 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.core.auth; + +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ATTACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_DETACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_ROLE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.CATALOG_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_ATTACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_DETACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.NAMESPACE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_ATTACH; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_DETACH; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_READ; +import static org.apache.polaris.core.entity.PolarisPrivilege.POLICY_WRITE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_MANAGE_GRANTS_FOR_GRANTEE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_RESET_CREDENTIALS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_MANAGE_GRANTS_FOR_GRANTEE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROLE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_ROTATE_CREDENTIALS; +import static org.apache.polaris.core.entity.PolarisPrivilege.PRINCIPAL_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.SERVICE_MANAGE_ACCESS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_PARTITION_SPEC; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_SCHEMA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_SNAPSHOT; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ADD_SORT_ORDER; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ASSIGN_UUID; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_ATTACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_DETACH_POLICY; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_READ_DATA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_PARTITION_SPECS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_SNAPSHOTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_SNAPSHOT_REF; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_REMOVE_STATISTICS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_CURRENT_SCHEMA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_DEFAULT_SORT_ORDER; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_LOCATION; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_SNAPSHOT_REF; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_SET_STATISTICS; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_UPGRADE_FORMAT_VERSION; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_WRITE_DATA; +import static org.apache.polaris.core.entity.PolarisPrivilege.TABLE_WRITE_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_CREATE; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_DROP; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_LIST; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_LIST_GRANTS; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_MANAGE_GRANTS_ON_SECURABLE; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_READ_PROPERTIES; +import static org.apache.polaris.core.entity.PolarisPrivilege.VIEW_WRITE_PROPERTIES; + +import com.google.common.base.Preconditions; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.List; +import org.apache.polaris.core.entity.PolarisPrivilege; + +/** Polaris RBAC-specific interpretation of an authorizable operation. */ +record RbacOperationSemantics( + EnumSet<PolarisPrivilege> targetPrivileges, + EnumSet<PolarisPrivilege> secondaryPrivileges, + ResolvedPathRooting targetScope, + ResolvedPathRooting secondaryScope) { Review Comment: `secondaryScope` is either null (90% of cases), or identical to `targetScope`. Can we use one single `ResolvedPathRooting` maybe? ########## polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizableOperation.java: ########## Review Comment: Nice! ########## polaris-core/src/main/java/org/apache/polaris/core/auth/FullyQualifiedPath.java: ########## @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.core.auth; + +import com.google.common.base.Preconditions; +import jakarta.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import org.apache.polaris.core.entity.PolarisEntityType; +import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; +import org.apache.polaris.core.persistence.ResolvedPolarisEntity; + +/** Lexical fully qualified resource path split into leaf and ordered parent segments. */ +public record FullyQualifiedPath(PathSegment leaf, List<PathSegment> parents) { + + public FullyQualifiedPath { + Preconditions.checkNotNull(leaf, "leaf"); + Preconditions.checkNotNull(parents, "parents"); + parents = List.copyOf(parents); + } + + public static FullyQualifiedPath of( + PolarisSecurable securable, @Nullable String referenceCatalogName) { + List<PathSegment> namePartSegments = namePartSegments(securable); + Preconditions.checkState( + !namePartSegments.isEmpty(), + "FullyQualifiedPath produced no segments for entityType=%s nameParts=%s", + securable.getEntityType(), + securable.getNameParts()); + + int leafIndex = namePartSegments.size() - 1; + PathSegment leaf = namePartSegments.get(leafIndex); + List<PathSegment> parents = new ArrayList<>(); + if (isCatalogScopedType(securable.getEntityType())) { + Preconditions.checkArgument( + referenceCatalogName != null && !referenceCatalogName.isBlank(), + "referenceCatalogName must be non-empty for catalog-scoped securable entityType=%s nameParts=%s", + securable.getEntityType(), + securable.getNameParts()); + parents.add(new PathSegment(PolarisEntityType.CATALOG, referenceCatalogName)); + } + parents.addAll(namePartSegments.subList(0, leafIndex)); + return new FullyQualifiedPath(leaf, parents); + } + + /** + * Temporary adapter used while OPA serialization still accepts resolved paths alongside intent + * paths. Remove this overload when resolved-path callers are retired. + */ + public static FullyQualifiedPath of(PolarisResolvedPathWrapper wrapper) { + Preconditions.checkNotNull(wrapper, "wrapper"); + ResolvedPolarisEntity resolvedLeaf = wrapper.getResolvedLeafEntity(); + Preconditions.checkNotNull(resolvedLeaf, "wrapper.getResolvedLeafEntity()"); + + PathSegment leaf = + new PathSegment(resolvedLeaf.getEntity().getType(), resolvedLeaf.getEntity().getName()); + List<PathSegment> parents = new ArrayList<>(); + List<ResolvedPolarisEntity> resolvedParents = wrapper.getResolvedParentPath(); + if (resolvedParents != null) { + for (ResolvedPolarisEntity resolvedParent : resolvedParents) { + // Omit ROOT from fully qualified paths. It is an internal RBAC-only ancestor + if (resolvedParent.getEntity().getType() == PolarisEntityType.ROOT) { + continue; + } Review Comment: Ack, but we are introducing a specific behavior in polaris-core. Shouldn't we instead keep the `ROOT` entity here, and let specific authorizers filter it out? I feel like the `ROOT` case deserves some more thinking. It's also troubling that the current code sometimes prepends it, and sometimes not. ########## polaris-core/src/main/java/org/apache/polaris/core/auth/AuthorizationRequest.java: ########## @@ -56,6 +67,13 @@ static AuthorizationRequest of( @Nonnull List<AuthorizationTargetBinding> getTargetBindings(); + /** Returns the request reference catalog name, if provided by the caller. */ + @Nullable + @Value.Default + default String getReferenceCatalogName() { + return null; + } Review Comment: This should be enough: ```suggestion @Nullable String getReferenceCatalogName(); ``` But how about using an `Optional` here? ########## polaris-core/src/main/java/org/apache/polaris/core/auth/FullyQualifiedPath.java: ########## @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.core.auth; + +import com.google.common.base.Preconditions; +import jakarta.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import org.apache.polaris.core.entity.PolarisEntityType; +import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; +import org.apache.polaris.core.persistence.ResolvedPolarisEntity; + +/** Lexical fully qualified resource path split into leaf and ordered parent segments. */ +public record FullyQualifiedPath(PathSegment leaf, List<PathSegment> parents) { Review Comment: But this class is in polaris-core, which tends to indicate that it's not only for the OPA authorizer. Having both models in polaris-core seems a bit overkill. This model is imho richer than `PolarisSecurable`. I wonder if you couldn't merge both models together, e.g.: ```java @PolarisImmutable public interface PolarisSecurable { /** Returns the path segments that identify the securable, in hierarchical order. */ @Nonnull List<PathSegment> getPathSegments(); default PathSegment getLeafPathSegment() { return getPathSegments().getLast(); } @Value.Check default void validate() { Preconditions.checkState(!getPathSegments().isEmpty(), "path segments must not be empty"); } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
