Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

java api access security hbase ticket expires

avatar
Contributor

My keytab ticket maxlife time is 7days. with the api code

UserGroupInformation.loginUserFromKeytab(conf.get("hbase.master.kerberos.principal"), conf.get("hbase.keytab.path"));

The ticket will expire 7days later,how to fix it? (How to access hbase all the time?)

 

rube

1 ACCEPTED SOLUTION

avatar
Mentor
If you cannot get the admins to provide your app with a near-infinite
ticket lifetime, you need to instead loop the login process via a
daemon thread, such as via this thread snippet as an example:

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(ELEVEN_MINUTES);
} catch (IOException e) {
e.printStackTrace();
interrupt();
} catch (InterruptedException e) {
e.printStackTrace();
interrupt();
}
}
}
};
reloginThread.setDaemon(true);
reloginThread.start();
}

View solution in original post

1 REPLY 1

avatar
Mentor
If you cannot get the admins to provide your app with a near-infinite
ticket lifetime, you need to instead loop the login process via a
daemon thread, such as via this thread snippet as an example:

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(ELEVEN_MINUTES);
} catch (IOException e) {
e.printStackTrace();
interrupt();
} catch (InterruptedException e) {
e.printStackTrace();
interrupt();
}
}
}
};
reloginThread.setDaemon(true);
reloginThread.start();
}