【问题标题】:Azure Storage List Blobs using AAD Authentication - Audience validation failed使用 AAD 身份验证的 Azure 存储列表 Blob - 受众验证失败
【发布时间】:2020-08-06 21:05:25
【问题描述】:

使用 Postman,获取成功列出存储帐户和资源组的 Bearer 令牌。在同一个集合中,尝试列出容器中的 Blob 并获得“受众验证失败。受众不匹配”。任何诊断此错误的帮助将不胜感激。

【问题讨论】:

  • 您获得不记名令牌的受众群体是什么?我相信要列出 blob,您需要获得 https://<account>.blob.core.windows.nethttps://storage.azure.com/ 的令牌。
  • 您能告诉我您是如何获得 Azure AD 访问令牌的吗?

标签: azure rest authentication azure-blob-storage


【解决方案1】:

如果要使用 Azure AD 访问令牌访问 Azure Blob Rest API,我们需要分配 Azure RABC 角色(Storage Blob Data OwnerStorage Blob Data Contributor存储 Blob 数据读取器)到服务主体或 AD 用户。更多详情请参考document

例如(我使用服务主体) 1. 创建服务主体并为 sp 分配 Azure RABC 角色。

az login
az account set --subscription "<your subscription id>"
# it will assign Storage Blob Data Reader to the sp at storage accountlevel
az ad sp create-for-rbac -n "mysample" --role Storage Blob Data Reader --scopes <the resource id of storage account>

  1. 获取 AD 访问令牌
POST /<your sp tenant id>/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

grant_type =client_credentials
&client_id=<your sp appId>
&client_secret=<your sp password>k
&resource=https://storage.azure.com/
  1. 列出 blob
GET https://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=list

x-ms-version: 2017-11-09
Authorization: Bearer <access token>

【讨论】:

  • 非常感谢。我从使用 Logic Apps 的工作中复制了 Postman 集合,但忽略了将资源更改为 storage.azure.com。一旦我解决了这个问题,一切都很好。
猜你喜欢
  • 2021-10-16
  • 1970-01-01
  • 2017-10-30
  • 2021-11-28
  • 1970-01-01
  • 2017-11-15
  • 2021-09-24
  • 2019-01-13
  • 2020-07-24
相关资源
最近更新 更多