'The key was not found in the key ring
I have a netcoreapp3.1
application deployed to on-prem IIS instances using the .NET Core Hosting Bundle. Because the app is deployed to 2 load balanced servers we are using Data Protection Key management - seen in the last line here:
public class Startup
{
private readonly IConfiguration _config;
private readonly AppSettings _appSettings;
public Startup(IConfiguration config)
{
_config = config;
_appSettings = _config.Get<AppSettings>();
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => false;
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
options.OnAppendCookie = cookieContext => cookieContext.CookieOptions.SameSite = SameSiteMode.Unspecified;
options.OnDeleteCookie = cookieContext => cookieContext.CookieOptions.SameSite = SameSiteMode.Unspecified;
});
services.Configure<AppSettings>(_config);
...
services.AddControllers();
...
services.UseGroupPolicies(_appSettings);
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(_appSettings.SharedFolderPath));
}
For a long time this was running just fine but I've recently noticed that the application is logging a lot of these errors:
The key {<GUID>} was not found in the key ring.
With this stack trace:
System.Security.Cryptography.CryptographicException:
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore (Microsoft.AspNetCore.DataProtection, Version=3.1.9.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect (Microsoft.AspNetCore.DataProtection, Version=3.1.9.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect (Microsoft.AspNetCore.DataProtection, Version=3.1.9.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Session.CookieProtection.Unprotect (Microsoft.AspNetCore.Session, Version=3.1.9.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
The two servers have a shared folder which allows them to share the data protection key file. This folder continues to have the appropriate permissions assigned and is not logging any issues with access to it.
What data is the application actually encrypting with these keys and how can I expunge any data encrypted with keys no longer in the key ring?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|