Skip to content

[Bug] Transient managed-identity assertion failure leaves credential permanently skipped #4080

Description

Library and version

Microsoft.Identity.Web 4.14.2, using CredentialSource.SignedAssertionFromManagedIdentity for application token acquisition on .NET 10.

Describe the bug

A transient failure while initially loading a managed-identity client assertion can leave the shared credential description permanently skipped. Subsequent application-token requests then fail with IDW10109 without retrying assertion loading, even after the original dependency failure has recovered.

Reproduction

  1. Configure application-token acquisition with a SignedAssertionFromManagedIdentity client credential and keep the token-acquisition services alive across requests.
  2. During the first assertion load, inject a single MsalServiceException from managed-identity token acquisition, representing a temporary endpoint/network failure.
  3. Restore successful managed-identity token acquisition without restarting the process or replacing its service provider.
  4. Request an application token again using the same services and credential description.

Actual: Later requests fail with IDW10109. The credential remains Skip = true, so the credential-loading path is not attempted again.

Expected: A transient managed-identity failure should not permanently disable this credential for the lifetime of the process. A later request should be able to retry with bounded backoff once the dependency recovers, while still propagating authentication failures and respecting cancellation.

Source-level observations

In the 4.14.2 sources:

Workaround

Calling the public ICredentialsLoader.ResetCredentials API on the affected live credential descriptions allows a subsequent request to load the assertion and obtain the application token. Recreating the token-acquisition services also removes the stuck state.

Suggested regression test

Inject one transient failure into the initial managed-identity assertion load, restore the simulated dependency, and verify that a later request obtains the final application access token using the same long-lived services, without an application-issued credential reset or process restart.

Activity

  1. berndverst commented on Oct 1, 2026

    @berndverst
    Author

    FYI - we run into this issue when using User Managed Identities on App Service which we have federated with our First Party App. We perform the client assertion token exchange from Managed Identity credential to then call checkAccess API for RBAC admission decisions.

    This limitation here makes it very difficult to seamlessly recover dataplane RBAC. We need Microsoft.Identity.Web to have a mechanism to retry / reload credentials - ignore skipped etc.

    Note - we are not direct consumers of Microsoft.Identity.Web.
    Our backend → MISE → Microsoft.Identity.Web → MSAL → managed-identity / Entra endpoints

  2. berndverst commented on Oct 1, 2026

    @berndverst
    Author

    Bogdan Gavril (@bgavrilMS) I saw you commented on an issue related in nature. Perhaps you can chime in here? :)

  3. bgavrilMS commented on Oct 1, 2026

    @bgavrilMS
    Member

    Hi Bernd Verst (@berndverst) - I believe Neha Bhargava (@neha-bhargava) just fixed this and released Identity.Web. Neha Bhargava (@neha-bhargava) - can you please confirm?

  4. added
    bug
    on Oct 1, 2026
  5. bgavrilMS commented on Oct 1, 2026

    @bgavrilMS
    Member

    IMO there are 2 options:

    1. A one-time FIC failure should not skip the credential. If FIC is a configured credential, the SDK should always respect it, never skip it.
    2. If there is only 1 credential in the chain defined, it should NEVER be skipped.

    Solution 2 is safer, but solution 1 is better for reliability.

  6. berndverst commented on Oct 1, 2026

    @berndverst
    Author

    Thanks for looking into this. I reviewed the default branch (master) at commit 9c5066ed6c05, and the persistent-skip behavior still appears present for our configuration.

    We explicitly configure both the authority and TokenExchangeUrl for deployments across multiple clouds, including Azure US Government. We need recovery to work with those values explicitly supplied.

    The failure path still appears present

    1. SignedAssertionFromManagedIdentityCredentialLoader still catches MsalServiceException, sets credentialDescription.Skip = true, and rethrows.
    2. CredentialsProvider still enters the credential-loading path only when !credential.Skip. Subsequent calls therefore skip the affected credential.
    3. When no usable credential remains, it throws IDW10109. The existing token-acquisition retry condition handles selected invalid_client errors, rather than the initial managed_identity_unreachable_network failure described here.

    The per-request credential copy does not cover explicit TokenExchangeUrl

    There is a per-request copy for cloud-specific audience resolution, but it is conditional on:

    • SourceType == SignedAssertionFromManagedIdentity
    • TokenExchangeUrl being empty
    • An authority being supplied

    That copy can prevent a failed load from marking the shared original credential skipped when the audience is inferred. With an explicit TokenExchangeUrl, however, the copy is not made: the loader operates on the shared credential description and can leave it permanently skipped.

    Suggested regression coverage

    Please include a case with both authority and TokenExchangeUrl explicitly configured:

    1. Configure a single SignedAssertionFromManagedIdentity credential.
    2. Inject one transient MsalServiceException during initial assertion loading.
    3. Restore successful managed-identity acquisition.
    4. Request an application token again through the same long-lived token-acquisition services.
    5. Verify eventual success without an application-issued ResetCredentials() call, service-provider replacement, or process restart.

    This assessment is based on the source at the commit above. Could you link the fix/PR and released version you had in mind, and confirm whether it covers the explicit-TokenExchangeUrl case?

  7. berndverst commented on Oct 2, 2026

    @berndverst
    Author

    Additional production background: this was the original temporary failure that caused our only configured SignedAssertionFromManagedIdentity credential to be marked Skip = true:

    MSAL.NetCore.4.84.2.0.MsalServiceException
    ErrorCode: managed_identity_unreachable_network
    
    No connection could be made because the target machine actively refused it.
    (127.0.0.1:41116)
    
    System.Net.Sockets.SocketException (10061)
    

    The failure occurred while obtaining the managed-identity assertion from the local token service, before exchanging it for the application's access token. Once Identity Web marked that credential skipped, subsequent requests could not recover even after the dependency recovered: there was no second credential to fall back to. We explicitly configure both authority and TokenExchangeUrl.

    Why MSAL's retries did not prevent this

    We checked MSAL 4.84.2, matching the production exception, and reproduced the behavior using the published NuGet package with a mocked App Service HTTP transport:

    • The transport throws HttpRequestException wrapping SocketException(10061) on its first invocation. This test does not inject MsalServiceException; MSAL creates it.
    • MSAL throws MsalServiceException with managed_identity_unreachable_network after one transport attempt, with zero automatic retries.
    • After the simulated dependency recovers, a second acquisition through the same IManagedIdentityApplication instance succeeds. No application replacement or reset is needed at the MSAL layer. No real endpoint was contacted in this reproduction.

    The 4.84.2 source explains this:

    This was a connection refusal, not an HTTP 429/5xx response or a timeout. For the App Service flow, MSAL reads the local endpoint from IDENTITY_ENDPOINT; the port is not hard-coded by MSAL. The exception itself does not establish why that local endpoint was temporarily unavailable.

    There are two separate resilience concerns: MSAL could potentially add bounded retries for this class of transient MI connection failure, but Identity Web must still allow later recovery after an acquisition fails. Even an improved bounded retry policy can eventually give up. That must not permanently disable the only configured credential. The persistent-skip fix in #4081 is therefore necessary independently of any MSAL retry improvement.

  8. berndverst commented on Oct 2, 2026

    @berndverst
    Author

    Perhaps a different solution could be:
    If all credentials are marked as Skip=True throw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions