You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specification/changes/2024-02-29-encryption-context/background.md
+22-19
Original file line number
Diff line number
Diff 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
+
1
4
# Additional Encryption Context
2
5
3
6
## Motivation
7
+
4
8
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.
5
9
6
10
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
12
16
13
17
Designate some sign-only attributes to be available to customers for branch key calculations, KMS encryption contexts and such.
14
18
15
-
### Where to handle the additions
19
+
### Where to handle the additions
16
20
17
-
#### Option Taken : Add attributes to the encryption context.
21
+
#### Option Taken : Add attributes to the encryption context
18
22
19
23
Advantages include :
20
24
* Simple user story
21
25
* Tiny change to API
22
26
23
-
#### Option Not Taken : Pass attributes to the keyring.
27
+
#### Option Not Taken : Pass attributes to the keyring
24
28
25
29
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.
26
30
@@ -33,16 +37,15 @@ Drawbacks include :
33
37
34
38
### Which Attributes to Include
35
39
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
37
41
38
42
Where the customer used to designate “sign only” they now specify a subset of those to be in the encryption context.
39
43
40
44
#### Option Not Taken : Include all signed fields
41
45
42
46
Simplest for the customer, but this could be very large in some cases, and the KMS limit on encryption context size is fairly small.
43
47
44
-
45
-
### Versioning
48
+
### Versioning
46
49
47
50
We need some way, at decrypt time, to know which attributes were used in the encryption context.
48
51
@@ -64,33 +67,37 @@ Once we support version 2, we always write version 2. The downside to this is th
64
67
65
68
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.
66
69
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
68
71
69
72
This keeps a consistent meaning for all the CryptoActions, while not requiring a version2 header for customers not using the new feature.
70
73
71
74
#### Option Not Taken - Primary keys MUST still be SIGN_ONLY
75
+
72
76
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
73
77
74
78
#### Option Not Taken - Primary keys can be either SIGN_ONLY or SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT
79
+
75
80
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
76
81
77
82
### Where to calculate the new encryption context entries?
78
83
79
84
Currently, we generate the encryption context in the Item Encryptor, but only the Structure Encryptor has access to the header and its legend.
80
85
81
-
#### Option Taken - Structure Encryptor
86
+
#### Option Taken - Structure Encryptor
87
+
82
88
On Decrypt, the Structure Encryptor has the necessary context to determine which attributes were used in the encryption context.
83
89
84
90
On encrypt, the Structure Encryptor adds to the required encryption context any attributes marked as SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT.
85
91
86
92
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.
87
93
88
94
#### Option Not Taken - Item Encryptor
95
+
89
96
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.
90
97
91
98
# User Friendly Encryption Context
92
99
93
-
## Background
100
+
## Background
94
101
95
102
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.
96
103
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.
106
113
107
114
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.
108
115
109
-
####Option Taken - plain strings, plus a legend.
116
+
### Option Taken - plain strings, plus a legend
110
117
111
118
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.
112
119
@@ -123,7 +130,7 @@ Whenever we generate an encryption context, we know what record version we’re
123
130
124
131
If a customer wants this new functionality, they can simply change their primary hash and sort keys to SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT.
125
132
126
-
####Option Not Taken : DynamoDB's JSON syntax
133
+
### Option Not Taken : DynamoDB's JSON syntax
127
134
128
135
We could do without the legend if we used the DynamoDB JSON syntax for values. Thus key would become {”S“ : ”key“}
129
136
@@ -133,28 +140,24 @@ This has the advantage of simplicity, and is more user friendly then the current
133
140
* A key policy referring directly to {”S“ : ”key“} is still a suboptimal user experience
134
141
* 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.
135
142
136
-
####Option Not Taken - Change interface to branch key selector
143
+
### Option Not Taken - Change interface to branch key selector
137
144
138
145
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.
139
146
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
141
148
142
149
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.
143
150
144
-
####Option Not Taken - Deduce the type
151
+
### Option Not Taken - Deduce the type
145
152
146
153
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.
147
154
This would work 99% of the time, but we need 100%.
148
155
149
-
####Option Not Taken - Pass in everything as a string
156
+
### Option Not Taken - Pass in everything as a string
150
157
151
158
We could store everything in this new way, but don’t keep the legend. Then wrap everything up as an AttributeValue of type String.
152
159
Any customer with a binary key would be out of luck entirely.
153
160
Any customer that actually cares about the difference between String(123) and Number(123) would also be sad.
154
161
155
162
Add type information to the config for every SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT attribute.
156
163
This would be great, except that the branch key selector doesn’t have access to the config.
Copy file name to clipboardExpand all lines: specification/changes/2024-02-29-encryption-context/change.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ and therefore available to the Branch Key Selector.
27
27
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`.
28
28
29
29
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.
31
31
32
32
If any SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT attribute is configured,
33
33
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
62
62
### Parsed Header
63
63
64
64
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.
66
66
67
67
Similarly, the Parsed Header returned from Item Encryptor operations now
68
68
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.
71
71
## Implementation Changes
72
72
73
73
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,
75
75
The logical table name, plus the names and values of the primary hash and sort keys,
76
76
and so the full encryption context,
77
77
along with the associated RequiredEncryptionContextCMM,
@@ -93,13 +93,13 @@ another layer of RequiredEncryptionContextCMM to include those value.
93
93
To use this new functionality with the DynamoDB Enhanced Client in Java,
94
94
tag your attribute with `@DynamoDbEncryptionSignAndIncludeInEncryptionContext`
95
95
96
-
###Single Table Design
96
+
## Single Table Design
97
97
98
98
To better handle [Single-Table Design](https://aws.amazon.com/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/),
99
99
one can now specify multiple schemas when building a DynamoDbEnhancedTableEncryptionConfig
0 commit comments