问题描述
本人在使用HiveStreaming的过程中,使用kerberos keytab进行安全验证,程序会保持长期连接。(hive jdbc 连接也要同样的问题)
登录主要代码:
LoginContext lc = new LoginContext(clientName, new TextCallbackHandler());
lc.login();
UserGroupInformation.loginUserFromSubject(lc.getSubject());
问题:
根据我们的kerberos设置,我们的票据Kerberos tgt 生命周期为24小时,到了24小时后,程序会报错连接失败。
报错信息:
Caused by: org.ietf.jgss.GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)
at sun.security.jgss.krb5.Krb5InitCredential.getInstance(Krb5InitCredential.java:147)
at sun.security.jgss.krb5.Krb5MechFactory.getCredentialElement(Krb5MechFactory.java:122)
at sun.security.jgss.krb5.Krb5MechFactory.getMechanismContext(Krb5MechFactory.java:187)
at sun.security.jgss.GSSManagerImpl.getMechanismContext(GSSManagerImpl.java:224)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:212)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179)
at com.sun.security.sasl.gsskerb.GssKrb5Client.evaluateChallenge(GssKrb5Client.java:192)
... 53 common frames omitted
无票据可用。
解决方法
跟踪HiveStreaming连接的源码关键调用过程
//代码1 自己写的代码 创建连接
connection = HiveStreamingConnection.newBuilder()
.withDatabase(database)
.withTable(tableName)
.withAgentInfo(tableName + "_hiveStreaming-agent")
.withRecordWriter(writer)
.withHiveConf(hiveConf)
.connect();
//代码2 源码 创建hive客户端
this.msClient = getMetaStoreClient(this.conf, this.metastoreUri,