2017-12-25 4 views
4

Ich habe in meiner Azure Funktion App nach diesem Artikel Azure Key Vault implmented: https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0bWert kann nicht von Azure Key Vault lesen

Wie in dem Artikel beschrieben, ich bin mit Managed Service Identity (MSI) aber es sieht so aus, als ob ich Werte aus Key Vault nicht lesen kann. Das Folgende ist die Zeile, die den Wert lesen soll.

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

Dies ist, was wie meine Einträge aussehen auf Azure KeyVault: enter image description here

Soll ich die key für meinen Eintrag verwenden, das heißt documentDb oder die Version Id, die derjenige, der mit bf2550f4e beginnt, ist?

Hier Fehler:

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…

Was könnte der Grund, warum ich nicht in der Lage Werte von meinem Azure KeyVault zu lesen?

+0

Haben Sie ein Update zu diesem Thema? –

Antwort

2

System.ArgumentNullException : Value cannot be null


Nach der Ausnahme, zeigt es an, dass Environment.GetEnvironmentVariable("documentDbkey") null ist.

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

Wenn wirEnvironment.GetEnvironmentVariable („documentDbkey“) verwenden möchten, müssen wir die azur Funktion app Einstellung config den Schlüssel documentDbkey mit Wert https://{yourkeyvalue}.vault.azure.net/Secrets/{yourSecretName} in Ihrem Fall hinzuzufügen.

enter image description here

enter image description here

Update:

Sie können den folgenden Code verwenden, um direkt das Geheimnis zu bekommen.

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

enter image description here

Im article erwähnte auch, dass er für die Speicherung der Schlüssel Gewölbe geheime ID der Anwendungseinstellungen verwenden.

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

Ich versuche, diese Werte aus Azure Key Vault, nicht App-Einstellungen zu lesen. Der Artikel, dem ich folge, enthält den folgenden Code, der zum Lesen von Werten aus Azure Key Vault verwendet wird und aussieht wie 'GetEnvironmentVariable()' im Kontext des Azure Key Vault-Clients verwendet wird. Hier ist der Code: 'kvClient.GetSecretAsync (Environment.GetEnvironmentVariable (" EventHubSecretId "))). Wert;' – Sam

+0

Ich habe die Antwort aktualisiert. In Ihrem Blog haben Sie erwähnt, dass der Autor die Umgebungsvariable (Anwendungseinstellung) zum Speichern der geheimen ID verwendet. Sie können die geheime ID auch direkt verwenden. 'kvClient.GetSecretAsync (" https: // {yourkeyvalue} .vault.azure.net/Geheimnisse/{yourSecretName} ") .Wert' –

+0

Danke! 'GetSecretAsync()' hat funktioniert! Danke noch einmal! – Sam

Verwandte Themen