Skip to content

Commit 782d91f

Browse files
committed
changes documents
1 parent 77242bc commit 782d91f

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

specification/changes/2024-02-29-encryption-context/background.md

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved."
2+
[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0"
3+
14
# Additional Encryption Context
25

36
## Motivation
7+
48
In the current design, the primary hash and sort keys are made available for branch key calculations. This is sufficient for any system specifically designed with branch keys in mind, but may be insufficient for some legacy systems.
59

610
For example, imagine two tables : Users and Groups.
@@ -12,15 +16,15 @@ Thus when querying the User table, the GroupID is unavailable to the branch key
1216

1317
Designate some sign-only attributes to be available to customers for branch key calculations, KMS encryption contexts and such.
1418

15-
### Where to handle the additions
19+
### Where to handle the additions
1620

17-
#### Option Taken : Add attributes to the encryption context.
21+
#### Option Taken : Add attributes to the encryption context
1822

1923
Advantages include :
2024
* Simple user story
2125
* Tiny change to API
2226

23-
#### Option Not Taken : Pass attributes to the keyring.
27+
#### Option Not Taken : Pass attributes to the keyring
2428

2529
We could have extended the keyring interface to receive a set of key-value pairs, and then passed all signed attributes to the keyring, which would use that to choose the branch key.
2630

@@ -33,16 +37,15 @@ Drawbacks include :
3337

3438
### Which Attributes to Include
3539

36-
#### Option Taken : Allow the user to configure which signed fields are included.
40+
#### Option Taken : Allow the user to configure which signed fields are included
3741

3842
Where the customer used to designate “sign only” they now specify a subset of those to be in the encryption context.
3943

4044
#### Option Not Taken : Include all signed fields
4145

4246
Simplest for the customer, but this could be very large in some cases, and the KMS limit on encryption context size is fairly small.
4347

44-
45-
### Versioning
48+
### Versioning
4649

4750
We need some way, at decrypt time, to know which attributes were used in the encryption context.
4851

@@ -64,33 +67,37 @@ Once we support version 2, we always write version 2. The downside to this is th
6467

6568
Currently, the primary hash and sort keys must be SIGN_ONLY, even though they behave as SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT. Going forward, the primary keys must continue to have the SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT functionality.
6669

67-
#### Option Taken - If any attributes are marked SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT then primary keys must also be SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT.
70+
#### Option Taken - If any attributes are marked SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT then primary keys must also be SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT
6871

6972
This keeps a consistent meaning for all the CryptoActions, while not requiring a version2 header for customers not using the new feature.
7073

7174
#### Option Not Taken - Primary keys MUST still be SIGN_ONLY
75+
7276
When customers adopt SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT, they don’t need to update their primary keys; however, this means that SIGN_ONLY sometimes means SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT leading to confusion
7377

7478
#### Option Not Taken - Primary keys can be either SIGN_ONLY or SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT
79+
7580
Even easier on customers, as they can change or not, but this still means that SIGN_ONLY sometimes means SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT leading to confusion
7681

7782
### Where to calculate the new encryption context entries?
7883

7984
Currently, we generate the encryption context in the Item Encryptor, but only the Structure Encryptor has access to the header and its legend.
8085

81-
#### Option Taken - Structure Encryptor
86+
#### Option Taken - Structure Encryptor
87+
8288
On Decrypt, the Structure Encryptor has the necessary context to determine which attributes were used in the encryption context.
8389

8490
On encrypt, the Structure Encryptor adds to the required encryption context any attributes marked as SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT.
8591

8692
On decrypt, the Structure Encryptor examines the legend in the header to determine which fields were SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT, and performs the same operation as in encrypt.
8793

8894
#### Option Not Taken - Item Encryptor
95+
8996
This would be simplest for Encrypt, as we already generate the encryption context in the Item Encryptor and pass it into the Structure Encryptor. Unfortunately, on Decrypt things are more complex, and we need to parse the header to find out which attributes were used in the encryption context. Trying to do this in the Item Encryptor would require too much back and forth across the Item/Structure boundary.
9097

9198
# User Friendly Encryption Context
9299

93-
## Background
100+
## Background
94101

95102
In the DBESDK, we include the values of the primary hash and sort keys in the encryption context. We serialize the AttributeValue into a a sequence of bytes (as per StructuredEncryption) and then Base64 encode the result.
96103
Thus the string “key” is in the encryption context as “AAFrZXk=”.
@@ -106,7 +113,7 @@ The branch key selector function takes a map of AttributeName to AttributeValue.
106113

107114
Further, we can’t ameliorate this with something in the config file, or even the encrypted record’s version number, because the only input to the branch key selector function is the encryption context.
108115

109-
#### Option Taken - plain strings, plus a legend.
116+
### Option Taken - plain strings, plus a legend
110117

111118
In the version 2 records, add a new entry to the encryption context : aws-crypto-legend. Much like the legend in the StructuredEncryption header, this holds one character per attribute in the encryption context. Sort the keys in the encryption context and the values in the legend are in that same order.
112119

@@ -123,7 +130,7 @@ Whenever we generate an encryption context, we know what record version we’re
123130

124131
If a customer wants this new functionality, they can simply change their primary hash and sort keys to SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT.
125132

126-
#### Option Not Taken : DynamoDB's JSON syntax
133+
### Option Not Taken : DynamoDB's JSON syntax
127134

128135
We could do without the legend if we used the DynamoDB JSON syntax for values. Thus key would become {”S“ : ”key“}
129136

@@ -133,28 +140,24 @@ This has the advantage of simplicity, and is more user friendly then the current
133140
* A key policy referring directly to {”S“ : ”key“} is still a suboptimal user experience
134141
* This would increase the size of the encryption context. Eventually somebody’s going to bump up against the 4K barrier for encryption contexts in KMS.
135142

136-
#### Option Not Taken - Change interface to branch key selector
143+
### Option Not Taken - Change interface to branch key selector
137144

138145
If this took a map of string to string, instead of an AttributeMap, then it would be ok to lose the type information. Unfortunately, this would break all the customers currently using one.
139146

140-
#### Option Not Taken - Change interface to branch key selector for version 2 records
147+
### Option Not Taken - Change interface to branch key selector for version 2 records
141148

142149
The place where we construct the branchKeyIdSupplier, we don’t know the version. Once we know the version, we’ve lost the knowledge of which supplier we are using.
143150

144-
#### Option Not Taken - Deduce the type
151+
### Option Not Taken - Deduce the type
145152

146153
Skip the legend. If it looks like a number or a literal, that’s what it is. If it ends with a ‘=’ it’s binary, otherwise it’s a string.
147154
This would work 99% of the time, but we need 100%.
148155

149-
#### Option Not Taken - Pass in everything as a string
156+
### Option Not Taken - Pass in everything as a string
150157

151158
We could store everything in this new way, but don’t keep the legend. Then wrap everything up as an AttributeValue of type String.
152159
Any customer with a binary key would be out of luck entirely.
153160
Any customer that actually cares about the difference between String(123) and Number(123) would also be sad.
154161

155162
Add type information to the config for every SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT attribute.
156163
This would be great, except that the branch key selector doesn’t have access to the config.
157-
158-
159-
160-

specification/changes/2024-02-29-encryption-context/change.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ and therefore available to the Branch Key Selector.
2727
A fourth Crypto Action will be made available : `SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT`, to join the existing `DO_NOTHING`, `SIGN_ONLY` and `ENCRYPT_AND_SIGN`.
2828

2929
The presence of any SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT attribute in the configuration
30-
will cause a version 2 record to be written.
30+
will cause a version 2 record to be written.
3131

3232
If any SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT attribute is configured,
3333
then the primary partition and sort keys must also be SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT.
@@ -62,7 +62,7 @@ based solely on the encryption context -- since no configuration or version numb
6262
### Parsed Header
6363

6464
For both record versions, the Parsed Header returned from Structured Encryption operations now
65-
contains an additional field : the full encryption context.
65+
contains an additional field : the full encryption context.
6666

6767
Similarly, the Parsed Header returned from Item Encryptor operations now
6868
contains two additional fields : the full encryption context,
@@ -71,7 +71,7 @@ and the value map that would be passed to the Branch Key Selector.
7171
## Implementation Changes
7272

7373
For version 1 records, only the Item Encryptor operations know which attributes should
74-
be in the encryption context,
74+
be in the encryption context,
7575
The logical table name, plus the names and values of the primary hash and sort keys,
7676
and so the full encryption context,
7777
along with the associated RequiredEncryptionContextCMM,
@@ -93,13 +93,13 @@ another layer of RequiredEncryptionContextCMM to include those value.
9393
To use this new functionality with the DynamoDB Enhanced Client in Java,
9494
tag your attribute with `@DynamoDbEncryptionSignAndIncludeInEncryptionContext`
9595

96-
### Single Table Design
96+
## Single Table Design
9797

9898
To better handle [Single-Table Design](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/),
9999
one can now specify multiple schemas when building a DynamoDbEnhancedTableEncryptionConfig
100100
as shown below.
101101

102-
```
102+
```java
103103
TableSchema<SimpleClass> tableSchema1 = TableSchema.fromBean(Class1.class);
104104
TableSchema<SimpleClass2> tableSchema2 = TableSchema.fromBean(Class2.class);
105105
TableSchema<SimpleClass3> tableSchema3 = TableSchema.fromBean(Class3.class);
@@ -121,4 +121,4 @@ TransactWriteItemsEnhancedRequest.builder()
121121
.addPutItem(table2, item2)
122122
.addPutItem(table3, item3)
123123
.build();
124-
```
124+
```

0 commit comments

Comments
 (0)