-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Support key deletion in Data Protection #53860
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
07666ab
Add key deletion APIs to IKeyManager
amcasey 36d663c
Add element removal APIs to IXmlRepository
amcasey 2dac469
Implement IXmlRepository deletion for EF, FS, and registry
amcasey a0cc3e1
Make API manifest per-framework
amcasey 9ce136a
Implement missing logging methods
amcasey 2f086d6
Update IKeyManager API to parallel IXmlRepository
amcasey 161f5bf
Pass entire list of XElements to RemoveElements callback
amcasey be09a95
Started implementing key manager deletion and hit roadblock
amcasey f7cd631
Return success from IXmlRepository.RemoveElements
amcasey c611fca
Finish implementing key manager deletion
amcasey 8a7d9ed
Add more logging
amcasey 22a30ba
Consume unsafeIncludeUnexpired
amcasey 98a408e
Change IXmlRepository.RemoveElements to use a mutating Action
amcasey 2fb6656
Tidy up diff
amcasey a5b35cb
Fix merge
amcasey aa0abf5
Remove unsafeIncludeUnexpired
amcasey 96524e4
Switch from ShouldDelete to DeletionOrder
amcasey 642d16f
Improve comments
amcasey 2d9456a
Implement deletion in EphemeralXmlRepository
amcasey e1e0d63
Add comment requested by API Review
amcasey e02e85f
Stub out RedisXmlRepository implementation for API Review
amcasey 3aeafca
Split out new interfaces so we don't need ifdefs
amcasey a3e5913
Actually stop iterating if some key deletion fails
amcasey a31d007
Add FileSystemXmlRepository tests
amcasey 80c7b4b
Add RegistryXmlRepository tests
amcasey 63531eb
Rename new interfaces
amcasey d8c1df6
Defer EF and Redis to a subsequent PR
amcasey bf4a92b
Add EphemeralXmlRepository tests
amcasey 5661a92
Revert EF logging
amcasey 8f919e0
Update copy-pasta doc comments
amcasey 2f1f46d
Add XmlKeyManager tests
amcasey 7e6e302
Correct log level
amcasey f41e8a2
Enumerate _storedElements under lock
amcasey 55d8ffa
Rename RemoveElements to DeleteElements for consistency
amcasey 6173458
Address PR feedback
amcasey 7d27727
Add clarifying comments.
amcasey b5ae707
Rename tests to match updated APIs
amcasey 7b4ad6e
Make registry tests conditional on registry availability
amcasey 8229f26
Skip DeleteElementsWithFailure on Linux
amcasey 1ad9807
Also skip on mac
amcasey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/DataProtection/DataProtection/src/KeyManagement/IDeletableKeyManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Threading; | ||
|
|
||
| namespace Microsoft.AspNetCore.DataProtection.KeyManagement; | ||
|
|
||
| /// <summary> | ||
| /// An extension of <see cref="IKeyManager"/> that supports key deletion. | ||
| /// </summary> | ||
| public interface IDeletableKeyManager : IKeyManager | ||
| { | ||
| /// <summary> | ||
| /// Indicates whether this key manager and the underlying <see cref="Repositories.IXmlRepository"/> support key deletion. | ||
| /// </summary> | ||
| /// <seealso cref="DeleteKeys"/> | ||
| bool CanDeleteKeys { get; } | ||
|
|
||
| /// <summary> | ||
| /// Deletes keys matching a predicate. | ||
| /// | ||
| /// Use with caution as deleting active keys will normally cause data loss. | ||
| /// </summary> | ||
| /// <param name="shouldDelete"> | ||
| /// A predicate applied to each key. | ||
| /// Returning true will cause the key to be deleted. | ||
| /// </param> | ||
| /// <returns> | ||
| /// True if all attempted deletions succeeded. | ||
| /// </returns> | ||
| /// <remarks> | ||
| /// Deletion is stronger than revocation. A revoked key is retained and can even be (forcefully) applied. | ||
| /// A deleted key is indistinguishable from a key that never existed. | ||
| /// | ||
| /// Generally, keys should only be deleted to save space. If space is not a concern, keys | ||
| /// should be revoked or allowed to expire instead. | ||
| /// | ||
| /// This method will not mutate existing IKey instances. After calling this method, | ||
| /// all existing IKey instances should be discarded, and GetAllKeys should be called again. | ||
| /// </remarks> | ||
| /// <exception cref="NotSupportedException"> | ||
| /// If <see cref="CanDeleteKeys"/> is false. | ||
| /// </exception> | ||
| bool DeleteKeys(Func<IKey, bool> shouldDelete); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/DataProtection/DataProtection/src/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,14 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.DataProtection.KeyManagement.IDeletableKeyManager | ||
| Microsoft.AspNetCore.DataProtection.KeyManagement.IDeletableKeyManager.CanDeleteKeys.get -> bool | ||
| Microsoft.AspNetCore.DataProtection.KeyManagement.IDeletableKeyManager.DeleteKeys(System.Func<Microsoft.AspNetCore.DataProtection.KeyManagement.IKey!, bool>! shouldDelete) -> bool | ||
| Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.CanDeleteKeys.get -> bool | ||
| Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.DeleteKeys(System.Func<Microsoft.AspNetCore.DataProtection.KeyManagement.IKey!, bool>! shouldDelete) -> bool | ||
| Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement | ||
| Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement.DeletionOrder.get -> int? | ||
| Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement.DeletionOrder.set -> void | ||
| Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement.Element.get -> System.Xml.Linq.XElement! | ||
| Microsoft.AspNetCore.DataProtection.Repositories.IDeletableXmlRepository | ||
| Microsoft.AspNetCore.DataProtection.Repositories.IDeletableXmlRepository.DeleteElements(System.Action<System.Collections.Generic.IReadOnlyCollection<Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement!>!>! chooseElements) -> bool | ||
| virtual Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.DeleteElements(System.Action<System.Collections.Generic.IReadOnlyCollection<Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement!>!>! chooseElements) -> bool | ||
| virtual Microsoft.AspNetCore.DataProtection.Repositories.RegistryXmlRepository.DeleteElements(System.Action<System.Collections.Generic.IReadOnlyCollection<Microsoft.AspNetCore.DataProtection.Repositories.IDeletableElement!>!>! chooseElements) -> bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.