@@ -39,6 +39,12 @@ Required Prerequisites
39
39
* boto3 >= 1.10.0
40
40
* attrs
41
41
42
+ Recommended Prerequisites
43
+ =========================
44
+
45
+ * aws-cryptographic-material-providers: >= 1.0.0 (TODO)
46
+ * Requires Python 3.11+.
47
+
42
48
Installation
43
49
============
44
50
@@ -54,19 +60,39 @@ Installation
54
60
55
61
Concepts
56
62
========
57
- There are four main concepts that you need to understand to use this library:
63
+ There are three main concepts that you need to understand to use this library:
64
+
65
+ Data Keys
66
+ ---------
67
+ Data keys are the encryption keys that are used to encrypt your data. If your algorithm suite
68
+ uses a key derivation function, the data key is used to generate the key that directly encrypts the data.
69
+
70
+ Keyrings
71
+ --------
72
+ Keyrings are resources that generate, encrypt, and decrypt data keys.
73
+ You specify a keyring when encrypting and the same or a different keyring when decrypting.
74
+
75
+ Note: You must also install the `AWS Cryptographic Material Providers Library (MPL) `_ to create and use keyrings.
76
+
77
+ For more information, see the `AWS Documentation for Keyrings `_.
58
78
59
79
Cryptographic Materials Managers
60
80
--------------------------------
61
81
Cryptographic materials managers (CMMs) are resources that collect cryptographic materials and prepare them for
62
82
use by the Encryption SDK core logic.
63
83
64
- An example of a CMM is the default CMM, which is automatically generated anywhere a caller provides a master
65
- key provider. The default CMM collects encrypted data keys from all master keys referenced by the master key
66
- provider .
84
+ An example of a CMM is the default CMM,
85
+ which is automatically generated anywhere a caller provides a keyring.
86
+ The default CMM collects encrypted data keys from all configured keyrings .
67
87
68
88
An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by another CMM.
69
89
90
+ Legacy Concepts
91
+ ===============
92
+ These concepts mention components that have been deprecated since v4 of this library.
93
+ These components have been superseded by new components in the `AWS Cryptographic Material Providers Library (MPL) `_.
94
+ Please avoid using these and instead use components in the MPL.
95
+
70
96
Master Key Providers
71
97
--------------------
72
98
Master key providers are resources that provide master keys.
@@ -76,15 +102,20 @@ To encrypt data in this client, a ``MasterKeyProvider`` object must contain at l
76
102
77
103
``MasterKeyProvider `` objects can also contain other ``MasterKeyProvider `` objects.
78
104
105
+ NOTE: Master key providers are deprecated
106
+ and have been superseded by [keyrings](TODO)
107
+ provided by the `AWS Cryptographic Material Providers Library (MPL) `_.
108
+ Please install this library and migrate master key providers to keyring interfaces.
109
+
79
110
Master Keys
80
111
-----------
81
112
Master keys generate, encrypt, and decrypt data keys.
82
113
An example of a master key is a `KMS customer master key (CMK) `_.
83
114
84
- Data Keys
85
- ---------
86
- Data keys are the encryption keys that are used to encrypt your data. If your algorithm suite
87
- uses a key derivation function, the data key is used to generate the key that directly encrypts the data .
115
+ NOTE: Master keys are deprecated
116
+ and have been superseded by [keyrings](TODO)
117
+ provided by the ` AWS Cryptographic Material Providers Library (MPL) `_.
118
+ Please install this library and migrate master key providers to keyring interfaces .
88
119
89
120
*****
90
121
Usage
@@ -110,147 +141,71 @@ version of the AWS Encryption SDK, we recommend using the default value.
110
141
)
111
142
112
143
113
- You must then create an instance of either a master key provider or a CMM. The examples in this
114
- readme use the ``StrictAwsKmsMasterKeyProvider `` class.
144
+ You must then create an instance of either a keyring (with the MPL installed) or a CMM.
145
+ You may also provide an instance of a legacy master key provider.
146
+ The examples in this README use the ``AwsKmsKeyring `` class.
147
+ Note: You must install the `AWS Cryptographic Material Providers Library (MPL) `_ to use this class.
115
148
116
149
117
- StrictAwsKmsMasterKeyProvider
150
+ AwsKmsKeyring
118
151
=============================
119
- A ``StrictAwsKmsMasterKeyProvider `` is configured with an explicit list of AWS KMS
120
- CMKs with which to encrypt and decrypt data. On encryption, it encrypts the plaintext with all
121
- configured CMKs. On decryption, it only attempts to decrypt ciphertexts that have been wrapped
122
- with a CMK that matches one of the configured CMK ARNs.
123
-
124
- To create a ``StrictAwsKmsMasterKeyProvider `` you must provide one or more CMKs. For providers that will only
125
- be used for encryption, you can use any valid `KMS key identifier `_. For providers that will be used for decryption, you
126
- must use the key ARN; key ids, alias names, and alias ARNs are not supported.
127
-
128
- Because the ``StrictAwsKmsMasterKeyProvider `` uses the `boto3 SDK `_ to interact with `AWS KMS `_,
152
+ A ``AwsKmsKeyring `` is configured with an AWS KMS key ARN whose AWS KMS key
153
+ will be used to generate, encrypt, and decrypt data keys.
154
+ On encryption, it encrypts the plaintext with the data key.
155
+ On decryption, it decrypts an encrypted version of the data key, then uses the decrypted data key to decrypt the ciphertext.
156
+
157
+ To create a ``AwsKmsKeyring `` you must provide one or more AWS KMS key ARNs.
158
+ For keyrings that will only be used for encryption,
159
+ you can use any valid `KMS key identifier `_.
160
+ For providers that will be used for decryption,
161
+ you must use the key ARN.
162
+ Key ids, alias names, and alias ARNs are not supported.
163
+
164
+ Because the ``AwsKmsKeyring `` uses the `boto3 SDK `_ to interact with `AWS KMS `_,
129
165
it requires AWS Credentials.
130
166
To provide these credentials, use the `standard means by which boto3 locates credentials `_ or provide a
131
- pre-existing instance of a ``botocore session `` to the ``StrictAwsKmsMasterKeyProvider ``.
167
+ pre-existing instance of a ``botocore session `` to the ``AwsKmsKeyring ``.
132
168
This latter option can be useful if you have an alternate way to store your AWS credentials or
133
169
you want to reuse an existing instance of a botocore session in order to decrease startup costs.
134
170
135
- If you configure the the ``StrictAwsKmsMasterKeyProvider `` with multiple CMKs, the `final message `_
136
- will include a copy of the data key encrypted by each configured CMK.
137
-
138
- .. code :: python
139
-
140
- import aws_encryption_sdk
141
-
142
- kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids = [
143
- ' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
144
- ' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
145
- ])
171
+ TODO: Code example
146
172
147
- You can add CMKs from multiple regions to the ``StrictAwsKmsMasterKeyProvider ``.
148
-
149
- .. code :: python
173
+ If you want to configure a keyring with multiple AWS KMS keys, see the multi keyring.
150
174
151
- import aws_encryption_sdk
175
+ MultiKeyring
176
+ ============
152
177
153
- kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids = [
154
- ' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
155
- ' arn:aws:kms:us-west-2:3333333333333:key/33333333-3333-3333-3333-333333333333' ,
156
- ' arn:aws:kms:ap-northeast-1:4444444444444:key/44444444-4444-4444-4444-444444444444'
157
- ])
178
+ A ``MultiKeyring `` is configured with an optional generator keyring and a list of child keyrings.
158
179
180
+ TODO: Code example
159
181
160
182
DiscoveryAwsKmsMasterKeyProvider
161
183
================================
162
- We recommend using a ``StrictAwsKmsMasterKeyProvider `` in order to ensure that you can only
163
- encrypt and decrypt data using the AWS KMS CMKs you expect. However, if you are unable to
164
- explicitly identify the AWS KMS CMKs that should be used for decryption, you can instead
165
- use a ``DiscoveryAwsKmsMasterKeyProvider `` for decryption operations. This provider
184
+ We recommend using an ``AwsKmsKeyring `` in order to ensure that you can only
185
+ encrypt and decrypt data using the AWS KMS key ARN you expect,
186
+ or a ``MultiKeyring `` if you are using multiple keys. However, if you are unable to
187
+ explicitly identify the AWS KMS key ARNs that should be used for decryption, you can instead
188
+ use a ``AwsKmsDiscoveryKeyring `` for decryption operations. This provider
166
189
attempts decryption of any ciphertexts as long as they match a ``DiscoveryFilter `` that
167
190
you configure. A ``DiscoveryFilter `` consists of a list of AWS account ids and an AWS
168
191
partition.
169
192
170
- .. code :: python
171
-
172
- import aws_encryption_sdk
173
- from aws_encryption_sdk.key_providers.kms import DiscoveryFilter
174
-
175
- discovery_filter = DiscoveryFilter(
176
- account_ids = [' 222222222222' , ' 333333333333' ],
177
- partition = ' aws'
178
- )
179
- kms_key_provider = aws_encryption_sdk.DiscoveryAwsKmsMasterKeyProvider(
180
- discovery_filter = discovery_filter
181
- )
193
+ TODO: Code example
182
194
183
195
If you do not want to filter the set of allowed accounts, you can also omit the ``discovery_filter `` argument.
184
196
185
- Note that a ``DiscoveryAwsKmsMasterKeyProvider `` cannot be used for encryption operations.
197
+ Note that a ``AwsKmsDiscoveryKeyring `` cannot be used for encryption operations.
186
198
187
199
Encryption and Decryption
188
200
=========================
189
- After you create an instance of an ``EncryptionSDKClient `` and a ``MasterKeyProvider ``, you can use either of
201
+ After you create an instance of an ``EncryptionSDKClient `` and a ``Keyring ``, you can use either of
190
202
the client's two ``encrypt ``/``decrypt `` functions to encrypt and decrypt your data.
191
203
192
- .. code :: python
193
-
194
- import aws_encryption_sdk
195
- from aws_encryption_sdk.identifiers import CommitmentPolicy
196
-
197
- client = aws_encryption_sdk.EncryptionSDKClient(
198
- commitment_policy = CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
199
- )
200
-
201
- kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids = [
202
- ' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
203
- ' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
204
- ])
205
- my_plaintext = b ' This is some super secret data! Yup, sure is!'
206
-
207
- my_ciphertext, encryptor_header = client.encrypt(
208
- source = my_plaintext,
209
- key_provider = kms_key_provider
210
- )
211
-
212
- decrypted_plaintext, decryptor_header = client.decrypt(
213
- source = my_ciphertext,
214
- key_provider = kms_key_provider
215
- )
216
-
217
- assert my_plaintext == decrypted_plaintext
218
- assert encryptor_header.encryption_context == decryptor_header.encryption_context
204
+ TODO: Code example; basic example with keyring
219
205
220
206
You can provide an `encryption context `_: a form of additional authenticating information.
221
207
222
- .. code :: python
223
-
224
- import aws_encryption_sdk
225
- from aws_encryption_sdk.identifiers import CommitmentPolicy
226
-
227
- client = aws_encryption_sdk.EncryptionSDKClient(
228
- commitment_policy = CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
229
- )
230
-
231
- kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids = [
232
- ' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
233
- ' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
234
- ])
235
- my_plaintext = b ' This is some super secret data! Yup, sure is!'
236
-
237
- my_ciphertext, encryptor_header = client.encrypt(
238
- source = my_plaintext,
239
- key_provider = kms_key_provider,
240
- encryption_context = {
241
- ' not really' : ' a secret' ,
242
- ' but adds' : ' some authentication'
243
- }
244
- )
245
-
246
- decrypted_plaintext, decryptor_header = client.decrypt(
247
- source = my_ciphertext,
248
- key_provider = kms_key_provider
249
- )
250
-
251
- assert my_plaintext == decrypted_plaintext
252
- assert encryptor_header.encryption_context == decryptor_header.encryption_context
253
-
208
+ TODO: Code example with encryption context
254
209
255
210
Streaming
256
211
=========
@@ -259,6 +214,8 @@ memory at once, you can use this library's streaming clients directly. The strea
259
214
file-like objects, and behave exactly as you would expect a Python file object to behave,
260
215
offering context manager and iteration support.
261
216
217
+ TODO: Update code example to use a keyring
218
+
262
219
.. code :: python
263
220
264
221
import aws_encryption_sdk
@@ -309,20 +266,24 @@ to your use-case in order to obtain peak performance.
309
266
310
267
Thread safety
311
268
==========================
312
- The ``EncryptionSDKClient `` and all provided ``CryptoMaterialsManager `` are thread safe.
313
- But instances of ``BaseKMSMasterKeyProvider `` MUST not be shared between threads,
269
+ The ``EncryptionSDKClient `` and provided ``CryptoMaterialsManager `` are thread safe.
270
+ But instances of key material providers (i.e. keyrings or legacy master key providers) that call AWS KMS
271
+ (ex. ``AwsKmsKeyring `` or other KMS keyrings; ``BaseKmsMasterKeyProvider `` or children of this class)
272
+ MUST not be shared between threads
314
273
for the reasons outlined in `the boto3 docs <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html#multithreading-or-multiprocessing-with-resources >`_.
315
274
316
- Because the `` BaseKMSMaterKeyProvider `` creates a `new boto3 sessions <https://github.com/aws/aws-encryption-sdk-python/blob/08f305a9b7b5fc897d9cafac55fb98f3f2a6fe13/src/aws_encryption_sdk/key_providers/kms.py#L665-L674 >`_ per region,
275
+ Because these key material providers create a `new boto3 sessions <https://github.com/aws/aws-encryption-sdk-python/blob/08f305a9b7b5fc897d9cafac55fb98f3f2a6fe13/src/aws_encryption_sdk/key_providers/kms.py#L665-L674 >`_ per region,
317
276
users do not need to create a client for every region in every thread;
318
- a new `` BaseKMSMasterKeyProvider `` per thread is sufficient.
277
+ a single key material provider per thread is sufficient.
319
278
320
- (The ``BaseKMSMasterKeyProvider `` is the internal parent class of all the KMS Providers .)
279
+ (The ``BaseKMSMasterKeyProvider `` is the internal parent class of all the legacy KMS master key providers .)
321
280
322
281
Finally, while the ``CryptoMaterialsCache `` is thread safe,
323
282
sharing entries in that cache across threads needs to be done carefully
324
283
(see the !Note about partition name `in the API Docs <https://aws-encryption-sdk-python.readthedocs.io/en/latest/generated/aws_encryption_sdk.materials_managers.caching.html#aws_encryption_sdk.materials_managers.caching.CachingCryptoMaterialsManager >`_).
325
284
285
+ TODO: Note on MPL
286
+
326
287
.. _AWS Encryption SDK : https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html
327
288
.. _cryptography : https://cryptography.io/en/latest/
328
289
.. _cryptography installation guide : https://cryptography.io/en/latest/installation/
@@ -337,3 +298,5 @@ sharing entries in that cache across threads needs to be done carefully
337
298
.. _encryption context : https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context
338
299
.. _Security issue notifications : ./CONTRIBUTING.md#security-issue-notifications
339
300
.. _Support Policy : ./SUPPORT_POLICY.rst
301
+ .. _AWS Cryptographic Material Providers Library (MPL) : https://github.com/aws/aws-cryptographic-material-providers-library
302
+ .. _AWS Documentation for Keyrings : https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/choose-keyring.html
0 commit comments