Hadoop客户端对Azure Data Lake Gen2的用户名和密码访问问题

时间:2019-09-06 16:01:50

标签: azure hadoop azure-data-lake

尝试通过控制台中的Hadoop客户端使用用户名和密码身份验证类型连接到Azure Data Lake Storage Gen2并收到错误

java.lang.NullPointerException
        at org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.consumeInputStream(AzureADAuthenticator.java:341)
        at org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.getTokenSingleCall(AzureADAuthenticator.java:271)
        at org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.getTokenCall(AzureADAuthenticator.java:212)
        at org.apache.hadoop.fs.azurebfs.oauth2.AzureADAuthenticator.getTokenUsingClientCreds(AzureADAuthenticator.java:95)
        at org.apache.hadoop.fs.azurebfs.oauth2.UserPasswordTokenProvider.refreshToken(UserPasswordTokenProvider.java:54)
        at org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider.getToken(AccessTokenProvider.java:50)
        at org.apache.hadoop.fs.azurebfs.services.AbfsClient.getAccessToken(AbfsClient.java:546)
        at org.apache.hadoop.fs.azurebfs.services.AbfsRestOperation.executeHttpOperation(AbfsRestOperation.java:150)
        at org.apache.hadoop.fs.azurebfs.services.AbfsRestOperation.execute(AbfsRestOperation.java:124)
        at org.apache.hadoop.fs.azurebfs.services.AbfsClient.getFilesystemProperties(AbfsClient.java:197)
        at org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore.getIsNamespaceEnabled(AzureBlobFileSystemStore.java:181)
        at org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore.getFileStatus(AzureBlobFileSystemStore.java:454)
        at org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem.getFileStatus(AzureBlobFileSystem.java:395)
        at org.apache.hadoop.fs.Globber.getFileStatus(Globber.java:65)
        at org.apache.hadoop.fs.Globber.doGlob(Globber.java:294)
        at org.apache.hadoop.fs.Globber.glob(Globber.java:149)
        at org.apache.hadoop.fs.FileSystem.globStatus(FileSystem.java:2016)
        at org.apache.hadoop.fs.shell.PathData.expandAsGlob(PathData.java:353)
        at org.apache.hadoop.fs.shell.Command.expandArgument(Command.java:250)
        at org.apache.hadoop.fs.shell.Command.expandArguments(Command.java:233)
        at org.apache.hadoop.fs.shell.FsCommand.processRawArguments(FsCommand.java:104)
        at org.apache.hadoop.fs.shell.Command.run(Command.java:177)
        at org.apache.hadoop.fs.FsShell.run(FsShell.java:327)
        at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)
        at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:90)
        at org.apache.hadoop.fs.FsShell.main(FsShell.java:390)

完成了什么

  1. 使用https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-quickstart-create-account

  2. 创建的存储帐户
  3. 使用https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal

  4. 创建的Azure AD应用程序
  5. 在访问控制(IAM)中将AD用户作为存储BLOB数据所有者添加到存储帐户。

根据Apache documentation,我创建了一个控制台命令

hadoop fs -Dfs.azure.ssl.channel.mode=Default_JSSE
-Dfs.azure.account.auth.type=OAuth
-Dfs.azure.account.oauth.provider.type=org.apache.hadoop.fs.azurebfs.oauth2.UserPasswordTokenProvider
-Dfs.azure.account.oauth2.client.endpoint=https://login.microsoftonline.com/<TENANT ID>/oauth2/v2.0/authorize
-Dfs.azure.account.oauth2.user.name=<USER_NAME@mail.com>
-Dfs.azure.account.oauth2.user.password=<PASSWORD>
-ls abfss://<CONTAINER NAME>@<STORAGE ACCOUNT>.dfs.core.windows.net/

如果尝试使用此端点

https://login.microsoftonline.com/<TENANT ID>/oauth2/v2.0/token

输出为

ls: AADToken: HTTP connection failed for getting token from AzureAD. Http response: 400 Bad Request

因此,以下命令应显示容器中文件夹和文件的列表。命令或Azure中的容器配置有问题吗?请指教。

1 个答案:

答案 0 :(得分:0)

无论您使用的是Azure AD用户还是服务主体,都必须使用OAuth2 V1令牌终结点,因为它是Authenticator类支持的。这是令牌端点URL:

https://login.microsoftonline.com/{TENANT_ID}/oauth2/token

Here,您可以找到V1和V2端点之间的区别。

话虽如此,您必须使用的控制台命令变为:

hadoop fs -Dfs.azure.ssl.channel.mode=Default_JSSE \
-Dfs.azure.account.auth.type=OAuth \
-Dfs.azure.account.oauth.provider.type=org.apache.hadoop.fs.azurebfs.oauth2.UserPasswordTokenProvider \
-Dfs.azure.account.oauth2.client.endpoint=https://login.microsoftonline.com/{TENANT_ID}/oauth2/token \
-Dfs.azure.account.oauth2.user.name={USER_NAME@mail.com} \
-Dfs.azure.account.oauth2.user.password={PASSWORD} \
-ls abfss://{CONTAINER NAME}@{STORAGE_ACCOUNT}.dfs.core.windows.net/

根据您的问题,似乎您也可能想使用服务主体进行身份验证,在这种情况下,您必须使用 ClientCredsTokenProvider 代替 UserPasswordTokenProvider ,如下所示:

hadoop fs -Dfs.azure.ssl.channel.mode=Default_JSSE \
-Dfs.azure.account.auth.type=OAuth \
-Dfs.azure.account.oauth.provider.type=org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider \
-Dfs.azure.account.oauth2.client.endpoint=https://login.microsoftonline.com/{TENANT_ID}/oauth2/token \
-Dfs.azure.account.oauth2.client.id={CLIENT_ID} \
-Dfs.azure.account.oauth2.client.secret={SECRET_KEY} \
-ls abfss://{CONTAINER NAME}@{STORAGE_ACCOUNT}.dfs.core.windows.net/

您还可以将身份验证信息存储在core-site.xml文件中,如hadoop docs所述。如果要使用多个存储帐户,则可以将属性名称更改为以dfs端点结尾,如下例所示:

<property>
  <name>fs.azure.account.auth.type.{STORAGE_ACCOUNT}.dfs.core.windows.net</name>
  <value>OAuth</value>
  <description>
  Use OAuth authentication
  </description>
</property>
<property>
  <name>fs.azure.account.oauth.provider.type.{STORAGE_ACCOUNT}.dfs.core.windows.net</name>
  <value>org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider</value>
  <description>
  Use client credentials
  </description>
</property>
<property
  <name>fs.azure.account.oauth2.client.endpoint.{STORAGE_ACCOUNT}.dfs.core.windows.net</name>
  <value>https://login.microsoftonline.com/{TENANT_ID}/oauth2/token</value>
  <description>
  URL of OAuth endpoint
  </description>
</property>
<property>
  <name>fs.azure.account.oauth2.client.id.{STORAGE_ACCOUNT}.dfs.core.windows.net</name>
  <value>{CLIENT_ID}</value>
  <description>
  Client ID
  </description>
</property>
<property>
  <name>fs.azure.account.oauth2.client.secret.{STORAGE_ACCOUNT}.dfs.core.windows.net</name>
  <value>{SECRET_KEY}</value>
  <description>
  Secret
  </description>
</property>

很抱歉,为时已晚,我只是遇到了这个问题,而这个问题正处于寻找解决方案的道路上,当我将其付诸实践时,我认为有人可能会觉得有帮助。