You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "xunliu (via GitHub)" <gi...@apache.org> on 2024/08/28 14:12:10 UTC

[PR] [#4698] feat(core): Extended Apache Ranger authorization by configuration [gravitino]

xunliu opened a new pull request, #4744:
URL: https://github.com/apache/gravitino/pull/4744

   ### What changes were proposed in this pull request?
   
   1. Add `authorization-hive.properties`, we can use this command format to extend another Ranger authorization plugin.
   2. Read config file to initial Gravitino and Ranger privilege mapping and another params.
   
   ### Why are the changes needed?
   
   Fix: #4698
   
   ### Does this PR introduce _any_ user-facing change?
   
   NA
   
   ### How was this patch tested?
   
   CI Passed.
   


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by rules [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1765350708


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -63,18 +62,23 @@
  * 4. The Ranger policy also supports multiple users and groups, But we only use a user or group to
  * implement Gravitino Owner concept. <br>
  */
-public class RangerAuthorizationPlugin implements AuthorizationPlugin {
+public abstract class RangerAuthorizationPlugin
+    implements AuthorizationPlugin, RangerPrivilegesMappingProvider {
   private static final Logger LOG = LoggerFactory.getLogger(RangerAuthorizationPlugin.class);
 
-  protected String catalogProvider;
+  /** Mapping Gravitino privilege name to the Ranger privileges configuration. */
+  private Map<Privilege.Name, Set<RangerPrivilege>> privilegesMapping;
+  /** The owner privileges, the owner can do anything on the metadata object configuration */
+  private Set<RangerPrivilege> ownerPrivileges;
+  /** The Ranger policy resource defines configuration. */
+  private List<String> policyResourceDefines;

Review Comment:
   DONE.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationHivePlugin.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+import org.apache.gravitino.authorization.ranger.RangerPrivilege.RangerHivePrivilege;
+import org.apache.gravitino.authorization.ranger.reference.RangerDefines.PolicyResource;
+
+public class RangerAuthorizationHivePlugin extends RangerAuthorizationPlugin {
+  public RangerAuthorizationHivePlugin(Map<String, String> config) {
+    super(config);
+  }
+
+  /** Set the default mapping Gravitino privilege name to the Ranger rule */
+  public Map<Privilege.Name, Set<RangerPrivilege>> privilegesMappingRule() {
+    return ImmutableMap.of(
+        Privilege.Name.CREATE_SCHEMA,
+        ImmutableSet.of(RangerHivePrivilege.CREATE),
+        Privilege.Name.CREATE_TABLE,
+        ImmutableSet.of(RangerHivePrivilege.CREATE),
+        Privilege.Name.MODIFY_TABLE,
+        ImmutableSet.of(
+            RangerHivePrivilege.UPDATE, RangerHivePrivilege.ALTER, RangerHivePrivilege.WRITE),
+        Privilege.Name.SELECT_TABLE,
+        ImmutableSet.of(RangerHivePrivilege.READ, RangerHivePrivilege.SELECT));
+  }
+
+  /** Set the default owner rule. */
+  public Set<RangerPrivilege> ownerMappingRule() {
+    return ImmutableSet.of(RangerHivePrivilege.ALL);
+  }
+
+  /** Set Ranger policy resource rule. */
+  public List<String> policyResourceDefinesRule() {
+    return ImmutableList.of(
+        PolicyResource.DATABASE.getName(),
+        PolicyResource.TABLE.getName(),
+        PolicyResource.COLUMN.getName());

Review Comment:
   Changed to singleton.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +91,42 @@ public RangerAuthorizationPlugin(String catalogProvider, Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize privilegesMapping and ownerPrivileges
+    ownerPrivileges = ownerMappingRule();
+    privilegesMapping = privilegesMappingRule();
+    policyResourceDefines = policyResourceDefinesRule();

Review Comment:
   DONE.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +91,42 @@ public RangerAuthorizationPlugin(String catalogProvider, Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize privilegesMapping and ownerPrivileges
+    ownerPrivileges = ownerMappingRule();
+    privilegesMapping = privilegesMappingRule();
+    policyResourceDefines = policyResourceDefinesRule();
+
+    rangerHelper =
+        new RangerHelper(
+            rangerClient,
+            rangerAdminName,
+            rangerServiceName,
+            privilegesMapping,
+            ownerPrivileges,
+            policyResourceDefines);
+  }
+
+  public final Map<Privilege.Name, Set<RangerPrivilege>> getPrivilegesMapping() {
+    return privilegesMapping;
+  }
+
+  public final Set<RangerPrivilege> getOwnerPrivileges() {
+    return ownerPrivileges;
+  }
+
+  public final List<String> getPolicyResourceDefines() {
+    return policyResourceDefines;

Review Comment:
   DONE



##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/RangerContainer.java:
##########
@@ -38,7 +38,7 @@ public class RangerContainer extends BaseContainer {
   public static final String DEFAULT_IMAGE = System.getenv("GRAVITINO_CI_RANGER_DOCKER_IMAGE");
   public static final String HOST_NAME = "gravitino-ci-ranger";
   public static final int RANGER_SERVER_PORT = 6080;
-  public RangerClient rangerClient;
+  public RangerClientExtend rangerClient;

Review Comment:
   Changed to `RangerClientExtension`.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String getName();
+
+  boolean isEquals(String value);

Review Comment:
   DONE



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2323708706

   LGTM,  @jerqi @jerryshao  Would you like to take a look?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "lw-yang (via GitHub)" <gi...@apache.org>.
lw-yang commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2319625765

   LGTM.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by rules [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #4744:
URL: https://github.com/apache/gravitino/pull/4744


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2320096466

   @yuqi1129 I fixed all comments. Please help me review again, Thanks!


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1764693498


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilegesMappingProvider.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/**
+ * Ranger authorization use this provider to mapping Gravitino privilege to the Ranger privileges.
+ * We can use this it to support the different Ranger authorization components, such as Hive, HDFS,
+ * HBase, etc.
+ */
+public interface RangerPrivilegesMappingProvider {
+  /** Set the mapping Gravitino privilege name to the Ranger privileges rule. */
+  void privilegesMappingRule();
+
+  /** Set the owner privileges rule. */
+  void ownerMappingRule();
+
+  /** Set the policy resource defines rule. */
+  void policyResourceDefinesRule();

Review Comment:
   I still think that you should have the return value for the method you defined here. Otherwise, it is hard for others to implement a such interface.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(core): Extended Apache Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2315443360

   @lw-yang Please help me review this PR, thanks.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "lw-yang (via GitHub)" <gi...@apache.org>.
lw-yang commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2333017356

   @jerryshao This feature allows for custom configuration of the mapping relationship between Gravitino Privileges and Ranger Privileges. If the default mapping relationship in Gravitino does not meet our scenario, we can customize it. 
   
   For example, by default, Gravitino's MODIFY_TABLE maps to Ranger's RangerHivePrivilege.UPDATE, RangerHivePrivilege.ALTER, RangerHivePrivilege.WRITE. In our scenario, we need to add RangerHivePrivilege.DROP, so we can customize this mapping relationship.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1759610420


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationConfig.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+
+/**
+ * Ranger authorization use this configuration to mapping Gravitino privilege to the Ranger

Review Comment:
   I need to think a bit on this, my initial feeling is that This `RangerAuthorizationConfig` may not be easy for people to use. 
   
   Most of the interfaces like `initializePrivilegesMappingConfig()` is hard to people to understand from the definition. People doesn't know what should be implemented, what is the input, output and side-effect of this interface. Without knowing this, it is hard for the developers to extend or implement this interface.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String toString();
+
+  boolean equals(String value);
+
+  /** Ranger Hive privileges enumeration. */
+  enum RangerHivePrivilege implements RangerPrivilege {
+    ALL("all"),
+    SELECT("select"),
+    UPDATE("update"),
+    CREATE("create"),
+    DROP("drop"),
+    ALTER("alter"),
+    INDEX("index"),
+    LOCK("lock"),
+    READ("read"),
+    WRITE("write"),
+    REPLADMIN("repladmin"),
+    SERVICEADMIN("serviceadmin");
+
+    private final String string; // Access a type in the Ranger policy item

Review Comment:
   It is better to have a different name for this class variable, not similar to the reserved word.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationConfig.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+
+/**
+ * Ranger authorization use this configuration to mapping Gravitino privilege to the Ranger

Review Comment:
   It's OK for internal use. But if we want to expose to the developers to extend, seems the definition is not self-explanatory. The concept of `xxxConfig` makes people hard to understand without context.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String toString();
+
+  boolean equals(String value);

Review Comment:
   the interface name `equals` is conflicted with Java's built-in `equals` method name, also for `toString`, it is better to have another name.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1737852271


##########
authorizations/authorization-ranger/src/test/resources/authorization-defs/authorization-hive.properties:
##########
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+# Ranger Hive privileges enum RangerHivePrivilege: create, alter, drop, index, lock, select, insert, update, delete, read, write, all
+# defined in the `authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/RangerDefines.java`
+# Case insensitive
+gravitino.authorization.owner.privileges = all
+
+# Gravitino privileges defined in the `api/src/main/java/org/apache/gravitino/authorization/Privilege.java`
+# authorization.privilege.mapping.<Gravitino-Privilege> = <Ranger-Privilege>,<Ranger-Privilege>,...
+gravitino.authorization.privilege.mapping.CREATE_SCHEMA = create
+gravitino.authorization.privilege.mapping.CREATE_TABLE = create
+gravitino.authorization.privilege.mapping.SELECT_TABLE = read, select
+gravitino.authorization.privilege.mapping.MODIFY_TABLE = update, alter , WrIte

Review Comment:
   This is a nonstandard test, I changed it to a better name.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =
+      new ConfigBuilder("gravitino.authorization.owner.privileges")
+          .doc("The privileges that the owner of a security object has.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final ConfigEntry<List<String>> RANGER_POLICY_RESOURCE_DEFINES =
+      new ConfigBuilder("gravitino.authorization.ranger.policy.resource.defines")
+          .doc("The resource defines that are used in Ranger policies.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final String PRIVILEGE_MAPPING_PREFIX =
+      "gravitino.authorization.privilege.mapping.";
+
+  public static AuthorizationConfig loadConfig(String provideName) {

Review Comment:
   DONE



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =
+      new ConfigBuilder("gravitino.authorization.owner.privileges")
+          .doc("The privileges that the owner of a security object has.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final ConfigEntry<List<String>> RANGER_POLICY_RESOURCE_DEFINES =
+      new ConfigBuilder("gravitino.authorization.ranger.policy.resource.defines")
+          .doc("The resource defines that are used in Ranger policies.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final String PRIVILEGE_MAPPING_PREFIX =
+      "gravitino.authorization.privilege.mapping.";
+
+  public static AuthorizationConfig loadConfig(String provideName) {
+    AuthorizationConfig authorizationConfig = new AuthorizationConfig();
+    boolean testEnv = System.getenv("GRAVITINO_TEST") != null;
+    String propertyFilePath =
+        String.format("authorization-defs/authorization-%s.properties", provideName);
+
+    // Only load from resources in test environment
+    if (testEnv) {
+      URL resourceUrl = AuthorizationConfig.class.getResource(File.separator + propertyFilePath);
+      try {
+        if (resourceUrl != null) {
+          Properties properties =
+              authorizationConfig.loadPropertiesFromFile(new File(resourceUrl.getPath()));
+          authorizationConfig.loadFromProperties(properties);
+          return authorizationConfig;
+        }
+      } catch (IOException e) {
+        throw new IllegalArgumentException(
+            "Failed to load authorization config from resource " + resourceUrl, e);
+      }
+    }
+
+    // Load from configuration directory in production environment
+    String confPath =
+        String.join(
+            File.separator,
+            System.getenv("GRAVITINO_HOME"),
+            "authorizations",
+            "ranger",
+            "conf",
+            propertyFilePath);
+    try {
+      Properties properties = authorizationConfig.loadPropertiesFromFile(new File(confPath));
+      authorizationConfig.loadFromProperties(properties);
+    } catch (IOException e) {
+      throw new IllegalArgumentException(
+          "Failed to load authorization config from file " + confPath, e);
+    }

Review Comment:
   OK



##########
authorizations/authorization-ranger/build.gradle.kts:
##########
@@ -85,18 +85,36 @@ dependencies {
 
 tasks {
   val runtimeJars by registering(Copy::class) {
-    from(configurations.runtimeClasspath)
+    from(configurations.runtimeClasspath, "src/main/resources")
     into("build/libs")
+    rename { original ->
+      if (original.endsWith(".properties.template")) {

Review Comment:
   OK, I agree with your suggestion.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2332236871

   I'm a little confused about the changes here made, can you describe more clearly about the scenarios and how users will use this feature? It's really not easy to understand.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1752391728


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =

Review Comment:
   If these are generic configs, they should be put into the code module, not Ranger module. Also I'm curious how other plugins like JDBC, IAM can leverage these configurations later on. From my understanding, they're quite Ranger specific.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2357708599

   @jerryshao I accept your suggestion and modify the code, please help me review again, thanks.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1759763261


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationConfig.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+
+/**
+ * Ranger authorization use this configuration to mapping Gravitino privilege to the Ranger

Review Comment:
   Typically, it is hard to design an interface for like "initializeXXX" or "setXXX", because it is hard for developers to know how to correctly implement a code about "initializeXXX" or "setXXX". Instead, I would suggest like:
   
   ```
   interface RangerPrivilegesMappingProvider {
   
   Map<GravitinoPrivilege, Set<RangerPrivileges>> privilegesMappingRule()
   Map<GravitinoPrivilege, Set<RangerPrivileges>> ownerMappingRule()
   ...
   }
   ```
   Just for your reference, please take a look, thanks.
   



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1759628673


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationConfig.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+
+/**
+ * Ranger authorization use this configuration to mapping Gravitino privilege to the Ranger

Review Comment:
   Maybe we can change class name from`RangerAuthorizationConfig` to `PrivilegeMappingRules`?
   and change the function name from 
   1. `initializePrivilegesMappingConfig()` -> `setPrivilegesMappingRule()`
   2. `initializeOwnerPrivilegesConfig()` -> `setOwnerPrivilegesRule()`
   3. `initializePolicyResourceDefinesConfig()` -> `setPolicyResourceDefinesRule()`
   
   What do you think?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1764864204


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilegesMappingProvider.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/**
+ * Ranger authorization use this provider to mapping Gravitino privilege to the Ranger privileges.
+ * We can use this it to support the different Ranger authorization components, such as Hive, HDFS,
+ * HBase, etc.
+ */
+public interface RangerPrivilegesMappingProvider {
+  /** Set the mapping Gravitino privilege name to the Ranger privileges rule. */
+  void privilegesMappingRule();
+
+  /** Set the owner privileges rule. */
+  void ownerMappingRule();
+
+  /** Set the policy resource defines rule. */
+  void policyResourceDefinesRule();

Review Comment:
   Good idea.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1764537528


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationConfig.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+
+/**
+ * Ranger authorization use this configuration to mapping Gravitino privilege to the Ranger

Review Comment:
   OK, I accept your suggestion.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String toString();
+
+  boolean equals(String value);

Review Comment:
   OK, change `equals()` to `isEquals()`.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String toString();
+
+  boolean equals(String value);
+
+  /** Ranger Hive privileges enumeration. */
+  enum RangerHivePrivilege implements RangerPrivilege {
+    ALL("all"),
+    SELECT("select"),
+    UPDATE("update"),
+    CREATE("create"),
+    DROP("drop"),
+    ALTER("alter"),
+    INDEX("index"),
+    LOCK("lock"),
+    READ("read"),
+    WRITE("write"),
+    REPLADMIN("repladmin"),
+    SERVICEADMIN("serviceadmin");
+
+    private final String string; // Access a type in the Ranger policy item

Review Comment:
   DONE.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1759628673


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationConfig.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+
+/**
+ * Ranger authorization use this configuration to mapping Gravitino privilege to the Ranger

Review Comment:
   Change class name from`RangerAuthorizationConfig` to `PrivilegeMappingRules`?
   and change the function name from 
   1. `initializePrivilegesMappingConfig()` -> `setPrivilegesMappingRule()`
   2. `initializeOwnerPrivilegesConfig()` -> `setOwnerPrivilegesRule()`
   3. `initializePolicyResourceDefinesConfig()` -> `setPolicyResourceDefinesRule()`
   What do you think?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1738028447


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerHelper.java:
##########
@@ -56,83 +55,124 @@ public class RangerHelper {
   private static final Logger LOG = LoggerFactory.getLogger(RangerHelper.class);
 
   public static final String MANAGED_BY_GRAVITINO = "MANAGED_BY_GRAVITINO";
-  RangerAuthorizationPlugin rangerAuthorizationPlugin;
 
   /** Mapping Gravitino privilege name to the underlying authorization system privileges. */
-  protected Map<Privilege.Name, Set<String>> privilegesMapping = null;
+  protected Map<Privilege.Name, Set<RangerPrivilege>> privilegesMapping = new HashMap<>();
   /** The owner privileges, the owner can do anything on the metadata object */
-  protected Set<String> ownerPrivileges = null;
+  private Set<RangerPrivilege> ownerPrivileges = new HashSet<>();
 
   /**
    * Because Ranger doesn't support the precise search, Ranger will return the policy meets the
    * wildcard(*,?) conditions, If you use `db.table` condition to search policy, the Ranger will
    * match `db1.table1`, `db1.table2`, `db*.table*`, So we need to manually precisely filter this
    * research results. <br>
    * policySearchKeys: The search Ranger policy condition key defines. <br>
-   * policyPreciseFilterKeys: The precise filter Ranger search results key defines <br>
+   * policyResourceDefines: The Ranger policy resource defines. <br>
    */
-  protected List<String> policySearchKeys = null;
-
-  protected List<String> policyPreciseFilterKeys = null;
-
-  public RangerHelper(RangerAuthorizationPlugin rangerAuthorizationPlugin, String catalogProvider) {
-    this.rangerAuthorizationPlugin = rangerAuthorizationPlugin;
-    switch (catalogProvider) {
-      case "hive":
-        initPrivilegesMapping();
-        initOwnerPrivileges();
-        initPolicySearchKeys();
-        initPreciseFilterKeys();
-        break;
-      default:
-        throw new IllegalArgumentException(
-            "Authorization plugin unsupported catalog provider: " + catalogProvider);
-    }
+  private List<String> policySearchKeys = new ArrayList<>();
+
+  private List<String> policyResourceDefines = new ArrayList<>();
+
+  private final RangerClientExtend rangerClient;
+  private final String rangerAdminName;
+  private final String rangerServiceName;
+  private AuthorizationConfig authorizationConfig = null;
+
+  public RangerHelper(
+      String catalogProvider,
+      RangerClientExtend rangerClient,
+      String rangerAdminName,
+      String rangerServiceName) {
+    this.rangerClient = rangerClient;
+    this.rangerAdminName = rangerAdminName;
+    this.rangerServiceName = rangerServiceName;
+
+    this.authorizationConfig = AuthorizationConfig.loadConfig(catalogProvider);
+    initAuthorizationConfig(authorizationConfig);
   }
 
-  /** Initial mapping Gravitino privilege name to the underlying authorization system privileges. */
-  private void initPrivilegesMapping() {
-    privilegesMapping =
-        ImmutableMap.<Privilege.Name, Set<String>>builder()
-            .put(
-                Privilege.Name.CREATE_SCHEMA,
-                ImmutableSet.of(RangerDefines.ACCESS_TYPE_HIVE_CREATE))
-            .put(
-                Privilege.Name.CREATE_TABLE, ImmutableSet.of(RangerDefines.ACCESS_TYPE_HIVE_CREATE))
-            .put(
-                Privilege.Name.MODIFY_TABLE,
-                ImmutableSet.of(
-                    RangerDefines.ACCESS_TYPE_HIVE_UPDATE,
-                    RangerDefines.ACCESS_TYPE_HIVE_ALTER,
-                    RangerDefines.ACCESS_TYPE_HIVE_WRITE))
-            .put(
-                Privilege.Name.SELECT_TABLE,
-                ImmutableSet.of(
-                    RangerDefines.ACCESS_TYPE_HIVE_READ, RangerDefines.ACCESS_TYPE_HIVE_SELECT))
-            .build();
+  @VisibleForTesting
+  RangerHelper(AuthorizationConfig authorizationConfig) {
+    this.rangerClient = null;
+    this.rangerAdminName = null;
+    this.rangerServiceName = null;
+
+    this.authorizationConfig = authorizationConfig;
+    initAuthorizationConfig(authorizationConfig);
   }
 
-  /** Initial Owner privileges */
-  private void initOwnerPrivileges() {
-    ownerPrivileges = ImmutableSet.of(RangerDefines.ACCESS_TYPE_HIVE_ALL);
+  /**
+   * Initial mapping Gravitino privilege name to the underlying authorization system privileges.
+   * <br>
+   * Initial Owner privileges. <br>
+   * Initial Ranger policy search key defines. <br>
+   * Initial precise filter key defines. <br>
+   */
+  private void initAuthorizationConfig(AuthorizationConfig authorizationConfig) {

Review Comment:
   Should we provide default values as before, it's too complicated to set the mapping for most users and only those users that have special requirement will configure this value. 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2330236864

   Sorry for late response, I will take a look at this today.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2342352157

   @jerryshao I updated this PR, Please help me review it again, thanks.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1765081255


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationHivePlugin.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+import org.apache.gravitino.authorization.ranger.RangerPrivilege.RangerHivePrivilege;
+import org.apache.gravitino.authorization.ranger.reference.RangerDefines.PolicyResource;
+
+public class RangerAuthorizationHivePlugin extends RangerAuthorizationPlugin {
+  public RangerAuthorizationHivePlugin(Map<String, String> config) {
+    super(config);
+  }
+
+  /** Set the default mapping Gravitino privilege name to the Ranger rule */
+  public Map<Privilege.Name, Set<RangerPrivilege>> privilegesMappingRule() {
+    return ImmutableMap.of(
+        Privilege.Name.CREATE_SCHEMA,
+        ImmutableSet.of(RangerHivePrivilege.CREATE),
+        Privilege.Name.CREATE_TABLE,
+        ImmutableSet.of(RangerHivePrivilege.CREATE),
+        Privilege.Name.MODIFY_TABLE,
+        ImmutableSet.of(
+            RangerHivePrivilege.UPDATE, RangerHivePrivilege.ALTER, RangerHivePrivilege.WRITE),
+        Privilege.Name.SELECT_TABLE,
+        ImmutableSet.of(RangerHivePrivilege.READ, RangerHivePrivilege.SELECT));
+  }
+
+  /** Set the default owner rule. */
+  public Set<RangerPrivilege> ownerMappingRule() {
+    return ImmutableSet.of(RangerHivePrivilege.ALL);
+  }
+
+  /** Set Ranger policy resource rule. */
+  public List<String> policyResourceDefinesRule() {
+    return ImmutableList.of(
+        PolicyResource.DATABASE.getName(),
+        PolicyResource.TABLE.getName(),
+        PolicyResource.COLUMN.getName());

Review Comment:
   Seems like all these methods return immutable map or list, if so, I would suggest make them singletons, so that we don't have to create maps or lists for each call.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +91,42 @@ public RangerAuthorizationPlugin(String catalogProvider, Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize privilegesMapping and ownerPrivileges
+    ownerPrivileges = ownerMappingRule();
+    privilegesMapping = privilegesMappingRule();
+    policyResourceDefines = policyResourceDefinesRule();

Review Comment:
   Also please change the style to `this.xxx = xxx` for class variable assignment.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -63,18 +62,23 @@
  * 4. The Ranger policy also supports multiple users and groups, But we only use a user or group to
  * implement Gravitino Owner concept. <br>
  */
-public class RangerAuthorizationPlugin implements AuthorizationPlugin {
+public abstract class RangerAuthorizationPlugin
+    implements AuthorizationPlugin, RangerPrivilegesMappingProvider {
   private static final Logger LOG = LoggerFactory.getLogger(RangerAuthorizationPlugin.class);
 
-  protected String catalogProvider;
+  /** Mapping Gravitino privilege name to the Ranger privileges configuration. */
+  private Map<Privilege.Name, Set<RangerPrivilege>> privilegesMapping;
+  /** The owner privileges, the owner can do anything on the metadata object configuration */
+  private Set<RangerPrivilege> ownerPrivileges;
+  /** The Ranger policy resource defines configuration. */
+  private List<String> policyResourceDefines;

Review Comment:
   Can you please make these variables `final`?



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String getName();
+
+  boolean isEquals(String value);

Review Comment:
   "isEquals" is not correct for grammar, can you please change to `equalsTo(xxxx)`?  



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -63,18 +62,23 @@
  * 4. The Ranger policy also supports multiple users and groups, But we only use a user or group to
  * implement Gravitino Owner concept. <br>
  */
-public class RangerAuthorizationPlugin implements AuthorizationPlugin {
+public abstract class RangerAuthorizationPlugin
+    implements AuthorizationPlugin, RangerPrivilegesMappingProvider {
   private static final Logger LOG = LoggerFactory.getLogger(RangerAuthorizationPlugin.class);
 
-  protected String catalogProvider;
+  /** Mapping Gravitino privilege name to the Ranger privileges configuration. */
+  private Map<Privilege.Name, Set<RangerPrivilege>> privilegesMapping;
+  /** The owner privileges, the owner can do anything on the metadata object configuration */
+  private Set<RangerPrivilege> ownerPrivileges;
+  /** The Ranger policy resource defines configuration. */
+  private List<String> policyResourceDefines;

Review Comment:
   Also for other class variables.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +91,42 @@ public RangerAuthorizationPlugin(String catalogProvider, Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize privilegesMapping and ownerPrivileges
+    ownerPrivileges = ownerMappingRule();
+    privilegesMapping = privilegesMappingRule();
+    policyResourceDefines = policyResourceDefinesRule();
+
+    rangerHelper =
+        new RangerHelper(
+            rangerClient,
+            rangerAdminName,
+            rangerServiceName,
+            privilegesMapping,
+            ownerPrivileges,
+            policyResourceDefines);
+  }
+
+  public final Map<Privilege.Name, Set<RangerPrivilege>> getPrivilegesMapping() {
+    return privilegesMapping;
+  }
+
+  public final Set<RangerPrivilege> getOwnerPrivileges() {
+    return ownerPrivileges;
+  }
+
+  public final List<String> getPolicyResourceDefines() {
+    return policyResourceDefines;

Review Comment:
   Also do you still need these methods? I think you can directly call `privilegesMappingRule`, `ownerMappingRule`, etc.



##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/RangerContainer.java:
##########
@@ -38,7 +38,7 @@ public class RangerContainer extends BaseContainer {
   public static final String DEFAULT_IMAGE = System.getenv("GRAVITINO_CI_RANGER_DOCKER_IMAGE");
   public static final String HOST_NAME = "gravitino-ci-ranger";
   public static final int RANGER_SERVER_PORT = 6080;
-  public RangerClient rangerClient;
+  public RangerClientExtend rangerClient;

Review Comment:
   Can you please change this class name "RangerClientExtend" to "RangerExtendedClient" or "RangerClientExtension", the name "xxxExtend" is a verb not a noun.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2358553227

   @xunliu , can you please also update the PR title and description to reflect what you did currently.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2347975722

   @jerryshao I removed the use properties file to overwrite the default authorization configuration.
   Please help me review it again, thanks!


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1737612205


##########
authorizations/authorization-ranger/src/test/resources/authorization-defs/authorization-hive.properties:
##########
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+# Ranger Hive privileges enum RangerHivePrivilege: create, alter, drop, index, lock, select, insert, update, delete, read, write, all
+# defined in the `authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/RangerDefines.java`
+# Case insensitive
+gravitino.authorization.owner.privileges = all
+
+# Gravitino privileges defined in the `api/src/main/java/org/apache/gravitino/authorization/Privilege.java`
+# authorization.privilege.mapping.<Gravitino-Privilege> = <Ranger-Privilege>,<Ranger-Privilege>,...
+gravitino.authorization.privilege.mapping.CREATE_SCHEMA = create
+gravitino.authorization.privilege.mapping.CREATE_TABLE = create
+gravitino.authorization.privilege.mapping.SELECT_TABLE = read, select
+gravitino.authorization.privilege.mapping.MODIFY_TABLE = update, alter , WrIte

Review Comment:
   WrIte -> write?



##########
authorizations/authorization-ranger/build.gradle.kts:
##########
@@ -85,18 +85,36 @@ dependencies {
 
 tasks {
   val runtimeJars by registering(Copy::class) {
-    from(configurations.runtimeClasspath)
+    from(configurations.runtimeClasspath, "src/main/resources")
     into("build/libs")
+    rename { original ->
+      if (original.endsWith(".properties.template")) {

Review Comment:
   In some places, we directly use `replace(".template", "")`;



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =
+      new ConfigBuilder("gravitino.authorization.owner.privileges")
+          .doc("The privileges that the owner of a security object has.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final ConfigEntry<List<String>> RANGER_POLICY_RESOURCE_DEFINES =
+      new ConfigBuilder("gravitino.authorization.ranger.policy.resource.defines")
+          .doc("The resource defines that are used in Ranger policies.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final String PRIVILEGE_MAPPING_PREFIX =
+      "gravitino.authorization.privilege.mapping.";
+
+  public static AuthorizationConfig loadConfig(String provideName) {
+    AuthorizationConfig authorizationConfig = new AuthorizationConfig();
+    boolean testEnv = System.getenv("GRAVITINO_TEST") != null;
+    String propertyFilePath =
+        String.format("authorization-defs/authorization-%s.properties", provideName);
+
+    // Only load from resources in test environment
+    if (testEnv) {
+      URL resourceUrl = AuthorizationConfig.class.getResource(File.separator + propertyFilePath);
+      try {
+        if (resourceUrl != null) {
+          Properties properties =
+              authorizationConfig.loadPropertiesFromFile(new File(resourceUrl.getPath()));
+          authorizationConfig.loadFromProperties(properties);
+          return authorizationConfig;
+        }
+      } catch (IOException e) {
+        throw new IllegalArgumentException(
+            "Failed to load authorization config from resource " + resourceUrl, e);
+      }
+    }
+
+    // Load from configuration directory in production environment
+    String confPath =
+        String.join(
+            File.separator,
+            System.getenv("GRAVITINO_HOME"),
+            "authorizations",
+            "ranger",
+            "conf",
+            propertyFilePath);
+    try {
+      Properties properties = authorizationConfig.loadPropertiesFromFile(new File(confPath));
+      authorizationConfig.loadFromProperties(properties);
+    } catch (IOException e) {
+      throw new IllegalArgumentException(
+          "Failed to load authorization config from file " + confPath, e);
+    }

Review Comment:
   Can we merge these two parts and share the confPath?



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =
+      new ConfigBuilder("gravitino.authorization.owner.privileges")
+          .doc("The privileges that the owner of a security object has.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final ConfigEntry<List<String>> RANGER_POLICY_RESOURCE_DEFINES =
+      new ConfigBuilder("gravitino.authorization.ranger.policy.resource.defines")
+          .doc("The resource defines that are used in Ranger policies.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final String PRIVILEGE_MAPPING_PREFIX =
+      "gravitino.authorization.privilege.mapping.";
+
+  public static AuthorizationConfig loadConfig(String provideName) {

Review Comment:
   provideName -> providerName.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1739964285


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerHelper.java:
##########
@@ -56,83 +55,124 @@ public class RangerHelper {
   private static final Logger LOG = LoggerFactory.getLogger(RangerHelper.class);
 
   public static final String MANAGED_BY_GRAVITINO = "MANAGED_BY_GRAVITINO";
-  RangerAuthorizationPlugin rangerAuthorizationPlugin;
 
   /** Mapping Gravitino privilege name to the underlying authorization system privileges. */
-  protected Map<Privilege.Name, Set<String>> privilegesMapping = null;
+  protected Map<Privilege.Name, Set<RangerPrivilege>> privilegesMapping = new HashMap<>();
   /** The owner privileges, the owner can do anything on the metadata object */
-  protected Set<String> ownerPrivileges = null;
+  private Set<RangerPrivilege> ownerPrivileges = new HashSet<>();
 
   /**
    * Because Ranger doesn't support the precise search, Ranger will return the policy meets the
    * wildcard(*,?) conditions, If you use `db.table` condition to search policy, the Ranger will
    * match `db1.table1`, `db1.table2`, `db*.table*`, So we need to manually precisely filter this
    * research results. <br>
    * policySearchKeys: The search Ranger policy condition key defines. <br>
-   * policyPreciseFilterKeys: The precise filter Ranger search results key defines <br>
+   * policyResourceDefines: The Ranger policy resource defines. <br>
    */
-  protected List<String> policySearchKeys = null;
-
-  protected List<String> policyPreciseFilterKeys = null;
-
-  public RangerHelper(RangerAuthorizationPlugin rangerAuthorizationPlugin, String catalogProvider) {
-    this.rangerAuthorizationPlugin = rangerAuthorizationPlugin;
-    switch (catalogProvider) {
-      case "hive":
-        initPrivilegesMapping();
-        initOwnerPrivileges();
-        initPolicySearchKeys();
-        initPreciseFilterKeys();
-        break;
-      default:
-        throw new IllegalArgumentException(
-            "Authorization plugin unsupported catalog provider: " + catalogProvider);
-    }
+  private List<String> policySearchKeys = new ArrayList<>();
+
+  private List<String> policyResourceDefines = new ArrayList<>();
+
+  private final RangerClientExtend rangerClient;
+  private final String rangerAdminName;
+  private final String rangerServiceName;
+  private AuthorizationConfig authorizationConfig = null;
+
+  public RangerHelper(
+      String catalogProvider,
+      RangerClientExtend rangerClient,
+      String rangerAdminName,
+      String rangerServiceName) {
+    this.rangerClient = rangerClient;
+    this.rangerAdminName = rangerAdminName;
+    this.rangerServiceName = rangerServiceName;
+
+    this.authorizationConfig = AuthorizationConfig.loadConfig(catalogProvider);
+    initAuthorizationConfig(authorizationConfig);
   }
 
-  /** Initial mapping Gravitino privilege name to the underlying authorization system privileges. */
-  private void initPrivilegesMapping() {
-    privilegesMapping =
-        ImmutableMap.<Privilege.Name, Set<String>>builder()
-            .put(
-                Privilege.Name.CREATE_SCHEMA,
-                ImmutableSet.of(RangerDefines.ACCESS_TYPE_HIVE_CREATE))
-            .put(
-                Privilege.Name.CREATE_TABLE, ImmutableSet.of(RangerDefines.ACCESS_TYPE_HIVE_CREATE))
-            .put(
-                Privilege.Name.MODIFY_TABLE,
-                ImmutableSet.of(
-                    RangerDefines.ACCESS_TYPE_HIVE_UPDATE,
-                    RangerDefines.ACCESS_TYPE_HIVE_ALTER,
-                    RangerDefines.ACCESS_TYPE_HIVE_WRITE))
-            .put(
-                Privilege.Name.SELECT_TABLE,
-                ImmutableSet.of(
-                    RangerDefines.ACCESS_TYPE_HIVE_READ, RangerDefines.ACCESS_TYPE_HIVE_SELECT))
-            .build();
+  @VisibleForTesting
+  RangerHelper(AuthorizationConfig authorizationConfig) {
+    this.rangerClient = null;
+    this.rangerAdminName = null;
+    this.rangerServiceName = null;
+
+    this.authorizationConfig = authorizationConfig;
+    initAuthorizationConfig(authorizationConfig);
   }
 
-  /** Initial Owner privileges */
-  private void initOwnerPrivileges() {
-    ownerPrivileges = ImmutableSet.of(RangerDefines.ACCESS_TYPE_HIVE_ALL);
+  /**
+   * Initial mapping Gravitino privilege name to the underlying authorization system privileges.
+   * <br>
+   * Initial Owner privileges. <br>
+   * Initial Ranger policy search key defines. <br>
+   * Initial precise filter key defines. <br>
+   */
+  private void initAuthorizationConfig(AuthorizationConfig authorizationConfig) {

Review Comment:
   Good idea, I improved it, Please help me review this PR, again.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2332998719

   > I'm a little confused about the changes here made, can you describe more clearly about the scenarios and how users will use this feature? It's really not easy to understand.
   
   In gravitino, we specify that each Gravitino Privilege maps multiple Privileges on the underlying system(Ranger), but there are some users whose environments have different privilege mappings than ours, so we allow users to configure their own to meet their own personalized needs, in addition to using our default Privilege mappings.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1750640781


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =

Review Comment:
   Are these generic authorization configs or ranger authorization only configs?



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =
+      new ConfigBuilder("gravitino.authorization.owner.privileges")
+          .doc("The privileges that the owner of a security object has.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final String PRIVILEGE_MAPPING_PREFIX =
+      "gravitino.authorization.privilege.mapping.";
+
+  public static AuthorizationConfig loadConfig(String providerName) {
+    AuthorizationConfig authorizationConfig = new AuthorizationConfig();
+    boolean testEnv = System.getenv("GRAVITINO_TEST") != null;
+    String propertyFilePath =
+        String.format("authorization-defs/authorization-%s.properties", providerName);

Review Comment:
   Maybe we can directly put this file into the conf, not so necessary to add another "authorization-defs" folder, WDYT?



##########
docs/security/authorization-pushdown.md:
##########
@@ -28,6 +28,27 @@ In order to use the Authorization Ranger Hive Plugin, you need to configure the
 
 Once you have used the correct configuration, you can perform authorization operations by calling Gravitino [authorization RESTful API](https://gravitino.apache.org/docs/latest/api/rest/grant-roles-to-a-user).
 
+#### Gravitino authorization privilege mapping Hive privilege property configurations
+
+If you enable these property configurations, The RangerAuthorizationHivePlugin will use these properties to override the default configuration in the program.
+
+| Property Name                                             | Description                                                                           | Default Value        | Since Version |
+|-----------------------------------------------------------|---------------------------------------------------------------------------------------|----------------------|---------------|
+| `gravitino.authorization.owner.privileges`                | The owner privileges, the owner can do anything on the metadata object configuration. | `all`                | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.CREATE_SCHEMA` | Gravitino `CREATE_SCHEMA` privilege mapping Ranger privileges.                        | `create`             | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.CREATE_TABLE`  | Gravitino `CREATE_TABLE` privilege mapping Ranger privileges.                         | `create`             | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.SELECT_TABLE`  | Gravitino `SELECT_TABLE` privilege mapping Ranger privileges.                         | `read,select`        | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.MODIFY_TABLE`  | Gravitino `MODIFY_TABLE` privilege mapping Ranger privileges.                         | `update,alter,write` | 0.6.1         |
+
+:::caution
+Ranger Hive privileges enum RangerHivePrivilege: create, alter, drop, index, lock, select, insert, update, delete, read, write, all
+defined in the `authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java`
+Format: gravitino.authorization.owner.privileges = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+
+Gravitino privileges defined in the `api/src/main/java/org/apache/gravitino/authorization/Privilege.java`
+Format: authorization.privilege.mapping.<GRAVITINO-PRIVILEGE> = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+:::

Review Comment:
   I think the document here is not enough. You should clearly describe how to configure, what is the meaning, and give an example here.
   
   Also, do we only support 4 privileges for mapping, how do we support more privileges to map easily?



##########
authorizations/authorization-ranger/src/main/resources/authorization-defs/authorization-hive.properties.template:
##########
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+# If you enable these property configurations,
+# The RangerAuthorizationHivePlugin will use these properties to override the default configuration in the program.
+
+# Ranger Hive privileges enum RangerHivePrivilege: create, alter, drop, index, lock, select, insert, update, delete, read, write, all
+# defined in the `authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java`
+# Format: gravitino.authorization.owner.privileges = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+# gravitino.authorization.owner.privileges = all
+
+# Gravitino privileges defined in the `api/src/main/java/org/apache/gravitino/authorization/Privilege.java`
+# Format: authorization.privilege.mapping.<GRAVITINO-PRIVILEGE> = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+# gravitino.authorization.privilege.mapping.CREATE_SCHEMA = create
+# gravitino.authorization.privilege.mapping.CREATE_TABLE = create
+# gravitino.authorization.privilege.mapping.SELECT_TABLE = read,select

Review Comment:
   Do we handle the scenarios like having prefix and trailing whitespace in between policies for the conf value? like:
   
   ```
   gravitino.authorization.privilege.mapping.CREATE_TABLE = create, aaa, xxx,   aaa
   ```



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#discussion_r1751913437


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +100,89 @@ public RangerAuthorizationPlugin(String catalogProvider, Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize and use the configuration to update the privilegesMapping and ownerPrivileges
+    initializeOwnerPrivilegesConfig();
+    initializePrivilegesMappingConfig();
+    policyResourceDefines = initializePolicyResourceDefinesConfig();
+    AuthorizationConfig authorizationConfig = AuthorizationConfig.loadConfig(catalogProvider);
+    overrideAuthorizationConfig(authorizationConfig);
+
+    rangerHelper =
+        new RangerHelper(
+            rangerClient,
+            rangerAdminName,
+            rangerServiceName,
+            privilegesMapping,
+            ownerPrivileges,
+            policyResourceDefines);
+  }
+
+  /** override the default ranger authorization configuration. <br> */
+  protected void overrideAuthorizationConfig(AuthorizationConfig authorizationConfig) {
+    // Update mapping Gravitino privilege name to the Ranger privileges.
+    try {
+      authorizationConfig
+          .getConfigsWithPrefix(AuthorizationConfig.PRIVILEGE_MAPPING_PREFIX)
+          .forEach(
+              (key, value) -> {
+                Privilege.Name gravitinoPrivilege =
+                    Privilege.Name.valueOf(key.trim().toUpperCase());

Review Comment:
   hi @jerryshao 
   These codes can convert any String to a Gravitino Privilege enum value.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =

Review Comment:
   These are generic authorization configs.



##########
authorizations/authorization-ranger/src/main/resources/authorization-defs/authorization-hive.properties.template:
##########
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+# If you enable these property configurations,
+# The RangerAuthorizationHivePlugin will use these properties to override the default configuration in the program.
+
+# Ranger Hive privileges enum RangerHivePrivilege: create, alter, drop, index, lock, select, insert, update, delete, read, write, all
+# defined in the `authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java`
+# Format: gravitino.authorization.owner.privileges = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+# gravitino.authorization.owner.privileges = all
+
+# Gravitino privileges defined in the `api/src/main/java/org/apache/gravitino/authorization/Privilege.java`
+# Format: authorization.privilege.mapping.<GRAVITINO-PRIVILEGE> = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+# gravitino.authorization.privilege.mapping.CREATE_SCHEMA = create
+# gravitino.authorization.privilege.mapping.CREATE_TABLE = create
+# gravitino.authorization.privilege.mapping.SELECT_TABLE = read,select

Review Comment:
   Yes, I have test case to cover these scenarios.
   `authorizations/authorization-ranger/src/test/resources/authorization-defs/authorization-hive-nonstandard.properties`



##########
docs/security/authorization-pushdown.md:
##########
@@ -28,6 +28,27 @@ In order to use the Authorization Ranger Hive Plugin, you need to configure the
 
 Once you have used the correct configuration, you can perform authorization operations by calling Gravitino [authorization RESTful API](https://gravitino.apache.org/docs/latest/api/rest/grant-roles-to-a-user).
 
+#### Gravitino authorization privilege mapping Hive privilege property configurations
+
+If you enable these property configurations, The RangerAuthorizationHivePlugin will use these properties to override the default configuration in the program.
+
+| Property Name                                             | Description                                                                           | Default Value        | Since Version |
+|-----------------------------------------------------------|---------------------------------------------------------------------------------------|----------------------|---------------|
+| `gravitino.authorization.owner.privileges`                | The owner privileges, the owner can do anything on the metadata object configuration. | `all`                | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.CREATE_SCHEMA` | Gravitino `CREATE_SCHEMA` privilege mapping Ranger privileges.                        | `create`             | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.CREATE_TABLE`  | Gravitino `CREATE_TABLE` privilege mapping Ranger privileges.                         | `create`             | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.SELECT_TABLE`  | Gravitino `SELECT_TABLE` privilege mapping Ranger privileges.                         | `read,select`        | 0.6.1         |
+| `gravitino.authorization.privilege.mapping.MODIFY_TABLE`  | Gravitino `MODIFY_TABLE` privilege mapping Ranger privileges.                         | `update,alter,write` | 0.6.1         |
+
+:::caution
+Ranger Hive privileges enum RangerHivePrivilege: create, alter, drop, index, lock, select, insert, update, delete, read, write, all
+defined in the `authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java`
+Format: gravitino.authorization.owner.privileges = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+
+Gravitino privileges defined in the `api/src/main/java/org/apache/gravitino/authorization/Privilege.java`
+Format: authorization.privilege.mapping.<GRAVITINO-PRIVILEGE> = <RANGER-PRIVILEGE>,<RANGER-PRIVILEGE>,...
+:::

Review Comment:
   > I think the document here is not enough. You should clearly describe how to configure, what is the meaning, and give an example here.
   
   OK, I added example in the docs.
   
   > Also, do we only support 4 privileges for mapping, how do we support more privileges to map easily?
   
   No, We can support all Gravitino privileges to configurations.
   Because I use 
   
   ```
   Privilege.Name gravitinoPrivilege =
                       Privilege.Name.valueOf(key.trim().toUpperCase());
   ```
   These codes can convert any String to a Gravitino Privilege enum value.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationConfig.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.gravitino.authorization.ranger;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.config.ConfigBuilder;
+import org.apache.gravitino.config.ConfigConstants;
+import org.apache.gravitino.config.ConfigEntry;
+
+public class AuthorizationConfig extends Config {
+  public static final ConfigEntry<List<String>> AUTHORIZATION_OWNER_PRIVILEGES =
+      new ConfigBuilder("gravitino.authorization.owner.privileges")
+          .doc("The privileges that the owner of a security object has.")
+          .version(ConfigConstants.VERSION_0_7_0)
+          .stringConf()
+          .toSequence()
+          .checkValue(
+              valueList ->
+                  valueList != null && valueList.stream().allMatch(StringUtils::isNotBlank),
+              ConfigConstants.NOT_BLANK_ERROR_MSG)
+          .createWithDefault(Lists.newArrayList());
+
+  public static final String PRIVILEGE_MAPPING_PREFIX =
+      "gravitino.authorization.privilege.mapping.";
+
+  public static AuthorizationConfig loadConfig(String providerName) {
+    AuthorizationConfig authorizationConfig = new AuthorizationConfig();
+    boolean testEnv = System.getenv("GRAVITINO_TEST") != null;
+    String propertyFilePath =
+        String.format("authorization-defs/authorization-%s.properties", providerName);

Review Comment:
   OK, I moved it to `distribution/package/authorizations/ranger/conf/authorization-hive.properties`.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#4698] feat(auth-ranger): Extended Ranger authorization by configuration [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #4744:
URL: https://github.com/apache/gravitino/pull/4744#issuecomment-2345171363

   This is just a discussion instead of review suggestion.
   In my opinion,
   
   What's the difference between users and developers.
   Users can only change the configurations. Developers can use the interface to custom their need.
   
   This feature should be used by developers instead of users. So I prefer extracting an interface `PrivilegeMappingProviderPlugin` to let other developer extend other mapping relation.  
   
   Configuration has less restriction than the interface. The interface can help us define better behaviour.
   
   This is just my cent, not a strong suggestion.  


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org