On 2018-02-05 we started getting exceptions with our existing Azure Functions when attempting to read from Key Vault. Our code hadn't changed, and it started failing across multiple Azure Functions in our Azure environments.
The Azure Function is precompiled from Visual Studio 2017, targetting .NET 4.6.2.
We're using Microsoft.IdentityModel.Clients.ActiveDirectory 3.14.1.
This could be an issue with the Azure Functions host switching to .NET 4.7: pnp/PnP-Sites-Core#1405
We confirmed that the certificate wass available, key vault itself works, the key is there, etc. All of this was working up until this happened. It only affects our Azure Functions, not Web Apps using the same code/technique to load secrets from Key Vault.
We resolved the issue by switching to Managed Service Identity (https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0b).
2018-02-05T17:28:39.273 A ScriptHost error has occurred
2018-02-05T17:28:39.273 System.NullReferenceException : Object reference not set to an instance of an object.
at Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.GetCryptoProviderForSha256(RSACryptoServiceProvider rsaProvider)
at Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.SignWithCertificate(String message,X509Certificate2 certificate)
at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate.Sign(String message)
at Microsoft.IdentityModel.Clients.ActiveDirectory.JsonWebToken.Sign(IClientAssertionCertificate credential)
at Microsoft.IdentityModel.Clients.ActiveDirectory.ClientKey.AddToParameters(IDictionary`2 parameters)
at async Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.SendTokenRequestAsync()
at async Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.RunAsync()
at async Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenForClientCommonAsync(String resource,ClientKey clientKey)
at async Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenAsync(??)
at async http://Empactis.HRCM.Data.Store .Cosmos.Factory.CertificateHelper.GetAccessToken(String authority,String resource,String scope)
at async http://Microsoft.Azure .KeyVault.KeyVaultCredential.PreAuthenticate(Uri url)
at async http://Microsoft.Azure .KeyVault.KeyVaultCredential.ProcessHttpRequestAsync(HttpRequestMessage request,CancellationToken cancellationToken)
at async http://Microsoft.Azure .KeyVault.KeyVaultClient.GetSecretWithHttpMessagesAsync(String vaultBaseUrl,String secretName,String secretVersion,Dictionary`2 customHeaders,CancellationToken cancellationToken)
at async http://Microsoft.Azure .KeyVault.KeyVaultClientExtensions.GetSecretAsync(??)
at http://Empactis.HRCM.Data.Store .Cosmos.Factory.KeyVaultSecretFinder.Find(KeyVaultSecretFinderParams keyVaultSecretFinderParams)
at http://Empactis.HRCM.Data.Store .Cosmos.Factory.DocumentClientFactory.CreateDocumentClient(ConsistencyLevel consistencyLevel)
at Empactis.HRCM.AzureFunctions.Common.ExtensionConfigProvider.BuildEntityStore(ISecretService secretService)
at Empactis.HRCM.AzureFunctions.Common.ExtensionConfigProvider.RegisterServices(IServiceCollection services)
at Empactis.HRCM.AzureFunctions.Common.ExtensionConfigProvider.Initialize(ExtensionConfigContext context)
at http://Microsoft.Azure.WebJobs.Host .Executors.JobHostConfigurationExtensions.InvokeExtensionConfigProviders(ExtensionConfigContext context)
at http://Microsoft.Azure.WebJobs.Host .Executors.JobHostConfigurationExtensions.CreateStaticServices(JobHostConfiguration config)
at http://Microsoft.Azure .WebJobs.JobHost.InitializeServices()
at http://Microsoft.Azure .WebJobs.Script.Utility.CreateMetadataProvider(JobHost host) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Utility.cs : 362
at http://Microsoft.Azure .WebJobs.Script.ScriptHost.Initialize() at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHost.cs : 465
at http://Microsoft.Azure .WebJobs.Script.ScriptHostManager.RunAndBlock(CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script\Host\ScriptHostManager.cs : 181
2018-02-05T17:28:39.273 Stopping Host
On 2018-02-05 we started getting exceptions with our existing Azure Functions when attempting to read from Key Vault. Our code hadn't changed, and it started failing across multiple Azure Functions in our Azure environments.
The Azure Function is precompiled from Visual Studio 2017, targetting .NET 4.6.2.
We're using
Microsoft.IdentityModel.Clients.ActiveDirectory3.14.1.This could be an issue with the Azure Functions host switching to .NET 4.7: pnp/PnP-Sites-Core#1405
We confirmed that the certificate wass available, key vault itself works, the key is there, etc. All of this was working up until this happened. It only affects our Azure Functions, not Web Apps using the same code/technique to load secrets from Key Vault.
We resolved the issue by switching to Managed Service Identity (https://medium.com/statuscode/getting-key-vault-secrets-in-azure-functions-37620fd20a0b).