Skip to content

Commit 3fc301c

Browse files
authored
PYTHON-3256 Obtain AWS credentials for CSFLE in the same way as for MONGODB-AWS (mongodb#1035)
1 parent 228edd2 commit 3fc301c

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

.evergreen/run-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ if [ -n "$TEST_ENCRYPTION" ]; then
147147
python -c "import pymongocrypt; print('libmongocrypt version: '+pymongocrypt.libmongocrypt_version())"
148148
# PATH is updated by PREPARE_SHELL for access to mongocryptd.
149149

150+
# Need aws dependency for On-Demand KMS Credentials.
151+
python -m pip install '.[aws]'
152+
150153
# Get access to the AWS temporary credentials:
151154
# CSFLE_AWS_TEMP_ACCESS_KEY_ID, CSFLE_AWS_TEMP_SECRET_ACCESS_KEY, CSFLE_AWS_TEMP_SESSION_TOKEN
152155
. $DRIVERS_TOOLS/.evergreen/csfle/set-temp-creds.sh

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ Wire protocol compression with zstandard requires `zstandard
130130
$ python -m pip install "pymongo[zstd]"
131131

132132
Client-Side Field Level Encryption requires `pymongocrypt
133-
<https://pypi.org/project/pymongocrypt/>`_::
133+
<https://pypi.org/project/pymongocrypt/>`_ and
134+
`pymongo-auth-aws <https://pypi.org/project/pymongo-auth-aws/>`_::
134135

135136
$ python -m pip install "pymongo[encryption]"
136137

doc/examples/encryption.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Dependencies
2323

2424
To get started using client-side field level encryption in your project,
2525
you will need to install the
26-
`pymongocrypt <https://pypi.org/project/pymongocrypt/>`_ library
26+
`pymongocrypt <https://pypi.org/project/pymongocrypt/>`_ and
27+
`pymongo-auth-aws <https://pypi.org/project/pymongo-auth-aws/>`_ libraries
2728
as well as the driver itself. Install both the driver and a compatible
28-
version of pymongocrypt like this::
29+
version of the dependencies like this::
2930

3031
$ python -m pip install 'pymongo[encryption]'
3132

doc/installation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ Wire protocol compression with zstandard requires `zstandard
7070
$ python3 -m pip install "pymongo[zstd]"
7171

7272
:ref:`Client-Side Field Level Encryption` requires `pymongocrypt
73-
<https://pypi.org/project/pymongocrypt/>`_::
73+
<https://pypi.org/project/pymongocrypt/>`_ and
74+
`pymongo-auth-aws <https://pypi.org/project/pymongo-auth-aws/>`_::
7475

7576
$ python3 -m pip install "pymongo[encryption]"
7677

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,14 @@ def build_extension(self, ext):
278278
# https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context.set_default_verify_paths
279279
pyopenssl_reqs.append("certifi")
280280

281+
aws_reqs = ["pymongo-auth-aws<2.0.0"]
282+
281283
extras_require = {
282-
"encryption": ["pymongocrypt>=1.3.0,<2.0.0"],
284+
"encryption": ["pymongocrypt>=1.3.0,<2.0.0"] + aws_reqs,
283285
"ocsp": pyopenssl_reqs,
284286
"snappy": ["python-snappy"],
285287
"zstd": ["zstandard"],
286-
"aws": ["pymongo-auth-aws<2.0.0"],
288+
"aws": aws_reqs,
287289
"srv": [], # PYTHON-3423 Removed in 4.3 but kept here to avoid pip warnings.
288290
"tls": [], # PYTHON-2133 Removed in 4.0 but kept here to avoid pip warnings.
289291
}

test/test_encryption.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,37 @@ def run_test(self, src_provider, dst_provider):
23042304
self.assertEqual(decrypt_result2, "test")
23052305

23062306

2307+
# https://github.com/mongodb/specifications/blob/5cf3ed/source/client-side-encryption/tests/README.rst#on-demand-aws-credentials
2308+
class TestOnDemandAWSCredentials(EncryptionIntegrationTest):
2309+
def setUp(self):
2310+
super(TestOnDemandAWSCredentials, self).setUp()
2311+
self.master_key = {
2312+
"region": "us-east-1",
2313+
"key": ("arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0"),
2314+
}
2315+
2316+
@unittest.skipIf(any(AWS_CREDS.values()), "AWS environment credentials are set")
2317+
def test_01_failure(self):
2318+
self.client_encryption = ClientEncryption(
2319+
kms_providers={"aws": {}},
2320+
key_vault_namespace="keyvault.datakeys",
2321+
key_vault_client=client_context.client,
2322+
codec_options=OPTS,
2323+
)
2324+
with self.assertRaises(EncryptionError):
2325+
self.client_encryption.create_data_key("aws", self.master_key)
2326+
2327+
@unittest.skipUnless(any(AWS_CREDS.values()), "AWS environment credentials are not set")
2328+
def test_02_success(self):
2329+
self.client_encryption = ClientEncryption(
2330+
kms_providers={"aws": {}},
2331+
key_vault_namespace="keyvault.datakeys",
2332+
key_vault_client=client_context.client,
2333+
codec_options=OPTS,
2334+
)
2335+
self.client_encryption.create_data_key("aws", self.master_key)
2336+
2337+
23072338
class TestQueryableEncryptionDocsExample(EncryptionIntegrationTest):
23082339
# Queryable Encryption is not supported on Standalone topology.
23092340
@client_context.require_no_standalone

0 commit comments

Comments
 (0)