我正在尝试使用 Python SDK 迭代 Azure datalake Gen1 中的所有文件夹。我正在使用分配有所有者角色的服务主体。但是,当我尝试访问某些文件夹时,出现权限被拒绝错误。我不确定我是否还需要任何其他角色,因为我猜所有者拥有最高权限。
下面是我正在使用的代码
%pip install azure-mgmt-resource
%pip install azure-mgmt-datalake-store
%pip install azure-datalake-store
import re
import datetime;
from azure.datalake.store import lib, core
from azure.common.credentials import ServicePrincipalCredentials
from pyspark.sql.types import StringType
from pyspark.sql.functions import udf,split, explode,col,when,concat,array_contains,lit
import datetime;
def authenticate(clientId, secretId, tenantId):
RESOURCE = 'https://datalake.azure.net/'
tenant = tenantId
client_id = clientId
client_secret = secretId
adlCreds = lib.auth(tenant_id=tenant,
client_secret=client_secret,
client_id=client_id,
resource=RESOURCE)
adl = core.AzureDLFileSystem(adlCreds, store_name="xxx")
return adl
clientId = dbutils.secrets.get(scope = "datalakesecurity", key = "datalakeclientid")
secretId = dbutils.secrets.get(scope = "datalakesecurity", key = "datalakecredential")
tenantId = 'xxxxx'
adl = authenticate(clientId, secretId, tenantId)
path_to_look= '/'
level1 = adl.ls(path_to_look)
print(level1)
最佳答案
Azure Datalake Gen1 Permission Denied while iterating over folders.
在 Azure Data Lake Gen1 中,“所有者”角色拥有对整个 Data Lake 帐户(包括所有文件夹和文件)的完全访问权限。即使您拥有所有者角色,某些文件夹级权限可能仍会阻止您访问特定文件夹。您还可以为您的服务主体授予贡献者职位。
According to this MS Document Along with the owner role you need to explicitly give the permission to read, write, execute on a folder level.
即使您的服务原则具有所有者角色,但您没有上述权限,您也会面临权限被拒绝的错误。
关于迭代文件夹时 Azure Datalake Gen1 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76228802/