Java client for Secure HBase

Hi, I am trying to write a java client for secure hbase.
I want to do kinit from the code itself, because I am using the user group information class.
Can anyone point out where I am wrong?

This is the main way I am trying to connect to hbase.

I have to add configuration in the CONfiguration object instead of using xml, because the client can be located anywhere.< /p>

Please refer to the following code:

public static void main(String [] args) {
try {
System.setProperty( CommonConstants.KRB_REALM, ConfigUtil.getProperty(CommonConstants.HADOOP_CONF, "krb.realm"));
System.setProperty(CommonConstants.KRB_KDC, ConfigUtil.getProperty(CommonConstants.HADOOP_CONF,"krb.kdc /> System.setProperty(CommonConstants.KRB_DEBUG, "true");

final Configuration config = HBaseConfiguration.create();

config.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, AUTH_KRB );
config.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, AUTHORIZATION);
config.set(CommonConfigurationKeysPublic.FS_AUTOMATIC_CLOSE_KEY, AUTO_CLOSE);
config.set(CommonConfiguration_KeysPublic); > config.set("hbase.zookeeper.quo rum", ConfigUtil.getProperty(CommonConstants.HBASE_CONF, "hbase.host"));
config.set("hbase.zookeeper.property.clientPort", ConfigUtil.getProperty(CommonConstants.HBASE_CONF, "hbase.port" ));
config.set("hbase.client.retries.number", Integer.toString(0));
config.set("zookeeper.session.timeout", Integer.toString(6000 ));
config.set("zookeeper.recovery.retry", Integer.toString(0));
config.set("hbase.master", "gauravt-namenode.pbi.global. pvt:60000");
config.set("zookeeper.znode.parent", "/hbase-secure");
config.set("hbase.rpc.engine", "org.apache .hadoop.hbase.ipc.SecureRpcEngine");
config.set("hbase.security.authentication", AUTH_KRB);
config.set("hbase.security.authorization", AUTHORIZATION);< br /> config.set("hbase.master.kerberos.principal", "hbase/[email protected]");
config.set("hbase.master .keytab.file", "D:/var/lib/bda/se cure/keytabs/hbase.service.keytab");
config.set("hbase.regionserver.kerberos.principal", "hbase/[email protected]") ;
config.set("hbase.regionserver.keytab.file", "D:/var/lib/bda/secure/keytabs/hbase.service.keytab");

UserGroupInformation .setConfiguration(config);
UserGroupInformation userGroupInformation = UserGroupInformation.loginUserFromKeytabAndReturnUGI("hbase/[email protected]", "D:/var/lib/bda/secure/keytabs /hbase.service.keytab");
UserGroupInformation.setLoginUser(userGroupInformation);

User user = User.create(userGroupInformation);

user.runAs( new PrivilegedExceptionAction() {

@Override
public Object run() throws Exception {
HBaseAdmin admins = new HBaseAdmin(config);

if(admins.isTableAvailable("ambarismoketest")) { System.out.println("Table is available");
};

HConnection connection = HConnectionManager.createConnection(config);

HTableInterface table = connection.getTable("ambarismoketest");



admins.close();
System.out.println(table.get(new Get(null )));
return table.get(new Get(null));
}
});
System.out.println(UserGroupInformation.getLoginUser().getUserName( ));


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}< /pre>

I get the following exception:

Caused by: org.apache.hadoop.ipc.RemoteException(javax.security.sasl.SaslException): GSS initiate failed 
at org.apache.hadoop.hbase.security.HBaseSaslRpcClient.readStatus(HBaseSaslRpcClient.java:110)
at org.apache.hadoop.hbase.security.HBas eSaslRpcClient.saslConnect(HBaseSaslRpcClient.java:146)
at org.apache.hadoop.hbase.ipc.RpcClient$Connection.setupSaslConnection(RpcClient.java:762)
at org.apache.hadoop.hbase. ipc.RpcClient$Connection.access$600(RpcClient.java:354)
at org.apache.hadoop.hbase.ipc.RpcClient$Connection$2.run(RpcClient.java:883)
at org. apache.hadoop.hbase.ipc.RpcClient$Connection$2.run(RpcClient.java:880)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject. doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491)
at org.apache.hadoop.hbase.ipc.RpcClient$Connection. setupIOstreams(RpcClient.java:880)
... 33 more

Any pointer will help.

< /div>

Not sure if you still need help. I think your code snippet is missing the setting "hadoop.security.authentication" attribute.

I use the following The code snippet connects to secure HBase (on CDH5). You can try it.

config.set("hbase.zookeeper.quorum", zookeepe rHosts);
config.set("hbase.zookeeper.property.clientPort", zookeeperPort);
config.set("hadoop.security.authentication", "kerberos");
config .set("hbase.security.authentication", "kerberos");
config.set("hbase.master.kerberos.principal", HBASE_MASTER_PRINCIPAL);
config.set("hbase.regionserver. kerberos.principal", HBASE_RS_PRINCIPAL);

UserGroupInformation.setConfiguration(config);
UserGroupInformation.loginUserFromKeytab(ZOOKEEPER_PRINCIPAL,ZOOKEEPER_KEYTAB);

HBaseAdmin Admins = new HBaseAdmin admins config);
TableName[] tables = admins.listTableNames();

for(TableName table: tables){
System.out.println(table.toString()) ;
}

Hi, I am trying to write a java client for secure hbase.
I want to do kinit from the code itself because I use The category is user group information.
Can anyone point out where I am wrong?

This is the main way I am trying to connect to hbase.

I have to add configuration in the CONfiguration object instead of using xml, because the client can be located anywhere.< /p>

Please refer to the following code:

public static void main(String [] args) {
try {
System.setProperty( CommonConstants.KRB_REALM, ConfigUtil.getProperty(CommonConstants.HADOOP_CONF, "krb.realm"));
System.setProperty(CommonConstants.KRB_KDC, ConfigUtil.getProperty(CommonConstants.HADOOP_CONF,"krb.kdc /> System.setProperty(CommonConstants.KRB_DEBUG, "true");

final Configuration config = HBaseConfiguration.create();

config.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, AUTH_KRB );
config.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, AUTHORIZATION);
config.set(CommonConfigurationKeysPublic.FS_AUTOMATIC_CLOSE_KEY, AUTO_CLOSE);
config.set(CommonConfiguration_KeysPublic); > config.set("hbase.zookeeper.quorum", ConfigUtil.getProperty(CommonConstants.HBASE_CONF, "hbase.host"));
config.set("hbase.zookeeper.property.clientPort", ConfigUtil.getProperty(CommonConstants.HBASE_CONF, "hbase.port"));
config.set("hbase.client.retries.number", Integer.toString(0));
config.set("zookeeper.session.timeout", Integer.toString(6000));
config.set("zookeeper.recovery.retry", Integer.toString(0));
config.set("hbase.master", "gauravt-namenode.pbi.global.pvt:60000 ");
config.set("zookeeper.znode.parent", "/hbase-secure");
config.set("hbase.rpc.engine", "org.apache.hadoop. hbase.ipc.SecureRpcEngine");
config.set("hbase.security.authentication", AUTH_KRB);
config.set("hbase.security.authorization", AUTHORIZATION);
config.set("hbase.master.kerberos.principal", "hbase/[email protected]");
config.set("hbase.master.keytab. file", "D:/var/lib/bda/secure/ keytabs/hbase.service.keytab");
config.set("hbase.regionserver.kerberos.principal", "hbase/[email protected]");< br /> config.set("hbase.regionserver.keytab.file", "D:/var/lib/bda/secure/keytabs/hbase.service.keytab");

UserGroupInformation.setConfiguration (config);
UserGroupInformation userGroupInformation = UserGroupInformation.loginUserFromKeytabAndReturnUGI("hbase/[email protected]", "D:/var/lib/bda/secure/keytabs/hbase .service.keytab");
UserGroupInformation.setLoginUser(userGroupInformation);

User user = User.create(userGroupInformation);

user.runAs(new PrivilegedExceptionAction () {

@Override
public Object run() throws Exception {
HBaseAdmin admins = new HBaseAdmin(config);

if (admins.isTableAvailable("ambarismoketest")) {
System.out.println("Table is available");
};

HConnection connection = HConnectionManager.createConnection(config);

HTableInterface table = connection. getTable("ambarismoketest");



admins.close();
System.out.println(table.get(new Get(null))) ;
return table.get(new Get(null));
}
});
System.out.println(UserGroupInformation.getLoginUser().getUserName());


} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

I get the following exception:

Caused by: org.apache.hadoop.ipc.RemoteException(javax.security.sasl.SaslException): GSS initiate failed
at org.apache.hadoop.hbase.security.HBaseSaslRpcClient.readStatus(HBaseSaslRpcClient.java:110)
at org.apache.hadoop.hbase.security.HBaseSaslRpc Client.saslConnect(HBaseSaslRpcClient.java:146)
at org.apache.hadoop.hbase.ipc.RpcClient$Connection.setupSaslConnection(RpcClient.java:762)
at org.apache.hadoop.hbase. ipc.RpcClient$Connection.access$600(RpcClient.java:354)
at org.apache.hadoop.hbase.ipc.RpcClient$Connection$2.run(RpcClient.java:883)
at org. apache.hadoop.hbase.ipc.RpcClient$Connection$2.run(RpcClient.java:880)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject. doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1491)
at org.apache.hadoop.hbase.ipc.RpcClient$Connection. setupIOstreams(RpcClient.java:880)
... 33 more

Any pointer will help.

No Determine if you still need help. I think your code snippet is missing the setting "hadoop.security.authentication" property.

I used the following code snippet to connect to secure HBase (on CDH5). You can try it.

config.set("hbase.zookeeper.quorum", zookeeperHosts);
config.set("hbase.zookeeper.property.clientPort ", zookeeperPort);
config.set("hadoop.security.authentication", "kerberos");
config.set("hbase.security.authentication", "kerberos");
config .set("hbase.master.kerberos.principal", HBASE_MASTER_PRINCIPAL);
config.set("hbase.regionserver.kerberos.principal", HBASE_RS_PRINCIPAL);

UserGroupInformation.setConfiguration(config );
UserGroupInformation.loginUserFromKeytab(ZOOKEEPER_PRINCIPAL,ZOOKEEPER_KEYTAB);

HBaseAdmin admins = new HBaseAdmin(config);
TableName[] tables = admins.listTableNames();

for(TableName table: tables){
System.out.println(table.toString());
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4437 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.