Azure Function App Slow /msi/token call with ManagedIdentityCredential

Nathan 55 Reputation points
2023-08-04T12:49:36.0033333+00:00

I've got an Azure Function App that is connecting to Azure Key Vault using a System-Assigned Managed Identity. The Azure Key Vault is in RBAC mode, not Policy-based.

This works as expected, but is very slow. Tracking in Application Insights we can see that the use of DefaultAzureCredential.GetToken (ManagedIdentityCredential.GetToken) makes a call to /msi/token, which is often taking upwards of 4 seconds to return.

We've updated Functions, KeyVault, and Identity assemblies to latest versions. Any ideas what could be causing the performance issue?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,476 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. JamesTran-MSFT 36,371 Reputation points Microsoft Employee
    2023-08-07T20:55:19.5+00:00

    @Nathan

    Thank you for your post and I apologize for the delayed response!

    I understand that your Function App is connecting to your Key Vault using a System-Assigned Managed Identity, which is working as expected but there are some performance/latency issues. To hopefully point you in the right direction or resolve your issue, I'll share my findings below.


    Findings:

    When it comes to the DefaultAzureCredential side of things, it looks like this is a known bug when using DefaultAzureCredential with a Managed Identity. Based off the GitHub thread it looks like the fix is still in-progress and is actively being worked on/tracked through this issue - GitHub #29471.

    From the solutions discussed throughout the GitHub issue, it looks like they all seem to point to multiple credential providers within the DefaultAzureCredential, with the main culprit being ManagedIdentityCredential. For more info.

    Since I'm not too familiar with the Azure SDK for dotnet, I'd also recommend reaching out to the experts within the Azure SDK for NET GitHub repo so they can look into your issue as well. For more info - Azure SDK for NET GitHub Issues.


    Additional Links:

    I hope this helps!

    If you have any other questions, please let me know. Thank you for your time and patience throughout this issue.


    If the information helped address your question, please Accept the answer. This will help us and also improve searchability for others in the community who might be researching similar information.