-
Notifications
You must be signed in to change notification settings - Fork 456
CDRIVER-4548 Support ENVIRONMENT:azure for MONGODB-OIDC.
#2166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
73a9caa
a031652
f848d34
373d1d0
95df9b4
df70d96
435ec48
d525dfe
7e7678c
4499785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||
| set -o errexit | ||||||||||||||||||||||||||||||||||||||||||||
| set -o pipefail | ||||||||||||||||||||||||||||||||||||||||||||
| set -o nounset | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck source=.evergreen/scripts/use-tools.sh | ||||||||||||||||||||||||||||||||||||||||||||
| . "$(dirname "${BASH_SOURCE[0]}")/use-tools.sh" paths # Sets MONGOC_DIR | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| cd "$MONGOC_DIR" | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working directory is already set to bash_exec(
working_dir="mongoc",
add_expansions_to_env=True,
command_type=EvgCommandType.TEST,
script='.evergreen/scripts/oidc-azure-compile.sh',
), |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [[ "${distro_id:?}" == "debian11-small" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| # Temporary workaround for lack of uv on `debian11`. TODO: remove after DEVPROD-23011 is resolved. | ||||||||||||||||||||||||||||||||||||||||||||
| uv_dir="$(mktemp -d)" | ||||||||||||||||||||||||||||||||||||||||||||
| python3 -m virtualenv "${uv_dir:?}" | ||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck source=/dev/null | ||||||||||||||||||||||||||||||||||||||||||||
| (. "${uv_dir:?}/bin/activate" && python -m pip install uv) | ||||||||||||||||||||||||||||||||||||||||||||
| PATH="${uv_dir:?}/bin:${PATH:-}" | ||||||||||||||||||||||||||||||||||||||||||||
| command -V uv >/dev/null | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| . .evergreen/scripts/install-build-tools.sh | ||||||||||||||||||||||||||||||||||||||||||||
| install_build_tools | ||||||||||||||||||||||||||||||||||||||||||||
| export CMAKE_GENERATOR="Ninja" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Use ccache if able. | ||||||||||||||||||||||||||||||||||||||||||||
| . .evergreen/scripts/find-ccache.sh | ||||||||||||||||||||||||||||||||||||||||||||
| find_ccache_and_export_vars "$(pwd)" || true | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| echo "Compile test-libmongoc ... begin" | ||||||||||||||||||||||||||||||||||||||||||||
| # Disable unnecessary dependencies. test-libmongoc is copied to a remote host for testing, which may not have all dependent libraries. | ||||||||||||||||||||||||||||||||||||||||||||
| cmake \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_SASL=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_SNAPPY=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_ZSTD=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_ZLIB=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_SRV=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_CLIENT_SIDE_ENCRYPTION=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_EXAMPLES=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -DENABLE_SRV=OFF \ | ||||||||||||||||||||||||||||||||||||||||||||
| -S. -Bcmake-build | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Avoid awkward backslashes + redundant |
||||||||||||||||||||||||||||||||||||||||||||
| cmake --build cmake-build --target test-libmongoc --parallel | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Ninja generator already uses max parallelism by default. |
||||||||||||||||||||||||||||||||||||||||||||
| echo "Compile test-libmongoc ... end" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Create tarball for remote testing. | ||||||||||||||||||||||||||||||||||||||||||||
| echo "Creating test-libmongoc tarball ... begin" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Copy test binary and JSON test files. All JSON test files are needed to start test-libmongoc. | ||||||||||||||||||||||||||||||||||||||||||||
| tar -czf test-libmongoc.tar.gz \ | ||||||||||||||||||||||||||||||||||||||||||||
| .evergreen/scripts/oidc-azure-test.sh \ | ||||||||||||||||||||||||||||||||||||||||||||
| ./cmake-build/src/libmongoc/test-libmongoc \ | ||||||||||||||||||||||||||||||||||||||||||||
| src/libmongoc/tests/json \ | ||||||||||||||||||||||||||||||||||||||||||||
| src/libbson/tests/json | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Avoid awkward backslashes. |
||||||||||||||||||||||||||||||||||||||||||||
| echo "Creating test-libmongoc tarball ... end" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| cat <<EOT > oidc-remote-test-expansion.yml | ||||||||||||||||||||||||||||||||||||||||||||
| OIDC_TEST_TARBALL: ${MONGOC_DIR}/test-libmongoc.tar.gz | ||||||||||||||||||||||||||||||||||||||||||||
| EOT | ||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
| set -o errexit | ||
| set -o pipefail | ||
| set -o nounset | ||
|
|
||
| export MONGOC_TEST_OIDC="ON" | ||
| export MONGOC_TEST_USER="$OIDC_ADMIN_USER" | ||
| export MONGOC_TEST_PASSWORD="$OIDC_ADMIN_PWD" | ||
| export MONGOC_AZURE_RESOURCE="$AZUREOIDC_RESOURCE" | ||
|
|
||
| # Install required OpenSSL runtime library. | ||
| sudo apt install -y libssl-dev | ||
|
|
||
| ./cmake-build/src/libmongoc/test-libmongoc -d --match '/auth/unified/*' --match '/oidc/*' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this include Aside: I think most scripts use the shorter |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,17 +23,23 @@ | |||||||||||||||||||
|
|
||||||||||||||||||||
| #define AZURE_API_VERSION "2018-02-01" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static const char *const DEFAULT_METADATA_PATH = | ||||||||||||||||||||
| "/metadata/identity/oauth2/" | ||||||||||||||||||||
| "token?api-version=" AZURE_API_VERSION "&resource=https%3A%2F%2Fvault.azure.net"; | ||||||||||||||||||||
| static const char *const DEFAULT_METADATA_PATH = "/metadata/identity/oauth2/token?api-version=" AZURE_API_VERSION; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void | ||||||||||||||||||||
| bool | ||||||||||||||||||||
| mcd_azure_imds_request_init(mcd_azure_imds_request *req, | ||||||||||||||||||||
| const char *token_resource, | ||||||||||||||||||||
| const char *const opt_imds_host, | ||||||||||||||||||||
| int opt_port, | ||||||||||||||||||||
| const char *const opt_extra_headers) | ||||||||||||||||||||
| const char *const opt_extra_headers, | ||||||||||||||||||||
| const char *const opt_client_id) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| BSON_ASSERT_PARAM(req); | ||||||||||||||||||||
| BSON_ASSERT_PARAM(token_resource); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| bool ok = false; | ||||||||||||||||||||
| char *encoded_token_resource = NULL; | ||||||||||||||||||||
| mcommon_string_append_t path = {0}; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| _mongoc_http_request_init(&req->req); | ||||||||||||||||||||
| // The HTTP host of the IMDS server | ||||||||||||||||||||
| req->req.host = req->_owned_host = bson_strdup(opt_imds_host ? opt_imds_host : "169.254.169.254"); | ||||||||||||||||||||
|
|
@@ -50,9 +56,33 @@ mcd_azure_imds_request_init(mcd_azure_imds_request *req, | |||||||||||||||||||
| req->req.extra_headers = req->_owned_headers = bson_strdup_printf("Metadata: true\r\n" | ||||||||||||||||||||
| "Accept: application/json\r\n%s", | ||||||||||||||||||||
| opt_extra_headers ? opt_extra_headers : ""); | ||||||||||||||||||||
| // The default path is suitable. In the future, we may want to add query | ||||||||||||||||||||
| // parameters to disambiguate a managed identity. | ||||||||||||||||||||
| req->req.path = req->_owned_path = bson_strdup(DEFAULT_METADATA_PATH); | ||||||||||||||||||||
| // Build the path with query parameters. | ||||||||||||||||||||
| encoded_token_resource = mongoc_percent_encode(token_resource); | ||||||||||||||||||||
| if (!encoded_token_resource) { | ||||||||||||||||||||
| goto fail; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| mcommon_string_new_as_append(&path); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!mcommon_string_append(&path, DEFAULT_METADATA_PATH) || | ||||||||||||||||||||
| !mcommon_string_append_printf(&path, "&resource=%s", encoded_token_resource)) { | ||||||||||||||||||||
| goto fail; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (opt_client_id) { | ||||||||||||||||||||
| if (!mcommon_string_append_printf(&path, "&client_id=%s", opt_client_id)) { | ||||||||||||||||||||
| goto fail; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| req->req.path = req->_owned_path = mcommon_string_from_append_destroy_with_steal(&path); | ||||||||||||||||||||
| path = (mcommon_string_append_t){0}; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ok = true; | ||||||||||||||||||||
| fail: | ||||||||||||||||||||
| bson_free(encoded_token_resource); | ||||||||||||||||||||
| mcommon_string_from_append_destroy(&path); | ||||||||||||||||||||
| return ok; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void | ||||||||||||||||||||
|
|
@@ -156,11 +186,15 @@ mcd_azure_access_token_destroy(mcd_azure_access_token *c) | |||||||||||||||||||
|
|
||||||||||||||||||||
| bool | ||||||||||||||||||||
| mcd_azure_access_token_from_imds(mcd_azure_access_token *const out, | ||||||||||||||||||||
| const char *token_resource, | ||||||||||||||||||||
| const char *const opt_imds_host, | ||||||||||||||||||||
| int opt_port, | ||||||||||||||||||||
| const char *opt_extra_headers, | ||||||||||||||||||||
| int opt_timeout_ms, | ||||||||||||||||||||
| const char *opt_client_id, | ||||||||||||||||||||
| bson_error_t *error) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| BSON_ASSERT_PARAM(token_resource); | ||||||||||||||||||||
| BSON_ASSERT_PARAM(out); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| bool okay = false; | ||||||||||||||||||||
|
|
@@ -172,9 +206,17 @@ mcd_azure_access_token_from_imds(mcd_azure_access_token *const out, | |||||||||||||||||||
| _mongoc_http_response_init(&resp); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| mcd_azure_imds_request req = MCD_AZURE_IMDS_REQUEST_INIT; | ||||||||||||||||||||
| mcd_azure_imds_request_init(&req, opt_imds_host, opt_port, opt_extra_headers); | ||||||||||||||||||||
| if (!mcd_azure_imds_request_init(&req, token_resource, opt_imds_host, opt_port, opt_extra_headers, opt_client_id)) { | ||||||||||||||||||||
| _mongoc_set_error(error, MONGOC_ERROR_AZURE, MONGOC_ERROR_KMS_SERVER_HTTP, "Failed to initialize request"); | ||||||||||||||||||||
| goto fail; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| int timeout_ms = 3 * 1000; // Default 3 second timeout | ||||||||||||||||||||
| if (opt_timeout_ms > 0) { | ||||||||||||||||||||
| timeout_ms = opt_timeout_ms; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+214
to
+217
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggest implementing new timer/expiry/duration code in terms of mlib utilities when able. |
||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!_mongoc_http_send(&req.req, 3 * 1000, false, NULL, &resp, error)) { | ||||||||||||||||||||
| if (!_mongoc_http_send(&req.req, timeout_ms, false, NULL, &resp, error)) { | ||||||||||||||||||||
| goto fail; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project-level default timeout is already set to 1 hour and applies to both pre and task setup commands (but not task teardown or post commands).