Skip to content

Commit d18e1c1

Browse files
CSHARP-2838: MONGODB-AWS Support
1 parent 719731c commit d18e1c1

22 files changed

+1986
-86
lines changed

build.cake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ Task("Test")
137137
);
138138
});
139139

140+
Task("TestAwsAuthentication")
141+
.IsDependentOn("Build")
142+
.DoesForEach(
143+
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
144+
testProject =>
145+
{
146+
DotNetCoreTest(
147+
testProject.FullPath,
148+
new DotNetCoreTestSettings {
149+
NoBuild = true,
150+
NoRestore = true,
151+
Configuration = configuration,
152+
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
153+
Filter = "Category=\"AwsMechanism\""
154+
}
155+
);
156+
});
157+
140158
// currently we are not running this Task on Evergreen (only locally occassionally)
141159
Task("TestAllGuidRepresentations")
142160
.IsDependentOn("Build")

evergreen/evergreen.yml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ functions:
206206
TOPOLOGY=${TOPOLOGY} \
207207
AUTH=${AUTH} \
208208
SSL=${SSL} \
209+
STORAGE_ENGINE=${STORAGE_ENGINE} \
209210
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
210211
sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
211212
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
@@ -261,6 +262,152 @@ functions:
261262
${PREPARE_SHELL}
262263
MONGODB_URI="${plain_auth_mongodb_uri}" evergreen/run-plain-auth-tests.sh
263264
265+
add-aws-auth-variables-to-file:
266+
- command: shell.exec
267+
type: test
268+
params:
269+
working_dir: mongo-csharp-driver
270+
silent: true
271+
script: |
272+
cat <<EOF > ${DRIVERS_TOOLS}/.evergreen/auth_aws/aws_e2e_setup.json
273+
{
274+
"iam_auth_ecs_account" : "${iam_auth_ecs_account}",
275+
"iam_auth_ecs_secret_access_key" : "${iam_auth_ecs_secret_access_key}",
276+
"iam_auth_ecs_account_arn": "arn:aws:iam::557821124784:user/authtest_fargate_user",
277+
"iam_auth_ecs_cluster": "${iam_auth_ecs_cluster}",
278+
"iam_auth_ecs_task_definition": "${iam_auth_ecs_task_definition}",
279+
"iam_auth_ecs_subnet_a": "${iam_auth_ecs_subnet_a}",
280+
"iam_auth_ecs_subnet_b": "${iam_auth_ecs_subnet_b}",
281+
"iam_auth_ecs_security_group": "${iam_auth_ecs_security_group}",
282+
"iam_auth_assume_aws_account" : "${iam_auth_assume_aws_account}",
283+
"iam_auth_assume_aws_secret_access_key" : "${iam_auth_assume_aws_secret_access_key}",
284+
"iam_auth_assume_role_name" : "${iam_auth_assume_role_name}",
285+
"iam_auth_ec2_instance_account" : "${iam_auth_ec2_instance_account}",
286+
"iam_auth_ec2_instance_secret_access_key" : "${iam_auth_ec2_instance_secret_access_key}",
287+
"iam_auth_ec2_instance_profile" : "${iam_auth_ec2_instance_profile}"
288+
}
289+
EOF
290+
291+
run-aws-auth-test-with-regular-aws-credentials:
292+
- command: shell.exec
293+
type: test
294+
params:
295+
working_dir: mongo-csharp-driver
296+
script: |
297+
${PREPARE_SHELL}
298+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
299+
mongo aws_e2e_regular_aws.js
300+
- command: shell.exec
301+
type: test
302+
params:
303+
working_dir: mongo-csharp-driver
304+
script: |
305+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
306+
alias urlencode='python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus(sys.argv[1]))"'
307+
USER=$(urlencode "${iam_auth_ecs_account}")
308+
PASS=$(urlencode "${iam_auth_ecs_secret_access_key}")
309+
MONGODB_URI="mongodb://$USER:$PASS@localhost"
310+
EOF
311+
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} evergreen/run-mongodb-aws-test.sh
312+
313+
run-aws-auth-test-with-assume-role-credentials:
314+
- command: shell.exec
315+
type: test
316+
params:
317+
working_dir: mongo-csharp-driver
318+
script: |
319+
${PREPARE_SHELL}
320+
# The aws_e2e_assume_role script requires python3 with boto3.
321+
virtualenv -p C:/python/Python38/python.exe mongovenv
322+
. mongovenv/Scripts/activate
323+
pip install boto3
324+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
325+
mongo aws_e2e_assume_role.js
326+
- command: shell.exec
327+
type: test
328+
params:
329+
working_dir: mongo-csharp-driver
330+
script: |
331+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
332+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
333+
alias urlencode='python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus(sys.argv[1]))"'
334+
alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json'
335+
USER=$(jsonkey AccessKeyId)
336+
USER=$(urlencode $USER)
337+
PASS=$(jsonkey SecretAccessKey)
338+
PASS=$(urlencode $PASS)
339+
SESSION_TOKEN=$(jsonkey SessionToken)
340+
SESSION_TOKEN=$(urlencode $SESSION_TOKEN)
341+
MONGODB_URI="mongodb://$USER:$PASS@localhost"
342+
EOF
343+
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} DRIVERS_TOOLS=${DRIVERS_TOOLS} evergreen/run-mongodb-aws-test.sh
344+
345+
run-aws-auth-test-with-aws-EC2-credentials:
346+
- command: shell.exec
347+
type: test
348+
params:
349+
working_dir: mongo-csharp-driver
350+
script: |
351+
${PREPARE_SHELL}
352+
# The aws_e2e_assume_role script requires python3 with boto3.
353+
virtualenv -p C:/python/Python38/python.exe mongovenv
354+
. mongovenv/Scripts/activate
355+
pip install boto3
356+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
357+
mongo aws_e2e_ec2.js
358+
- command: shell.exec
359+
type: test
360+
params:
361+
working_dir: mongo-csharp-driver
362+
script: |
363+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
364+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
365+
MONGODB_URI="mongodb://localhost"
366+
EOF
367+
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} evergreen/run-mongodb-aws-test.sh
368+
369+
run-aws-auth-test-with-aws-credentials-as-environment-variables:
370+
- command: shell.exec
371+
type: test
372+
params:
373+
working_dir: mongo-csharp-driver
374+
script: |
375+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
376+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
377+
export AWS_ACCESS_KEY_ID=${iam_auth_ecs_account}
378+
export AWS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key}
379+
MONGODB_URI="mongodb://localhost"
380+
EOF
381+
- command: shell.exec
382+
type: test
383+
params:
384+
working_dir: mongo-csharp-driver
385+
script: |
386+
${PREPARE_SHELL}
387+
evergreen/run-mongodb-aws-test.sh
388+
389+
run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables:
390+
- command: shell.exec
391+
type: test
392+
params:
393+
working_dir: mongo-csharp-driver
394+
script: |
395+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
396+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
397+
alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json'
398+
export AWS_ACCESS_KEY_ID=$(jsonkey AccessKeyId)
399+
export AWS_SECRET_ACCESS_KEY=$(jsonkey SecretAccessKey)
400+
export AWS_SESSION_TOKEN=$(jsonkey SessionToken)
401+
MONGODB_URI="mongodb://localhost"
402+
EOF
403+
- command: shell.exec
404+
type: test
405+
params:
406+
working_dir: mongo-csharp-driver
407+
script: |
408+
${PREPARE_SHELL}
409+
evergreen/run-mongodb-aws-test.sh
410+
264411
run-ocsp-test:
265412
- command: shell.exec
266413
type: test
@@ -465,6 +612,24 @@ tasks:
465612
commands:
466613
- func: run-plain-auth-tests
467614

615+
- name: aws-auth-tests
616+
depends_on:
617+
- variant: windows-64-compile
618+
name: compile
619+
commands:
620+
- func: bootstrap-mongo-orchestration
621+
vars:
622+
AUTH: "auth"
623+
ORCHESTRATION_FILE: "auth-aws.json"
624+
TOPOLOGY: "server"
625+
- func: add-aws-auth-variables-to-file
626+
- func: run-aws-auth-test-with-regular-aws-credentials
627+
- func: run-aws-auth-test-with-assume-role-credentials
628+
- func: run-aws-auth-test-with-aws-credentials-as-environment-variables
629+
- func: run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables
630+
- func: run-aws-auth-test-with-aws-EC2-credentials
631+
# ECS test is skipped untill testing on Linux becomes possible
632+
468633
- name: publish-snapshot
469634
depends_on:
470635
- variant: ".tests-variant"
@@ -944,6 +1109,14 @@ buildvariants:
9441109
tasks:
9451110
- name: ".ocsp"
9461111

1112+
- matrix_name: aws-auth-tests
1113+
matrix_spec: { version: ["latest"], topology: "standalone", os: "*" }
1114+
display_name: "MONGODB-AWS Auth test"
1115+
run_on:
1116+
- windows-64-vs2017-test
1117+
tasks:
1118+
- name: aws-auth-tests
1119+
9471120
- name: atlas-connectivity-tests
9481121
display_name: "Atlas Connectivity Tests"
9491122
run_on:

evergreen/run-mongodb-aws-test.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env 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 username/password to use to connect to the server via MONGODBAWS authentication mechanism
8+
9+
############################################
10+
# Main Program #
11+
############################################
12+
13+
echo "Running MONGODB-AWS authentication tests"
14+
15+
# Provision the correct connection string and set up SSL if needed
16+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do setx $var z:\\data\\tmp; export $var=z:\\data\\tmp; done
17+
18+
# ensure no secrets are printed in log files
19+
set +x
20+
21+
# load the script
22+
shopt -s expand_aliases # needed for `urlencode` alias
23+
[ -s "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" ] && source "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
24+
25+
if [ -z ${MONGODB_URI+x} ]; then
26+
echo "MONGODB_URI is not set";
27+
exit 1
28+
fi
29+
MONGODB_URI="${MONGODB_URI}/aws?authMechanism=MONGODB-AWS"
30+
if [[ -n ${SESSION_TOKEN} ]]; then
31+
MONGODB_URI="${MONGODB_URI}&authMechanismProperties=AWS_SESSION_TOKEN:${SESSION_TOKEN}"
32+
fi
33+
export MONGODB_URI
34+
export AWS_TESTS_ENABLED=true
35+
36+
# show test output
37+
set -x
38+
39+
powershell.exe .\\build.ps1 -target TestAwsAuthentication

0 commit comments

Comments
 (0)