-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Occasionally (25 times in last 30 days) users of my Blazor App are triggering an exception in our Azure hosted App Service.
The key {72bbd744-b488-0000-0000-000000000000} was not found in the key ring. For more information go to http://aka.ms/dataprotectionwarning
System.Security.Cryptography.CryptographicException
Often times the app is working fine and I assume the key is being used to encrypt and decrypt the keys.
Expected Behavior
The App Service should always be able to access the key and the cryptographic exception should not occur.
Steps To Reproduce
I have followed this guide https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-7.0 and configure my Data Protection like so,
services.AddDataProtection()
.PersistKeysToAzureBlobStorage(new Uri(options.KeyRingBlobUri), new DefaultAzureCredential())
.ProtectKeysWithAzureKeyVault(new Uri(options.EncryptionKeyUri), new DefaultAzureCredential());
I believe my Azure access is configured correctly as it works fine for most of the time.
- App Service has role Storage Blob Data Contributor for the Blob.
- App Service has role Storage Key Vault Crypto Service Encryption User for the Encryption Key Store.
- The App is running under a Windows App Service Plan on the .NET 6.0 runtime.
- Azure.Extensions.AspNetCore.DataProtection.Blobs 1.3.2
- Azure.Extensions.AspNetCore.DataProtection.Keys 1.2.2
Exceptions (if any)
The key {72bbd744-b488-0000-0000-000000000000} was not found in the key ring. For more information go to http://aka.ms/dataprotectionwarning
System.Security.Cryptography.CryptographicException:
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore (Microsoft.AspNetCore.DataProtection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect (Microsoft.AspNetCore.DataProtection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.DataProtection.DataProtectionCommonExtensions.Unprotect (Microsoft.AspNetCore.DataProtection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage.ProtectedBrowserStorage.Unprotect (Microsoft.AspNetCore.Components.Server, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage.ProtectedBrowserStorage+<GetAsync>d__8`1.MoveNext (Microsoft.AspNetCore.Components.Server, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Threading.Tasks.ValueTask`1.get_Result (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
.NET Version
6
Anything else?
From the code in KeyRingBasedDataProtector it looks like it can access the key but the one with the specific ID is not found?
aspnetcore/src/DataProtection/DataProtection/src/KeyManagement/KeyRingBasedDataProtector.cs
Line 244 in d1f00b0
| throw Error.Common_KeyNotFound(keyIdFromPayload); |