Reply
Highlighted
New Contributor
Posts: 1
Registered: ‎11-24-2015

HBase using Java:SASL authentication failed and Failed to find any Kerberos tgt in secured cluster

 

Hi all,

 

I am trying to access HBase using Java API and I am running Java program on my local windows machine. I am using hbase-site.xml also. Connection is getting established for zookeeper and getting kerberos and sasl exception.

 

configuration config = HBaseConfiguration.create();
config.addResource(new Path(System.getenv("HBASE_CONF_DIR"),"hbase-site.xml"));


UserGroupInformation.setConfiguration(config);
UserGroupInformation userGroupInformation = UserGroupInformation.loginUserFromKeytabAndReturnUGI("username", "krb5.keytab");
UserGroupInformation.setLoginUser(userGroupInformation);
System.out.println("getLoginUser :: "+UserGroupInformation.getLoginUser());
System.out.println(config);
Admin admin=null;
System.out.println("passed conf");
Connection connection = ConnectionFactory.createConnection(config);
admin = connection.getAdmin();

System.out.println("passed admin");

TableName[] tables = admin.listTableNames();
System.out.println("passed tablename");
for(TableName table: tables){
System.out.println("Table name is");
System.out.println(table.toString());
}

 

 

2015-11-23 22:38:59,650 INFO [main-SendThread(myhostname:2181)] zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(975)) – Opening socket connection to server myhostname/myport. Will not attempt to authenticate using SASL (unknown error)
2015-11-23 22:38:59,708 INFO [main-SendThread(myhostname:2181)] zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(852)) – Socket connection established to myhostname/myport. :2181, initiating session
2015-11-23 22:38:59,779 INFO [main-SendThread(myhostname:2181)] zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1235)) – Session establishment complete on server myhostname/myport:2181, sessionid = 0x150fe9c9404fc98, negotiated timeout = 200000
passed admin —-my debugging statement
2015-11-23 22:39:05,524 WARN [main] ipc.AbstractRpcClient (RpcClientImpl.java:run(699)) – Exception encountered while connecting to the server : javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]
2015-11-23 22:39:05,524 FATAL [main] ipc.AbstractRpcClient (RpcClientImpl.java:run(709)) – SASL authentication failed. The most likely cause is missing or invalid credentials. Consider ‘kinit’.
javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]

 

Posts: 1,885
Kudos: 424
Solutions: 298
Registered: ‎07-31-2013

Re: HBase using Java:SASL authentication failed and Failed to find any Kerberos tgt in secured clust

The below is the method I usually add (and call at the very beginning of my applications) and it usually works without issues:

 

	private void runLoginAndRenewalThread(final Configuration conf) throws IOException {
		// Do a blocking login first
		SecurityUtil.login(conf, KEYTAB_CONF, KEYTAB_USER);
		// Spawn the relogin thread next
		Thread reloginThread = new Thread() {
			@Override
			public void run() {
				while (true) {
					try {
						SecurityUtil.login(conf, KEYTAB_CONF, KEYTAB_USER);
						Thread.sleep(SIXTY_MINUTES_IN_MS);
					} catch (IOException e) {
						e.printStackTrace();
						interrupt();
					} catch (InterruptedException e) {
						e.printStackTrace();
						interrupt();
					}
				}
			}
		};
		reloginThread.setDaemon(true);
		reloginThread.start();
	}

 

Announcements