2017-12-25 9 views
4

私はこの記事の次に私Azureの機能のアプリでアズールキーVaultをimplmentedました: https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0bは、Azureのキーボールトから値を読み取ることができません

記事で説明したように、私はマネージド使用しているサービスID(MSI) Key Vaultから値を読み取ることができないように見えます。以下は、値を読み取るはずの行です。

var myValue = (await kvClient.GetSecretAsync(Environment.GetEnvironmentVariable("documentDbkey"))).Value; 

これは私のエントリは、AzureのKeyVaultにどのように見えるかです: enter image description here

私はbf2550f4eで始まる1である私のエントリすなわちdocumentDbまたはバージョンIDのためkeyを使用することになっているだろうか?

はここでエラーです:

Exception while executing function: IngridNotificationsFunction Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: IngridNotificationsFunction ---> System.ArgumentNullException : Value cannot be null. Parameter name: secretIdentifier at async Microsoft.Azure.KeyVault.KeyVaultClientExtensions.GetSecretAsync(??)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Ingrid.Notifications.IngridNotifications.Initialize() at C:\Users\Sam\Documents\Visual Studio 2017\Projects\Ingrid.Notifications\Ingrid.Notifications\IngridNotifications.cs : 83 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Ingrid.Notifications.IngridNotifications.Run(String myQueueItem) at C:\Users\Sam\Documents\Visual Studio 2017\Projects\Ingrid.Notifications\Ingrid.Notifications\IngridNotifications.cs : 38 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker 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 2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments) at 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から値を読み取ることができませんよ理由だろうか?

+0

このスレッドについての最新情報を教えてください。 –

答えて

2

System.ArgumentNullException : Value cannot be null


例外によれば、Environment.GetEnvironmentVariable("documentDbkey")がヌルであることを示しています。

What could be the reason why I'm unable to read values from my Azure KeyVault?

我々はEnvironment.GetEnvironmentVariable(「documentDbkey」)を使用したい場合は、私たちはあなたのケースで値https://{yourkeyvalue}.vault.azure.net/Secrets/{yourSecretName}とキーdocumentDbkeyを追加するために設定紺碧の機能アプリを設定へ必要があります。

enter image description here

enter image description here

更新:

あなたは秘密を取得するために、直接、次のコードを使用することができます。 article

enter image description here

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

はまた、彼はキー金庫秘密のIDを格納するためのアプリケーションの設定を使用することを述べました。

You’ll notice I am using an environment variable (application setting) in this case for the key vault secret ID, but that itself is not a secret — just a location of where the secret is stored

+0

私はこれらの値をAzure Key Vaultから読み込もうとしています。アプリの設定ではありません。私が従う記事にはAzure Key Vaultの値を読み取るために使用される次のコードがあり、Azure Key Vaultクライアントのコンテキストで 'GetEnvironmentVariable()'が使用されているようです。 'kvClient.GetSecretAsync(Environment.GetEnvironmentVariable(" EventHubSecretId ")))。値;' – Sam

+0

私は答えを更新しました。あなたは、著者が秘密のIDを格納するために環境変数(アプリケーション設定)を使用するブログを述べました。秘密のIDを直接使用することもできます。 'kvClient.GetSecretAsync(" https:// {yourkeyvalue} .vault.azure.net/Secrets/{yourSecretName} ").Value' –

+0

ありがとうございました! 'GetSecretAsync()'が機能しました!再度、感謝します! – Sam

関連する問題