You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

生成ADLS SAS令牌时指定路径导致授权失败问题排查

用户委托SAS令牌指定路径后403认证失败问题解决

问题背景

使用Azure Java SDK生成用户委托SAS令牌时,path为null或空串时能正常授权访问,但指定具体路径(如data/testTable)时,Postman请求和Iceberg SQL操作均返回403错误:

Status code 403
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.</Message>
</Error>

核心生成代码如下:

TokenCredential tokenCredential =
    new ClientSecretCredentialBuilder()
        .tenantId(tenantId)
        .clientId(clientId)
        .clientSecret(clientSecret)
        .build();

DataLakeServiceClient dataLakeServiceClient =
    new DataLakeServiceClientBuilder()
        .endpoint(endpoint)
        .credential(tokenCredential)
        .buildClient();

UserDelegationKey userDelegationKey =
    dataLakeServiceClient.getUserDelegationKey(start, expiry);

PathSasPermission pathSasPermission =
    PathSasPermission.parse("rwdlca");
DataLakeServiceSasSignatureValues signatureValues =
    new DataLakeServiceSasSignatureValues(expiry, pathSasPermission);

String sasToken =
    new DataLakeSasImplUtil(signatureValues,container, path, true)
        .generateUserDelegationSas(userDelegationKey, accountName, Context.NONE);

排查与修复步骤

1. 校验路径格式

Azure Data Lake路径有严格格式要求:

  • 路径开头不能加斜杠,用data/testTable而非/data/testTable
  • 目录路径末尾不要加斜杠(除非需授权目录下所有资源,此时权限需匹配)
  • 路径大小写必须与存储容器中实际路径完全一致(Azure存储路径区分大小写)

2. 确认服务主体权限

生成用户委托密钥的服务主体需具备数据层面权限:

  • 必须分配Storage Blob Data Contributor或更高权限(Storage Account Contributor仅为管理权限,不适用数据访问)
  • 权限需直接作用于目标容器或具体路径,而非仅存储账户级别

3. 修正SAS签名的资源类型

指定路径时,需明确设置SAS签名的资源类型:

// 授权目录时设置resource为"d"
signatureValues.setResource("d"); 
// 授权文件时设置为"b"
// signatureValues.setResource("b");

String sasToken =
    new DataLakeSasImplUtil(signatureValues, container, path, true)
        .generateUserDelegationSas(userDelegationKey, accountName, Context.NONE);

若授权目录,PathSasPermission需包含目录相关权限(如l列出、d删除等)。

4. 验证SAS令牌参数

生成SAS后,可解码查看关键参数:

  • sr需为d(目录)或b(文件),与实际资源类型匹配
  • spath值需与指定路径完全一致,无多余斜杠或编码错误

5. SQL操作的额外配置

使用Iceberg通过SAS访问时:

  • Spark配置中的路径需与SAS授权路径完全匹配
  • Iceberg catalog配置需准确指向授权容器和路径,避免路径前缀不一致
  • SQL中尽量使用完整路径,避免相对路径

6. 检查权限继承

若路径为嵌套目录,需确认服务主体权限是否继承到子目录:

  • 在Azure门户的目标路径Access Control (IAM)中,查看服务主体权限是否直接分配或通过继承获得
  • 用Azure CLI验证访问权限:
az storage blob directory exists --account-name <你的存储账户名> --container-name <容器名> --name <目标路径> --auth-mode login

返回true则说明服务主体有权访问该路径。

内容的提问来源于stack exchange,提问作者Jun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 14:47:32