Skip to content

Fix regional managed identity attestation endpoint selection by Azure cloud - #6238

Merged
Gladwin Johnson VR (gladjohn) merged 2 commits into
mainfrom
gladjohn/fix-imds-attestation-cloud-endpoint
Oct 27, 2026
Merged

Gladwin Johnson VR (gladjohn) merged 2 commits into
mainfrom
gladjohn/fix-imds-attestation-cloud-endpoint

Conversation

@gladjohn

@gladjohn Gladwin Johnson VR (gladjohn) commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Changes proposed in this request

Select the KeyGuard attestation service in MSAL Core using azEnvironment and location from the same IMDS response at /metadata/instance/compute?api-version=2021-02-01, rather than always using the endpoint supplied by /metadata/identity/getplatformmetadata.

Azure environment Attestation endpoint
AzurePublicCloud https://{location}.attestation.microsoft.com
AzureUSGovernmentCloud https://{location}.attestation.microsoftonline.us
AzureChinaCloud https://{location}.attestation.partner.microsoftonline.cn
AzureBleuCloud https://{location}.attestation.sovcloud-identity.fr
  • Use the IMDS region directly as a hostname prefix (for example, westus2.attestation.microsoft.com). The compute response supplies location; no missing-region fallback is added, and no second metadata request is needed.
  • Match cloud identifiers using ordinal, case-insensitive comparisons.
  • If metadata is unavailable or the cloud is missing/unmapped, log and retain the original IMDS-provided endpoint. No new unsupported-cloud exception.
  • Resolve only when minting a binding with a KeyGuard key and a configured attestation provider. Cached bindings and unattested requests do not incur the additional lookup.
  • Preserve cancellation for both the HTTP operation and retry delays, using named arguments for the existing two-token helper.
  • Keep existing CSR metadata validation and attestation failure behavior.

Compatibility and regression risk

  • No caller-, platform-, build-, or package-observable behavior changes
  • Observable changes are intentional and described below

Base behavior: Attestation receives the endpoint from CSR/platform metadata.

New behavior: Supported Azure clouds use the endpoints above. Other clouds retain the original endpoint. No public API or package dependency changes.

Affected scenarios: Attested managed identity v2 certificate minting, including PoP and bearer-over-mTLS flows. IMDSv1 capability discovery is unchanged.

PPE limitation: azEnvironment does not distinguish PPE/PPE-EAPv2 from production. AzurePublicCloud selects the production endpoint; this change adds no PPE override. Fallback applies only to unavailable/missing/unmapped cloud metadata, not to recognized public-cloud metadata.

Testing

Added end-to-end mocked coverage for all four regional mappings, distinct public-cloud regions, case-insensitive matching, missing/unmapped cloud values, the original-endpoint fallback, unavailable/malformed compute metadata, cancellation, and cached-token behavior. Updated existing attestation mocks for the additional metadata request.

After the regional-prefix correction, all managed identity unit tests were rerun: 500 passed, 1 skipped, 0 failed on each of .NET Framework 4.8 and .NET 8.

Before the regional-prefix correction, the full unit suite passed, with RunConfiguration.DisableAppDomain=true for the local .NET Framework adapter:

  • .NET Framework 4.8: 2,478 passed, 22 skipped, 0 failed.
  • .NET 8: 2,473 passed, 25 skipped, 0 failed.

Other suites were attempted; these are not claimed as passing:

  • .NET integration: Selenium process errors; the net8 integration run reached its 180-second session limit and was aborted.
  • Cache compatibility: helper executable startup failed with file-not-found errors.
  • Managed identity and SNI mTLS E2E: all 20 infrastructure-gated cases skipped; no live attested E2E validation claimed.

git diff --check passes. Formatting verification reports existing whitespace on unchanged lines; those unrelated lines were left intact.

Performance impact

Adds an IMDS compute-metadata lookup when a new attested binding is minted, using the existing IMDS retry policy. No additional lookup on token/certificate-cache hits or requests without an attestation provider. No performance benchmark results claimed.

Documentation

  • All relevant documentation is updated.

Documentation edits are intentionally excluded from this PR.

Resolve the attestation service from IMDS compute metadata on attested binding cache misses. Log and retain the platform endpoint for unavailable or unmapped cloud metadata, preserving cancellation and existing validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 30f6db0b-e29c-474d-8fba-b560bd96f1bf
Copilot AI balanced review requested due to automatic review settings October 27, 2026 19:51

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 are recorded for the cloud-specific KeyGuard endpoint selection change.

No open issues πŸŽ‰

What changed in this PR

This PR updates managed identity v2 attestation in MSAL.NET to select the KeyGuard endpoint from IMDS Azure cloud metadata, while retaining the original endpoint when metadata is unavailable or unmapped.

Changes:

  • Adds case-insensitive endpoint mappings for Azure Public, US Government, China, and Bleu clouds.
  • Resolves the endpoint only when minting an attested binding, preserving cancellation and avoiding extra lookups for cached bindings or unattested requests.
  • Adds mocked regression coverage for mappings, fallback, cancellation, and cached-token behavior.

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

File Description
tests/​Microsoft.Identity.Test.Unit/​ManagedIdentityTests/​ImdsV2Tests.cs Adds endpoint-selection tests and updates attestation request mocks.
src/​client/​Microsoft.Identity.Lab.Api/​Http/​MockHelpers.cs Adds configurable Azure environment metadata to mock responses.
src/​client/​Microsoft.Identity.Client/​ManagedIdentity/​V2/​ImdsV2ManagedIdentitySource.cs Resolves the cloud-specific endpoint before invoking attestation.
src/​client/​Microsoft.Identity.Client/​ManagedIdentity/​ImdsComputeMetadataManager.cs Maps cloud identifiers to endpoints with an original-endpoint fallback.
src/​client/​Microsoft.Identity.Client/​ManagedIdentity/​ComputeMetadataResponse.cs Deserializes the IMDS azEnvironment field.

Review effort: Balanced

Use location from the same compute metadata response for all mapped cloud endpoints. Preserve the existing unsupported-cloud fallback and verify regional endpoint delivery to the attestation provider.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 30f6db0b-e29c-474d-8fba-b560bd96f1bf
@gladjohn Gladwin Johnson VR (gladjohn) changed the title Fix managed identity attestation endpoint selection by Azure cloud Fix regional managed identity attestation endpoint selection by Azure cloud Oct 27, 2026
Copilot AI balanced review requested due to automatic review settings October 27, 2026 21:06

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 are recorded for the regional attestation endpoint changes.

No open issues πŸŽ‰

Review effort: Balanced

@gladjohn
Gladwin Johnson VR (gladjohn) merged commit 0991b2d into main Oct 27, 2026
19 checks passed
@gladjohn
Gladwin Johnson VR (gladjohn) deleted the gladjohn/fix-imds-attestation-cloud-endpoint branch October 27, 2026 22:16
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants