You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/06/02 07:19:10 UTC

[GitHub] [hive] aasha commented on a change in pull request #2240: HIVE-25086: Create Ranger Deny Policy for replication db in all cases.

aasha commented on a change in pull request #2240:
URL: https://github.com/apache/hive/pull/2240#discussion_r643714087



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ranger/RangerRestClientImpl.java
##########
@@ -172,6 +168,40 @@ public String getRangerExportUrl(String sourceRangerEndpoint, String rangerHiveS
     return rangerPoliciesToImport;
   }
 
+  @Override
+  public void deleteRangerPolicy(String policyName, String baseUrl, String rangerHiveServiceName,
+                                 HiveConf hiveConf) throws Exception {
+    String finalUrl = getRangerDeleteUrl(baseUrl, policyName, rangerHiveServiceName);
+    LOG.debug("URL to delete policy on target Ranger: {}", finalUrl);
+    Retryable retryable = Retryable.builder()
+            .withHiveConf(hiveConf)
+            .withRetryOnException(Exception.class).build();
+    try {
+      retryable.executeCallable(() -> {
+        ClientResponse clientResp = null;
+        WebResource.Builder builder = getRangerResourceBuilder(finalUrl, hiveConf);
+        clientResp = builder.delete(ClientResponse.class);
+        if (clientResp != null) {
+          switch (clientResp.getStatus()) {
+            case HttpServletResponse.SC_NO_CONTENT:
+              LOG.debug("Ranger policy: {} deleted successfully", policyName);
+              break;
+            case HttpServletResponse.SC_NOT_FOUND:
+              LOG.debug("Ranger policy: {} not found.", policyName);
+              break;
+            case HttpServletResponse.SC_UNAUTHORIZED:
+              throw new Exception("Authentication Failure while communicating to Ranger admin");
+            default:
+              throw new Exception("Ranger policy deletion failed, Please refer target Ranger admin logs.");
+          }
+        }
+        return null;
+      });
+    } catch (Exception e) {
+      throw new SemanticException(ErrorMsg.REPL_RETRY_EXHAUSTED.format(e.getMessage()), e);

Review comment:
       if its unauthorised even retry will not help
   what about any other error

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/RangerDenyTask.java
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.hadoop.hive.ql.exec.repl;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.utils.SecurityUtils;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.repl.ranger.RangerRestClient;
+import org.apache.hadoop.hive.ql.exec.repl.ranger.RangerRestClientImpl;
+import org.apache.hadoop.hive.ql.exec.repl.ranger.NoOpRangerRestClient;
+import org.apache.hadoop.hive.ql.exec.repl.ranger.RangerPolicy;
+import org.apache.hadoop.hive.ql.exec.repl.ranger.RangerExportPolicyList;
+import org.apache.hadoop.hive.ql.exec.repl.util.ReplUtils;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.parse.repl.metric.event.Status;
+import org.apache.hadoop.hive.ql.plan.api.StageType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * RangerDenyTask.
+ *
+ * Task to add Ranger Deny Policy
+ **/
+public class RangerDenyTask extends Task<RangerDenyWork> implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private static final Logger LOG = LoggerFactory.getLogger(RangerDenyTask.class);
+
+    private transient RangerRestClient rangerRestClient;
+
+    public RangerDenyTask() {
+        super();
+    }
+
+    @VisibleForTesting
+    RangerDenyTask(final RangerRestClient rangerRestClient, final HiveConf conf, final RangerDenyWork work) {
+        this.conf = conf;
+        this.work = work;
+        this.rangerRestClient = rangerRestClient;
+    }
+
+    @Override
+    public String getName() {
+        return "RANGER_DENY";
+    }
+
+    @Override
+    public int execute() {
+        try {
+            LOG.info("Checking Ranger Deny Policy for {}", work.getTargetDbName());
+            SecurityUtils.reloginExpiringKeytabUser();
+            if (rangerRestClient == null) {
+                rangerRestClient = getRangerRestClient();
+            }
+            URL url = work.getRangerConfigResource();
+            if (url == null) {
+                throw new SemanticException(ErrorMsg.REPL_INVALID_CONFIG_FOR_SERVICE
+                        .format("Ranger configuration is not valid "
+                                + ReplUtils.RANGER_CONFIGURATION_RESOURCE_NAME, ReplUtils.REPL_RANGER_SERVICE));
+            }
+            conf.addResource(url);

Review comment:
       why do we need to add to conf

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplLoadTask.java
##########
@@ -127,6 +127,9 @@ public int execute() {
       if (shouldLoadAtlasMetadata()) {
         addAtlasLoadTask();
       }
+      if (conf.getBoolVar(HiveConf.ConfVars.REPL_RANGER_HANDLE_DENY_POLICY_TARGET)) {

Review comment:
       if this conf is set to false but ranger replication is enabled what do you do

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ranger/RangerRestClientImpl.java
##########
@@ -79,6 +74,7 @@
   private static final String RANGER_REST_URL_EXPORTJSONFILE = "service/plugins/policies/exportJson";
   private static final String RANGER_REST_URL_IMPORTJSONFILE =
       "service/plugins/policies/importPoliciesFromFile";
+  private static final String RANGER_REST_URL_DELETEPOLICY = "service/public/v2/api/policy";

Review comment:
       Please cross check with Ranger team/public docs

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ranger/RangerRestClientImpl.java
##########
@@ -444,7 +482,7 @@ boolean checkConnectionPlain(String url, HiveConf hiveConf) {
     List<RangerPolicy.RangerPolicyItemAccess> denyExceptionsPolicyItemAccesses = new ArrayList<RangerPolicy.
         RangerPolicyItemAccess>();
 
-    resourceNameList.add(sourceDb);

Review comment:
       why is the source db needed?




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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org