-
Notifications
You must be signed in to change notification settings - Fork 26
feat(KeyStore): Mitigate Update Race in Branch Key Store #286
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
3 commits
Select commit
Hold shift + click to select a range
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
103 changes: 103 additions & 0 deletions
103
changes/2025-01-16_key-store-mitigate-update-race/background.md
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,103 @@ | ||
[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved." | ||
[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0" | ||
|
||
# Mitigate Update Race in Branch Key Store | ||
|
||
# Definitions | ||
|
||
## MPL | ||
|
||
Material Providers Library | ||
|
||
## Conventions used in this document | ||
|
||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", | ||
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be | ||
interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). | ||
|
||
# Background | ||
|
||
The [branch key store](../../framework/branch-key-store.md) needs to persist branch key versions. | ||
DynamoDB was selected as an easy-to-use option, | ||
with an interface later introduced to allow customers | ||
to implement other storage options. | ||
|
||
The behavior of the `WriteNewEncryptedBranchKeyVersion` operation | ||
leaves open a possibility for a normally benign overwrite | ||
of the cipher-text of a Branch Key, | ||
should two or more agents a Version a Branch Key simultaneously. | ||
|
||
This change mitigates this. | ||
|
||
## Detailed Explanation | ||
|
||
The Key Store's `VersionKey` operation does NOT, | ||
at this time, | ||
validate that the ACTIVE item has NOT been modified | ||
since it read the item. | ||
|
||
This allows the Key Store's `VersionKey` operation | ||
to race itself. | ||
|
||
`VersionKey`'s self-race is benign; | ||
the only consequence is an additional | ||
but unneeded versions of the Branch Key. | ||
|
||
However, | ||
Crypto Tools or it's customers may write logic | ||
that modify Branch Key items in other ways. | ||
|
||
Such modifications, | ||
if overwritten due to a race, | ||
may break customers or methods Crypto Tools | ||
introduces to modify Branch Keys. | ||
|
||
Thus, | ||
Crypto Tools should refactor the Storage interface | ||
to mitigate the unintended overwrite. | ||
|
||
## Optimistic Lock | ||
|
||
We will mitigate this via an Optimistic Lock on the cipher-text. | ||
|
||
All writes to ACTIVE, | ||
except those by `CreateKey`, | ||
would include a condition expression of | ||
`attribute_exists(branch-key-id) AND enc = <old-cipher-text-value>`, | ||
as [expressed in DynamoDB Syntax](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html). | ||
|
||
`enc` gives an assertion on the state of: | ||
|
||
- any custom encryption context | ||
- the creation date | ||
- the hierarchy-version | ||
- the Logical Key Store Name | ||
|
||
`enc` contains the Auth Tag from | ||
the AES-GCM operation executed by KMS. | ||
|
||
Thus, by asserting `enc` has not changed, | ||
the Key Store asserts that nothing has changed! | ||
|
||
Since this _Optimistic Lock_ is only | ||
applied AFTER the `enc` value has | ||
been validated by KMS | ||
during the Version routine, | ||
the Key Store KNOWS `enc` is valid. | ||
|
||
If `enc` has been changed, | ||
the write will fail with an error detailing the condition check failure. | ||
|
||
# Changes | ||
|
||
The change is to use an Optimistic Lock | ||
on the old cipher-text value. | ||
|
||
This refactors: | ||
|
||
- The [Branch Key Store's VersionKey](../../framework/branch-key-store.md#versionkey) | ||
- The [Key Storage's WriteNewEncryptedBranchKeyVersion](../../framework/key-store/key-storage.md#writenewencryptedbranchkeyversion) | ||
- The [Dynamodb Key Storage's WriteNewEncryptedBranchKeyVersion](../../framework/key-store/dynamodb-key-storage.md#writenewencryptedbranchkeyversion) | ||
|
||
These refactors are to use the old Active's cipher-text | ||
as the optimistic lock. |
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
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
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.