Skip IMDS lookup for explicit regions#6092
Merged
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes MSAL’s region selection so that when an explicit region is configured via WithAzureRegion(<region>) or MSAL_FORCE_REGION, MSAL validates and uses that region immediately instead of performing IMDS-based region auto-discovery (previously done for telemetry-only mismatch detection). Auto-detect mode (WithAzureRegion() / “AttemptRegionDiscovery”) continues to use the existing discovery flow.
Changes:
RegionManager.GetAzureRegionAsyncnow short-circuits for explicit regions (with format validation) and skips IMDS discovery.- Unit tests were updated to reflect that explicit-region scenarios no longer populate autodetection telemetry fields / outcomes.
- Public API tests for regional + mTLS PoP scenarios were updated to remove region discovery mocks and to expect
RegionOutcome.None.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Identity.Test.Unit/TelemetryTests/RegionalTelemetryTests.cs | Updates telemetry assertions so explicit-region flows no longer expect region auto-discovery source/outcome fields. |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/MtlsPopTests.cs | Removes region discovery mock and updates expectations for explicit-region mTLS PoP flows. |
| tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientCredentialWithRegionTests.cs | Removes region discovery mocks and updates expected region autodetection source/outcome for explicit-region paths. |
| tests/Microsoft.Identity.Test.Unit/CoreTests/RegionDiscoveryProviderTests.cs | Updates region discovery provider tests to assert IMDS isn’t called when an explicit region is configured. |
| src/client/Microsoft.Identity.Client/Instance/Region/RegionManager.cs | Implements the explicit-region short-circuit (validate + return) before running auto-discovery. |
bgavrilMS
reviewed
Jun 25, 2026
bgavrilMS
requested changes
Jul 3, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bgavrilMS
approved these changes
Jul 6, 2026
Avery-Dunn
reviewed
Jul 7, 2026
Avery-Dunn
reviewed
Jul 7, 2026
neha-bhargava
approved these changes
Jul 7, 2026
neha-bhargava
left a comment
Contributor
There was a problem hiding this comment.
Approve with the suggestion to have RegionOutcome as UserProvided to track this source of region used
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
neha-bhargava
approved these changes
Jul 8, 2026
neha-bhargava
approved these changes
Jul 8, 2026
neha-bhargava
added a commit
that referenced
this pull request
Jul 8, 2026
…6105) Fix FailedTokenRequest metadata test broken by explicit-region IMDS skip PR #6092 stopped calling IMDS for explicitly-configured regions and dropped the region-discovery mocks from the sibling region tests, but missed FailedTokenRequest_SurfacesMetadataOnMsalServiceException_Async (added concurrently in #6096). Its stale AddRegionDiscoveryMockHandler left the IMDS mock first in the queue, so the token POST dequeued it and the URL assertion failed. Remove the stale mock; the region still surfaces via explicit config. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jul 11, 2026
Open
Open
Merged
neha-bhargava
added a commit
that referenced
this pull request
Jul 14, 2026
Add 4.86.0 changelog section (#6096 failure metadata, #6099 background-refresh callback, #6092 explicit-region IMDS skip, #6081 KeyGuard attestation fixes) and a backfilled 4.85.2 section (#6077 refresh-token cache partitioning, #6059 mTLS PoP min-strength), then move all unshipped public API entries to shipped across the six TFMs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jul 15, 2026
Closed
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.
Summary
Skip IMDS region discovery when
WithAzureRegion(...)is configured with an explicit region. The explicit region is now validated and used immediately instead of blocking token acquisition on telemetry-only auto-discovery.Auto-detect mode still uses the existing IMDS discovery flow.