![](/img/trans.png)
[英]Unable to access a mounted Azure Data Lake storage using Azure Databricks
[英]Unable to mount Azure Data Lake Storage Gen 2 with Azure Databricks
我尝试装入Azure的数据存储湖第二代使用服务主体和OAuth 2.0帐户解释在这里:
configs = {
"fs.azure.account.auth.type": "OAuth",
"fs.azure.account.oauth.provider.type": "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider",
"fs.azure.account.oauth2.client.id": "<application-id>",
"fs.azure.account.oauth2.client.secret": dbutils.secrets.get(scope = "<scope-name>", key = "<key-name-for-service-credential>"),
"fs.azure.account.oauth2.client.endpoint": "https://login.microsoftonline.com/<directory-id>/oauth2/token"}
dbutils.fs.mount(
source = "abfss://<file-system-name>@<storage-account-name>.dfs.core.windows.net/",
mount_point = "/mnt/<mount-name>",
extra_configs = configs
)
我使用的服务主体在存储帐户级别具有Storage Blob Data Contributor
角色,并且在容器级别具有rwx
访问权限。
无论如何,我收到此错误:
ExecutionError: An error occurred while calling o242.mount.
: HEAD https://<storage-account-name>.dfs.core.windows.net/<file-system-name>?resource=filesystem&timeout=90
StatusCode=403
StatusDescription=This request is not authorized to perform this operation.
我什至尝试使用此处所述的存储帐户访问密钥直接访问它,但没有成功:
spark.conf.set(
"fs.azure.account.key.<storage-account-name>.dfs.core.windows.net",
dbutils.secrets.get(scope = "<scope-name>", key = "<key-name-for-service-credential>")
)
dbutils.fs.ls("abfss://<file-system-name>@<storage-account-name>.dfs.core.windows.net/<directory-name>")
问题是,使用 Azure CLI 与此存储帐户交互没有问题:
az login --service-principal --username <application-id> --tenant <directory-id>
az storage container list --account-name <storage-account-name> --auth-mode login
此外,在我的机器上使用REST API没问题,但我在集群上收到一次AuthorizationFailure
:
from getpass import getpass
import requests
from msal import ConfidentialClientApplication
client_id = "<application-id>"
client_password = getpass()
authority = "https://login.microsoftonline.com/<directory-id>"
scope = ["https://storage.azure.com/.default"]
app = ConfidentialClientApplication(
client_id, authority=authority, client_credential=client_password
)
tokens = app.acquire_token_for_client(scopes=scope)
headers = {
"Authorization": "Bearer " + tokens["access_token"],
"x-ms-version": "2019-07-07" # THIS IS REQUIRED OTHERWISE I GET A 400 RESPONSE
}
endpoint = (
"https://<account-name>.dfs.core.windows.net/<filesystem>//?action=getAccessControl"
)
response = requests.head(endpoint, headers=headers)
print(response.headers)
防火墙设置为仅允许受信任的 Microsoft 服务访问存储帐户。
我进入了一个黑洞还是有人在 Databricks 上遇到同样的问题? 是不是ABFS驱动引起的?
确实,问题出在防火墙设置上。 谢谢阿克塞尔R!
我被误导了,因为我也有一个具有相同防火墙设置的 ADLS Gen 1,并且没有问题。
但是,魔鬼在细节中。 Gen 1 防火墙例外允许所有Azure 服务访问资源。 同时,第 2 代只允许受信任的Azure 服务。
我希望这可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.