Azure 应用程序仅访问 Key Vault key

标签 azure azure-web-app-service azure-keyvault

我有一个 Multi-Tenancy 应用程序。 我需要这个应用程序来:

  1. 能够读取所有租户(已同意)的所有保险库中的 key 。
  2. 无法读取任何 secret 。

我设法使用委派权限(用户模拟)获得对保管库的完全访问权限。 然而,这不是我想要的,因为此权限也为我提供了访问 secret 的权限。

我看到( here )有一个角色只能访问 key 。 角色名称为:Key Vault 加密官员(id:14b46e9e-c2b7-41b4-b07b-48a6ebf60603)

问题是: 是否可以使我的应用程序需要(仅?)此角色。这将允许它读取 key 但不能读取 secret ?不确定我是否以正确的方式思考角色,我对此没有太多经验。

请注意,如果重要的话,我不介意请求委派/应用程序权限。

谢谢

最佳答案

Note that, it's not possible to read keys in vaults of all tenants using multi-tenant application.

为订阅下的 Multi-Tenancy 应用程序分配 Key Vault Crypto Executive 角色,可仅授予读取所有 Key Vault key 一个租户 链接到该订阅,而不是其他租户。

我尝试在我的环境中重现相同的结果并得到以下结果:

我通过在访问配置中选择 Azure 基于角色的访问控制创建了一个名为 srikv07 的 key 保管库,如下所示:

enter image description here

在上面的 keystore 中,我创建了一些像这样的 key 和 secret :

按键: enter image description here

secret : enter image description here

现在,我注册了一个名为 KVmultiapp Multi-Tenancy Azure AD 应用程序,如下所示:

enter image description here

根据我的订阅,我向该 Multi-Tenancy 应用程序分配了 Key Vault CryptoOfficer 角色:

转到 Azure 门户 -> 订阅 -> 选择订阅 -> 访问控制 (IAM) -> 添加角色分配

enter image description here

现在,我通过 Postman 使用客户端凭据流生成了访问 token ,如下所示:

POST https://login.microsoftonline.com/common/oauth2/v2.0/token
client_id: <appID>
grant_type:client_credentials
scope: https://vault.azure.net/.default
client_secret: <secret> 

回应:

enter image description here

当我使用此 token 读取启用 RBAC key 保管库的 key 时,我收到如下错误:

GET https://<yourkvname>.vault.azure.net//keys?api-version=7.3

回应:

enter image description here

要解决此错误,您需要在生成访问 token 时包含tenantID,如下所示:

POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token
client_id: <appID>
grant_type:client_credentials
scope: https://vault.azure.net/.default
client_secret: <secret> 

回应:

enter image description here

现在,我使用这个 token 来检索 key 并成功获得响应,如下所示:

GET https://<yourkvname>.vault.azure.net//keys?api-version=7.3

回应:

enter image description here

当我使用相同的 token 获取 keyvault 的 secret 时,我收到 403 Forbidden 错误,因为该角色仅允许访问 key 。

GET https://<yourkvname>.vault.azure.net//secrets?api-version=7.3

回应:

enter image description here

关于Azure 应用程序仅访问 Key Vault key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75363185/

相关文章:

azure - 使用 Azure 通知中心进行徽章管理

c# - Windows Azure 存储的默认顺序是什么?

azure-devops - Azure DevOps 发布管道变量嵌套/组合/表达式

bash - 如何在 Azure Devops bash 任务中使用可能未定义的 secret 变量

azure - 如何使用 Azure PowerShell 创建 Azure 网络安全组流日志

Azure Policy - 与数组参数中的通配符匹配

Azure Web 应用程序不使用 GZip 压缩

azure-web-app-service - 启用 Azure 网站应用程序诊断

wordpress - 容器 Web 应用程序 - Wordpress Https

azure - 查看 Azure KeyVault 中 Secret 的内容