java—如何在hadoop webhdfs中启用oauth2

vltsax25  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(637)

我正在运行hadoopver2.8.2,并尝试为webhdfs客户机应用程序配置oauth2客户机凭据授予流。我遵循这里的指导:webhdfsrestapi。进入此页后,搜索oauth2以查找有关为webhdfs配置oauth2的部分。
以下是我添加到hdfs-site.xml的oauth 2属性:

<!-- OAuth2 properties -->
  <property>
    <name>dfs.webhdfs.oauth2.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>dfs.webhdfs.oauth2.access.token.provider</name>
    <value>org.apache.hadoop.hdfs.web.oauth2.ConfCredentialBasedAccessTokenProvider</value>
  </property>
  <property>
    <name>dfs.webhdfs.oauth2.client.id</name>
    <value>webHdfsClient</value>
  </property>
  <property>
    <name>dfs.webhdfs.oauth2.credential</name>
    <value>secret</value>
  </property>
  <property>
    <name>dfs.webhdfs.oauth2.refresh.url</name>
    <value>https://<hostname:port of OAuth 2 token endpoint></value>
  </property>

对于my core-site.xml,以下是我认为可能与oauth2配置相关的属性:

<property>
    <name>hadoop.http.authentication.simple.anonymous.allowed</name>
    <value>false</value>
  </property>
  <property>
    <name>hadoop.http.authentication.type</name>
    <value>simple</value>
  </property>

我想,也许错了,匿名认证不应该被允许。根据文档,使用“simple”要求在第一次通过web控制台访问webhdfs时将user.name=username作为查询字符串参数包含在内。我不认为使用simple与通过oauth到webhdfs的客户机应用程序身份验证有任何关系,但是我认为如果simple确实起到了作用,我应该提到它。
然后,我创建了一个java客户机应用程序来访问webhdfs端点。我已经为ssl配置了webhdfs,以便webhdfs端点和令牌管理服务器都使用https协议进行侦听。
下面是我编写的用于访问webhdfs端点(hdserver.local)根的小型java应用程序的主要方法:

public static void main(String[] args) throws IOException {
    Configuration conf = new Configuration();
    conf.set("fs.defaultFS","swebhdfs://hdserver.local:44305");
    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());
    }
}

这将正确返回,而无需从令牌端点检索承载令牌并将其发送到webhdfs进行身份验证。我以为呼叫会失败,告诉我我的呼叫没有被授权,或者请求中缺少一个承载令牌。请告诉我哪里出错了。

0pizxfdo

0pizxfdo1#

hadoop.http.authentication.type和hadoop.http.authentication.simple.anonymous.allowed配置仅与hadoop的web控制台(jobtracker、namenode等)相关。webhdfs即使通过http,也与这些设置不正交。是的,这让人困惑。
其他设置似乎正确。您能在namenode日志中看到oauth2配置生效吗?

相关问题