Accessing kerberos secured WebHDFS without SPnego

后端 未结 2 437
耶瑟儿~
耶瑟儿~ 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:27

    Using Java code plus the Hadoop Java API to open a Kerberized session, get the Delegation Token for the session, and pass that Token to the other app -- as suggested by @tellisnz -- has a drawback: the Java API requires quite a lot of dependencies (i.e. a lot of JARs, plus Hadoop native libraries). If you run you app on Windows, in particular, it will be a tough ride.

    Another option is to use Java code plus WebHDFS to run a single SPNEGOed query and GET the Delegation Token, then pass it to the other app -- that option requires absolutely no Hadoop library on your server. The barebones version would be sthg like

    URL urlGetToken = new URL("http://:/webhdfs/v1/?op=GETDELEGATIONTOKEN") ;
    HttpURLConnection cnxGetToken =(HttpURLConnection) urlGetToken.openConnection() ;
    BufferedReader httpMessage = new BufferedReader( new InputStreamReader(cnxGetToken.getInputStream()), 1024) ;
    Pattern regexHasToken =Pattern.compile("urlString[\": ]+(.[^\" ]+)") ;
    String httpMessageLine ;
    while ( (httpMessageLine =httpMessage.readLine()) != null)
    { Matcher regexToken =regexHasToken.matcher(httpMessageLine) ;
      if (regexToken.find())
      { System.out.println("Use that template: http://:/webhdfs/v1%AbsPath%?delegation=" +regexToken.group(1) +"&op=...") ; }
    }
    httpMessage.close() ;
    

    That's what I use to access HDFS from a Windows Powershell script (or even an Excel macro). Caveat: with Windows you have to create your Kerberos TGT on the fly, by passing to the JVM a JAAS config pointing to the appropriate keytab file. But that caveat also applies to the Java API, anyway.

提交回复
热议问题