我有一个场景,当我尝试在 Visual Studio 中调试 ASP.NET Core Web 应用程序时遇到以下异常,该应用程序已连接 Azure Key Vault 的服务和连接到应用服务的 Azure 应用程序配置资源。我登录到 Visual Studio 的用户似乎对 KV 具有正确的权限,并且与另一个没有收到我所做的错误的开发人员相同。我还可以在使用同一用户登录 Azure 时成功查看和检查 AKV 的“机密”页面中所有机密的值。
错误:
<块引用>C:\Professional\Projects\Inventive\inventivegroup\mgr360>dotnet watch run 观看:开始 未处理的异常。 Azure.RequestFailedException:服务请求失败。 状态:403(禁止)
内容: {"error":{"code":"Forbidden","message":"调用者无权对资源执行操作。\r\n如果最近更改了角色分配、拒绝分配或角色定义,请观察传播时间。 \r\n调用方:appid=c41ed4ac-ID-SNIP;oid=3108ce41-ID-SNIP;iss=https://sts.windows.net/359ccce3-ID-SNIP/\r\n操作:'Microsoft.KeyVault/vaults /secrets/readMetadata/action'\r\n资源:'/subscriptions/666a80a4-ID-SNIP/resourcegroups/RESOURCEGROUPNAME/providers/microsoft.keyvault/vaults/webappvaultname'\r\n分配:(未找到)\r\nVault: NameOfWebAppvault;location=eastus\r\n","innererror":{"code":"ForbiddenByRbac"}}}
标题: 缓存控制:无缓存 编译指示:无缓存 x-ms-keyvault-region:eastus x-ms-client-request-id: bd5ef0e5-ID-SNIP x-ms-request-id: 8053b6d8-ID-SNIP x-ms-keyvault-service-version: 1.2.236.0 x-ms-keyvault-network-info: conn_type=Ipv4;addr=50.IP.SNIP;act_addr_fam=InterNetwork; x-ms-keyvault-rbac-cache: ra_age=0;da_age=7453;rd_age=7453;brd_age=11547;ra_notif_age=99;dec_lev=3; X-Powered-By: ASP.NET 严格传输安全:max-age=31536000;includeSubDomains X-Content-Type-Options: nosniff 日期:2021 年 4 月 23 日星期五 18:21:57 GMT 内容长度:701 内容类型:应用程序/json;字符集=utf-8 过期时间:-1
在 Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync(请求请求,CancellationToken 取消令牌)
在 Azure.Security.KeyVault.KeyVaultPipeline.GetPageAsync[T](Uri firstPageUri, String nextLink, Func1 itemFactory, String operationName, CancellationToken cancellationToken) at Azure.Core.PageResponseEnumerator.FuncAsyncPageable
1.AsPages(String continuationToken, Nullable1 pageSizeHint)+MoveNext() at Azure.Core.PageResponseEnumerator.FuncAsyncPageable
1.AsPages(String continuationToken, Nullable{{1) }}1.GetAsyncEnumerator(CancellationTokenCancellationToken)+MoveNext()
在 Azure.AsyncPageable1 pageSizeHint)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at Azure.AsyncPageable
1.GetAsyncEnumerator(CancellationToken cancellingToken)+System.Threading.Tasks.Sources.IValueTaskSource
watch : 退出错误代码 -532462766
代码(也会在运行“dotnet watch run”时发生):
1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext() at Azure.AsyncPageable
我通过 PowerShell 验证了我的登录用户,以确保它是正确的:
这些是访问控制中的角色分配:
我知道错误引用了“观察传播时间”,但已经过了几个小时,昨天发生了同样的错误。这是租客的问题吗? Azure KV 或 RBAC 配置问题?代码问题?开发环境/用户帐户问题?
答案 0 :(得分:1)
作为所有者或贡献者,您无法从 Key Vault 读取密钥。
作为所有者,您确实有权授予自己读取密钥的权限。
如果您为自己提供 Key Vault 管理员角色,您将能够读取密钥。
<块引用>Key Vault Contributor 角色用于管理平面操作 管理密钥保管库。它不允许访问密钥、秘密和 证书。
见:https://docs.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli