-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Allow retries in DefaultKeyResolver.CanCreateAuthenticatedEncryptor #54711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This will probably have undesirable perf consequences if we don't also do #54675. |
src/DataProtection/DataProtection/src/KeyManagement/KeyManagementOptions.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Outdated
Show resolved
Hide resolved
Sadly, this does not actually work, in its present state. The key stores the decryption result in a Lazy, effectively caching the failure. The tests didn't catch this because I was mocking IKey and my mock didn't cache. Edit: with that fixed, this seems effective against simulated failures. PR updates pending. |
This code is trying to ensure that the selected key can be decrypted (i.e. is usable). It may fail if, for example, Azure KeyVault is unreachable due to connectivity issues. If it fails, there's a log message and then an immediately-activated key will be generated. An immediately-activated key can cause problems for sessions making requests to multiple app instances and those problems won't obviously be connected to the (almost silent) failure in CanCreateAuthenticatedEncryptor. Rather than effectively swallowing such errors, we should allow some retries. Part of dotnet#52678, which is part of dotnet#36157
Force push is a trivial rebase - diff should be the same. |
Retries against the actual `Key` type weren't working because the exception was getting cached in the key's lazy descriptor. Implement our own simple lazy and expose a method for clearing the cached value and exception.
src/DataProtection/DataProtection/src/KeyManagement/KeyManagementOptions.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Outdated
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Show resolved
Hide resolved
...tion/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/DefaultKeyResolverTests.cs
Show resolved
Hide resolved
src/DataProtection/DataProtection/src/KeyManagement/DefaultKeyResolver.cs
Show resolved
Hide resolved
CI failure is in IIS shadow copy and is unrelated. It'll re-run next time I push, so I won't bother doing it now. |
This code is trying to ensure that the selected key can be decrypted (i.e. is usable). It may fail if, for example, Azure KeyVault is unreachable due to connectivity issues. If it fails, there's a log message and then an immediately-activated key will be generated. An immediately-activated key can cause problems for sessions making requests to multiple app instances and those problems won't obviously be connected to the (almost silent) failure in CanCreateAuthenticatedEncryptor. Rather than effectively swallowing such errors, we should allow some retries.
Part of #36157