-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Allow deletion of Data Protection keys #53502
Comments
I'm generally skeptical of this, and strongly agree that "key deletion is a foot gun"! I suppose the xmldoc saying not to use this unless space constraints are forcing you to do so is good. I'm just having a hard time imagining an environment that is so space constrained that this is needed. It seems like a pretty extreme edge case, and for the very small number of use cases, there's nothing stopping you from deleting the keys in the store outside the manager. The advantage of NOT doing this is that it makes it obvious to the user how destructive this is. You can have in the docs that this is so destructive that we don't even have an api for it. |
I'm aware of the risks, that's why I included suggestions like the Let me give you the higher-level picture:
Overall, having a delete API gives us the safest, most compatible way to interact with storage, and lets us keep a clean house (or many) indefinitely. |
We can do the usual thing of adding scary doc comments and prepending "Unsafe" to the name, but I can't say I've ever seen that make a difference in practice. |
I like the idea of having a flag like evenIfActive to help prevent data loss, but I worry about the case where a key is retired but the data it protected is still needed. In IdentityServer, we use data protection to protect some fairly long lived data. For example:
Maybe instead of a flag, you could do something like |
Interesting idea. I don't think method TimeSpan args can have default parameters; they have to be consts? |
You could make it nullable and use a (computed?) default value on null. |
By that logic 0 would allow deleting any expired key and you'd need a negative value to delete an active key 😆. I like it. |
API review notes:
Updated API: namespace Microsoft.AspNetCore.DataProtection.KeyManagement;
public interface IKeyManager
{
+ bool CanDeleteKeys => false;
+ void DeleteKey(Guid keyId, TimeSpan? expiredFor = default) => throw new NotSupportedException();
} API approved! |
I guess new APIs will be needed on things like IXmlRepository too? |
@brockallen Can you elaborate? What APIs would be needed on the repository? |
Well, some sort of delete, right? Or am I misunderstanding where that fits into the DP stack? |
Nope, you're quite right. That's what I get for making the proposal issue without a backing PR. The manager uses the repository, which is also a public API. Thanks! Edit: There's no revoke member on the repository because revocation is represented as a form of storage. Obviously, that won't be the case for deletion, since the goal is to avoid excessive storage. |
Not having random access completely changes the shape of the API. I'll file a new issue once I've got a concrete implementation we can discuss. |
I know of many implementations of IXmlRepository in the wild, so please keep this in mind as new features are added/designed. |
@brockallen Are any of them running of framework? That's harder because we can't depend on default interface implementation. |
You mean "on"? As in older .NET Framework? I don't think so -- most of them would have been .NET Core and beyond. |
Yep, sorry for the typo. |
Background and Motivation
Data Protection has no facility for deleting keys. The design assumes that they will simply accumulate forever so that data protected with old keys will always be decryptable in an emergency. Per our docs:
However, for a very long-running application, there's a risk of long-defunct keys consuming too many resources. As part of #52916, we should consider allowing deletion.
Proposed API
Usage Examples
Alternative Designs
We talked about
TryDelete
, but I didn't like that it was returning a value for all keys, rather than the specific argument.We don't presently see a need for
DeleteAllKeys
and it could be added later as a default interface method.Risks
As with revocation, in memory representations of the deleted key will be unaffected.
We'll have to be careful how we revise/supplement the docs, since key deletion is a foot-gun.
The text was updated successfully, but these errors were encountered: