Skip to content

Commit 0266a55

Browse files
readme
1 parent 693b776 commit 0266a55

File tree

1 file changed

+87
-124
lines changed

1 file changed

+87
-124
lines changed

README.rst

+87-124
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ Required Prerequisites
3939
* boto3 >= 1.10.0
4040
* attrs
4141

42+
Recommended Prerequisites
43+
=========================
44+
45+
* aws-cryptographic-material-providers: >= 1.0.0 (TODO)
46+
* Requires Python 3.11+.
47+
4248
Installation
4349
============
4450

@@ -54,19 +60,39 @@ Installation
5460
5561
Concepts
5662
========
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`_.
5878

5979
Cryptographic Materials Managers
6080
--------------------------------
6181
Cryptographic materials managers (CMMs) are resources that collect cryptographic materials and prepare them for
6282
use by the Encryption SDK core logic.
6383

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.
6787

6888
An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by another CMM.
6989

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+
7096
Master Key Providers
7197
--------------------
7298
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
76102

77103
``MasterKeyProvider`` objects can also contain other ``MasterKeyProvider`` objects.
78104

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+
79110
Master Keys
80111
-----------
81112
Master keys generate, encrypt, and decrypt data keys.
82113
An example of a master key is a `KMS customer master key (CMK)`_.
83114

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.
88119

89120
*****
90121
Usage
@@ -110,147 +141,71 @@ version of the AWS Encryption SDK, we recommend using the default value.
110141
)
111142
112143
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.
115148

116149

117-
StrictAwsKmsMasterKeyProvider
150+
AwsKmsKeyring
118151
=============================
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`_,
129165
it requires AWS Credentials.
130166
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``.
132168
This latter option can be useful if you have an alternate way to store your AWS credentials or
133169
you want to reuse an existing instance of a botocore session in order to decrease startup costs.
134170

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
146172

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.
150174

151-
import aws_encryption_sdk
175+
MultiKeyring
176+
============
152177

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.
158179

180+
TODO: Code example
159181

160182
DiscoveryAwsKmsMasterKeyProvider
161183
================================
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
166189
attempts decryption of any ciphertexts as long as they match a ``DiscoveryFilter`` that
167190
you configure. A ``DiscoveryFilter`` consists of a list of AWS account ids and an AWS
168191
partition.
169192

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
182194

183195
If you do not want to filter the set of allowed accounts, you can also omit the ``discovery_filter`` argument.
184196

185-
Note that a ``DiscoveryAwsKmsMasterKeyProvider`` cannot be used for encryption operations.
197+
Note that a ``AwsKmsDiscoveryKeyring`` cannot be used for encryption operations.
186198

187199
Encryption and Decryption
188200
=========================
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
190202
the client's two ``encrypt``/``decrypt`` functions to encrypt and decrypt your data.
191203

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
219205

220206
You can provide an `encryption context`_: a form of additional authenticating information.
221207

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
254209

255210
Streaming
256211
=========
@@ -259,6 +214,8 @@ memory at once, you can use this library's streaming clients directly. The strea
259214
file-like objects, and behave exactly as you would expect a Python file object to behave,
260215
offering context manager and iteration support.
261216

217+
TODO: Update code example to use a keyring
218+
262219
.. code:: python
263220
264221
import aws_encryption_sdk
@@ -309,20 +266,24 @@ to your use-case in order to obtain peak performance.
309266

310267
Thread safety
311268
==========================
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
314273
for the reasons outlined in `the boto3 docs <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html#multithreading-or-multiprocessing-with-resources>`_.
315274

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,
317276
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.
319278

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.)
321280

322281
Finally, while the ``CryptoMaterialsCache`` is thread safe,
323282
sharing entries in that cache across threads needs to be done carefully
324283
(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>`_).
325284

285+
TODO: Note on MPL
286+
326287
.. _AWS Encryption SDK: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html
327288
.. _cryptography: https://cryptography.io/en/latest/
328289
.. _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
337298
.. _encryption context: https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context
338299
.. _Security issue notifications: ./CONTRIBUTING.md#security-issue-notifications
339300
.. _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

Comments
 (0)