Skip to content

Commit a0823d4

Browse files
author
Oleksandr Poliakov
committed
CSHARP-4448: Implement OIDC SASL mechanism
1 parent 1bb081a commit a0823d4

File tree

66 files changed

+4240
-852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4240
-852
lines changed

build.cake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ Task("TestGssapiNetStandard20").IsDependentOn("TestGssapi");
257257
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
258258
Task("TestGssapiNet60").IsDependentOn("TestGssapi");
259259

260+
Task("TestMongoDbOidc")
261+
.IsDependentOn("Build")
262+
.DoesForEach(
263+
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
264+
action: (BuildConfig buildConfig, Path testProject) =>
265+
RunTests(buildConfig, testProject, filter: "Category=\"MongoDbOidc\""));
266+
260267
Task("TestServerless")
261268
.IsDependentOn("Build")
262269
.DoesForEach(
@@ -692,7 +699,7 @@ public class BuildConfig
692699
string[] CreateLoggers(string projectName)
693700
{
694701
var testResultsFile = outputDirectory.Combine("test-results").Combine($"TEST-{projectName}-{target.ToLowerInvariant()}-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.xml");
695-
702+
696703
// Evergreen CI server requires JUnit output format to display test results
697704
var junitLogger = $"junit;LogFilePath={testResultsFile};FailureBodyFormat=Verbose";
698705
var consoleLogger = "console;verbosity=detailed";

evergreen/evergreen.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ functions:
452452
params:
453453
file: mongo-csharp-driver/benchmarks/MongoDB.Driver.Benchmarks/Benchmark.Artifacts/results/evergreen-results.json
454454

455+
assume-ec2-role:
456+
- command: ec2.assume_role
457+
params:
458+
role_arn: ${aws_test_secrets_role}
459+
455460
add-aws-auth-variables-to-file:
456461
- command: ec2.assume_role
457462
params:
@@ -707,6 +712,19 @@ functions:
707712
-v \
708713
--fault revoked
709714
715+
run-mongodb-oidc-tests:
716+
- command: subprocess.exec
717+
type: test
718+
params:
719+
working_dir: mongo-csharp-driver
720+
binary: bash
721+
include_expansions_in_env:
722+
- "DRIVERS_TOOLS"
723+
- "OS"
724+
- "FRAMEWORK"
725+
args:
726+
- evergreen/run-mongodb-oidc-tests.sh
727+
710728
run-serverless-tests:
711729
- command: shell.exec
712730
type: test
@@ -1237,6 +1255,11 @@ tasks:
12371255
commands:
12381256
- func: run-atlas-search-index-helpers-test
12391257

1258+
- name: test-oidc-auth-aws
1259+
commands:
1260+
- func: assume-ec2-role
1261+
- func: run-mongodb-oidc-tests
1262+
12401263
- name: test-serverless
12411264
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
12421265
commands:
@@ -2218,6 +2241,12 @@ buildvariants:
22182241
tasks:
22192242
- name: plain-auth-tests
22202243

2244+
- matrix_name: mongodb-oidc-tests
2245+
matrix_spec: { os: [ "windows-64", "ubuntu-2004", "macos-1100" ] }
2246+
display_name: "MongoDB-OIDC Auth tests - ${os}"
2247+
tasks:
2248+
- name: test-oidc-auth-aws
2249+
22212250
- matrix_name: "ocsp-tests"
22222251
matrix_spec: { version: ["4.4", "5.0", "6.0", "7.0", "rapid", "latest"], auth: "noauth", ssl: "ssl", topology: "standalone", os: "windows-64" }
22232252
display_name: "OCSP ${version} ${os}"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# Don't trace since the URI contains a password that shouldn't show up in the logs
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
DOTNET_SDK_PATH="$(pwd)/.dotnet"
7+
8+
echo "Downloading .NET SDK installer into $DOTNET_SDK_PATH folder..."
9+
curl -Lfo ./dotnet-install.sh https://dot.net/v1/dotnet-install.sh
10+
echo "Installing .NET LTS SDK..."
11+
bash ./dotnet-install.sh --channel 6.0 --install-dir "$DOTNET_SDK_PATH" --no-path
12+
export PATH=$PATH:$DOTNET_SDK_PATH
13+
14+
echo "test variables"
15+
16+
source ./env.sh
17+
cat ./env.sh
18+
19+
MONGODB_URI="mongodb://${OIDC_ADMIN_USER}:${OIDC_ADMIN_PWD}@${MONGODB_URI:10}?authSource=admin"
20+
21+
echo "Final MongoUri:"
22+
echo $MONGODB_URI
23+
24+
dotnet test --no-build --framework net6.0 --filter Category=MongoDbOidc -e OIDC_ENV=azure -e TOKEN_RESOURCE="${AZUREOIDC_RESOURCE}" -e MONGODB_URI="${MONGODB_URI}" --results-directory ./build/test-results --logger "console;verbosity=detailed" ./tests/MongoDB.Driver.Tests/bin/Debug/net6.0/MongoDB.Driver.Tests.dll

evergreen/run-mongodb-oidc-tests.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
# Don't trace since the URI contains a password that shouldn't show up in the logs
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
############################################
7+
# Main Program #
8+
############################################
9+
10+
if [ "$OS" = "Windows_NT" ]; then
11+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do
12+
setx $var z:\\data\\tmp
13+
export $var=z:\\data\\tmp
14+
done
15+
else
16+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do
17+
export $var=/data/tmp;
18+
done
19+
fi
20+
21+
# Make the OIDC tokens.
22+
set -x
23+
OIDC_ENV=${OIDC_ENV:-"test"}
24+
25+
if [ $OIDC_ENV == "test" ]; then
26+
# Make sure DRIVERS_TOOLS is set.
27+
if [ -z "$DRIVERS_TOOLS" ]; then
28+
echo "Must specify DRIVERS_TOOLS"
29+
exit 1
30+
fi
31+
32+
source ${DRIVERS_TOOLS}/.evergreen/auth_oidc/secrets-export.sh
33+
if [[ ! $OS =~ ubuntu.* ]]; then
34+
# Ubuntu uses local server with already build admin credentials in connection string
35+
MONGODB_URI="mongodb+srv://${OIDC_ADMIN_USER}:${OIDC_ADMIN_PWD}@${MONGODB_URI:14}?authSource=admin"
36+
fi
37+
elif [ $OIDC_ENV == "azure" ]; then
38+
source ./env.sh
39+
else
40+
echo "Unrecognized OIDC_ENV $OIDC_ENV"
41+
exit 1
42+
fi
43+
44+
export OIDC_ENV=$OIDC_ENV
45+
export MONGODB_URI=$MONGODB_URI
46+
47+
if [ "Windows_NT" = "$OS" ]; then
48+
powershell.exe .\\build.ps1 --target "TestMongoDbOidc"
49+
else
50+
./build.sh --target="TestMongoDbOidc"
51+
fi

specifications/auth/tests/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Auth Tests
2+
3+
## Introduction
4+
5+
This document describes the format of the driver spec tests included in the JSON and YAML files included in the `legacy`
6+
sub-directory. Tests in the `unified` directory are written using the
7+
[Unified Test Format](../../unified-test-format/unified-test-format.md).
8+
9+
The YAML and JSON files in the `legacy` directory tree are platform-independent tests that drivers can use to prove
10+
their conformance to the Auth Spec at least with respect to connection string URI input.
11+
12+
Drivers should do additional unit testing if there are alternate ways of configuring credentials on a client.
13+
14+
Driver must also conduct the prose tests in the Auth Spec test plan section.
15+
16+
## Format
17+
18+
Each YAML file contains an object with a single `tests` key. This key is an array of test case objects, each of which
19+
have the following keys:
20+
21+
- `description`: A string describing the test.
22+
- `uri`: A string containing the URI to be parsed.
23+
- `valid:` A boolean indicating if the URI should be considered valid.
24+
- `credential`: If null, the credential must not be considered configured for the the purpose of deciding if the driver
25+
should authenticate to the topology. If non-null, it is an object containing one or more of the following properties
26+
of a credential:
27+
- `username`: A string containing the username. For auth mechanisms that do not utilize a password, this may be the
28+
entire `userinfo` token from the connection string.
29+
- `password`: A string containing the password.
30+
- `source`: A string containing the authentication database.
31+
- `mechanism`: A string containing the authentication mechanism. A null value for this key is used to indicate that a
32+
mechanism wasn't specified and that mechanism negotiation is required. Test harnesses should modify the mechanism
33+
test as needed to assert this condition.
34+
- `mechanism_properties`: A document containing mechanism-specific properties. It specifies a subset of properties
35+
that must match. If a key exists in the test data, it must exist with the corresponding value in the credential.
36+
Other values may exist in the credential without failing the test.
37+
38+
If any key is missing, no assertion about that key is necessary. Except as specified explicitly above, if a key is
39+
present, but the test value is null, the observed value for that key must be uninitialized (whatever that means for a
40+
given driver and data type).
41+
42+
## Implementation notes
43+
44+
Testing whether a URI is valid or not should simply be a matter of checking whether URI parsing (or MongoClient
45+
construction) raises an error or exception.
46+
47+
If a credential is configured, its properties must be compared to the `credential` field.

specifications/auth/tests/README.rst

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)