Skip to content

Fix GetManagedIdentitySourceAsync caching wrong IMDS source#6025

Open
bgavrilMS wants to merge 4 commits into
rginsburg/mtls_restart_orphan_checkfrom
bogavril/fix-imds-source-caching-6024
Open

Fix GetManagedIdentitySourceAsync caching wrong IMDS source#6025
bgavrilMS wants to merge 4 commits into
rginsburg/mtls_restart_orphan_checkfrom
bogavril/fix-imds-source-caching-6024

Conversation

@bgavrilMS
Copy link
Copy Markdown
Member

Summary

Fixes #6024

When the Azure SDK calls GetManagedIdentitySourceAsync first (probing), it caches Imds (v1). A subsequent mTLS PoP request then fails because the cached source is v1 which doesn't support mTLS PoP.

Changes

Core fix (ManagedIdentityClient.cs):

  • Simplified GetManagedIdentitySourceAsync to only probe IMDSv1 (removed v2 probe entirely from discovery)
  • Changed GetOrSelectManagedIdentitySourceAsync to automatically route to IMDSv2 when cached source is Imds and mTLS PoP is requested (instead of throwing)
  • Removed s_imdsV1UsedForPreview preview guard and related logic

Tests (ImdsV2Tests.cs, ManagedIdentityTests.cs):

  • Replaced \ImdsV2EndpointsAreNotAvailableButMtlsPopTokenWasRequested\ with \ImdsV1Cached_MtlsPopRequested_RoutesToImdsV2\ (validates routing works)
  • Updated probe tests to reflect v1-only discovery
  • Removed tests for v2 probing during discovery (no longer applicable)
  • All 383 ManagedIdentity tests pass

Backward compatibility:

  • ImdsV2FailureReason property and CannotSwitchBetweenImdsVersionsForPreview const kept (in PublicAPI.Shipped.txt)

bgavrilMS and others added 2 commits May 22, 2026 13:55
Simplify GetManagedIdentitySourceAsync to only probe IMDSv1 and assume
IMDSv2 infrastructure is always available when IMDS is detected.

Previously, if Azure SDK called GetManagedIdentitySourceAsync, it would
detect v1 and cache it, causing subsequent mTLS PoP requests to fail
because the cached source was Imds (v1) which doesn't support token
binding.

Now:
- Discovery only probes IMDSv1 to determine IMDS availability
- When cached source is Imds and mTLS PoP is requested, routes to IMDSv2
- Removes the preview guard that prevented switching between versions

Fixes #6024

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace ImdsV2EndpointsAreNotAvailableButMtlsPopTokenWasRequested with
  ImdsV1Cached_MtlsPopRequested_RoutesToImdsV2 (validates mTLS PoP routes
  to IMDSv2 when v1 is cached, instead of throwing)
- Update ProbeImdsEndpointAsyncSucceeds to test v1 probe only
- Replace ProbeImdsEndpointAsyncSucceedsAfterRetry and
  ProbeImdsEndpointAsyncFails404 with ProbeImdsEndpointAsyncFails_ReturnsNoneFound
  (v2 is no longer probed during discovery)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bgavrilMS bgavrilMS requested a review from a team as a code owner May 22, 2026 13:10
bgavrilMS and others added 2 commits May 22, 2026 14:52
Since discovery now only probes IMDSv1, replace the separate
ImdsV1FailureReason and ImdsV2FailureReason properties with a single
ImdsFailureReason property on ManagedIdentitySourceResult.

Breaking change: ImdsV1FailureReason and ImdsV2FailureReason removed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ImdsV1Cached_MtlsPopRequested_RoutesToImdsV2 now explicitly calls
GetManagedIdentitySourceAsync (caching Imds v1) followed by
AcquireTokenForManagedIdentity with mTLS PoP, matching the exact
scenario from issue #6024 where Azure SDK probes first.

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.

1 participant