Skip to content

Conversation

@kevinAlbs
Copy link
Collaborator

Summary

Support ENVIRONMENT:azure for MONGODB-OIDC.

  • Extend mcd-azure.h to support Azure IMDS requests for OIDC. This internal header previously only supported Azure IMDS requests to Azure Key Vault for In-Use Encryption.
  • Add a percent encoding utility to encode the token resource string.

Patch build: https://spruce.mongodb.com/version/6904afbc379d3a0007e1ac83

Testing

Evergreen testing is described in the drivers-evergreen-tools README.md. Testing follows a similar pattern to the testazurekms-task: build test-libmongoc on an Evergreen host, create a remote Azure VM with a matching OS, copy the binary, run the test.

oidc-compile-azure.sh includes a temporary workaround to install UV (as was done in #2163).

@kevinAlbs kevinAlbs marked this pull request as ready for review October 31, 2025 17:27
@kevinAlbs kevinAlbs requested a review from a team as a code owner October 31, 2025 17:27
@kevinAlbs kevinAlbs requested review from connorsmacd and removed request for mdb-ad November 10, 2025 14:30
@kevinAlbs kevinAlbs requested a review from eramongodb November 12, 2025 16:05
Copy link
Contributor

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor feedback remaining; otherwise, LGTM.

tar -czf test-libmongoc.tar.gz "${files[@]}"
echo "Creating test-libmongoc tarball ... end"

cat <<EOT > oidc-remote-test-expansion.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat <<EOT > oidc-remote-test-expansion.yml
cat <<EOT >oidc-remote-test-expansion.yml

Formatting.

bash_exec(
command_type=EvgCommandType.SETUP,
include_expansions_in_env=['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN'],
env={"AZUREOIDC_VMNAME_PREFIX": "CDRIVER"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
env={"AZUREOIDC_VMNAME_PREFIX": "CDRIVER"},
env={'AZUREOIDC_VMNAME_PREFIX': 'CDRIVER'},

Formatting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatted file with Ruff formatter.

bash_exec(
command_type=EvgCommandType.SETUP,
script='./drivers-evergreen-tools/.evergreen/auth_oidc/azure/delete-vm.sh',
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
),

Formatting.

Comment on lines 61 to 62
const mlib_duration remaining = mlib_duration((*timeout_us, us), minus, (bson_get_monotonic_time(), us));
timer = mlib_expires_after(remaining);
Copy link
Contributor

@eramongodb eramongodb Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const mlib_duration remaining = mlib_duration((*timeout_us, us), minus, (bson_get_monotonic_time(), us));
timer = mlib_expires_after(remaining);
timer = mlib_expires_at((mlib_time_point){.time_since_monotonic_start = mlib_duration(*timeout_us, us)});

timeout_us is a time point (in microseconds). bson_get_monotonic_time() calls mlib_now(). I do not think there is a need to go through a duration computation before calling mlib_expires_after() (which calls mlib_now() again).

Note: internal code need not follow public API documentation's instructions to compare against bson_get_monotonic_time().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added comment above call to mongoc_oidc_callback_params_set_timeout that bson_get_monotonic_time() calls mlib_now().

Copy link
Collaborator

@connorsmacd connorsmacd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from nitpicks.

Comment on lines 1126 to 1128
for (char const *i = (char *)str; *i; i++) {
if (needs_percent_encoding((unsigned char)*i)) {
encoded_len += 3u;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (char const *i = (char *)str; *i; i++) {
if (needs_percent_encoding((unsigned char)*i)) {
encoded_len += 3u;
static const size_t percent_encoded_char_len = 3u;
for (char const *i = (char *)str; *i; i++) {
if (needs_percent_encoding((unsigned char)*i)) {
encoded_len += percent_encoded_char_len;

Suggest using a constant here since the meaning of 3u wasn't immediately obvious to me.

int req = bson_snprintf(o, 4, "%%%02X", (unsigned char)*i);
// Expect no truncation.
BSON_ASSERT(req == 3);
o += 3u;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
o += 3u;
o += percent_encoded_char_len;

@kevinAlbs kevinAlbs merged commit e35f024 into mongodb:master Nov 14, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants