Skip to content

Commit 6136620

Browse files
docs: clarify KMSMasterKeyProvider credentials configuration (#251)
* Readme: Update KMSMasterKeyProvider credentials configuration for better understanding * Readme: Move KMSMasterKeyProvider usage information into its docstring * Format KMSMasterKeyProvider docstring * Fix pylint max character error in kms.py * docs: copyedit, rst formatting, and rearranging Co-authored-by: Matt Bullock <bullocm@amazon.com>
1 parent b70d397 commit 6136620

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

README.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ to your use-case in order to obtain peak performance.
112112
.. _GitHub: https://github.com/aws/aws-encryption-sdk-python/
113113
.. _AWS KMS: https://docs.aws.amazon.com/kms/latest/developerguide/overview.html
114114
.. _KMS customer master key (CMK): https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys
115-
.. _boto3 SDK: https://boto3.readthedocs.io/en/latest/
116-
.. _standard means by which boto3 locates credentials: https://boto3.readthedocs.io/en/latest/guide/configuration.html
117-
.. _final message: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html
118115
.. _encryption context: https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context
119116
.. _examples: https://github.com/aws/aws-encryption-sdk-python/tree/master/examples
120117
.. _Security issue notifications: https://github.com/aws/aws-encryption-sdk-python/tree/master/CONTRIBUTING.md#security-issue-notifications

src/aws_encryption_sdk/key_providers/kms.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,58 @@ class KMSMasterKeyProvider(MasterKeyProvider):
8282
Master key providers are deprecated.
8383
Use :class:`aws_encryption_sdk.keyrings.aws_kms.AwsKmsKeyring` instead.
8484
85-
>>> import aws_encryption_sdk
86-
>>> kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids=[
87-
... 'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
88-
... 'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
85+
To encrypt data, you must configure :class:`KMSMasterKeyProvider` with at least one CMK.
86+
If you configure :class:`KMSMasterKeyProvider` with multiple CMKs,
87+
it generates the data key using the first CMK and encrypts that data key using the rest,
88+
so that the `encrypted message`_ includes a copy of the data key encrypted under each configured CMK.
89+
90+
.. _encrypted message: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html
91+
92+
>>> from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
93+
>>> kms_key_provider = KMSMasterKeyProvider(key_ids=[
94+
... "arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222",
95+
... "arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333",
96+
... ])
97+
98+
You can also configure :class:`KMSMasterKeyProvider` with CMKs in multiple regions:
99+
100+
>>> from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
101+
>>> kms_key_provider = KMSMasterKeyProvider(key_ids=[
102+
... "arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222",
103+
... "arn:aws:kms:us-west-2:3333333333333:key/33333333-3333-3333-3333-333333333333",
104+
... "arn:aws:kms:ap-northeast-1:4444444444444:key/44444444-4444-4444-4444-444444444444",
89105
... ])
90-
>>> kms_key_provider.add_master_key('arn:aws:kms:ap-northeast-1:4444444444444:alias/another-key')
91106
92-
.. note::
93-
If no botocore_session is provided, the default botocore session will be used.
107+
:class:`KMSMasterKeyProvider` needs AWS credentials in order to interact with `AWS KMS`_.
108+
There are two ways that you can provide these credentials:
109+
110+
.. _AWS KMS: https://docs.aws.amazon.com/kms/latest/developerguide/overview.html
111+
112+
1. Provide your AWS credentials in one of the standard `AWS credential discovery locations`_
113+
and the :class:`KMSMasterKeyProvider` instance automatically discovers those credentials.
114+
115+
.. _AWS credential discovery locations:
116+
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#configuring-credentials
117+
118+
>>> from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
119+
>>> import botocore.session
120+
>>> kms_key_provider = KMSMasterKeyProvider()
94121
95-
.. note::
96-
If multiple AWS Identities are needed, one of two options are available:
122+
2. Provide an existing botocore session to :class:`KMSMasterKeyProvider`.
123+
This option can be useful if you want to use specific credentials
124+
or if you want to reuse an existing botocore session instance to decrease startup costs.
97125
98-
* Additional KMSMasterKeyProvider instances may be added to the primary MasterKeyProvider.
126+
>>> from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
127+
>>> import botocore.session
128+
>>> existing_botocore_session = botocore.session.Session(profile="custom")
129+
>>> kms_key_provider = KMSMasterKeyProvider(botocore_session=existing_botocore_session)
99130
100-
* KMSMasterKey instances may be manually created and added to this KMSMasterKeyProvider.
131+
If you need different credentials to use different CMKs,
132+
you can combine multiple :class:`KMSMasterKeyProvider` or :class:`KMSMasterKey` instances,
133+
each with their own credentials.
134+
However, we recommend that you use
135+
:class:`aws_encryption_sdk.keyrings.aws_kms.AwsKmsKeyring` and client suppliers
136+
for a simpler user experience.
101137
102138
:param config: Configuration object (optional)
103139
:type config: aws_encryption_sdk.key_providers.kms.KMSMasterKeyProviderConfig

0 commit comments

Comments
 (0)