![](/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.