Skip to content

Commit ec07732

Browse files
committed
Add remaining environments (azure, gcp), evergreen testing, API naming updates
1 parent a67791b commit ec07732

File tree

13 files changed

+888
-285
lines changed

13 files changed

+888
-285
lines changed

.evergreen/.evg.yml

Lines changed: 146 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ stepback: true
1212
# Actual testing tasks are marked with `type: test`
1313
command_type: system
1414

15-
# Protect ourself against rogue test case, or curl gone wild, that runs forever
16-
# 12 minutes is the longest we'll ever run
17-
exec_timeout_secs: 3600 # 12 minutes is the longest we'll ever run
15+
# Protect ourselves against rogue test case, or curl gone wild, that runs forever
16+
exec_timeout_secs: 7200
1817

1918
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
2019
timeout:
@@ -934,6 +933,58 @@ tasks:
934933
- func: "run load-balancer"
935934
- func: "run load-balancer tests"
936935

936+
- name: "oidc-auth-test-latest"
937+
commands:
938+
- command: subprocess.exec
939+
type: test
940+
params:
941+
working_dir: "src"
942+
binary: bash
943+
include_expansions_in_env: ["DRIVERS_TOOLS", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
944+
args:
945+
- .evergreen/run-mongodb-oidc-test.sh
946+
947+
- name: "oidc-auth-test-azure-latest"
948+
commands:
949+
- command: shell.exec
950+
params:
951+
shell: bash
952+
env:
953+
JAVA_HOME: ${JAVA_HOME}
954+
script: |-
955+
set -o errexit
956+
${PREPARE_SHELL}
957+
cd src
958+
git add .
959+
git commit -m "add files"
960+
# uncompressed tar used to allow appending .git folder
961+
export AZUREOIDC_DRIVERS_TAR_FILE=/tmp/mongo-java-driver.tar
962+
git archive -o $AZUREOIDC_DRIVERS_TAR_FILE HEAD
963+
tar -rf $AZUREOIDC_DRIVERS_TAR_FILE .git
964+
export AZUREOIDC_TEST_CMD="OIDC_ENV=azure ./.evergreen/run-mongodb-oidc-test.sh"
965+
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/azure/run-driver-test.sh
966+
967+
- name: "oidc-auth-test-gcp-latest"
968+
commands:
969+
- command: shell.exec
970+
params:
971+
shell: bash
972+
script: |-
973+
set -o errexit
974+
${PREPARE_SHELL}
975+
cd src
976+
git add .
977+
git commit -m "add files"
978+
# uncompressed tar used to allow appending .git folder
979+
export GCPOIDC_DRIVERS_TAR_FILE=/tmp/mongo-java-driver.tar
980+
git archive -o $GCPOIDC_DRIVERS_TAR_FILE HEAD
981+
tar -rf $GCPOIDC_DRIVERS_TAR_FILE .git
982+
# Define the command to run on the VM.
983+
# Ensure that we source the environment file created for us, set up any other variables we need,
984+
# and then run our test suite on the vm.
985+
export GCPOIDC_TEST_CMD="OIDC_ENV=gcp ./.evergreen/run-mongodb-oidc-test.sh"
986+
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/gcp/run-driver-test.sh
987+
937988
- name: serverless-test
938989
commands:
939990
- func: "run serverless"
@@ -2025,6 +2076,77 @@ task_groups:
20252076
tasks:
20262077
- test-aws-lambda-deployed
20272078

2079+
- name: testoidc_task_group
2080+
setup_group:
2081+
- func: fetch source
2082+
- func: prepare resources
2083+
- func: fix absolute paths
2084+
- command: ec2.assume_role
2085+
params:
2086+
role_arn: ${aws_test_secrets_role}
2087+
- command: subprocess.exec
2088+
params:
2089+
binary: bash
2090+
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
2091+
args:
2092+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/setup.sh
2093+
teardown_task:
2094+
- command: subprocess.exec
2095+
params:
2096+
binary: bash
2097+
args:
2098+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/teardown.sh
2099+
setup_group_can_fail_task: true
2100+
setup_group_timeout_secs: 1800
2101+
tasks:
2102+
- oidc-auth-test-latest
2103+
2104+
- name: testazureoidc_task_group
2105+
setup_group:
2106+
- func: fetch source
2107+
- func: prepare resources
2108+
- func: fix absolute paths
2109+
- command: subprocess.exec
2110+
params:
2111+
binary: bash
2112+
env:
2113+
AZUREOIDC_VMNAME_PREFIX: "JAVA_DRIVER"
2114+
args:
2115+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/create-and-setup-vm.sh
2116+
teardown_task:
2117+
- command: subprocess.exec
2118+
params:
2119+
binary: bash
2120+
args:
2121+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/delete-vm.sh
2122+
setup_group_can_fail_task: true
2123+
setup_group_timeout_secs: 1800
2124+
tasks:
2125+
- oidc-auth-test-azure-latest
2126+
2127+
- name: testgcpoidc_task_group
2128+
setup_group:
2129+
- func: fetch source
2130+
- func: prepare resources
2131+
- func: fix absolute paths
2132+
- command: subprocess.exec
2133+
params:
2134+
binary: bash
2135+
env:
2136+
GCPOIDC_VMNAME_PREFIX: "JAVA_DRIVER"
2137+
args:
2138+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/gcp/setup.sh
2139+
teardown_task:
2140+
- command: subprocess.exec
2141+
params:
2142+
binary: bash
2143+
args:
2144+
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/gcp/teardown.sh
2145+
setup_group_can_fail_task: true
2146+
setup_group_timeout_secs: 1800
2147+
tasks:
2148+
- oidc-auth-test-gcp-latest
2149+
20282150
buildvariants:
20292151

20302152
# Test packaging and other release related routines
@@ -2176,6 +2298,27 @@ buildvariants:
21762298
tasks:
21772299
- name: "test_atlas_task_group_search_indexes"
21782300

2301+
- name: "oidc-auth-test"
2302+
display_name: "OIDC Auth"
2303+
run_on: ubuntu2204-small
2304+
tasks:
2305+
- name: testoidc_task_group
2306+
batchtime: 20160 # 14 days
2307+
2308+
- name: testazureoidc-variant
2309+
display_name: "OIDC Auth Azure"
2310+
run_on: ubuntu2204-small
2311+
tasks:
2312+
- name: testazureoidc_task_group
2313+
batchtime: 20160 # 14 days
2314+
2315+
- name: testgcpoidc-variant
2316+
display_name: "OIDC Auth GCP"
2317+
run_on: ubuntu2204-small
2318+
tasks:
2319+
- name: testgcpoidc_task_group
2320+
batchtime: 20160 # 14 days
2321+
21792322
- matrix_name: "aws-auth-test"
21802323
matrix_spec: { ssl: "nossl", jdk: ["jdk8", "jdk17", "jdk21"], version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu",
21812324
aws-credential-provider: "*" }

.evergreen/run-mongodb-oidc-test.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
set +x # Disable debug trace
4+
set -eu
5+
6+
echo "Running MONGODB-OIDC authentication tests"
7+
8+
OIDC_ENV=${OIDC_ENV:-"test"}
9+
10+
echo "OIDC_ENV $OIDC_ENV"
11+
12+
if [ $OIDC_ENV == "test" ]; then
13+
if [ -z "$DRIVERS_TOOLS" ]; then
14+
echo "Must specify DRIVERS_TOOLS"
15+
exit 1
16+
fi
17+
source ${DRIVERS_TOOLS}/.evergreen/auth_oidc/secrets-export.sh
18+
# java will not need to be installed, but we need to config
19+
RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE:-$0}")"
20+
source "${RELATIVE_DIR_PATH}/javaConfig.bash"
21+
elif [ $OIDC_ENV == "azure" ]; then
22+
source ./env.sh
23+
elif [ $OIDC_ENV == "gcp" ]; then
24+
source ./secrets-export.sh
25+
else
26+
echo "Unrecognized OIDC_ENV $OIDC_ENV"
27+
exit 1
28+
fi
29+
30+
31+
if ! which java ; then
32+
echo "Installing java..."
33+
sudo apt install openjdk-17-jdk -y
34+
echo "Installed java."
35+
fi
36+
37+
which java
38+
export OIDC_TESTS_ENABLED=true
39+
export OIDC_ENV="$OIDC_ENV" # read by tests
40+
41+
# use admin credentials for tests
42+
TO_REPLACE="mongodb://"
43+
REPLACEMENT="mongodb://$OIDC_ADMIN_USER:$OIDC_ADMIN_PWD@"
44+
ADMIN_URI=${MONGODB_URI/$TO_REPLACE/$REPLACEMENT}
45+
46+
./gradlew -Dorg.mongodb.test.uri="$ADMIN_URI" \
47+
--stacktrace --debug --info --no-build-cache driver-core:cleanTest \
48+
driver-sync:test --tests OidcAuthenticationProseTests --tests UnifiedAuthTest \
49+
driver-reactive-streams:test --tests OidcAuthenticationAsyncProseTests \

driver-core/src/main/com/mongodb/ConnectionString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ private MongoCredential createCredentials(final Map<String, List<String>> option
916916

917917
if (credential != null && authMechanismProperties != null) {
918918
for (String part : authMechanismProperties.split(",")) {
919-
String[] mechanismPropertyKeyValue = part.split(":");
919+
String[] mechanismPropertyKeyValue = part.split(":", 2);
920920
if (mechanismPropertyKeyValue.length != 2) {
921921
throw new IllegalArgumentException(format("The connection string contains invalid authentication properties. "
922922
+ "'%s' is not a key value pair", part));

driver-core/src/main/com/mongodb/MongoCredential.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_1;
3838
import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_256;
3939
import static com.mongodb.assertions.Assertions.notNull;
40+
import static com.mongodb.internal.connection.OidcAuthenticator.OidcValidator.validateCreateOidcCredential;
4041
import static com.mongodb.internal.connection.OidcAuthenticator.OidcValidator.validateOidcCredentialConstruction;
4142

4243
/**
@@ -185,7 +186,7 @@ public final class MongoCredential {
185186
public static final String AWS_CREDENTIAL_PROVIDER_KEY = "AWS_CREDENTIAL_PROVIDER";
186187

187188
/**
188-
* The provider name. The value must be a string.
189+
* The environment. The value must be a string.
189190
* <p>
190191
* If this is provided,
191192
* {@link MongoCredential#OIDC_CALLBACK_KEY} and
@@ -195,7 +196,7 @@ public final class MongoCredential {
195196
* @see #createOidcCredential(String)
196197
* @since 4.10
197198
*/
198-
public static final String PROVIDER_NAME_KEY = "PROVIDER_NAME";
199+
public static final String ENVIRONMENT_KEY = "ENVIRONMENT";
199200

200201
/**
201202
* This callback is invoked when the OIDC-based authenticator requests
@@ -204,7 +205,7 @@ public final class MongoCredential {
204205
* and a {@linkplain OidcCallbackResult#getRefreshToken() refresh token}
205206
* must not be returned by the callback.
206207
* <p>
207-
* If this is provided, {@link MongoCredential#PROVIDER_NAME_KEY}
208+
* If this is provided, {@link MongoCredential#ENVIRONMENT_KEY}
208209
* and {@link MongoCredential#OIDC_HUMAN_CALLBACK_KEY}
209210
* must not be provided.
210211
*
@@ -219,7 +220,7 @@ public final class MongoCredential {
219220
* from the MongoDB server. The type of the value must be
220221
* {@link OidcCallback}.
221222
* <p>
222-
* If this is provided, {@link MongoCredential#PROVIDER_NAME_KEY}
223+
* If this is provided, {@link MongoCredential#ENVIRONMENT_KEY}
223224
* and {@link MongoCredential#OIDC_CALLBACK_KEY}
224225
* must not be provided.
225226
*
@@ -253,6 +254,13 @@ public final class MongoCredential {
253254
public static final List<String> DEFAULT_ALLOWED_HOSTS = Collections.unmodifiableList(Arrays.asList(
254255
"*.mongodb.net", "*.mongodb-qa.net", "*.mongodb-dev.net", "*.mongodbgov.net", "localhost", "127.0.0.1", "::1"));
255256

257+
/**
258+
* The token resource.
259+
*
260+
* @since TODO-OIDC update all
261+
*/
262+
public static final String TOKEN_RESOURCE_KEY = "TOKEN_RESOURCE";
263+
256264
/**
257265
* Creates a MongoCredential instance with an unspecified mechanism. The client will negotiate the best mechanism based on the
258266
* version of the server that the client is authenticating to.
@@ -408,7 +416,7 @@ public static MongoCredential createAwsCredential(@Nullable final String userNam
408416
* @return the credential
409417
* @since 4.10
410418
* @see #withMechanismProperty(String, Object)
411-
* @see #PROVIDER_NAME_KEY
419+
* @see #ENVIRONMENT_KEY
412420
* @see #OIDC_CALLBACK_KEY
413421
* @see #OIDC_HUMAN_CALLBACK_KEY
414422
* @see #ALLOWED_HOSTS_KEY
@@ -463,6 +471,7 @@ public MongoCredential withMechanism(final AuthenticationMechanism mechanism) {
463471

464472
if (mechanism == MONGODB_OIDC) {
465473
validateOidcCredentialConstruction(source, mechanismProperties);
474+
validateCreateOidcCredential(password);
466475
}
467476

468477
if (userName == null && !Arrays.asList(MONGODB_X509, MONGODB_AWS, MONGODB_OIDC).contains(mechanism)) {
@@ -697,6 +706,7 @@ public interface IdpInfo {
697706
/**
698707
* @return Unique client ID for this OIDC client.
699708
*/
709+
@Nullable
700710
String getClientId();
701711

702712
/**

0 commit comments

Comments
 (0)