hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khorg...@apache.org
Subject hive git commit: HIVE-17083 Merge credentials in DagUtils instead of overwriting
Date Fri, 14 Jul 2017 18:46:25 GMT
Repository: hive
Updated Branches:
  refs/heads/master 4ec00d364 -> d3ba76d1e


HIVE-17083 Merge credentials in DagUtils instead of overwriting

StorageHandlers are going to set credentials in the JobConf which
ultimately get set in the DAG's credentials. This call would overwrite
those credentials, breaking any delegation-token use by those storage
handlers (the credentials would be missing).

Signed-off-by: Sushanth Sowmyan <khorgath@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/d3ba76d1
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/d3ba76d1
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/d3ba76d1

Branch: refs/heads/master
Commit: d3ba76d1e1fe0e9c817fc2c26fa6dc5406b3aeae
Parents: 4ec00d3
Author: Josh Elser <elserj@apache.org>
Authored: Thu Jul 13 17:04:06 2017 -0400
Committer: Sushanth Sowmyan <khorgath@gmail.com>
Committed: Fri Jul 14 11:46:21 2017 -0700

----------------------------------------------------------------------
 .../hadoop/hive/ql/exec/tez/DagUtils.java       |  2 +-
 .../hadoop/hive/ql/exec/tez/TestDagUtils.java   | 69 ++++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/d3ba76d1/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java
index b6e55c0..51beaad 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/DagUtils.java
@@ -1219,7 +1219,7 @@ public class DagUtils {
    * Set up credentials for the base work on secure clusters
    */
   public void addCredentials(BaseWork work, DAG dag) throws IOException {
-    dag.setCredentials(UserGroupInformation.getCurrentUser().getCredentials());
+    dag.getCredentials().mergeAll(UserGroupInformation.getCurrentUser().getCredentials());
     if (work instanceof MapWork) {
       addCredentials((MapWork) work, dag);
     } else if (work instanceof ReduceWork) {

http://git-wip-us.apache.org/repos/asf/hive/blob/d3ba76d1/ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestDagUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestDagUtils.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestDagUtils.java
new file mode 100644
index 0000000..84e3b10
--- /dev/null
+++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestDagUtils.java
@@ -0,0 +1,69 @@
+/*
+ * 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.tez;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import java.security.PrivilegedExceptionAction;
+
+import org.apache.hadoop.hive.ql.plan.BaseWork;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.Credentials;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.security.token.TokenIdentifier;
+import org.apache.tez.dag.api.DAG;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class TestDagUtils {
+  
+  @Test
+  public void testCredentialsNotOverwritten() throws Exception {
+    final UserGroupInformation testUser = UserGroupInformation.createUserForTesting("test_user",
new String[0]);
+    final DagUtils dagUtils = DagUtils.getInstance();
+
+    Credentials originalCredentials = new Credentials();
+    final Text testTokenAlias = new Text("my_test_token");
+    @SuppressWarnings("unchecked")
+    Token<? extends TokenIdentifier> testToken = mock(Token.class);
+    originalCredentials.addToken(testTokenAlias, testToken);
+    Credentials testUserCredentials = new Credentials();
+
+    testUser.addCredentials(testUserCredentials);
+
+    final BaseWork work = mock(BaseWork.class);
+    final DAG dag = DAG.create("test_credentials_dag");
+
+    dag.setCredentials(originalCredentials);
+
+    testUser.doAs(new PrivilegedExceptionAction<Void>() {
+      @Override
+      public Void run() throws Exception {
+        dagUtils.addCredentials(work, dag);
+        return null;
+      }
+    });
+
+    Token<? extends TokenIdentifier> actualToken = dag.getCredentials().getToken(testTokenAlias);
+    assertEquals(testToken, actualToken);
+  }
+  
+}


Mime
View raw message