gh-yzou commented on code in PR #1357:
URL: https://github.com/apache/polaris/pull/1357#discussion_r2047814705


##########
polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java:
##########
@@ -457,6 +463,36 @@ public class PolarisAuthorizerImpl implements 
PolarisAuthorizer {
     SUPER_PRIVILEGES.putAll(
         CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE,
         List.of(CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE, 
CATALOG_MANAGE_ACCESS));
+
+    // Policy

Review Comment:
   nit -> Policy privileges



##########
polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java:
##########
@@ -457,6 +463,36 @@ public class PolarisAuthorizerImpl implements 
PolarisAuthorizer {
     SUPER_PRIVILEGES.putAll(
         CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE,
         List.of(CATALOG_ROLE_MANAGE_GRANTS_FOR_GRANTEE, 
CATALOG_MANAGE_ACCESS));
+
+    // Policy
+    SUPER_PRIVILEGES.putAll(
+        POLICY_CREATE,
+        List.of(
+            POLICY_CREATE, POLICY_FULL_METADATA, CATALOG_MANAGE_METADATA, 
CATALOG_MANAGE_CONTENT));
+    SUPER_PRIVILEGES.putAll(
+        POLICY_WRITE,
+        List.of(
+            POLICY_WRITE, POLICY_FULL_METADATA, CATALOG_MANAGE_METADATA, 
CATALOG_MANAGE_CONTENT));
+    SUPER_PRIVILEGES.putAll(
+        POLICY_DROP,
+        List.of(
+            POLICY_DROP, POLICY_FULL_METADATA, CATALOG_MANAGE_METADATA, 
CATALOG_MANAGE_CONTENT));
+    SUPER_PRIVILEGES.putAll(
+        POLICY_READ,
+        List.of(
+            POLICY_READ,
+            POLICY_WRITE,
+            POLICY_FULL_METADATA,
+            CATALOG_MANAGE_METADATA,
+            CATALOG_MANAGE_CONTENT));
+    SUPER_PRIVILEGES.putAll(
+        POLICY_LIST,

Review Comment:
   Does it mean people with POLICY_READ or POLICY_WRITE capability, may not 
have capability to list the policies? it sounds little bit wired to me, usually 
if I have the read capability, i assume we should be able to list all policies, 
right? Do we intend to stay similar as how the previliege look like for tables 
or veiw? 



##########
service/common/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalogHandler.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.service.catalog.policy;
+
+import jakarta.ws.rs.core.SecurityContext;
+import java.util.Arrays;
+import java.util.HashSet;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
+import org.apache.polaris.core.auth.PolarisAuthorizer;
+import org.apache.polaris.core.catalog.PolarisCatalogHelpers;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.persistence.PolarisEntityManager;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.resolver.ResolverPath;
+import org.apache.polaris.core.policy.PolicyType;
+import org.apache.polaris.core.policy.exceptions.NoSuchPolicyException;
+import org.apache.polaris.service.catalog.common.CatalogHandler;
+import org.apache.polaris.service.types.CreatePolicyRequest;
+import org.apache.polaris.service.types.ListPoliciesResponse;
+import org.apache.polaris.service.types.LoadPolicyResponse;
+import org.apache.polaris.service.types.PolicyIdentifier;
+import org.apache.polaris.service.types.UpdatePolicyRequest;
+
+public class PolicyCatalogHandler extends CatalogHandler {
+
+  private PolarisMetaStoreManager metaStoreManager;
+
+  private PolicyCatalog policyCatalog;
+
+  public PolicyCatalogHandler(
+      CallContext callContext,
+      PolarisEntityManager entityManager,
+      PolarisMetaStoreManager metaStoreManager,
+      SecurityContext securityContext,
+      String catalogName,
+      PolarisAuthorizer authorizer) {
+    super(callContext, entityManager, securityContext, catalogName, 
authorizer);
+    this.metaStoreManager = metaStoreManager;
+  }
+
+  @Override
+  protected void initializeCatalog() {
+    this.policyCatalog = new PolicyCatalog(metaStoreManager, callContext, 
this.resolutionManifest);
+  }
+
+  public ListPoliciesResponse listPolicies(Namespace parent, PolicyType 
policyType) {
+    PolarisAuthorizableOperation op = PolarisAuthorizableOperation.LIST_POLICY;
+    authorizeBasicNamespaceOperationOrThrow(op, parent);
+
+    return ListPoliciesResponse.builder()
+        .setIdentifiers(new HashSet<>(policyCatalog.listPolicies(parent, 
policyType)))
+        .build();
+  }
+
+  public LoadPolicyResponse createPolicy(Namespace namespace, 
CreatePolicyRequest request) {
+    PolarisAuthorizableOperation op = 
PolarisAuthorizableOperation.CREATE_POLICY;
+    PolicyIdentifier identifier =
+        
PolicyIdentifier.builder().setNamespace(namespace).setName(request.getName()).build();
+
+    authorizeCreatePolicyUnderNamespaceOperationOrThrow(op, identifier);
+
+    return LoadPolicyResponse.builder()
+        .setPolicy(
+            policyCatalog.createPolicy(
+                identifier, request.getType(), request.getDescription(), 
request.getContent()))
+        .build();
+  }
+
+  public LoadPolicyResponse loadPolicy(PolicyIdentifier identifier) {
+    PolarisAuthorizableOperation op = PolarisAuthorizableOperation.LOAD_POLICY;
+    authorizeBasicPolicyOperationOrThrow(op, identifier);
+
+    return 
LoadPolicyResponse.builder().setPolicy(policyCatalog.loadPolicy(identifier)).build();
+  }
+
+  public LoadPolicyResponse updatePolicy(PolicyIdentifier identifier, 
UpdatePolicyRequest request) {
+    PolarisAuthorizableOperation op = 
PolarisAuthorizableOperation.UPDATE_POLICY;
+    authorizeBasicPolicyOperationOrThrow(op, identifier);
+
+    return LoadPolicyResponse.builder()
+        .setPolicy(
+            policyCatalog.updatePolicy(
+                identifier,
+                request.getDescription(),
+                request.getContent(),
+                request.getCurrentPolicyVersion()))
+        .build();
+  }
+
+  public boolean dropPolicy(PolicyIdentifier identifier, boolean detachAll) {
+    PolarisAuthorizableOperation op = PolarisAuthorizableOperation.DROP_POLICY;
+    authorizeBasicPolicyOperationOrThrow(op, identifier);
+
+    return policyCatalog.dropPolicy(identifier, detachAll);
+  }
+
+  private void authorizeCreatePolicyUnderNamespaceOperationOrThrow(
+      PolarisAuthorizableOperation op, PolicyIdentifier identifier) {
+    resolutionManifest =
+        entityManager.prepareResolutionManifest(callContext, securityContext, 
catalogName);
+    resolutionManifest.addPath(
+        new ResolverPath(
+            Arrays.asList(identifier.getNamespace().levels()), 
PolarisEntityType.NAMESPACE),
+        identifier.getNamespace());
+
+    // When creating an entity under a namespace, the authz target is the 
namespace, but we must
+    // also
+    // add the actual path that will be created as an "optional" passthrough 
resolution path to
+    // indicate that the underlying catalog is "allowed" to check the creation 
path for a
+    // conflicting
+    // entity.
+    resolutionManifest.addPassthroughPath(

Review Comment:
   This code seems mostly duplicate with 
authorizeBasicNamespaceOperationOrThrow, maybe we can simply add a parameter 
extraPassthroughPolicies there, and let them go through the same code to make 
sure we can maximize the reuse.
   We probably should switch 
authorizeCreateTableLikeUnderNamespaceOperationOrThrow to use this also, but i 
don't  think you need to do that in your PR



##########
service/common/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java:
##########
@@ -213,7 +214,8 @@ public Policy updatePolicy(
               currentPolicyVersion, policyVersion));
     }
 
-    if (newDescription.equals(policy.getDescription()) && 
newContent.equals(policy.getContent())) {
+    if (Objects.equals(newDescription, policy.getDescription())

Review Comment:
   what is the reason to change the comparison method here?



-- 
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]

Reply via email to