Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here. Want to know more about what has changed? Check out the Community News blog.

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

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

New Contributor

 

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)]

 

1 REPLY 1

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

Master Guru

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();
	}