aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Support key deletion in Data Protection

Open amcasey opened this issue 1 year ago • 5 comments

Add the ability to delete keys to support #52916. The approach is more complicated than you'd expect to account for the fact that IXmlRepository offers only two (possibly slow) operations: enumerate and add - there's no random access.

Deleting keys remains discouraged.

Fixes #53880

amcasey avatar Feb 06 '24 23:02 amcasey

I had to move to per-target-platform API manifests because DIM isn't available on framework.

amcasey avatar Feb 07 '24 22:02 amcasey

I'll add tests once the API is reviewed, but the shape has changed several times already.

amcasey avatar Feb 07 '24 22:02 amcasey

Force push is a rebase - I'll address API Review feedback separately.

amcasey avatar May 02 '24 19:05 amcasey

I also prepared a version where the key manager gets to return an ordered list of IDeletableElements to delete, but I was unhappy with the fact that the implementation could return duplicate elements or elements that were not in the list it received. These are both solvable problems, but every repository implementation would need these safeguards, which I found less appealing than having every repository sort.

amcasey avatar May 03 '24 23:05 amcasey

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

Force push is a trivial rebase on main.

amcasey avatar Jul 11 '24 20:07 amcasey

TODO: Redis impl TODO: add tests

Edit: tests added, redis & EF impls deferred

amcasey avatar Jul 11 '24 21:07 amcasey

/azp run

amcasey avatar Jul 15 '24 22:07 amcasey

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jul 15 '24 22:07 azure-pipelines[bot]

I'm definitely a little curious how my new tests could pass only on Windows. Investigating.

Edit: Opening a file with FileShare.None doesn't prevent its deletion on Linux (where there is also no registry 🤦).

amcasey avatar Jul 17 '24 23:07 amcasey

I found this while building a custom repository for Mongodb.

One idea that may be to late, since you look like you are pretty far along. You could simplify this by just adding a DeleteElement(string keyid) to IXmlRepository. Then let devs developing their own repositories to create the delete code. DeleteElement() method could be fired by Data Protection using a TTL. A TTL could be added to every key automatically when its created. Since the minimum expiration that can be set to a Key is 7 days. Data Protection could check the TTL every 7 days and fire deletes for all the expired keys. TTL date could be (expired date + time to live length) = TTL. Time to live length could be a setting with a default of (expired date * 2). I would make it so that devs would have to turn this feature on too.

donnyv avatar Aug 25 '24 05:08 donnyv

@donnyv The reason we didn't add DeleteElement(string keyid) is that random access is not presently part of the IXmlRepository contract and a number of existing implementations (e.g. file system) couldn't implement it efficiently.

Having said that, it was certainly our intention that IXmlRepository implementers would be able to provide their own implementations. Are you finding that not to be the case?

Unless we hear a lot of demand (feel free to open an issue to collect feedback), I don't think we're likely to add an automated TTL mechanism. Generally speaking, we recommend keys never be deleted, so we want doing so to be a very explicit action on the app author's part.

amcasey avatar Sep 05 '24 16:09 amcasey