Skip to content

Commit 03b76ef

Browse files
feat(keystore): Re-add mitigate version race condition in branch key store (#301)
1 parent 639d679 commit 03b76ef

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

changes/2025-01-16_key-store-mitigate-update-race/background.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved."
22
[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0"
33

4-
# Mitigate Update Race in Branch Key Store
4+
# Mitigate Version Race Condition in Branch Key Store
55

66
# Definitions
77

@@ -18,11 +18,9 @@ interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119).
1818
# Background
1919

2020
The [branch key store](../../framework/branch-key-store.md) needs to persist branch key versions.
21-
DynamoDB was selected as an easy-to-use option,
22-
with an interface later introduced to allow customers
23-
to implement other storage options.
21+
As of July 22, 2025, DynamoDB is the only option of storage for branch key storage.
2422

25-
The behavior of the `WriteNewEncryptedBranchKeyVersion` operation
23+
The behavior of the `VersionKey` operation
2624
leaves open a possibility for a normally benign overwrite
2725
of the cipher-text of a Branch Key,
2826
should two or more agents a Version a Branch Key simultaneously.
@@ -96,8 +94,6 @@ on the old cipher-text value.
9694
This refactors:
9795

9896
- The [Branch Key Store's VersionKey](../../framework/branch-key-store.md#versionkey)
99-
- The [Key Storage's WriteNewEncryptedBranchKeyVersion](../../framework/key-store/key-storage.md#writenewencryptedbranchkeyversion)
100-
- The [Dynamodb Key Storage's WriteNewEncryptedBranchKeyVersion](../../framework/key-store/dynamodb-key-storage.md#writenewencryptedbranchkeyversion)
10197

10298
These refactors are to use the old Active's cipher-text
10399
as the optimistic lock.

framework/branch-key-store.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
## Version
77

8-
0.8.0
8+
0.9.0
99

1010
### Changelog
1111

12+
- 0.9.0
13+
- Re-add [Mitigate Version Race Condition in the Branch Key Store](../changes/2025-01-16_key-store-mitigate-update-race/background.md) with DynamoDB as the only branch key storage option
1214
- 0.8.0
1315
- Revert Key store storage option. This reverts changes in 0.6.0 and 0.7.0
1416
- 0.7.1
@@ -476,7 +478,8 @@ List of TransactWriteItem:
476478
- “hierarchy-version” (N): 1
477479
- Every key-value pair of the custom [encryption context](./structures.md#encryption-context-3) that is associated with the branch key
478480
MUST be added with an Attribute Name of `aws-crypto-ec:` + the Key and Attribute Value (S) of the value.
479-
- ConditionExpression: `attribute_exists(branch-key-id)`
481+
- ConditionExpression: `attribute_exists(branch-key-id) AND enc = :encOld`
482+
- ExpressionAttributeValues: `{":encOld" := DDB.AttributeValue.B(oldCiphertextBlob)}`
480483
- TableName: the configured Table Name
481484

482485
TransactWriteItemRequest:
@@ -486,6 +489,10 @@ TransactWriteItemRequest:
486489
If DDB TransactWriteItems is successful, this operation MUST return a successful response containing no additional data.
487490
Otherwise, this operation MUST yield an error.
488491

492+
The condition expression for the Active Input ensures
493+
the Active Item in DynamoDB has not changed since it was read.
494+
This prevents overwrites due to a race in updating the Active Item.
495+
489496
#### Authenticating a Keystore item
490497

491498
The operation MUST use the configured `KMS SDK Client` to authenticate the value of the keystore item.

0 commit comments

Comments
 (0)