Skip to content

Add COSMIC_LOCATION to region auto-detection - #6240

Merged
Neha Bhargava (neha-bhargava) merged 3 commits into
mainfrom
nebharg/cosmicRegion
Oct 27, 2026
Merged

Neha Bhargava (neha-bhargava) merged 3 commits into
mainfrom
nebharg/cosmicRegion

Conversation

@neha-bhargava

Copy link
Copy Markdown
Contributor

Issue: n/a (requested enhancement).

Changes proposed in this request

Add COSMIC_LOCATION as a region auto-detection source before contacting IMDS.

  • Preserve discovery precedence: REGION_NAME, then COSMIC_LOCATION, then IMDS.
  • Apply existing environment-region normalization and validation; unusable values fall through to IMDS.
  • Preserve explicit-region configuration, opt-in auto-detection, process-wide region caching, and EnvVariable telemetry.
  • Include the COSMIC environment-variable reference beside the new lookup.

Testing

Tests cover source precedence, normalization, missing/empty/invalid values falling back to IMDS, explicit-region precedence, auto-detection remaining opt-in, and end-to-end regional token requests with environment-source and cached-source telemetry.

Validated with .NET SDK 8.0.418:

dotnet test tests\Microsoft.Identity.Test.Unit\Microsoft.Identity.Test.Unit.csproj -f net8.0 --no-restore --filter 'FullyQualifiedName~RegionDiscoveryProviderTests|FullyQualifiedName~RegionalTelemetryTests|FullyQualifiedName~ConfidentialClientWithRegionTests' --verbosity quiet --nologo

Passed: 103 tests, 0 failed, 0 skipped. The command built the affected product and test projects with warnings treated as errors.

dotnet format whitespace tests\Microsoft.Identity.Test.Unit\Microsoft.Identity.Test.Unit.csproj --include src\client\Microsoft.Identity.Client\Instance\Region\RegionManager.cs tests\Microsoft.Identity.Test.Unit\CoreTests\RegionDiscoveryProviderTests.cs tests\Microsoft.Identity.Test.Unit\TelemetryTests\RegionalTelemetryTests.cs --verify-no-changes --no-restore --verbosity quiet

Passed.

git --no-pager diff --check

Passed.

Integration tests and .NET Framework tests were not run.

Performance impact

Avoids an IMDS network request when COSMIC_LOCATION provides a valid region and REGION_NAME does not. Existing discovery caching is unchanged. No performance benchmarks were run.

Documentation

  • All relevant documentation is updated.

Reference: COSMIC environment variables. The link is included in source; its contents require authenticated access and were not independently verified.

assistance: agentic-cli
type: feature
agent-tool: copilot-cli
agent-model: gpt-6.1-sol
work-item: AB#n/a

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 813d151a-7ed9-46c3-87ba-689f6ff9e23c
@neha-bhargava Neha Bhargava (neha-bhargava) added agentic-cli Terminal AI agent drove the bulk of the edits feature labels Oct 27, 2026
Copilot AI balanced review requested due to automatic review settings October 27, 2026 21:45

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.

🟒 Approval recommended

No active review issues remain for the environment-based region discovery change.

No open issues πŸŽ‰

What changed in this PR

Adds COSMIC_LOCATION as an environment-based region discovery source in MSAL.NET, avoiding an IMDS request when it provides a valid region.

Changes:

  • Preserves discovery precedence: REGION_NAME, then COSMIC_LOCATION, then IMDS, using existing normalization and validation.
  • Adds tests for precedence, invalid-value fallback, explicit-region behavior, and opt-in discovery.
  • Extends telemetry acceptance coverage to both environment variables, including cached discovery.

Review limitation: base-branch provenance of the loaded repository guidance was not verified.

File Description
tests/​Microsoft.Identity.Test.Unit/​TelemetryTests/​RegionalTelemetryTests.cs Runs telemetry acceptance tests with either environment source.
tests/​Microsoft.Identity.Test.Unit/​CoreTests/​RegionDiscoveryProviderTests.cs Adds COSMIC discovery coverage and environment isolation.
src/​client/​Microsoft.Identity.Client/​Instance/​Region/​RegionManager.cs Checks COSMIC_LOCATION after unusable REGION_NAME and before IMDS.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 22:40
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 813d151a-7ed9-46c3-87ba-689f6ff9e23c

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.

🟒 Approval recommended

No active review issues block the COSMIC_LOCATION region-discovery change.

No open issues πŸŽ‰

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 22: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.

🟒 Approval recommended

No active review issues block the addition of COSMIC_LOCATION to region auto-detection.

No open issues πŸŽ‰

Review effort: Balanced

This was referenced Nov 12, 2026
maksii pushed a commit to maksii/paqvilo that referenced this pull request Nov 16, 2026
Updated
[Microsoft.Identity.Client](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet)
from 4.91.1 to 4.92.0.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Identity.Client's
releases](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/releases)._

## 4.92.0

### New Features

- Added `COSMIC_LOCATION` as a regional auto-detection source, after
`REGION_NAME` and before IMDS.
[#​6240](AzureAD/microsoft-authentication-library-for-dotnet#6240)
- Added `ITokenCacheSnapshotProvider` and `TokenCacheSnapshot` for
process-local token-cache capture and restore without repeated JSON
serialization. Use V3 serialization for persistence.
[#​6229](AzureAD/microsoft-authentication-library-for-dotnet#6229)

### Bug Fixes

- Fixed certificate private-key attachment on .NET Framework 4.7.2 to
support non-exportable CNG keys.
[#​6244](AzureAD/microsoft-authentication-library-for-dotnet#6244)
- Fixed managed identity KeyGuard attestation endpoint selection to use
cloud-specific regional endpoints from IMDS compute metadata.
[#​6238](AzureAD/microsoft-authentication-library-for-dotnet#6238)
- Fixed Android broker request serialization by registering
`BrokerRequest` in the source-generated JSON serializer context.
[#​6226](AzureAD/microsoft-authentication-library-for-dotnet#6226)

### Changes

- Updated `Microsoft.Identity.Client.NativeInterop` from 0.20.6 to
0.20.7.
[#​6230](AzureAD/microsoft-authentication-library-for-dotnet#6230)
- Reduced OpenTelemetry metric-tag allocations using `TagList` and
cached canonical tag-key sets. Custom enrichers should use noncanonical
tag names.
[#​6227](AzureAD/microsoft-authentication-library-for-dotnet#6227)


Commits viewable in [compare
view](AzureAD/microsoft-authentication-library-for-dotnet@4.91.1...4.92.0).
</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentic-cli Terminal AI agent drove the bulk of the edits feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants