I have 2 load balanced IIS servers - mirrored. Each server has multiple .NetFramework web applications. Each app is running under different pool user and the code is placed in different folders.
Now I need to migrate these apps to .NET6
I have MSSQL database with dp.Keys table. And I faced with the problem with DataProtection - all apps are using the same key. Because of this I can't use DpapiNG keys protection. I also want to have 1 key per app (app1 on 1st server and app1 on 2nd server use key1 from DB).
Here is my code:
services
.AddDataProtection()
.SetApplicationName("App1")
.AddKeyManagementOptions(options => options.XmlRepository = new SqlServerXmlRepository(connectionString, "dp", "Keys"));
I made some digging and found that DefaultKeyResolver (is used by AddDataProtection()) takes FirstOrDefault() key. It does not look for a key for this particular app.
var preferredDefaultKey = (from key in allKeys
where key.ActivationDate <= now + _maxServerToServerClockSkew
orderby key.ActivationDate descending, key.KeyId ascending
select key).FirstOrDefault();
Is that expected behavior? Is that safe to use 1 key for all apps? Looks like the only option with keys protection is certificate?