Skip to content

Skip IMDS lookup for explicit regions#6092

Merged
4gust merged 4 commits into
mainfrom
4gust/skip-explicit-region-imds
Jul 8, 2026
Merged

Skip IMDS lookup for explicit regions#6092
4gust merged 4 commits into
mainfrom
4gust/skip-explicit-region-imds

Conversation

@4gust

@4gust 4gust commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@4gust
4gust requested a review from a team as a code owner June 25, 2026 15:34
Copilot AI review requested due to automatic review settings June 25, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.GetAzureRegionAsync now 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.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread tests/Microsoft.Identity.Test.Unit/CoreTests/RegionDiscoveryProviderTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/TelemetryTests/RegionalTelemetryTests.cs Outdated
Comment thread tests/Microsoft.Identity.Test.Unit/CoreTests/RegionDiscoveryProviderTests.cs Outdated

@neha-bhargava neha-bhargava left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>
Copilot AI review requested due to automatic review settings July 8, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 8, 2026 16:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

@4gust
4gust merged commit de04e9a into main Jul 8, 2026
16 checks passed
@4gust
4gust deleted the 4gust/skip-explicit-region-imds branch July 8, 2026 17:55
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
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>
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.

5 participants