Skip to content

Commit 62829f7

Browse files
CSHARP-4266: Add support for GCP attached service accounts when using GCP KMS.
1 parent ac5917f commit 62829f7

File tree

13 files changed

+708
-229
lines changed

13 files changed

+708
-229
lines changed

build.cake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,29 @@ Task("TestCsfleWithMongocryptdNetStandard20").IsDependentOn("TestCsfleWithMongoc
460460
Task("TestCsfleWithMongocryptdNetStandard21").IsDependentOn("TestCsfleWithMongocryptd");
461461
Task("TestCsfleWithMongocryptdNet60").IsDependentOn("TestCsfleWithMongocryptd");
462462

463+
Task("TestCsfleWithGcpKms")
464+
.IsDependentOn("Build")
465+
.DoesForEach(
466+
items: GetFiles("./**/*.Tests.csproj"),
467+
action: (BuildConfig buildConfig, Path testProject) =>
468+
{
469+
var settings = new DotNetTestSettings
470+
{
471+
NoBuild = true,
472+
NoRestore = true,
473+
Configuration = configuration,
474+
Loggers = CreateLoggers(),
475+
ArgumentCustomization = args => args.Append($"-- RunConfiguration.TargetPlatform={buildConfig.TargetPlatform}"),
476+
Filter = "Category=\"CsfleGCPKMS\"",
477+
Framework = buildConfig.Framework
478+
};
479+
480+
DotNetTest(
481+
testProject.FullPath,
482+
settings
483+
);
484+
});
485+
463486
Task("Docs")
464487
.IsDependentOn("ApiDocs")
465488
.IsDependentOn("RefDocs");

evergreen/evergreen.yml

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ functions:
330330
set +x
331331
${PREPARE_CSFLE}
332332
export KMS_MOCK_SERVERS_ENABLED=true
333+
export GCE_METADATA_HOST="localhost:5000"
333334
${PREPARE_SHELL}
334335
set +o xtrace
335336
OS=${OS} \
@@ -741,7 +742,7 @@ functions:
741742
cd ${DRIVERS_TOOLS}/.evergreen/csfle
742743
$PYTHON -u kms_http_server.py -v --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 8002 --require_client_cert
743744
744-
start-kms-kmip-server:
745+
start-kms-mock-kmip-server:
745746
- command: shell.exec
746747
params:
747748
script: |
@@ -756,6 +757,25 @@ functions:
756757
cd ${DRIVERS_TOOLS}/.evergreen/csfle
757758
$PYTHON -u kms_kmip_server.py
758759
760+
start-kms-mock-gcp-server:
761+
- command: shell.exec
762+
params:
763+
script: |
764+
${PREPARE_SHELL}
765+
cd ${DRIVERS_TOOLS}/.evergreen/csfle
766+
. ./activate_venv.sh
767+
- command: shell.exec
768+
params:
769+
background: true
770+
script: |
771+
PYTHON=$(Venv="${DRIVERS_TOOLS}/.evergreen/csfle/kmstlsvenv" OS=${OS} ${PROJECT_DIRECTORY}/evergreen/get-python-path.sh);
772+
cd ${DRIVERS_TOOLS}/.evergreen/csfle/gcpkms
773+
$PYTHON -m pip install PyJWT
774+
mkdir ${DRIVERS_TOOLS}/tmp
775+
echo '${GOOGLE_APPLICATION_CREDENTIALS_CONTENT}' > ${DRIVERS_TOOLS}/tmp/testgcpkms_key_file.json
776+
export GOOGLE_APPLICATION_CREDENTIALS=${DRIVERS_TOOLS}/tmp/testgcpkms_key_file.json
777+
$PYTHON -u mock_server.py
778+
759779
cleanup:
760780
- command: shell.exec
761781
params:
@@ -874,7 +894,8 @@ tasks:
874894
- name: test-csfle-with-mocked-kms-tls-net472
875895
commands:
876896
- func: start-kms-mock-servers
877-
- func: start-kms-kmip-server
897+
- func: start-kms-mock-kmip-server
898+
- func: start-kms-mock-gcp-server
878899
- func: bootstrap-mongo-orchestration
879900
- func: run-csfle-with-mocked-kms-tests
880901
vars:
@@ -883,7 +904,8 @@ tasks:
883904
- name: test-csfle-with-mocked-kms-tls-netstandard20
884905
commands:
885906
- func: start-kms-mock-servers
886-
- func: start-kms-kmip-server
907+
- func: start-kms-mock-kmip-server
908+
- func: start-kms-mock-gcp-server
887909
- func: bootstrap-mongo-orchestration
888910
- func: run-csfle-with-mocked-kms-tests
889911
vars:
@@ -892,7 +914,8 @@ tasks:
892914
- name: test-csfle-with-mocked-kms-tls-netstandard21
893915
commands:
894916
- func: start-kms-mock-servers
895-
- func: start-kms-kmip-server
917+
- func: start-kms-mock-kmip-server
918+
- func: start-kms-mock-gcp-server
896919
- func: bootstrap-mongo-orchestration
897920
- func: run-csfle-with-mocked-kms-tests
898921
vars:
@@ -1350,6 +1373,40 @@ tasks:
13501373
# OCSP_ALGORITHM: "ecdsa"
13511374
# OCSP_TLS_SHOULD_SUCCEED: "false"
13521375

1376+
- name: test-csfle-with-gcp-kms
1377+
commands:
1378+
- command: shell.exec
1379+
type: setup
1380+
params:
1381+
working_dir: mongo-csharp-driver
1382+
shell: "bash"
1383+
script: |
1384+
${PREPARE_SHELL}
1385+
echo "Copying files ... begin"
1386+
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD}
1387+
export GCPKMS_PROJECT=${GCPKMS_PROJECT}
1388+
export GCPKMS_ZONE=${GCPKMS_ZONE}
1389+
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME}
1390+
tar czf /tmp/mongo-csharp-driver.tgz .
1391+
GCPKMS_SRC=/tmp/mongo-csharp-driver.tgz GCPKMS_DST=$GCPKMS_INSTANCENAME: $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/copy-file.sh
1392+
echo "Copying files ... end"
1393+
echo "Untarring file ... begin"
1394+
GCPKMS_CMD="tar xf mongo-csharp-driver.tgz" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
1395+
echo "Untarring file ... end"
1396+
1397+
- command: shell.exec
1398+
type: test
1399+
params:
1400+
working_dir: "mongo-csharp-driver"
1401+
shell: "bash"
1402+
script: |
1403+
${PREPARE_SHELL}
1404+
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD}
1405+
export GCPKMS_PROJECT=${GCPKMS_PROJECT}
1406+
export GCPKMS_ZONE=${GCPKMS_ZONE}
1407+
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME}
1408+
GCPKMS_CMD="MONGODB_URI='mongodb://localhost:27017' ./evergreen/run-csfle-gcp-tests.sh" $DRIVERS_TOOLS/.evergreen/csfle/gcpkms/run-command.sh
1409+
13531410
axes:
13541411
- id: version
13551412
display_name: MongoDB Version
@@ -1467,6 +1524,46 @@ axes:
14671524
variables:
14681525
COMPRESSOR: "zstd"
14691526

1527+
task_groups:
1528+
- name: testgcpkms-task-group
1529+
setup_group_can_fail_task: true
1530+
setup_group_timeout_secs: 1800 # 30 minutes
1531+
setup_group:
1532+
- func: fetch-source
1533+
- func: prepare-resources
1534+
- func: windows-fix
1535+
- func: fix-absolute-paths
1536+
- func: init-test-results
1537+
- func: make-files-executable
1538+
- command: shell.exec
1539+
params:
1540+
shell: "bash"
1541+
script: |
1542+
${PREPARE_SHELL}
1543+
echo '${GOOGLE_APPLICATION_CREDENTIALS_CONTENT}' > /tmp/testgcpkms_key_file.json
1544+
export GCPKMS_KEYFILE=/tmp/testgcpkms_key_file.json
1545+
export GCPKMS_DRIVERS_TOOLS=$DRIVERS_TOOLS
1546+
export GCPKMS_SERVICEACCOUNT="${GCPKMS_SERVICEACCOUNT}"
1547+
export GCPKMS_MACHINETYPE="e2-standard-4"
1548+
$DRIVERS_TOOLS/.evergreen/csfle/gcpkms/create-and-setup-instance.sh
1549+
# Load the GCPKMS_GCLOUD, GCPKMS_INSTANCE, GCPKMS_REGION, and GCPKMS_ZONE expansions.
1550+
- command: expansions.update
1551+
params:
1552+
file: testgcpkms-expansions.yml
1553+
teardown_group:
1554+
- command: shell.exec
1555+
params:
1556+
shell: "bash"
1557+
script: |
1558+
${PREPARE_SHELL}
1559+
export GCPKMS_GCLOUD=${GCPKMS_GCLOUD}
1560+
export GCPKMS_PROJECT=${GCPKMS_PROJECT}
1561+
export GCPKMS_ZONE=${GCPKMS_ZONE}
1562+
export GCPKMS_INSTANCENAME=${GCPKMS_INSTANCENAME}
1563+
$DRIVERS_TOOLS/.evergreen/csfle/gcpkms/delete-instance.sh
1564+
tasks:
1565+
- test-csfle-with-gcp-kms
1566+
14701567
buildvariants:
14711568

14721569
- matrix_name: "secure-tests"
@@ -1716,3 +1813,9 @@ buildvariants:
17161813
tasks:
17171814
- name: test-csfle-with-mongocryptd-netstandard21
17181815

1816+
- matrix_name: "csfle-with-gcp-kms-tests-linux"
1817+
matrix_spec: { ssl: "nossl", os: "ubuntu-1804" }
1818+
display_name: "CSFLE with GCP KMS ${os}"
1819+
batchtime: 20160 # 14 days
1820+
tasks:
1821+
- name: testgcpkms-task-group

evergreen/run-csfle-gcp-tests.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -o xtrace
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Supported/used environment variables:
7+
# MONGODB_URI Set the URI, including an optional username/password to use to connect to the server
8+
############################################
9+
# Main Program #
10+
############################################
11+
12+
echo "Running GCP Credential Acquisition Test"
13+
14+
# fixing https://github.com/dotnet/core/issues/2186#issuecomment-671105420
15+
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
16+
export CSFLE_GCP_KMS_TESTS_ENABLED=true
17+
18+
./build.sh --target=TestCsfleWithGcpKms

0 commit comments

Comments
 (0)