Skip to content

Commit 20241aa

Browse files
committed
Add integration test for AWS web identity credential fetching (#1063)
JAVA-4234
1 parent d0e4e5e commit 20241aa

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

.evergreen/.evg.yml

+79-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,13 @@ functions:
353353
354354
"iam_auth_ec2_instance_account" : "${iam_auth_ec2_instance_account}",
355355
"iam_auth_ec2_instance_secret_access_key" : "${iam_auth_ec2_instance_secret_access_key}",
356-
"iam_auth_ec2_instance_profile" : "${iam_auth_ec2_instance_profile}"
356+
"iam_auth_ec2_instance_profile" : "${iam_auth_ec2_instance_profile}",
357+
358+
"iam_auth_assume_web_role_name": "${iam_auth_assume_web_role_name}",
359+
"iam_web_identity_issuer": "${iam_web_identity_issuer}",
360+
"iam_web_identity_rsa_key": "${iam_web_identity_rsa_key}",
361+
"iam_web_identity_jwks_uri": "${iam_web_identity_jwks_uri}",
362+
"iam_web_identity_token_file": "${iam_web_identity_token_file}"
357363
}
358364
EOF
359365
@@ -434,6 +440,67 @@ functions:
434440
echo "" > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
435441
JAVA_VERSION=${JAVA_VERSION} AWS_CREDENTIAL_PROVIDER=${AWS_CREDENTIAL_PROVIDER} .evergreen/run-mongodb-aws-test.sh
436442
443+
"run aws auth test with web identity credentials":
444+
- command: shell.exec
445+
type: test
446+
params:
447+
working_dir: "src"
448+
shell: "bash"
449+
script: |
450+
${PREPARE_SHELL}
451+
cd ${DRIVERS_TOOLS}/.evergreen/auth_aws
452+
. ./activate-authawsvenv.sh
453+
mongo aws_e2e_web_identity.js
454+
- command: shell.exec
455+
type: test
456+
params:
457+
working_dir: "src"
458+
shell: "bash"
459+
silent: true
460+
script: |
461+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
462+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
463+
export AWS_ROLE_ARN="${iam_auth_assume_web_role_name}"
464+
export AWS_WEB_IDENTITY_TOKEN_FILE="${iam_web_identity_token_file}"
465+
EOF
466+
- command: shell.exec
467+
type: test
468+
params:
469+
working_dir: "src"
470+
shell: "bash"
471+
script: |
472+
${PREPARE_SHELL}
473+
if [ "${AWS_CREDENTIAL_PROVIDER}" = "builtIn" ]; then
474+
echo "Built-in AWS credential provider does not support the web identity auth test, skipping..."
475+
exit 0
476+
fi
477+
JAVA_VERSION=${JAVA_VERSION} AWS_CREDENTIAL_PROVIDER=${AWS_CREDENTIAL_PROVIDER} ASSERT_NO_URI_CREDS=true .evergreen/run-mongodb-aws-test.sh
478+
- command: shell.exec
479+
type: test
480+
params:
481+
working_dir: "src"
482+
shell: "bash"
483+
silent: true
484+
script: |
485+
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
486+
cat <<'EOF' > "${PROJECT_DIRECTORY}/prepare_mongodb_aws.sh"
487+
export AWS_ROLE_ARN="${iam_auth_assume_web_role_name}"
488+
export AWS_WEB_IDENTITY_TOKEN_FILE="${iam_web_identity_token_file}"
489+
export AWS_ROLE_SESSION_NAME="test"
490+
EOF
491+
- command: shell.exec
492+
type: test
493+
params:
494+
working_dir: "src"
495+
shell: "bash"
496+
script: |
497+
${PREPARE_SHELL}
498+
if [ "${AWS_CREDENTIAL_PROVIDER}" = "builtIn" ]; then
499+
echo "Built-in AWS credential provider does not support the web identity auth test, skipping..."
500+
exit 0
501+
fi
502+
JAVA_VERSION=${JAVA_VERSION} AWS_CREDENTIAL_PROVIDER=${AWS_CREDENTIAL_PROVIDER} ASSERT_NO_URI_CREDS=true .evergreen/run-mongodb-aws-test.sh
503+
437504
"run aws auth test with aws credentials as environment variables":
438505
- command: shell.exec
439506
type: test
@@ -900,6 +967,16 @@ tasks:
900967
- func: "add aws auth variables to file"
901968
- func: "run aws auth test with aws EC2 credentials"
902969

970+
- name: "aws-auth-test-with-web-identity-credentials"
971+
commands:
972+
- func: "bootstrap mongo-orchestration"
973+
vars:
974+
AUTH: "auth"
975+
ORCHESTRATION_FILE: "auth-aws.json"
976+
TOPOLOGY: "server"
977+
- func: "add aws auth variables to file"
978+
- func: "run aws auth test with web identity credentials"
979+
903980
- name: "aws-ECS-auth-test"
904981
commands:
905982
- func: "bootstrap mongo-orchestration"
@@ -1909,6 +1986,7 @@ buildvariants:
19091986
- name: "aws-auth-test-with-aws-credentials-as-environment-variables"
19101987
- name: "aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables"
19111988
- name: "aws-auth-test-with-aws-EC2-credentials"
1989+
- name: "aws-auth-test-with-web-identity-credentials"
19121990

19131991
- matrix_name: "aws-ecs-auth-test"
19141992
matrix_spec: { ssl: "nossl", jdk: ["jdk8", "jdk17"], version: ["4.4", "5.0", "6.0"], os: "ubuntu" }

driver-core/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ dependencies {
5151
// Optionally depend on both AWS SDK v2 and v1. The driver will use v2 is present, v1 if present, or built-in functionality if
5252
// neither are present
5353
implementation "software.amazon.awssdk:auth:$awsSdkV2Version", optional
54+
implementation "software.amazon.awssdk:sts:$awsSdkV2Version", optional
5455
implementation "com.amazonaws:aws-java-sdk-core:$awsSdkV1Version", optional
56+
implementation "com.amazonaws:aws-java-sdk-sts:$awsSdkV1Version", optional
5557

5658
implementation "org.xerial.snappy:snappy-java:$snappyVersion", optional
5759
implementation "com.github.luben:zstd-jni:$zstdVersion", optional

0 commit comments

Comments
 (0)