尝试在 Functions v2 应用设置中设置以下内容时我做错了什么。
@Microsoft.KeyVault(SecretUri=<uri>)
在函数内部读取此内容,我得到了完整的字符串,而不是像我预期的那样从 keystore 中获取连接字符串。
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var value = config["cstring"];
var connectionString = Environment.GetEnvironmentVariable("cstring");
log.Info(value); // Prints "@Microsoft.KeyVault(SecretUri=<uri>)"
log.Info(connectionString); // Prints "@Microsoft.KeyVault(SecretUri=<uri>)"
我需要采取更多步骤吗?
作为有权访问 key 保管库的 MSI 的功能。
多个在线教程使这看起来非常简单并且开箱即用。
最佳答案
为 Azure Function 启用 MSI 后,我进入 key 保管库并添加访问策略,以便我的 Azure Function 应用程序有权读取 secret 。该功能应适用于 Azure 中托管的所有版本的 Azure Functions。它在本地不起作用。
因此,请转到您的 Azure Key Vault 并向其添加 MSI 原则,并授予 Get
secret 权限。
关于Azure 函数 key 保管库应用程序设置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54146488/