我正在尝试使用Azure密钥保管库来存储一些秘密。遵循本教程: https://docs.microsoft.com/en-us/azure/key-vault/vs-secure-secret-appsettings
在调试时有效,但是当我将应用程序发布到Azure时,它会因为我的密钥返回null而失败。
这在调试期间也有效,但是当我发布到Azure时,它也会因为我的密钥返回null而失败。
我应该在哪里寻求如何解决这个问题的任何帮助都会很棒。为什么我会在生产中获取null,但在提供相同的凭据时不进行调试?
答案 0 :(得分:1)
为了让应用程序能够使用AppAuthentication库访问Azure中的密钥保管库,它应该启用托管服务标识。
此外,需要为自动创建的服务主体授予对Key Vault中秘密的访问权限。
在Azure中指定KeyVault端点URL可以使用第一个示例中的密钥except
的应用设置完成。
答案 1 :(得分:0)
// Create a new secret client using the default credential from Azure.Identity using environment variables previously set,
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
var client = new SecretClient(vaultUri: new Uri(keyVaultUrl), credential: new DefaultAzureCredential());
// Create a new secret using the secret client.
KeyVaultSecret secret = client.SetSecret("secret-name", "secret-value");
// Retrieve a secret using the secret client.
secret = client.GetSecret("secret-name");