x-pack/metricbeat/module/azure: fix authentication on sovereign clouds#52175
Draft
zmoog wants to merge 2 commits into
Draft
x-pack/metricbeat/module/azure: fix authentication on sovereign clouds#52175zmoog wants to merge 2 commits into
zmoog wants to merge 2 commits into
Conversation
The monitor metricset mutated a copy of the ResourceManager service configuration without writing it back into the services map, so resource_manager_audience and resource_manager_endpoint never reached the ARM clients and every request used public-cloud values. The billing metricset had the write-back but applied it to the SDK's global cloud.AzurePublic configuration, leaking sovereign-cloud settings process-wide. The metrics batch API endpoint was hardcoded to the public cloud DNS suffix. Derive the whole cloud configuration (ARM endpoint and audience, batch metrics endpoint and audience, from the SDK's predefined public, government, and china clouds) from resource_manager_endpoint, keeping resource_manager_endpoint/resource_manager_audience as overrides for non-standard environments, on a deep-copied services map. The batch API now fails at setup time on clouds with no known metrics endpoint. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
🤖 GitHub commentsJust comment with:
|
Contributor
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
Use maps.Copy for the services map copy and the min builtin in the batching loops, per the modernize linter. Document that sovereign cloud audiences are now derived from resource_manager_endpoint, that resource_manager_audience is only needed for non-standard environments, and that the metrics batch API is rejected at startup for clouds with no known metrics endpoint. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
🔍 Preview links for changed docs |
Contributor
Elastic Docs Style Checker (Vale)Summary: 1 suggestion found 💡 Suggestions (1): Optional style improvements. Apply when helpful.
The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed commit message
The monitor metricset mutated a copy of the ResourceManager service configuration without writing it back into the services map, so
resource_manager_audienceandresource_manager_endpointnever reached the ARM clients and every request used public-cloud values (endpointhttps://management.azure.com, token audiencehttps://management.core.windows.net/), regardless of configuration. This has been the case since the SDK migration in #33585, which introducedresource_manager_audience.The billing metricset had the write-back, but applied it to the SDK's global
cloud.AzurePublicconfiguration (the services map is copied by reference), leaking sovereign-cloud settings process-wide to every other Azure SDK consumer in the same beat.Additionally, the batch metrics API endpoint was hardcoded to the public-cloud DNS suffix (
https://<region>.metrics.monitor.azure.com), and theazmetricsclient's token audience (a separate service key,query/azmetrics) was never configurable at all, soenable_batch_apicould not work outside the public cloud.This change adds a
BuildCloudConfighelper, shared by the monitor and billing services, that:cloud.AzurePublic/cloud.AzureGovernment/cloud.AzureChinaconfiguration based onresource_manager_endpoint(the same valueValidate()already uses to pick the AD authority), so ARM and batch metrics audiences/endpoints are consistent per cloud with no config changes required from users;resource_manager_endpointandresource_manager_audienceas explicit overrides on top of the selected cloud, for non-standard environments (e.g. Azure Stack);The batch API endpoint is now derived per cloud, and
NewServicefails at setup time whenenable_batch_apiis enabled for a cloud with no known metrics endpoint, instead of silently sending doomed requests to the public-cloud endpoint.Checklist
I have made corresponding change to the default configuration filesstresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Disruptive User Impact
monitor,billing, and derived metricsets get working authentication with their existing configuration (resource_manager_endpoint+active_directory_endpoint) — the correct token audience is now derived automatically.enable_batch_apion an unrecognized resource manager endpoint now fails at metricset setup with a clear error instead of querying the public-cloud metrics endpoint.How to test this PR locally
Against a real Azure Government subscription, configure the module with:
and verify metrics are collected (before this change, token acquisition fails because the credential requests the public-cloud ARM audience from the Gov authority).
Related issues
🤖 Generated with Claude Code