Accessing kerberos secured WebHDFS without SPnego

后端 未结 2 438
耶瑟儿~
耶瑟儿~ 2020-12-20 04:43

I have a working application for managing HDFS using WebHDFS. I need to be able to do this on a Kerberos secured cluster.

The problem is, that there is no library or

2条回答
  •  情深已故
    2020-12-20 05:44

    You could take a look at the hadoop-auth client and create a service which does the first connection, then you might be able to grab the 'Authorization' and 'X-Hadoop-Delegation-Token' headers and cookie from it and add it to your basic client's requests.

    First you'll need to have either used kinit to authenticate your user for application before running. Otherwise, you're going to have to do a JAAS login for your user, this tutorial provides a pretty good overview on how to do that.

    Then, to do the login to WebHDFS/HttpFS, we'll need to do something like:

    URL url = new URL("http://youhost:8080/your-kerberised-resource");
    AuthenticatedURL.Token token = new AuthenticatedURL.Token();
    HttpURLConnection conn = new AuthenticatedURL().openConnection(url, token);
    
    String authorizationTokenString = conn.getRequestProperty("Authorization");
    String delegationToken = conn.getRequestProperty("X-Hadoop-Delegation-Token");
    ...
    // do what you have to to get your basic client connection
    ...
    myBasicClientConnection.setRequestProperty("Authorization", authorizationTokenString);
    myBasicClientConnection.setRequestProperty("Cookie", "hadoop.auth=" + token.toString());
    myBasicClientConnection.setRequestProperty("X-Hadoop-Delegation-Token", delegationToken);
    

提交回复
热议问题