从UDF中查找Hbase Tbl(Beeline,Hbase,委托令牌)

时间:2018-10-16 21:24:15

标签: hive hbase kerberos cloudera-cdh apache-sentry

我需要编写自定义UDF以便从Hbase Table查找数据。

注意:我已经完成了HIVE的单元测试。它似乎正在工作。

但是当我使用相同的UDF Beeline时,它失败了。默认情况下,Cloudera限制模拟,并且仅允许蜂巢用户在Beeline中运行查询。在Job启动时,YarnChild将设置以下委托令牌。

我想添加令牌(种类: HBASE_AUTH_TOKEN )来处理Hbase。

Kind: mapreduce.job
Kind: HDFS_DELEGATION_TOKEN 
Kind: kms-dt

我研究并发现了HbaseStorageHandler如何将委托令牌(即HBASE_AUTH_TOKEN)用于Hbase。因此,我使用了相同的功能集,但它们也不起作用。

HbasestorageHandler的功能(以获取Job的令牌):

private void addHBaseDelegationToken(Configuration conf, JobConf jconf) throws IOException {
        if (User.isHBaseSecurityEnabled(conf)) {
            try {
                logger.info("isHbaseSecurityEnabled :True ");
                User e = User.getCurrent();
                logger.info("isHbaseSecurityEnabled :User ==> " + e.toString());
                Token authToken = getAuthToken(conf, e);
                logger.info("isHbaseSecurityEnabled :AuthToken==> "+authToken.toString());
                Job job = new Job(conf);
                if(authToken == null) {
                    UserGroupInformation ugi = UserGroupInformation.getLoginUser();
                    ugi.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS);
                    e.obtainAuthTokenForJob(jconf);
  } else {
                    logger.info("authToken is not null"+authToken.toString());
                    job.getCredentials().addToken(authToken.getService(), authToken);
                }

                logger.info("obtained Token /....");
            } catch (InterruptedException var5) {
                throw new IOException("Error while obtaining hbase delegation token", var5);
            }
        }

    }


private static Token<AuthenticationTokenIdentifier> getAuthToken(Configuration conf, User user) throws IOException, InterruptedException {
        ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "mr-init-credentials", (Abortable) null);

        Token var4;
        try {
            String e = ZKClusterId.readClusterIdZNode(zkw);
            logger.info("====== clusterID : " + e);
            var4 = (new AuthenticationTokenSelector()).selectToken(new Text(e), user.getUGI().getTokens());
             if (var4 == null) {
                logger.info("var4 is null===========================");
            } else {
                logger.info("====== Hbase Token : " + var4.toString());
            }
        } catch (KeeperException var8) {
            throw new IOException(var8);
        } catch (NullPointerException np) {
            return null;
        } finally {
            zkw.close();
        }
        return var4;
 }

在UDF的configure()中调用addHBaseDelegationToken()之后。我收到以下异常。我不确定如何使hvie用户与Hbase进行对话,因为hive.keytab由Cloudera及其安全性处理。

任何输入可能会有所帮助。谢谢!

异常StackTrace:

  

2018-10-11 04:48:07,625警告[main] org.apache.hadoop.security.UserGroupInformation:PriviledgedActionException as:hive(auth:SIMPLE)原因:javax.security.sasl.SaslException:GSS启动失败[由GSSException引起:没有提供有效的凭据(机制级别:找不到任何Kerberos tgt)   2018-10-11 04:48:07,627警告[main] org.apache.hadoop.hbase.ipc.RpcClientImpl:连接到服务器时遇到异常:javax.security.sasl.SaslException:GSS启动失败[由GSSException引起:没有提供有效的凭据(机制级别:找不到任何Kerberos tgt)   2018-10-11 04:48:07,628致命[main] org.apache.hadoop.hbase.ipc.RpcClientImpl:SASL身份验证失败。最可能的原因是缺少凭据或凭据无效。考虑“ kinit”。   javax.security.sasl.SaslException:GSS初始化失败[由GSSException引起:没有提供有效的凭证(机制级别:未能找到任何Kerberos tgt)]       在com.sun.security.sasl.gsskerb.GssKrb5Client.evaluateChallenge(GssKrb5Client.java:211)       在org.apache.hadoop.hbase.security.HBaseSaslRpcClient.saslConnect(HBaseSaslRpcClient.java:181)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection.setupSaslConnection(RpcClientImpl.java:618)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection.access $ 700(RpcClientImpl.java:163)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection $ 2.run(RpcClientImpl.java:744)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection $ 2.run(RpcClientImpl.java:741)       在java.security.AccessController.doPrivileged(本机方法)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1920)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection.setupIOstreams(RpcClientImpl.java:741)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection.writeRequest(RpcClientImpl.java:907)       在org.apache.hadoop.hbase.ipc.RpcClientImpl $ Connection.tracedWriteRequest(RpcClientImpl.java:874)       在org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1246)       在org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:227)       在org.apache.hadoop.hbase.ipc.AbstractRpcClient $ BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:336)       在org.apache.hadoop.hbase.protobuf.generation.ClientProtos $ ClientService $ BlockingStub.execService(ClientProtos.java:34118)       在org.apache.hadoop.hbase.protobuf.ProtobufUtil.execService(ProtobufUtil.java:1633)       在org.apache.hadoop.hbase.ipc.RegionCoprocessorRpcChannel $ 1.call(RegionCoprocessorRpcChannel.java:104)       在org.apache.hadoop.hbase.ipc.RegionCoprocessorRpcChannel $ 1.call(RegionCoprocessorRpcChannel.java:94)       在org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:136)       在org.apache.hadoop.hbase.ipc.RegionCoprocessorRpcChannel.callExecService(RegionCoprocessorRpcChannel.java:107)       在org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel.callBlockingMethod(CoprocessorRpcChannel.java:73)       在org.apache.hadoop.hbase.protobuf.generation.AuthenticationProtos $ AuthenticationService $ BlockingStub.getAuthenticationToken(AuthenticationProtos.java:4512)       在org.apache.hadoop.hbase.security.token.TokenUtil.obtainToken(TokenUtil.java:86)       在org.apache.hadoop.hbase.security.token.TokenUtil $ 1.run(TokenUtil.java:111)       在org.apache.hadoop.hbase.security.token.TokenUtil $ 1.run(TokenUtil.java:108)       在java.security.AccessController.doPrivileged(本机方法)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1920)       在org.apache.hadoop.hbase.security.User $ SecureHadoopUser.runAs(User.java:340)       在org.apache.hadoop.hbase.security.token.TokenUtil.obtainToken(TokenUtil.java:108)       在com.barclaycardus.hadoop.utils.udfs.HbaseTblLookupUDF.configure(HbaseTblLookupUDF.java:131)       在org.apache.hadoop.hive.ql.exec.MapredContext.setup(MapredContext.java:120)       在org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator.initialize(ExprNodeGenericFuncEvaluator.java:143)       在org.apache.hadoop.hive.ql.exec.Operator.initEvaluators(Operator.java:954)       在org.apache.hadoop.hive.ql.exec.Operator.initEvaluatorsAndReturnStruct(Operator.java:980)       在org.apache.hadoop.hive.ql.exec.SelectOperator.initializeOp(SelectOperator.java:63)       在org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)       在org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:469)       在org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:425)       在org.apache.hadoop.hive.ql.exec.TableScanOperator.initializeOp(TableScanOperator.java:196)       在org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)       在org.apache.hadoop.hive.ql.exec.MapOperator.initializeOp(MapOperator.java:431)       在org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:385)       在org.apache.hadoop.hive.ql.exec.mr.ExecMapper.configure(ExecMapper.java:126)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:106)       在org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)       在org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)       在org.apache.hadoop.mapred.MapRunner.configure(MapRunner.java:38)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:106)       在org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)       在org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)       在org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:455)       在org.apache.hadoop.mapred.MapTask.run(MapTask.java:343)       在org.apache.hadoop.mapred.YarnChild $ 2.run(YarnChild.java:164)       在java.security.AccessController.doPrivileged(本机方法)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1920)       在org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)   原因:GSSException:没有提供有效的凭据(机制级别:找不到任何Kerberos tgt)       在sun.security.jgss.krb5.Krb5InitCredential.getInstance(Krb5InitCredential.java:147)       在sun.security.jgss.krb5.Krb5MechFactory.getCredentialElement(Krb5MechFactory.java:122)       在sun.security.jgss.krb5.Krb5MechFactory.getMechanismContext(Krb5MechFactory.java:187)       在sun.security.jgss.GSSManagerImpl.getMechanismContext(GSSManagerImpl.java:224)       在sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:212)       在sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179)       在com.sun.security.sasl.gsskerb.GssKrb5Client.evaluateChallenge(GssKrb5Client.java:192)       ...另外66个

已经尝试以下选项:

https://github.com/apache/oozie/blob/master/core/src/main/java/org/apache/oozie/action/hadoop/HbaseCredentials.java

https://github.com/ibm-research-ireland/sparkoscope/blob/master/yarn/src/main/scala/org/apache/spark/deploy/yarn/security/HBaseCredentialProvider.scala

0 个答案:

没有答案