We have a java application running on the Liberty IBM WebSphere server and trying to connect to the HBase on the HDP cluster to persist some data.
Now we are facing issues to connect to HBase(kerberized) on HDP cluster.
We have been able to connect to HBase via Spark, Storm or application running with in the cluster but facing issue as we are sitting outside the cluster.
We have tried multiple approaches and followed these links https://community.hortonworks.com/articles/120858/connecting-to-kerberos-secured-hbase-cluster-from.html
So basically, we have copied the conf from the Hbase (hbase-site.xml, hdfs-site.xml and core-site.xml) to our application classpath and plus copied the Keytab for our service account user. We tried 4 different approachs
1)
Used hbase.zookeeper.quorum and hbase.zookeeper.property.clientPort
and
our service account user principle name and Keytab forUserGroupInformation.loginUserFromKeytab(principal, keytabLocation);
2)
Used hbase.zookeeper.quorum and hbase.zookeeper.property.clientPort
and
HBASE master principle name and Keytab forUserGroupInformation.loginUserFromKeytab(principal, keytabLocation);
3)
Used hbase-site.xml, hdfs-site.xml and core-site.xml
and our
service account user principle name and Keytab forUserGroupInformation.loginUserFromKeytab(principal, keytabLocation)
;
4)
Used hbase-site.xml, hdfs-site.xml and core-site.xml clientPort
and
HBASE master service account user principle name and Keytab forUserGroupInformation.loginUserFromKeytab(principal, keytabLocation);
Attached the below code snippet
public Connection getHBaseConnection() throws IOException, InterruptedException {
final Configuration configuration = HBaseConfiguration.create();
//configuration.set(HBASE_ZOOKEEPER_PROPERTY_CLIENT_PORT, environment.getProperty(HBASE_ZOOKEEPER_PROPERTY_CLIENT_PORT));
//configuration.set(HBASE_ZOOKEEPER_QUORUM, environment.getProperty(HBASE_ZOOKEEPER_QUORUM));
//configuration.set(ZOOKEEPER_ZNODE_PARENT, environment.getProperty(ZOOKEEPER_ZNODE_PARENT)); */
configuration.addResource(getClass().getResourceAsStream(CORE_SITE_PATH));
configuration.addResource(getClass().getResourceAsStream(HBASE_SITE_PATH));
configuration.addResource(getClass().getResourceAsStream(HDFS_SITE_PATH));
configuration.set("hadoop.security.authentication", "kerberos");
configuration.set("hbase.security.authentication", "kerberos");
configuration.set("hbase.cluster.distributed", "true");
configuration.set("hbase.rpc.protection", "authentication");
//System.setProperty("java.security.auth.login.config", "src/main/resources/sbx/hbase_client_jaas.conf");
//System.setProperty("java.security.krb5.conf","src/main/resources/sbx/krb5.conf");
//System.setProperty("sun.security.krb5.debug", "false");
//System.setProperty("java.security.krb5.realm", "HDP.SANDBOX.LOCAL");
//System.setProperty("java.security.krb5.kdc", "shared-serverbox-01.sandbox.local");
configuration.set("hbase.master.kerberos.principal", "hbase/_HOST@HDP.SANDBOX.LOCAL");
configuration.set("hbase.master.keytab.file", "src/main/resources/sbx/hbase.service.keytab");
configuration.set("hbase.regionserver.kerberos.principal", "hbase/_HOST@HDP.SANDBOX.LOCAL");
configuration.set("hbase.regionserver.keytab.file", "src/main/resources/sbx/hbase.service.keytab");
String keyTab = "src/main/resources/pasusr.keytab";
String principle = environment.getProperty(PRINCIPAL);
String keyTabHbase = "src/main/resources/sbx/hbase.service.keytab" ;
String principleHbase = "hbase/shared-serverbox-01.sandbox.localT@HDP.SANDBOX.LOCAL";
UserGroupInformation.setConfiguration(configuration);
UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principleHbase, keyTabHbase);
UserGroupInformation.setLoginUser(ugi);
return ugi.doAs(new PrivilegedExceptionAction<Connection>() {
@Override
public Connection run() throws IOException {
Connection connection = ConnectionFactory.createConnection(configuration);
System.out.println("Connected " + connection);
return connection;
}
});
}