-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3367 Add support for GCP attached service accounts when using GCP KMS #1064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ceec6de
84cdc94
2d4b129
b7ed5cb
a77b772
eee7984
1e6337e
e08290d
f45f004
7e0ce9c
cbaa9e7
53e6827
fd389bf
70fee00
20bbfed
3e9da38
3efa7ad
7a237ed
7b2734a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -o xtrace | ||
| set -o errexit # Exit the script with error if any of the commands fail | ||
|
|
||
| # Supported/used environment variables: | ||
| # MONGODB_URI Set the URI, including an optional username/password to use to connect to the server | ||
| # SUCCESS Whether the authentication is expected to succeed or fail. One of "true" or "false" | ||
| ############################################ | ||
| # Main Program # | ||
| ############################################ | ||
|
|
||
| if [[ -z "$1" ]]; then | ||
| echo "usage: $0 <MONGODB_URI>" | ||
| exit 1 | ||
| fi | ||
| export MONGODB_URI="$1" | ||
|
|
||
| if echo "$MONGODB_URI" | grep -q "@"; then | ||
| echo "MONGODB_URI unexpectedly contains user credentials in FLE GCP test!"; | ||
| exit 1 | ||
| fi | ||
| # Now we can safely enable xtrace | ||
| set -o xtrace | ||
|
|
||
| authtest () { | ||
| echo "Running GCP Credential Acquisition Test with $PYTHON" | ||
| $PYTHON --version | ||
| $PYTHON -m pip install --upgrade wheel setuptools pip | ||
| $PYTHON -m pip install '.[encryption]' | ||
| $PYTHON -m pip install https://github.com/mongodb/libmongocrypt#subdirectory=bindings/python | ||
| TEST_FLE_GCP_AUTO=1 $PYTHON test/test_on_demand_csfle.py | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need SUCCESS=true?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is passed in from the evergreen config. |
||
| } | ||
|
|
||
| PYTHON="python3" authtest | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the plan for testing other python versions?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't test multiple versions on ECS
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right I forgot this was running on a remote host. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Copyright 2022-present MongoDB, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Test client side encryption with on demand credentials.""" | ||
| import os | ||
| import sys | ||
| import unittest | ||
|
|
||
| sys.path[0:0] = [""] | ||
|
|
||
| from test import IntegrationTest, client_context | ||
|
|
||
| from bson.codec_options import CodecOptions | ||
| from pymongo.encryption import _HAVE_PYMONGOCRYPT, ClientEncryption, EncryptionError | ||
|
|
||
|
|
||
| class TestonDemandGCPCredentials(IntegrationTest): | ||
| @classmethod | ||
| @unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed") | ||
| @client_context.require_version_min(4, 2, -1) | ||
| def setUpClass(cls): | ||
| super(TestonDemandGCPCredentials, cls).setUpClass() | ||
|
|
||
| def setUp(self): | ||
| super(TestonDemandGCPCredentials, self).setUp() | ||
| self.master_key = { | ||
| "projectId": "devprod-drivers", | ||
| "location": "global", | ||
| "keyRing": "key-ring-csfle", | ||
| "keyName": "key-name-csfle", | ||
| } | ||
|
|
||
| @unittest.skipIf(not os.getenv("TEST_FLE_GCP_AUTO"), "Not testing FLE GCP auto") | ||
| def test_01_failure(self): | ||
| if os.environ["SUCCESS"].lower() == "true": | ||
| self.skipTest("Expecting success") | ||
| self.client_encryption = ClientEncryption( | ||
| kms_providers={"gcp": {}}, | ||
| key_vault_namespace="keyvault.datakeys", | ||
| key_vault_client=client_context.client, | ||
| codec_options=CodecOptions(), | ||
| ) | ||
| with self.assertRaises(EncryptionError): | ||
| self.client_encryption.create_data_key("gcp", self.master_key) | ||
|
|
||
| @unittest.skipIf(not os.getenv("TEST_FLE_GCP_AUTO"), "Not testing FLE GCP auto") | ||
| def test_02_success(self): | ||
| if os.environ["SUCCESS"].lower() == "false": | ||
| self.skipTest("Expecting failure") | ||
| self.client_encryption = ClientEncryption( | ||
| kms_providers={"gcp": {}}, | ||
| key_vault_namespace="keyvault.datakeys", | ||
| key_vault_client=client_context.client, | ||
| codec_options=CodecOptions(), | ||
| ) | ||
| self.client_encryption.create_data_key("gcp", self.master_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are any of these variables sensitive info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed not to be sensitive