无法从Azure Key Vault读取值

问题描述 投票:4回答:1

我在本文之后的Azure Functions应用程序中实现了Azure Key Vault:qazxsw poi

如本文所述,我正在使用托管服务标识(MSI),但看起来我无法读取密钥保管库的值。以下是应该读取该值的行。

https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0b

这就是我的条目在Azure KeyVault上的样子:var myValue = (await kvClient.GetSecretAsync(Environment.GetEnvironmentVariable("documentDbkey"))).Value;

我应该使用enter image description here作为我的条目,即key或版本Id是以documentDb开头的那个?

这是错误:

执行函数时出现异常:IngridNotificationsFunction Microsoft.Azure.WebJobs.Host.FunctionInvocationException:执行函数时出现异常:IngridNotificationsFunction ---> System.ArgumentNullException:Value不能为null。参数名称:async的secretIdentifier Microsoft.Azure.KeyVault.KeyVaultClientExtensions.GetSecretAsync(??) 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw的C:\ Users \ Sam \ Documents \ Visual Studio 2017 \ Projects \ Ingrid.Notifications \ Ingrid.Notifications \ IngridNotifications.cs:83中的异步Ingrid.Notifications.IngridNotifications.Initialize() ()在System.Runtime.ExceptionServices上的C:\ Users \ Sam \ Documents \ Visual Studio 2017 \ Projects \ Ingrid.Notifications \ Ingrid.Notifications \ IngridNotifications.cs:38中的异步Ingrid.Notifications.IngridNotifications.Run(String myQueueItem) .ExceptionDispatchInfo.Throw()在异步Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvokerbf2550f4e2.InvokeAsync [TReflected,TReturnValue](对象实例,对象[]参数)在C:\ projects \ azure-webjobs-sdk-rqm4t \ src \ Microsoft.Azure.WebJobs.Host \ Executors \ FunctionInvoker.cs:63 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)at C:\ projects \ azure-webjobs-sdk-rqm4t \ src \ Microsoft.Azure.WebJobs.Hos ...

可能是我无法从Azure KeyVault读取值的原因是什么?

azure-functions azure-keyvault
1个回答
2
投票

System.ArgumentNullException:值不能为null


根据例外,它表明2.InvokeAsync[TReflected,TReturnType](TReflected instance,Object[] arguments) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidTaskMethodInvoker.cs : 20 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker为空。

可能是我无法从Azure KeyVault读取值的原因是什么?

如果我们想使用Environment.GetEnvironmentVariable(“documentDbkey”),我们需要配置azure函数应用程序设置,以便在您的情况下添加值为Environment.GetEnvironmentVariable("documentDbkey")的密钥documentDbkey。

https://{yourkeyvalue}.vault.azure.net/Secrets/{yourSecretName}

enter image description here

更新:

您可以直接使用以下代码来获取秘密。

enter image description here

kvClient.GetSecretAsync("https://{yourkeyvalue}.vault.azure.net/Secrets/{yourSecretName}")​.Value

enter image description here中还提到他使用应用程序设置来存储密钥库秘密ID。

您会注意到我在这种情况下使用环境变量(应用程序设置)作为密钥保管库密钥ID,但这本身并不是秘密 - 只是存储密钥的位置

© www.soinside.com 2019 - 2024. All rights reserved.