Community Articles
Find and share helpful community-sourced technical articles
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (1)
Cloudera Employee

Short Description:

This sample code helps to connect to Kerberos enabled HBase cluster from Java program.

Github location:

Code Walkthrough:

Create HBaseConfiguration and pass HBase cluster parameters.

Configuration configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.quorum", ",");
configuration.set("", "2181");
configuration.set("", "kerberos");
configuration.set("", "kerberos");
configuration.set("hbase.cluster.distributed", "true");

// check this setting on HBase side
configuration.set("", "authentication"); 

Specify HBase master and regionserver principal and keytab file names. Please make sure keytab files are in respective folder.

// this is needed even if you connect over rpc/zookeeper
configuration.set("hbase.master.kerberos.principal", "hbase/_HOST@FIELD.HORTONWORKS.COM"); 
configuration.set("hbase.master.keytab.file", "src/hbase.service.keytab");
//what principal the master/region. servers use.
configuration.set("hbase.regionserver.kerberos.principal", "hbase/_HOST@FIELD.HORTONWORKS.COM"); 
configuration.set("hbase.regionserver.keytab.file", "src/hbase.service.keytab"); 

Add to system property or you could also pass it using

// Enable/disable krb5 debugging 
System.setProperty("", "false");

String principal = System.getProperty("kerberosPrincipal","hbase/");
String keytabLocation = System.getProperty("kerberosKeytab","src/hbase.service.keytab");

login user from keytab file:

UserGroupInformation.loginUserFromKeytab(principal, keytabLocation); 

Well, you are good to go now.

0 Kudos
New Contributor

Why use _HOST as opposed to

Is this to handle failovers?

New Contributor

Why the difference _HOST and for PRINCIPAL?


  1. configuration.set("hbase.master.kerberos.principal","hbase/_HOST@FIELD.HORTONWORKS.COM");
  2. configuration.set("hbase.regionserver.kerberos.principal","hbase/_HOST@FIELD.HORTONWORKS.COM");

Vs this:

  1. String principal =System.getProperty("kerberosPrincipal","hbase/");
New Contributor

Do we have to manually add actual hostname in place of _HOST here


Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
1 of 1
Last update:
‎08-04-2017 09:08 PM
Updated by:
Top Kudoed Authors