你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 Microsoft Entra ID 授权

Azure 存储提供与Microsoft Entra ID的集成,用于对 Blob、文件、队列和表服务的请求进行基于标识的授权。 使用 Microsoft Entra ID,可以使用基于角色的访问控制 (RBAC) 向用户、组或应用程序授予对 Blob、文件、队列和表资源的访问权限。 可以授予范围限定为单个容器、共享、队列或表级别的权限。

若要详细了解 Azure 存储中的Microsoft Entra ID集成,请参阅使用Microsoft Entra ID授权访问 Azure Blob 和队列

有关在应用程序中使用 Microsoft Entra ID 的优点的详细信息,请参阅与Microsoft 标识平台集成

提示

使用Microsoft Entra ID授权访问 blob、文件、队列和表数据,与其他授权选项相较,可提供更高的安全性和易用性。 使用 Microsoft Entra ID 对应用程序发出的请求进行授权时,可以避免使用代码存储帐户访问密钥,就像使用共享密钥授权一样。 虽然可以继续对 Blob、文件、队列和表应用程序使用共享密钥授权,但 Microsoft 建议尽可能迁移到Microsoft Entra ID。 有关 Azure 存储中Microsoft Entra ID集成的详细信息,请参阅使用 Microsoft Entra ID 授权访问 Azure Blob 和队列

使用 OAuth 访问令牌进行身份验证

Azure 存储接受来自与包含存储帐户的订阅关联的Microsoft Entra租户的 OAuth 2.0 访问令牌。 Azure 存储接受以下项的访问令牌:

  • 用户和组
  • 服务主体
  • Azure 资源的托管标识
  • 使用用户委托的权限的应用程序

Azure 存储公开名为 user_impersonation 的单个委派范围,允许应用程序执行用户允许的任何操作。

若要请求 Azure 存储的令牌,请指定资源 ID 的值 https://storage.azure.com/ 。 有关资源 ID 的详细信息,请参阅Microsoft 标识平台范围、权限 & 同意

有关从Microsoft Entra ID为用户和服务主体请求访问令牌的详细信息,请参阅身份验证流和应用程序方案

有关为配置了托管标识的资源请求访问令牌的详细信息,请参阅 如何在 Azure VM 上使用 Azure 资源的托管标识来获取访问令牌

使用 OAuth 令牌调用存储操作

若要使用 OAuth 访问令牌调用 Blob、文件、队列和表服务操作,请使用持有者方案在 Authorization 标头中传递访问令牌,并为文件服务指定服务版本 2017-11-09 (2022-11-02) 或更高版本,如以下示例所示:

Request:
GET /container/file.txt
x-ms-version: 2017-11-09
Authorization: Bearer eyJ0eXAiO...V09ccgQ
User-Agent: PostmanRuntime/7.6.0
Accept: */*
Host: sampleoautheast2.blob.core.windows.net
accept-encoding: gzip, deflate

Response:
HTTP/1.1 200
status: 200
Content-Length: 28
Content-Type: text/plain
Content-MD5: dxG7IgOBzApXPcGHxGg5SA==
Last-Modified: Wed, 30 Jan 2019 07:21:32 GMT
Accept-Ranges: bytes
ETag: "0x8D686838F9E8BA7"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 09f31964-e01e-00a3-8066-d4e6c2000000
x-ms-version: 2017-11-09
x-ms-creation-time: Wed, 29 Aug 2018 04:22:47 GMT
x-ms-lease-status: unlocked
x-ms-lease-state: available
x-ms-blob-type: BlockBlob
x-ms-server-encrypted: true
Date: Wed, 06 Mar 2019 21:50:50 GMT
Welcome to Azure Storage!!

持有者挑战

持有者质询是 OAuth 协议 RFC 6750 的一部分,用于颁发机构发现。 对于对 Blob 服务的匿名请求,或者对于使用无效 OAuth 持有者令牌发出的请求,服务器将返回状态代码 401 (包含标识提供者和资源信息的未授权) 。 请参阅链接,了解如何在Microsoft Entra ID身份验证期间使用这些值。

Azure 存储 Blob 和队列服务返回版本 2019-12-12 及更新版本的持有者质询。 Azure 存储表服务返回版本 2020-12-06 及更新版本的持有者质询。 Azure Data Lake Storage Gen2返回版本 2017-11-09 及更新版本的持有者质询。 Azure 文件服务返回版本 2022-11-02 及更新版本的持有者质询。

对匿名读取请求的响应

当 Blob 存储收到匿名请求时,如果满足以下所有条件,该请求将成功:

  • 允许对存储帐户进行匿名公共访问。
  • 容器配置为允许匿名公共访问。
  • 请求用于读取访问。

如果其中任一条件不满足,请求将失败。 失败时的响应代码取决于是否使用支持持有者质询的服务版本发出匿名请求。 服务版本 2019-12-12 及更新版本支持持有者质询:

  • 如果使用支持持有者质询的服务版本发出匿名请求,服务会返回错误代码 401(未授权)。
  • 如果使用不支持持有者质询的服务版本发出匿名请求,并且不允许对存储帐户进行匿名公共访问,服务会返回错误代码 409(冲突)。
  • 如果使用不支持持有者质询的服务版本发出匿名请求,并且允许对存储帐户进行匿名公共访问,服务会返回错误代码 404(未发现)。

有关持有者质询的详细信息,请参阅持有者质询

持有者质询的示例响应

下面是当客户端请求未在匿名下载 Blob 请求中包含持有者令牌时,持有者质询响应的示例:

Request:
GET /container/file.txt
x-ms-version: 2019-12-12
Host: sampleoautheast2.blob.core.windows.net

Response:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer authorization_uri=https://login.microsoftonline.com/<tenant_id>/oauth2/authorize resource_id=https://storage.azure.com

<?xml version="1.0" encoding="utf-8"?>
<Error>
    <Code>NoAuthenticationInformation</Code>
    <Message>Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
RequestId:ec4f02d7-1003-0006-21f9-c55bc8000000
Time:2020-01-08T08:01:46.2063459Z</Message>
</Error>
参数 说明
authorization_uri 授权服务器的 URI(物理终结点)。 此值还用作查找键,可从发现终结点获取有关服务器的详细信息。 客户端必须验证授权服务器是否受信任。 当资源受Microsoft Entra ID保护时,足以验证 URL 是否以https://login.microsoftonline.com或Microsoft Entra ID支持的其他主机名开头。 特定于租户的资源应始终返回特定于租户的授权 URI。
resource_id 返回资源的唯一标识符。 客户端应用程序在请求资源的访问令牌时,可以将此标识符用作资源参数的值。 客户端应用程序必须验证此值,否则恶意服务可能会诱发特权提升攻击。 防止攻击的建议策略是验证resource_id是否与正在访问的 Web API URL 的基数匹配。 Azure 存储资源 ID 为 https://storage.azure.com

使用 RBAC 管理访问权限

Microsoft Entra ID通过 RBAC 处理对受保护资源的访问授权。 使用 RBAC,可以将角色分配给用户、组或服务主体。 每个角色都包含一组资源权限。 将角色分配给用户、组或服务主体后,他们有权访问该资源。 可以使用 Azure 门户、Azure 命令行工具和 Azure 管理 API 分配访问权限。 有关 RBAC 的详细信息,请参阅 Role-Based 访问控制 入门

对于 Azure 存储,可以授予对存储帐户中容器或队列中的数据的访问权限。 Azure 存储提供这些内置 RBAC 角色,用于Microsoft Entra ID:

有关如何为 Azure 存储定义内置角色的详细信息,请参阅 了解 Azure 资源的角色定义

还可以定义用于 Blob 存储和 Azure 队列的自定义角色。 有关详细信息,请参阅针对 Azure 基于角色的访问控制创建自定义角色

用于调用数据操作的权限

下表描述了Microsoft Entra用户、组或服务主体调用特定 Azure 存储操作所需的权限。 若要使客户端能够调用特定操作,请确保客户端的已分配 RBAC 角色为该操作提供了足够的权限。

Blob 服务操作的权限

Blob 服务操作 RBAC 操作
列出容器 Microsoft.Storage/storageAccounts/blobServices/containers/read (范围限定为存储帐户或更高版本)
设置 Blob 服务属性 Microsoft.Storage/storageAccounts/blobServices/write
获取 Blob 服务属性 Microsoft.Storage/storageAccounts/blobServices/read
预检 Blob 请求 匿名
获取 Blob 服务统计信息 Microsoft.Storage/storageAccounts/blobServices/read
获取帐户信息 不支持
获取用户委派密钥 Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey/action
创建容器 Microsoft.Storage/storageAccounts/blobServices/containers/write
获取容器属性 Microsoft.Storage/storageAccounts/blobServices/containers/read
获取容器元数据 Microsoft.Storage/storageAccounts/blobServices/containers/read
设置容器元数据 Microsoft.Storage/storageAccounts/blobServices/containers/write
获取容器 ACL 不支持
Set Container ACL 不支持
Lease Container(租赁容器) Microsoft.Storage/storageAccounts/blobServices/containers/write
删除容器 Microsoft.Storage/storageAccounts/blobServices/containers/delete
还原容器 Microsoft.Storage/storageAccounts/blobServices/containers/write
列出 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
在容器中按标记查找 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/filter/action
放置 Blob 对于创建或替换:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
创建新 Blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action
从 URL 放置 Blob 对于创建或替换:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
创建新 Blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action
获取 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
获取 Blob 属性 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
设置 Blob 属性 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
获取 Blob 元数据 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
设置 Blob 元数据 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
获取 Blob 标记 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/read
设置 Blob 标记 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/write
按标记查找 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/filter/action
租用 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
快照 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write 或
Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action
复制 Blob 对于目标 blob:将新 blob 写入) 目标时,Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write 或 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action (
对于同一存储帐户中的源 Blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
对于其他存储帐户中的源 Blob:以匿名方式提供,或包含有效的 SAS 令牌
从 URL 复制 Blob 对于目标 blob:将新 blob 写入) 目标时,Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write 或 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action (
对于同一存储帐户中的源 Blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
对于其他存储帐户中的源 Blob:以匿名方式提供,或包含有效的 SAS 令牌
中止复制 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
删除 Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/delete
取消删除 Blob Microsoft.Storage/storageAccounts/blobServices/containers/write
设置 Blob 层 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
Blob Batch 父请求:Microsoft.Storage/storageAccounts/blobServices/containers/write
子请求:查看该请求类型的权限。
设置不可变性策略 Microsoft.Storage/storageAccounts/blobServices/containers/write
删除不可变性策略 Microsoft.Storage/storageAccounts/blobServices/containers/write
设置 Blob 法定保留 Microsoft.Storage/storageAccounts/blobServices/containers/write
放置块 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
从 URL 放置块 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
放置块列表 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
获取阻止列表 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
查询 Blob 内容 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
放置页 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
从 URL 放置页 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
获取页面范围 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
增量复制 Blob 对于目标 Blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write
对于源 blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read
对于新 Blob:Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action
追加块 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write 或 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action
通过 URL 追加块 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write 或 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action
设置 Blob 过期时间 Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write

队列服务操作的权限

队列服务操作 RBAC 操作
列出队列 Microsoft.Storage/storageAccounts/queueServices/queues/read (范围限定为存储帐户或更高版本)
设置队列服务属性 Microsoft.Storage/storageAccounts/queueServices/read
获取队列服务属性 Microsoft.Storage/storageAccounts/queueServices/read
预检队列请求 匿名
获取队列服务统计信息 Microsoft.Storage/storageAccounts/queueServices/read
创建队列 Microsoft.Storage/storageAccounts/queueServices/queues/write
删除队列 Microsoft.Storage/storageAccounts/queueServices/queues/delete
获取队列元数据 Microsoft.Storage/storageAccounts/queueServices/queues/read
设置队列元数据 Microsoft.Storage/storageAccounts/queueServices/queues/write
获取队列 ACL 无法通过 OAuth 使用
设置队列 ACL 无法通过 OAuth 使用
放置消息 Microsoft.Storage/storageAccounts/queueServices/queues/messages/add/action 或 Microsoft.Storage/storageAccounts/queueServices/queues/messages/write
Get Messages(获取消息) Microsoft.Storage/storageAccounts/queueServices/queues/messages/process/action 或 (Microsoft.Storage/storageAccounts/queueServices/queues/messages/delete 和 Microsoft.Storage/storageAccounts/queueServices/queues/messages/read)
查看消息 Microsoft.Storage/storageAccounts/queueServices/queues/messages/read
删除邮件 Microsoft.Storage/storageAccounts/queueServices/queues/messages/process/action 或 Microsoft.Storage/storageAccounts/queueServices/queues/messages/delete
清除消息 Microsoft.Storage/storageAccounts/queueServices/queues/messages/delete
更新消息 Microsoft.Storage/storageAccounts/queueServices/queues/messages/write

表服务操作的权限

表服务操作 RBAC 操作
设置表服务属性 Microsoft.Storage/storageAccounts/tableServices/write
获取表服务属性 Microsoft.Storage/storageAccounts/tableServices/read
预检表请求 匿名
获取表服务统计信息 Microsoft.Storage/storageAccounts/tableServices/read
执行实体组事务 子操作单独授权
查询表 Microsoft.Storage/storageAccounts/tableServices/tables/read (范围限定为存储帐户或更高版本)
创建表 Microsoft.Storage/storageAccounts/tableServices/tables/write
删除表 Microsoft.Storage/storageAccounts/tableServices/tables/delete
获取表 ACL 无法通过 OAuth 使用
设置表 ACL 无法通过 OAuth 使用
查询实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/read
插入实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/write 或 Microsoft.Storage/storageAccounts/tableServices/tables/entities/add/action
插入或合并实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/write 或 (Microsoft.Storage/storageAccounts/tableServices/tables/entities/add/action 和 Microsoft.Storage/storageAccounts/tableServices/tables/entities/update/action)
插入或替换实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/write 或 (Microsoft.Storage/storageAccounts/tableServices/tables/entities/add/action 和 Microsoft.Storage/storageAccounts/tableServices/tables/entities/update/action)
更新实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/write 或 Microsoft.Storage/storageAccounts/tableServices/tables/entities/update/action
合并实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/write 或 Microsoft.Storage/storageAccounts/tableServices/tables/entities/update/action
删除实体 Microsoft.Storage/storageAccounts/tableServices/tables/entities/delete

文件服务操作的权限

文件服务操作 RBAC 操作
获取文件服务属性 无法通过 OAuth 使用
设置文件服务属性 无法通过 OAuth 使用
预检文件请求 匿名
列出共享 无法通过 OAuth 使用
创建共享 无法通过 OAuth 使用
快照共享 (Snapshot Share) 无法通过 OAuth 使用
获取共享属性 无法通过 OAuth 使用
设置共享属性 无法通过 OAuth 使用
获取共享元数据 无法通过 OAuth 使用
设置共享元数据 无法通过 OAuth 使用
删除共享 无法通过 OAuth 使用
还原共享 无法通过 OAuth 使用
获取共享 ACL 无法通过 OAuth 使用
设置共享 ACL 无法通过 OAuth 使用
获取共享统计信息 无法通过 OAuth 使用
租约共享 无法通过 OAuth 使用
创建权限 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/modifypermissions/action 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
获取权限 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
列出目录和文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
创建目录 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
获取目录属性 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
设置目录属性 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action 和 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/modifypermissions/action(如果 x-ms-file-file-permission 或 x-ms-file-permission-key 包含在 HTTP 请求头中)。
删除目录 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
获取目录元数据 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
设置目录元数据 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
重命名目录 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
创建文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
获取文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
获取文件属性 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
设置文件属性 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action 和 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/modifypermissions/action(如果 x-ms-file-file-permission 或 x-ms-file-permission-key 包含在 HTTP 请求头中)。
放置范围 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
从 URL 放置范围 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
列出范围 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
获取文件元数据 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
设置文件元数据 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
删除文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
复制文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action 和 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/modifypermissions/action(如果 x-ms-file-file-permission 或 x-ms-file-permission-key 包含在 HTTP 请求头中)。
中止复制文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
列表句柄 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/read 和 Microsoft.Storage/storageAccounts/fileServices/readFileBackupSemantics/action
强制关闭句柄 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
租约文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action
重命名文件 Microsoft.Storage/storageAccounts/fileServices/fileShares/files/write 和 Microsoft.Storage/storageAccounts/fileServices/writeFileBackupSemantics/action

另请参阅