0

我想知道,如何将我的应用服务正确连接到也通过 KeyVault 支持的应用配置。

可悲的是,我并没有真正找到一个完美的教程,所以现在我有点困惑,这是行不通的。

这是我的错误:

Unhandled exception. Microsoft.Extensions.Configuration.AzureAppConfiguration.KeyVaultReferenceException: Key vault error. ErrorCode:, Key:copied out, Label:, Etag:copied out, SecretIdentifier:https://copied out.vault.azure.net/secrets/copied out
2021-03-21T00:07:43.756601504Z  ---> Azure.RequestFailedException: Service request failed.
2021-03-21T00:07:43.756608304Z Status: 403 (Forbidden)

2021-03-21T00:07:43.756614804Z Content:
2021-03-21T00:07:43.756614804Z {"error":{"code":"Forbidden","message":"The user, group or application 'appid=copied out;oid=copied out;iss=https://sts.windows.net/copied out/' does not have secrets get permission on key vault 'moonwatch;location=eastus'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287","innererror":{"code":"AccessDenied"}}}

(请注意,我已经复制了敏感数据

我有点为此烦恼。这是我的设置:

ConfigBuilder.AddAzureAppConfiguration(options =>
            {
                var credentials = new ManagedIdentityCredential();
                options.Connect(new Uri("https://copied out.azconfig.io"), credentials)
                    .ConfigureKeyVault(kv => kv.SetCredential(credentials));
            });

以下是我目前配置资源的方式:

  1. 我的应用服务具有托管的系统分配标识
  2. 应用程序配置包含我的所有配置,以及一些由 keyvault 支持的配置条目
  3. keyvault 设置为“Vault access”作为访问策略,并根据设置过程正确连接到应用程序配置
  4. 我的应用服务应用程序在我的应用配置中分配了“应用配置数据读取器”角色。

我现在不完全确定这个设置在哪里仍然出错。我现在尝试了几件事,切换到 RBAC,在这里和那里更改设置,但似乎还没有成功。RBAC 将错误更改为:

2021-03-21T00:07:43.756618504Z {"error":{"code":"Forbidden","message":"Caller is not authorized to perform action on resource.\r\nIf role assignments, deny assignments or role definitions were changed recently, please observe propagation time.\r\nCaller: appid=copied out;oid=copied out;iss=copied out/\r\nAction: 'Microsoft.KeyVault/vaults/secrets/getSecret/action'\r\nResource: '/subscriptions/copied out/resourcegroups/moonwatch/providers/microsoft.keyvault/vaults/copied out/secrets/copied out'\r\nAssignment: (not found)\r\nVault: copied out;location=eastus\r\n","innererror":{"code":"ForbiddenByRbac"}}} 

我哪里错了?我是否还需要以某种方式将我的应用程序本身连接到 keyvault?这看起来对我来说是一个传递的东西

4

1 回答 1

1

发生错误是因为您的应用服务无权访问您的 Key Vault。Azure 应用配置不会访问您的 Key Vault。您的应用程序可以。在 Key Vault 的访问策略中,请授予应用服务的托管标识“获取”机密权限。

于 2021-03-21T08:25:34.490 回答