Skip to content

Commit d04aa62

Browse files
kevinAlbsmdb-adconnorsmacd
authored
CDRIVER-4689 Implement OIDC machine callback (#2147)
* add binary op to BSON DSL * clarify timeout is a duration, not an absolute time point --------- Co-authored-by: mdb-ad <198671546+mdb-ad@users.noreply.github.com> Co-authored-by: Connor MacDonald <connor.macdonald@mongodb.com>
1 parent ec39911 commit d04aa62

Some content is hidden

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

43 files changed

+2257
-48
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from shrub.v3.evg_build_variant import BuildVariant
2+
from shrub.v3.evg_command import EvgCommandType, ec2_assume_role, KeyValueParam, expansions_update
3+
from shrub.v3.evg_task import EvgTask, EvgTaskRef
4+
from shrub.v3.evg_task_group import EvgTaskGroup
5+
6+
from config_generator.components.funcs.run_tests import RunTests
7+
from config_generator.components.funcs.fetch_det import FetchDET
8+
from config_generator.components.funcs.fetch_source import FetchSource
9+
from config_generator.components.sasl.openssl import SaslCyrusOpenSSLCompile
10+
from config_generator.etc.utils import bash_exec
11+
from config_generator.etc.distros import find_small_distro
12+
13+
14+
def task_groups():
15+
return [
16+
EvgTaskGroup(
17+
name='test-oidc-task-group',
18+
tasks=['oidc-auth-test-task'],
19+
setup_group_can_fail_task=True,
20+
setup_group_timeout_secs=60 * 60, # 1 hour
21+
teardown_group_can_fail_task=True,
22+
teardown_group_timeout_secs=180, # 3 minutes
23+
setup_group=[
24+
FetchDET.call(),
25+
ec2_assume_role(role_arn='${aws_test_secrets_role}'),
26+
bash_exec(
27+
command_type=EvgCommandType.SETUP,
28+
include_expansions_in_env=['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN'],
29+
script='./drivers-evergreen-tools/.evergreen/auth_oidc/setup.sh',
30+
),
31+
],
32+
teardown_group=[
33+
bash_exec(
34+
command_type=EvgCommandType.SETUP,
35+
script='./drivers-evergreen-tools/.evergreen/auth_oidc/teardown.sh',
36+
)
37+
],
38+
)
39+
]
40+
41+
42+
def tasks():
43+
return [
44+
EvgTask(
45+
name='oidc-auth-test-task',
46+
run_on=[find_small_distro('ubuntu2404').name],
47+
commands=[
48+
FetchSource.call(),
49+
SaslCyrusOpenSSLCompile.call(),
50+
expansions_update(
51+
updates=[
52+
KeyValueParam(key='CC', value='clang'),
53+
# OIDC test servers support both OIDC and user/password.
54+
KeyValueParam(key='AUTH', value='auth'), # Use user/password for default test clients.
55+
KeyValueParam(key='OIDC', value='oidc'), # Enable OIDC tests.
56+
KeyValueParam(key='MONGODB_VERSION', value='latest'),
57+
KeyValueParam(key='TOPOLOGY', value='replica_set'),
58+
]
59+
),
60+
RunTests.call(),
61+
],
62+
)
63+
]
64+
65+
66+
def variants():
67+
return [
68+
BuildVariant(
69+
name='oidc',
70+
display_name='OIDC',
71+
run_on=[find_small_distro('ubuntu2404').name],
72+
tasks=[EvgTaskRef(name='test-oidc-task-group')],
73+
),
74+
]
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
task_groups: []
1+
task_groups:
2+
- name: test-oidc-task-group
3+
setup_group:
4+
- func: fetch-det
5+
- command: ec2.assume_role
6+
params:
7+
role_arn: ${aws_test_secrets_role}
8+
- command: subprocess.exec
9+
type: setup
10+
params:
11+
binary: bash
12+
include_expansions_in_env:
13+
- AWS_ACCESS_KEY_ID
14+
- AWS_SECRET_ACCESS_KEY
15+
- AWS_SESSION_TOKEN
16+
args:
17+
- -c
18+
- ./drivers-evergreen-tools/.evergreen/auth_oidc/setup.sh
19+
setup_group_can_fail_task: true
20+
setup_group_timeout_secs: 3600
21+
tasks:
22+
- oidc-auth-test-task
23+
teardown_group:
24+
- command: subprocess.exec
25+
type: setup
26+
params:
27+
binary: bash
28+
args:
29+
- -c
30+
- ./drivers-evergreen-tools/.evergreen/auth_oidc/teardown.sh
31+
teardown_group_timeout_secs: 180

.evergreen/generated_configs/tasks.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,6 +4206,21 @@ tasks:
42064206
args:
42074207
- -c
42084208
- .evergreen/scripts/run-mock-server-tests.sh
4209+
- name: oidc-auth-test-task
4210+
run_on:
4211+
- ubuntu2404-small
4212+
commands:
4213+
- func: fetch-source
4214+
- func: sasl-cyrus-openssl-compile
4215+
- command: expansions.update
4216+
params:
4217+
updates:
4218+
- { key: CC, value: clang }
4219+
- { key: AUTH, value: auth }
4220+
- { key: OIDC, value: oidc }
4221+
- { key: MONGODB_VERSION, value: latest }
4222+
- { key: TOPOLOGY, value: replica_set }
4223+
- func: run-tests
42094224
- name: openssl-compat-1.0.2-shared-ubuntu2404-gcc
42104225
run_on: ubuntu2404-large
42114226
tags: [openssl-compat, openssl-1.0.2, openssl-shared, ubuntu2404, gcc]

.evergreen/generated_configs/variants.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ buildvariants:
253253
SANITIZE: address,undefined
254254
tasks:
255255
- name: mock-server-test
256+
- name: oidc
257+
display_name: OIDC
258+
run_on:
259+
- ubuntu2404-small
260+
tasks:
261+
- name: test-oidc-task-group
256262
- name: openssl-compat-matrix
257263
display_name: OpenSSL Compatibility Matrix
258264
tasks:

.evergreen/scripts/run-tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ check_var_opt SINGLE_MONGOS_LB_URI
2222
check_var_opt SKIP_CRYPT_SHARED_LIB
2323
check_var_opt SSL "nossl"
2424
check_var_opt URI
25+
check_var_opt OIDC "nooidc"
2526

2627
declare script_dir
2728
script_dir="$(to_absolute "$(dirname "${BASH_SOURCE[0]}")")"
@@ -154,6 +155,13 @@ if [[ "${DNS}" != "nodns" ]]; then
154155
fi
155156
fi
156157

158+
if [[ "${OIDC}" != "nooidc" ]]; then
159+
export MONGOC_TEST_OIDC="ON"
160+
# Only run OIDC tests.
161+
test_args+=("-l" "/oidc/*")
162+
test_args+=("-l" "/auth/unified/*")
163+
fi
164+
157165
wait_for_server() {
158166
declare name="${1:?"wait_for_server requires a server name"}"
159167
declare port="${2:?"wait_for_server requires a server port"}"

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ To run test cases with large allocations, set:
320320

321321
* `MONGOC_TEST_LARGE_ALLOCATIONS=on` This may result in sudden test suite termination due to allocation failure. Use with caution.
322322

323+
* `MONGOC_TEST_OIDC=on` to test OIDC using a test environment described [here](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/d7a7337b384392a09fbe7fc80a7244e6f1226c18/.evergreen/auth_oidc).
324+
323325
All tests should pass before submitting a patch.
324326

325327
## Configuring the test runner

src/common/src/bson-dsl.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ Generate an integral value from the given C integer expression.
261261
Generate a UTF-8 value from the given null-terminated character array beginning
262262
at `zstr`.
263263

264+
#### `binary(bson_subtype_t subtype, const uint8_t *binary, uint32_t length)`
265+
266+
Generate a binary value from a subtype, pointer, and length.
267+
264268

265269
#### `oid(const bson_oid_t* oid)`
266270

src/common/src/common-bson-dsl-private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ BSON_IF_GNU_LIKE(_Pragma("GCC diagnostic ignored \"-Wshadow\""))
275275
} \
276276
_bsonDSL_end
277277

278+
#define _bsonValueOperation_binary(SubType, Data, Len) \
279+
if (!bson_append_binary(_bsonBuildAppendArgs, (SubType), (Data), (Len))) { \
280+
bsonBuildError = "Error while appending binary(" _bsonDSL_str(Data) ")"; \
281+
} else \
282+
((void)0)
283+
278284
/// Insert the given BSON document into the parent document in-place
279285
#define _bsonDocOperation_insert(OtherBSON, Pred) \
280286
_bsonDSL_begin("Insert other document: [%s]", _bsonDSL_str(OtherBSON)); \

src/libmongoc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ set (MONGOC_SOURCES
557557
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-client-side-encryption.c
558558
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cluster.c
559559
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cluster-aws.c
560+
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cluster-oidc.c
560561
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cluster-sasl.c
561562
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-collection.c
562563
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-compression.c
@@ -1092,6 +1093,7 @@ set (test-libmongoc-sources
10921093
${PROJECT_SOURCE_DIR}/tests/test-mongoc-long-namespace.c
10931094
${PROJECT_SOURCE_DIR}/tests/test-mongoc-max-staleness.c
10941095
${PROJECT_SOURCE_DIR}/tests/test-mongoc-mongos-pinning.c
1096+
${PROJECT_SOURCE_DIR}/tests/test-mongoc-oidc.c
10951097
${PROJECT_SOURCE_DIR}/tests/test-mongoc-oidc-callback.c
10961098
${PROJECT_SOURCE_DIR}/tests/test-mongoc-oidc-cache.c
10971099
${PROJECT_SOURCE_DIR}/tests/test-mongoc-opts.c
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
:man_page: mongoc_client_pool_set_oidc_callback
2+
3+
mongoc_client_pool_set_oidc_callback()
4+
======================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_client_pool_set_oidc_callback(mongoc_client_pool_t *pool,
13+
const mongoc_oidc_callback_t *callback);
14+
15+
Register a callback for the ``MONGODB-OIDC`` authentication mechanism.
16+
17+
Parameters
18+
----------
19+
20+
* ``pool``: A :symbol:`mongoc_client_pool_t`.
21+
* ``callback``: A :symbol:`mongoc_oidc_callback_t`.
22+
23+
Returns
24+
-------
25+
26+
Returns true on success. Returns false and logs on error.
27+
28+
.. include:: includes/mongoc_client_pool_call_once.txt
29+
30+
.. seealso::
31+
| :doc:`mongoc_client_set_oidc_callback` for setting a callback on a single-threaded client.
32+
| :doc:`mongoc_oidc_callback_t`
33+
| :doc:`mongoc_oidc_callback_params_t`

0 commit comments

Comments
 (0)