Skip to content

Commit cee49ec

Browse files
authored
RUST-359 Implement MONGODB-AWS auth support (#202)
1 parent 3d0ec19 commit cee49ec

File tree

21 files changed

+1168
-121
lines changed

21 files changed

+1168
-121
lines changed

.evergreen/aws-ecs-test/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cargo.lock
2+
target

.evergreen/aws-ecs-test/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "aws-ecs-test"
3+
version = "0.1.0"
4+
authors = ["Saghm Rossi <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
tokio = "0.2.21"
9+
10+
[dependencies.mongodb]
11+
path = "../.."

.evergreen/aws-ecs-test/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use mongodb::Client;
2+
3+
#[tokio::main]
4+
async fn main() {
5+
let uri = std::env::var("MONGODB_URI").expect("no URI given!");
6+
let client = Client::with_uri_str(&uri).await.unwrap();
7+
8+
client
9+
.database("aws")
10+
.collection("somecoll")
11+
.find_one(None, None)
12+
.await
13+
.unwrap();
14+
}

.evergreen/config.yml

Lines changed: 275 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ functions:
7676
export TMPDIR="$MONGO_ORCHESTRATION_HOME/db"
7777
export PATH="$MONGODB_BINARIES:$PATH"
7878
export PROJECT="${project}"
79-
79+
8080
export AUTH=${AUTH}
8181
export SSL=${SSL}
8282
export TOPOLOGY=${TOPOLOGY}
@@ -90,6 +90,194 @@ functions:
9090
params:
9191
file: src/expansion.yml
9292

93+
"add aws auth variables to file":
94+
- command: shell.exec
95+
type: test
96+
params:
97+
working_dir: "src"
98+
silent: true
99+
script: |
100+
cat <<EOF > ${DRIVERS_TOOLS}/.evergreen/auth_aws/aws_e2e_setup.json
101+
{
102+
"iam_auth_ecs_account" : "${iam_auth_ecs_account}",
103+
"iam_auth_ecs_secret_access_key" : "${iam_auth_ecs_secret_access_key}",
104+
"iam_auth_ecs_account_arn": "arn:aws:iam::557821124784:user/authtest_fargate_user",
105+
"iam_auth_ecs_cluster": "${iam_auth_ecs_cluster}",
106+
"iam_auth_ecs_task_definition": "${iam_auth_ecs_task_definition}",
107+
"iam_auth_ecs_subnet_a": "${iam_auth_ecs_subnet_a}",
108+
"iam_auth_ecs_subnet_b": "${iam_auth_ecs_subnet_b}",
109+
"iam_auth_ecs_security_group": "${iam_auth_ecs_security_group}",
110+
"iam_auth_assume_aws_account" : "${iam_auth_assume_aws_account}",
111+
"iam_auth_assume_aws_secret_access_key" : "${iam_auth_assume_aws_secret_access_key}",
112+
"iam_auth_assume_role_name" : "${iam_auth_assume_role_name}",
113+
"iam_auth_ec2_instance_account" : "${iam_auth_ec2_instance_account}",
114+
"iam_auth_ec2_instance_secret_access_key" : "${iam_auth_ec2_instance_secret_access_key}",
115+
"iam_auth_ec2_instance_profile" : "${iam_auth_ec2_instance_profile}"
116+
}
117+
EOF
118+
119+
"run aws auth test with regular aws credentials":
120+
- command: shell.exec
121+
type: test
122+
params:
123+
working_dir: "src"
124+
script: |
125+
${PREPARE_SHELL}
126+
# The aws_e2e_assume_role script requires python3 with boto3.
127+
pip install boto3
128+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
129+
mongo aws_e2e_regular_aws.js
130+
- command: shell.exec
131+
type: test
132+
params:
133+
working_dir: "src"
134+
silent: true
135+
script: |
136+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
137+
alias urlencode='python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus(sys.argv[1]))"'
138+
USER=$(urlencode ${iam_auth_ecs_account})
139+
PASS=$(urlencode ${iam_auth_ecs_secret_access_key})
140+
MONGODB_URI="mongodb://$USER:$PASS@localhost"
141+
EOF
142+
- command: shell.exec
143+
type: test
144+
params:
145+
working_dir: "src"
146+
script: |
147+
${PREPARE_SHELL}
148+
ASYNC_RUNTIME=${ASYNC_RUNTIME} .evergreen/run-aws-tests.sh
149+
150+
"run aws auth test with assume role credentials":
151+
- command: shell.exec
152+
type: test
153+
params:
154+
working_dir: "src"
155+
script: |
156+
${PREPARE_SHELL}
157+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
158+
# The aws_e2e_assume_role script requires python3 with boto3.
159+
pip install boto3
160+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
161+
mongo aws_e2e_assume_role.js
162+
- command: shell.exec
163+
type: test
164+
params:
165+
working_dir: "src"
166+
silent: true
167+
script: |
168+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
169+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
170+
alias urlencode='python -c "import sys, urllib as ul; sys.stdout.write(ul.quote_plus(sys.argv[1]))"'
171+
alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json'
172+
USER=$(jsonkey AccessKeyId)
173+
USER=$(urlencode $USER)
174+
PASS=$(jsonkey SecretAccessKey)
175+
PASS=$(urlencode $PASS)
176+
SESSION_TOKEN=$(jsonkey SessionToken)
177+
SESSION_TOKEN=$(urlencode $SESSION_TOKEN)
178+
MONGODB_URI="mongodb://$USER:$PASS@localhost"
179+
EOF
180+
- command: shell.exec
181+
type: test
182+
params:
183+
working_dir: "src"
184+
script: |
185+
${PREPARE_SHELL}
186+
ASYNC_RUNTIME=${ASYNC_RUNTIME} .evergreen/run-aws-tests.sh
187+
188+
"run aws auth test with aws EC2 credentials":
189+
- command: shell.exec
190+
type: test
191+
params:
192+
working_dir: "src"
193+
script: |
194+
${PREPARE_SHELL}
195+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
196+
mongo aws_e2e_ec2.js
197+
- command: shell.exec
198+
type: test
199+
params:
200+
working_dir: "src"
201+
script: |
202+
${PREPARE_SHELL}
203+
ASYNC_RUNTIME=${ASYNC_RUNTIME} .evergreen/run-aws-tests.sh
204+
205+
"run aws auth test with aws credentials as environment variables":
206+
- command: shell.exec
207+
type: test
208+
params:
209+
working_dir: "src"
210+
silent: true
211+
script: |
212+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
213+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
214+
export AWS_ACCESS_KEY_ID=${iam_auth_ecs_account}
215+
export AWS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key}
216+
EOF
217+
- command: shell.exec
218+
type: test
219+
params:
220+
working_dir: "src"
221+
script: |
222+
${PREPARE_SHELL}
223+
ASYNC_RUNTIME=${ASYNC_RUNTIME} PROJECT_DIRECTORY=${PROJECT_DIRECTORY} .evergreen/run-aws-tests.sh
224+
225+
"run aws auth test with aws credentials and session token as environment variables":
226+
- command: shell.exec
227+
type: test
228+
params:
229+
working_dir: "src"
230+
silent: true
231+
script: |
232+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
233+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
234+
alias jsonkey='python -c "import json,sys;sys.stdout.write(json.load(sys.stdin)[sys.argv[1]])" < ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json'
235+
export AWS_ACCESS_KEY_ID=$(jsonkey AccessKeyId)
236+
export AWS_SECRET_ACCESS_KEY=$(jsonkey SecretAccessKey)
237+
export AWS_SESSION_TOKEN=$(jsonkey SessionToken)
238+
EOF
239+
- command: shell.exec
240+
type: test
241+
params:
242+
working_dir: "src"
243+
script: |
244+
${PREPARE_SHELL}
245+
ASYNC_RUNTIME=${ASYNC_RUNTIME} .evergreen/run-aws-tests.sh
246+
247+
"run aws ECS auth test":
248+
- command: shell.exec
249+
type: test
250+
params:
251+
working_dir: "src"
252+
script: |
253+
${PREPARE_SHELL}
254+
AUTH_AWS_DIR=${DRIVERS_TOOLS}/.evergreen/auth_aws
255+
ECS_SRC_DIR=$AUTH_AWS_DIR/src
256+
257+
mkdir -p $ECS_SRC_DIR/.evergreen
258+
259+
# fix issue with `TestData` in SERVER-46340
260+
sed -i '1s+^+TestData = {};\n+' $AUTH_AWS_DIR/lib/ecs_hosted_test.js
261+
262+
# compile mini test project
263+
cd $PROJECT_DIRECTORY/.evergreen/aws-ecs-test
264+
. ~/.cargo/env
265+
cargo build
266+
cd -
267+
268+
# copy mini test binary
269+
cp $PROJECT_DIRECTORY/.evergreen/run-mongodb-aws-ecs-test.sh $ECS_SRC_DIR/.evergreen
270+
cp $PROJECT_DIRECTORY/.evergreen/aws-ecs-test/target/debug/aws-ecs-test $ECS_SRC_DIR
271+
272+
cd $AUTH_AWS_DIR
273+
cat <<EOF > setup.js
274+
const mongo_binaries = "$MONGODB_BINARIES";
275+
const project_dir = "$ECS_SRC_DIR";
276+
EOF
277+
278+
cat setup.js
279+
mongo --nodb setup.js aws_e2e_ecs.js
280+
93281
"prepare resources":
94282
- command: shell.exec
95283
params:
@@ -112,7 +300,12 @@ functions:
112300
params:
113301
script: |
114302
${PREPARE_SHELL}
115-
MONGODB_VERSION=${MONGODB_VERSION} TOPOLOGY=${TOPOLOGY} AUTH=${AUTH} SSL=${SSL} sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
303+
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
304+
MONGODB_VERSION=${MONGODB_VERSION} \
305+
TOPOLOGY=${TOPOLOGY} \
306+
AUTH=${AUTH} \
307+
SSL=${SSL} \
308+
sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
116309
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
117310
- command: expansions.update
118311
params:
@@ -141,7 +334,7 @@ functions:
141334
working_dir: "src"
142335
script: |
143336
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
144-
export MONGO_ATLAS_TESTS=1
337+
export MONGO_ATLAS_TESTS=1
145338
export MONGO_ATLAS_FREE_TIER_REPL_URI='${MONGO_ATLAS_FREE_TIER_REPL_URI}'
146339
export MONGO_ATLAS_FREE_TIER_REPL_URI_SRV='${MONGO_ATLAS_FREE_TIER_REPL_URI_SRV}'
147340
ASYNC_RUNTIME=${ASYNC_RUNTIME} .evergreen/run-atlas-tests.sh
@@ -313,7 +506,7 @@ tasks:
313506
MONGODB_VERSION: "4.0"
314507
TOPOLOGY: "sharded_cluster"
315508
- func: "run tests"
316-
509+
317510
- name: "test-4.2-standalone"
318511
tags: ["4.2", "standalone"]
319512
commands:
@@ -341,6 +534,51 @@ tasks:
341534
TOPOLOGY: "sharded_cluster"
342535
- func: "run tests"
343536

537+
- name: "test-4.4-standalone"
538+
tags: ["4.4", "standalone"]
539+
commands:
540+
- func: "bootstrap mongo-orchestration"
541+
vars:
542+
MONGODB_VERSION: "4.4"
543+
TOPOLOGY: "server"
544+
- func: "run tests"
545+
546+
- name: "test-4.4-replica_set"
547+
tags: ["4.4", "replica_set"]
548+
commands:
549+
- func: "bootstrap mongo-orchestration"
550+
vars:
551+
MONGODB_VERSION: "4.4"
552+
TOPOLOGY: "replica_set"
553+
- func: "run tests"
554+
555+
- name: "test-4.4-sharded_cluster"
556+
tags: ["4.4", "sharded_cluster"]
557+
commands:
558+
- func: "bootstrap mongo-orchestration"
559+
vars:
560+
MONGODB_VERSION: "4.4"
561+
TOPOLOGY: "sharded_cluster"
562+
- func: "run tests"
563+
564+
- name: "test-4.4-aws-auth"
565+
# "4.4" explicitly left off to keep this out of the generic matrix
566+
tags: ["aws-auth"]
567+
commands:
568+
- func: "bootstrap mongo-orchestration"
569+
vars:
570+
ORCHESTRATION_FILE: "auth-aws.json"
571+
MONGODB_VERSION: "4.4"
572+
AUTH: "auth"
573+
TOPOLOGY: "server"
574+
- func: "add aws auth variables to file"
575+
- func: "run aws auth test with regular aws credentials"
576+
- func: "run aws auth test with assume role credentials"
577+
- func: "run aws auth test with aws credentials as environment variables"
578+
- func: "run aws auth test with aws credentials and session token as environment variables"
579+
- func: "run aws auth test with aws EC2 credentials"
580+
- func: "run aws ECS auth test"
581+
344582
- name: "test-latest-standalone"
345583
tags: ["latest", "standalone"]
346584
commands:
@@ -368,6 +606,24 @@ tasks:
368606
TOPOLOGY: "sharded_cluster"
369607
- func: "run tests"
370608

609+
- name: "test-latest-aws-auth"
610+
# "latest" explicitly left off to keep this out of the generic matrix
611+
tags: ["aws-auth"]
612+
commands:
613+
- func: "bootstrap mongo-orchestration"
614+
vars:
615+
ORCHESTRATION_FILE: "auth-aws.json"
616+
MONGODB_VERSION: "latest"
617+
AUTH: "auth"
618+
TOPOLOGY: "server"
619+
- func: "add aws auth variables to file"
620+
- func: "run aws auth test with regular aws credentials"
621+
- func: "run aws auth test with assume role credentials"
622+
- func: "run aws auth test with aws credentials as environment variables"
623+
- func: "run aws auth test with aws credentials and session token as environment variables"
624+
- func: "run aws auth test with aws EC2 credentials"
625+
- func: "run aws ECS auth test"
626+
371627
- name: "test-atlas-connectivity"
372628
tags: ["atlas-connect"]
373629
commands:
@@ -453,6 +709,9 @@ axes:
453709
- id: "os"
454710
display_name: OS
455711
values:
712+
- id: ubuntu-18.04
713+
display_name: "Ubuntu 18.04"
714+
run_on: ubuntu1804-test
456715
- id: ubuntu-16.04
457716
display_name: "Ubuntu 16.04"
458717
run_on: ubuntu1604-test
@@ -469,12 +728,15 @@ buildvariants:
469728
-
470729
matrix_name: "tests"
471730
matrix_spec:
472-
os: "*"
731+
os:
732+
- ubuntu-16.04
733+
- macos-10.14
473734
auth-and-tls: "*"
474735
async-runtime: "*"
475736
display_name: "${os} ${auth-and-tls} with ${async-runtime}"
476737
tasks:
477738
- ".latest"
739+
- ".4.4"
478740
- ".4.2"
479741
- ".4.0"
480742
- ".3.6"
@@ -487,6 +749,14 @@ buildvariants:
487749
display_name: "Atlas Connectivity ${os} with ${async-runtime}"
488750
tasks:
489751
- ".atlas-connect"
752+
- matrix_name: "aws-auth"
753+
matrix_spec:
754+
os:
755+
- ubuntu-18.04
756+
async-runtime: "tokio"
757+
display_name: "AWS Auth ${os} with ${async-runtime}"
758+
tasks:
759+
- ".aws-auth"
490760

491761
-
492762
name: "lint"

0 commit comments

Comments
 (0)