Share via

Unable to access KeyVault using User Managed Identity

Nicke Manarin 20 Reputation points
2026-03-08T05:16:30.9766667+00:00

I created a Key Vault and added a secret to it.
User's image

Then I created a Managed Identity and added the Key Vault Secrets User role, assigning to the base subscription the same way I did for my CDN managed identity which is working as expected.
User's image

Not sure if necessary, but I added the identity in the api > Identity as well:

User's image

Then I try using the credential to get the secret:

TokenCredential credential;
          
if (!string.IsNullOrWhiteSpace(settings!.ManagedIdentityId))
  credential = new ManagedIdentityCredential(ManagedIdentityId.FromUserAssignedClientId(settings.ManagedIdentityId));
else
  credential = new DefaultAzureCredential(); //In debug, it works normally because I use my VS login.
        
//Connect to Key Vault.
var secretClient = new SecretClient(new Uri(settings.KeyVaultUrl), credential);

KeyVaultSecret privateSecret = secretClient.GetSecret("my-private-key");

After running and trying to access any endpoint, I get this exception:

Azure.Identity.AuthenticationFailedException: ManagedIdentityCredential authentication failed: [Managed Identity] Error Message: No User Assigned or Delegated Managed Identity found for specified ClientId/ResourceId/PrincipalId. Managed Identity Correlation ID: 4422b072-8eff-4006-8562-ea6c9be2bf70 Use this Correlation ID for further investigation.
See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot
 ---> MSAL.NetCore.4.78.0.0.MsalServiceException:
	ErrorCode: managed_identity_request_failed
Microsoft.Identity.Client.MsalServiceException: [Managed Identity] Error Message: No User Assigned or Delegated Managed Identity found for specified ClientId/ResourceId/PrincipalId. Managed Identity Correlation ID: 4422b072-8eff-4006-8562-ea6c9be2bf70 Use this Correlation ID for further investigation.
   at Microsoft.Identity.Client.ManagedIdentity.AbstractManagedIdentity.HandleResponseAsync(AcquireTokenForManagedIdentityParameters parameters, HttpResponse response, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ManagedIdentity.AbstractManagedIdentity.AuthenticateAsync(AcquireTokenForManagedIdentityParameters parameters, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.ManagedIdentityAuthRequest.SendTokenRequestForManagedIdentityAsync(ILoggerAdapter logger, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.ManagedIdentityAuthRequest.GetAccessTokenAsync(CancellationToken cancellationToken, ILoggerAdapter logger)
   at Microsoft.Identity.Client.Internal.Requests.ManagedIdentityAuthRequest.ExecuteAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.<>c__DisplayClass11_1.<<RunAsync>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Identity.Client.Utils.StopwatchService.MeasureCodeBlockAsync(Func`1 codeBlock)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ApiConfig.Executors.ManagedIdentityExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenForManagedIdentityParameters managedIdentityParameters, CancellationToken cancellationToken)
   at Azure.Identity.MsalManagedIdentityClient.AcquireTokenForManagedIdentityAsyncCore(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)
   at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](ValueTask`1 task)
   at Azure.Identity.MsalManagedIdentityClient.AcquireTokenForManagedIdentity(TokenRequestContext requestContext, CancellationToken cancellationToken)
   at Azure.Identity.ManagedIdentityClient.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
   at Azure.Identity.ManagedIdentityCredential.GetTokenImplAsync(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)

I dont know what's happening.
Trying to access manually the URL of the key vault gives me a 404.
Trying to use the Kudu CLI to run this call fails: "curl -v -H "Metadata:true" "http://<IPREDACTED>/metadata/identity/oauth2/token?api-version=2019-08-01&resource=https://vault.azure.net""

Note: IP Redacted at support side.

Azure Key Vault
Azure Key Vault

An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.


1 answer

Sort by: Most helpful
  1. TP 155.5K Reputation points Volunteer Moderator
    2026-03-08T07:03:35.4366667+00:00

    Hi Nicke,

    To help troubleshoot, please see if you can retrieve token for your user assigned managed identity manually via Kudu console, using command similar to below:

    Windows

    curl -H "x-identity-header: %IDENTITY_HEADER%" "%IDENTITY_ENDPOINT%?api-version=2019-08-01&resource=https://vault.azure.net&client_id=xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx"
    

    Linux

    curl -H "x-identity-header: $IDENTITY_HEADER" "$IDENTITY_ENDPOINT?api-version=2019-08-01&resource=https://vault.azure.net&client_id=xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx"
    

    If above is successful then you can take a closer look at your code. If above fails, please test again only this time see if you can retrieve token for system assigned managed identity.

    Please reply back with your results, whether positive or negative.

    Thanks.

    -TP


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.