diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 5058fae720b..441f2997062 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -277,6 +277,16 @@ functions: "iam_auth_ec2_instance_profile" : "${iam_auth_ec2_instance_profile}" } EOF + setup aws env: + - command: shell.exec + type: test + params: + working_dir: src + script: | + ${PREPARE_SHELL} + cd ${DRIVERS_TOOLS}/.evergreen/auth_aws + . ./activate_venv.sh + cd - run aws auth test with regular aws credentials: - command: shell.exec type: test @@ -363,6 +373,9 @@ functions: working_dir: src silent: true script: | + cd ${DRIVERS_TOOLS}/.evergreen/auth_aws + ${MONGODB_BINARIES}/mongo --verbose aws_e2e_regular_aws.js + cd - cat < "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" export AWS_ACCESS_KEY_ID=${iam_auth_ecs_account} export AWS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key} @@ -382,6 +395,9 @@ functions: working_dir: src silent: true script: | + cd ${DRIVERS_TOOLS}/.evergreen/auth_aws + ${MONGODB_BINARIES}/mongo --verbose aws_e2e_assume_role.js + cd - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" export AWS_ACCESS_KEY_ID=$(jq -r '.AccessKeyId' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json) export AWS_SECRET_ACCESS_KEY=$(jq -r '.SecretAccessKey' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json) @@ -421,7 +437,7 @@ functions: cat setup.js . ./activate_venv.sh - mongo --nodb setup.js aws_e2e_ecs.js + ${MONGODB_BINARIES}/mongo --nodb setup.js aws_e2e_ecs.js run-ocsp-test: - command: shell.exec type: test @@ -1134,7 +1150,7 @@ tasks: - func: run-ocsp-test vars: OCSP_TLS_SHOULD_SUCCEED: 0 - - name: aws-latest-auth-test + - name: aws-latest-auth-test-run-aws-auth-test-with-regular-aws-credentials commands: - func: install dependencies - func: bootstrap mongo-orchestration @@ -1144,10 +1160,69 @@ tasks: ORCHESTRATION_FILE: auth-aws.json TOPOLOGY: server - func: add aws auth variables to file + - func: setup aws env - func: run aws auth test with regular aws credentials + - name: aws-latest-auth-test-run-aws-auth-test-with-assume-role-credentials + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: latest + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env - func: run aws auth test with assume role credentials + - name: aws-latest-auth-test-run-aws-auth-test-with-aws-EC2-credentials + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: latest + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env - func: run aws auth test with aws EC2 credentials - - name: aws-4.4-auth-test + - name: aws-latest-auth-test-run-aws-auth-test-with-aws-credentials-as-environment-variables + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: latest + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env + - func: run aws auth test with aws credentials as environment variables + - name: aws-latest-auth-test-run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: latest + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env + - func: run aws auth test with aws credentials and session token as environment variables + - name: aws-latest-auth-test-run-aws-ECS-auth-test + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: latest + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env + - func: run aws ECS auth test + - name: aws-4.4-auth-test-run-aws-auth-test-with-regular-aws-credentials commands: - func: install dependencies - func: bootstrap mongo-orchestration @@ -1157,9 +1232,68 @@ tasks: ORCHESTRATION_FILE: auth-aws.json TOPOLOGY: server - func: add aws auth variables to file + - func: setup aws env - func: run aws auth test with regular aws credentials + - name: aws-4.4-auth-test-run-aws-auth-test-with-assume-role-credentials + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: '4.4' + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env - func: run aws auth test with assume role credentials + - name: aws-4.4-auth-test-run-aws-auth-test-with-aws-EC2-credentials + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: '4.4' + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env - func: run aws auth test with aws EC2 credentials + - name: aws-4.4-auth-test-run-aws-auth-test-with-aws-credentials-as-environment-variables + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: '4.4' + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env + - func: run aws auth test with aws credentials as environment variables + - name: aws-4.4-auth-test-run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: '4.4' + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env + - func: run aws auth test with aws credentials and session token as environment variables + - name: aws-4.4-auth-test-run-aws-ECS-auth-test + commands: + - func: install dependencies + - func: bootstrap mongo-orchestration + vars: + VERSION: '4.4' + AUTH: auth + ORCHESTRATION_FILE: auth-aws.json + TOPOLOGY: server + - func: add aws auth variables to file + - func: setup aws env + - func: run aws ECS auth test - name: run-checks tags: - run-checks @@ -1515,5 +1649,15 @@ buildvariants: expansions: NODE_LTS_NAME: dubnium tasks: - - aws-latest-auth-test - - aws-4.4-auth-test + - aws-latest-auth-test-run-aws-auth-test-with-regular-aws-credentials + - aws-latest-auth-test-run-aws-auth-test-with-assume-role-credentials + - aws-latest-auth-test-run-aws-auth-test-with-aws-EC2-credentials + - aws-latest-auth-test-run-aws-auth-test-with-aws-credentials-as-environment-variables + - aws-latest-auth-test-run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables + - aws-latest-auth-test-run-aws-ECS-auth-test + - aws-4.4-auth-test-run-aws-auth-test-with-regular-aws-credentials + - aws-4.4-auth-test-run-aws-auth-test-with-assume-role-credentials + - aws-4.4-auth-test-run-aws-auth-test-with-aws-EC2-credentials + - aws-4.4-auth-test-run-aws-auth-test-with-aws-credentials-as-environment-variables + - aws-4.4-auth-test-run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables + - aws-4.4-auth-test-run-aws-ECS-auth-test diff --git a/.evergreen/config.yml.in b/.evergreen/config.yml.in index 2e72318aefe..e4d41f8b1f9 100644 --- a/.evergreen/config.yml.in +++ b/.evergreen/config.yml.in @@ -311,6 +311,17 @@ functions: } EOF + "setup aws env": + - command: shell.exec + type: test + params: + working_dir: "src" + script: | + ${PREPARE_SHELL} + cd ${DRIVERS_TOOLS}/.evergreen/auth_aws + . ./activate_venv.sh + cd - + "run aws auth test with regular aws credentials": - command: shell.exec type: test @@ -400,6 +411,9 @@ functions: working_dir: "src" silent: true script: | + cd ${DRIVERS_TOOLS}/.evergreen/auth_aws + ${MONGODB_BINARIES}/mongo --verbose aws_e2e_regular_aws.js + cd - cat < "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" export AWS_ACCESS_KEY_ID=${iam_auth_ecs_account} export AWS_SECRET_ACCESS_KEY=${iam_auth_ecs_secret_access_key} @@ -420,6 +434,9 @@ functions: working_dir: "src" silent: true script: | + cd ${DRIVERS_TOOLS}/.evergreen/auth_aws + ${MONGODB_BINARIES}/mongo --verbose aws_e2e_assume_role.js + cd - cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh" export AWS_ACCESS_KEY_ID=$(jq -r '.AccessKeyId' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json) export AWS_SECRET_ACCESS_KEY=$(jq -r '.SecretAccessKey' ${DRIVERS_TOOLS}/.evergreen/auth_aws/creds.json) @@ -460,7 +477,7 @@ functions: cat setup.js . ./activate_venv.sh - mongo --nodb setup.js aws_e2e_ecs.js + ${MONGODB_BINARIES}/mongo --nodb setup.js aws_e2e_ecs.js "run-ocsp-test": - command: shell.exec diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 4a6f4518005..5d28c6097dd 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -400,10 +400,18 @@ OCSP_VERSIONS.forEach(VERSION => { const AWS_AUTH_TASKS = []; AWS_AUTH_VERSIONS.forEach(VERSION => { - const name = `aws-${VERSION}-auth-test`; - AWS_AUTH_TASKS.push(name); - TASKS.push({ - name: name, + const name = (ex) => `aws-${VERSION}-auth-test-${ex.split(' ').join('-')}`; + const aws_funcs = [ + { func: 'run aws auth test with regular aws credentials' }, + { func: 'run aws auth test with assume role credentials' }, + { func: 'run aws auth test with aws EC2 credentials' }, + { func: 'run aws auth test with aws credentials as environment variables' }, + { func: 'run aws auth test with aws credentials and session token as environment variables' }, + { func: 'run aws ECS auth test' } + ]; + + const aws_tasks = aws_funcs.map(fn => ({ + name: name(fn.func), commands: [ { func: 'install dependencies' }, { @@ -416,17 +424,16 @@ AWS_AUTH_VERSIONS.forEach(VERSION => { } }, { func: 'add aws auth variables to file' }, - { func: 'run aws auth test with regular aws credentials' }, - { func: 'run aws auth test with assume role credentials' }, - { func: 'run aws auth test with aws EC2 credentials' }, - // FIXME: NODE-3113 - // { func: 'run aws auth test with aws credentials as environment variables' }, - // { func: 'run aws auth test with aws credentials and session token as environment variables' }, - // { func: 'run aws ECS auth test' } + { func: 'setup aws env' }, + fn ] - }); + })) + + TASKS.push(...aws_tasks); + AWS_AUTH_TASKS.push(...aws_tasks.map(t => t.name)) }); + const BUILD_VARIANTS = []; const getTaskList = (() => { diff --git a/.evergreen/run-mongodb-aws-ecs-test.sh b/.evergreen/run-mongodb-aws-ecs-test.sh index 54989bfe420..70cba09d02d 100755 --- a/.evergreen/run-mongodb-aws-ecs-test.sh +++ b/.evergreen/run-mongodb-aws-ecs-test.sh @@ -2,7 +2,7 @@ set -o xtrace # Write all commands first to stderr set -o errexit # Exit the script with error if any of the commands fail -MONGODB_URI="$1" +export MONGODB_URI="$1" PROJECT_DIRECTORY="$(pwd)/src" # untar packed archive @@ -16,5 +16,6 @@ export NVM_DIR="${PROJECT_DIRECTORY}/node-artifacts/nvm" set -x # run the tests -npm install aws4 -MONGODB_URI=$MONGODB_URI MONGODB_UNIFIED_TOPOLOGY=1 npx mocha test/functional/mongodb_aws.test.js +npm install aws4 + +npx mocha test/functional/mongodb_aws.test.js diff --git a/.evergreen/run-mongodb-aws-test.sh b/.evergreen/run-mongodb-aws-test.sh index 4a3dbcb5a38..ec0e179dbbf 100755 --- a/.evergreen/run-mongodb-aws-test.sh +++ b/.evergreen/run-mongodb-aws-test.sh @@ -22,4 +22,4 @@ shopt -s expand_aliases # needed for `urlencode` alias set -x npm install aws4 -MONGODB_UNIFIED_TOPOLOGY=1 npx mocha test/functional/mongodb_aws.test.js +npx mocha test/functional/mongodb_aws.test.js diff --git a/src/cmap/auth/mongodb_aws.ts b/src/cmap/auth/mongodb_aws.ts index 5da2303ec44..d47a7747146 100644 --- a/src/cmap/auth/mongodb_aws.ts +++ b/src/cmap/auth/mongodb_aws.ts @@ -43,7 +43,7 @@ export class MongoDBAWS extends AuthProvider { return; } - if (credentials.username == null) { + if (!credentials.username) { makeTempCredentials(credentials, (err, tempCredentials) => { if (err || !tempCredentials) return callback(err); @@ -144,7 +144,7 @@ interface AWSCredentials { function makeTempCredentials(credentials: MongoCredentials, callback: Callback) { function done(creds: AWSCredentials) { - if (creds.AccessKeyId == null || creds.SecretAccessKey == null || creds.Token == null) { + if (!creds.AccessKeyId || !creds.SecretAccessKey || !creds.Token) { callback(new MongoError('Could not obtain temporary MONGODB-AWS credentials')); return; }