diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java index 4bc7568f9d..2c597c5ac7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/mr/MapredLocalTask.java @@ -256,12 +256,22 @@ public int executeInChildVM(DriverContext driverContext) { // } - //Set HADOOP_USER_NAME env variable for child process, so that - // it also runs with hadoop permissions for the user the job is running as - // This will be used by hadoop only in unsecure(/non kerberos) mode - String endUserName = Utils.getUGI().getShortUserName(); - LOG.debug("setting HADOOP_USER_NAME\t" + endUserName); - variables.put("HADOOP_USER_NAME", endUserName); + //Set proper HADOOP_USER_NAME/HADOOP_PROXY_USER env variable for child process, + //so tha it also runs with hadoop permissions for the user the job is running as. + //This will be used by hadoop only in unsecure(/non kerberos) mod and this have to + //apply to both HiveCLI and HiveServer2. + UserGroupInformation hiveUGI = Utils.getUGI(); + if (hiveUGI.getAuthenticationMethod().equals(UserGroupInformation.AuthenticationMethod.PROXY)) { + String realUser = hiveUGI.getRealUser().getShortUserName(); + String proxyUser = hiveUGI.getShortUserName(); + LOG.info("setting HADOOP_USER_NAME:" + realUser + " and HADOOP_PROXY_USER:" + proxyUser); + variables.put("HADOOP_USER_NAME", realUser); + variables.put("HADOOP_PROXY_USER", proxyUser); + } else { + String realUser = hiveUGI.getShortUserName(); + LOG.info("setting HADOOP_USER_NAME:" + realUser); + variables.put("HADOOP_USER_NAME", realUser); + } if (variables.containsKey(HADOOP_OPTS_KEY)) { variables.put(HADOOP_OPTS_KEY, variables.get(HADOOP_OPTS_KEY) + hadoopOpts);