We have a remote hadoop cluster running on RHEL, and we need to access HDFS files from a windows Desktop. so I have written programs in java to do the same.
The thing is, we earlier did not have Kerberos enables, and so I could connect using the following code
Configuration conf = new Configuration();
conf.set("fs.defaultFS","hdfs://one.hdp:8020");
FileSystem fs = FileSystem.get(conf);
FileStatus[] fsStatus = fs.listStatus(new Path("/"));
for(int i = 0; i < fsStatus.length; i++){
System.out.println(fsStatus[i].getPath().toString());
}
Now that we have Kerberos code, I followed this site http://henning.kropponline.de/2016/02/14/a-secure-hdfs-client-example/, and created the following based on "Providing Credentials from Login" which uses the GSS-API to do a kinit like this
The Callback Handler :
private static String username = "hdfs-user";
private static char[] password = "hadoop".toCharArray();
public static LoginContext kinit() throws LoginException {
LoginContext lc = new LoginContext(HdfsMain.class.getSimpleName(), new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for(Callback c : callbacks){
if(c instanceof NameCallback)
((NameCallback) c).setName(username);
if(c instanceof PasswordCallback)
((PasswordCallback) c).setPassword(password);
}
}});
lc.login();
return lc;
}
HdfsMain.conf :
HdfsMain {
com.sun.security.auth.module.Krb5LoginModule required client=TRUE;
};
Code to connect :
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://one.hdp:8020");
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
LoginContext lc = kinit();
UserGroupInformation.loginUserFromSubject(lc.getSubject());
FileSystem fs = FileSystem.get(conf);
FileStatus[] fsStatus = fs.listStatus(new Path("/"));
for(int i = 0; i < fsStatus.length; i++){
System.out.println(fsStatus[i].getPath().toString());
}
Now im getting the following error :
Caused by: KrbException: null (68)
at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:76)
at sun.security.krb5.KrbAsReqBuilder.send(KrbAsReqBuilder.java:316)
at sun.security.krb5.KrbAsReqBuilder.action(KrbAsReqBuilder.java:361)
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:766)
... 15 more
Caused by: KrbException: Identifier doesn't match expected value (906)
at sun.security.krb5.internal.KDCRep.init(KDCRep.java:140)
at sun.security.krb5.internal.ASRep.init(ASRep.java:64)
at sun.security.krb5.internal.ASRep.<init>(ASRep.java:59)
at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:60)
... 18 more
And im not able to Login.
NOTE : I do not have a Keytab file to test out that approach.
Any kind of help will be appreciated