|
| 1 | +[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved." |
| 2 | +[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0" |
| 3 | + |
| 4 | +# Mitigate Update Race in Branch Key Store |
| 5 | + |
| 6 | +# Definitions |
| 7 | + |
| 8 | +## MPL |
| 9 | + |
| 10 | +Material Providers Library |
| 11 | + |
| 12 | +## Conventions used in this document |
| 13 | + |
| 14 | +The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", |
| 15 | +"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be |
| 16 | +interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119). |
| 17 | + |
| 18 | +# Background |
| 19 | + |
| 20 | +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. |
| 24 | + |
| 25 | +The behavior of the `WriteNewEncryptedBranchKeyVersion` operation |
| 26 | +leaves open a possibility for a normally benign overwrite |
| 27 | +of the cipher-text of a Branch Key, |
| 28 | +should two or more agents a Version a Branch Key simultaneously. |
| 29 | + |
| 30 | +This change mitigates this. |
| 31 | + |
| 32 | +## Detailed Explanation |
| 33 | + |
| 34 | +The Key Store's `VersionKey` operation does NOT, |
| 35 | +at this time, |
| 36 | +validate that the ACTIVE item has NOT been modified |
| 37 | +since it read the item. |
| 38 | + |
| 39 | +This allows the Key Store's `VersionKey` operation |
| 40 | +to race itself. |
| 41 | + |
| 42 | +`VersionKey`'s self-race is benign; |
| 43 | +the only consequence is an additional |
| 44 | +but unneeded versions of the Branch Key. |
| 45 | + |
| 46 | +However, |
| 47 | +Crypto Tools or it's customers may write logic |
| 48 | +that modify Branch Key items in other ways. |
| 49 | + |
| 50 | +Such modifications, |
| 51 | +if overwritten due to a race, |
| 52 | +may break customers or methods Crypto Tools |
| 53 | +introduces to modify Branch Keys. |
| 54 | + |
| 55 | +Thus, |
| 56 | +Crypto Tools should refactor the Storage interface |
| 57 | +to mitigate the unintended overwrite. |
| 58 | + |
| 59 | +## Optimistic Lock |
| 60 | + |
| 61 | +We will mitigate this via an Optimistic Lock on the cipher-text. |
| 62 | + |
| 63 | +All writes to ACTIVE, |
| 64 | +except those by `CreateKey`, |
| 65 | +would include a condition expression of |
| 66 | +`attribute_exists(branch-key-id) AND enc = <old-cipher-text-value>`, |
| 67 | +as [expressed in DynamoDB Syntax](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html). |
| 68 | + |
| 69 | +`enc` gives an assertion on the state of: |
| 70 | + |
| 71 | +- any custom encryption context |
| 72 | +- the creation date |
| 73 | +- the hierarchy-version |
| 74 | +- the Logical Key Store Name |
| 75 | + |
| 76 | +`enc` contains the Auth Tag from |
| 77 | +the AES-GCM operation executed by KMS. |
| 78 | + |
| 79 | +Thus, by asserting `enc` has not changed, |
| 80 | +the Key Store asserts that nothing has changed! |
| 81 | + |
| 82 | +Since this _Optimistic Lock_ is only |
| 83 | +applied AFTER the `enc` value has |
| 84 | +been validated by KMS |
| 85 | +during the Version routine, |
| 86 | +the Key Store KNOWS `enc` is valid. |
| 87 | + |
| 88 | +If `enc` has been changed, |
| 89 | +the write will fail with an error detailing the condition check failure. |
| 90 | + |
| 91 | +# Changes |
| 92 | + |
| 93 | +The change is to use an Optimistic Lock |
| 94 | +on the old cipher-text value. |
| 95 | + |
| 96 | +This refactors: |
| 97 | + |
| 98 | +- 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) |
| 101 | + |
| 102 | +These refactors are to use the old Active's cipher-text |
| 103 | +as the optimistic lock. |
0 commit comments