From b92c7fe361c32008eb8e0e994c50e2ef505c2978 Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Thu, 13 Jul 2017 17:04:06 -0400 Subject: [PATCH] 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). --- .../apache/hadoop/hive/ql/exec/tez/DagUtils.java | 2 +- .../hadoop/hive/ql/exec/tez/TestDagUtils.java | 69 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 ql/src/test/org/apache/hadoop/hive/ql/exec/tez/TestDagUtils.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 b6e55c0041..51beaadb10 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 Vertex createVertex(JobConf conf, BaseWork work, * 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) { 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 0000000000..84e3b107ec --- /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 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() { + @Override + public Void run() throws Exception { + dagUtils.addCredentials(work, dag); + return null; + } + }); + + Token actualToken = dag.getCredentials().getToken(testTokenAlias); + assertEquals(testToken, actualToken); + } + +} -- 2.12.2