Skip to content

[BUG] Possible breaking change in ChainedTokenCredential in Azure 1.13.0 and 1.13.1 #47057

Open
@kappa-mu

Description

@kappa-mu

Library name and version

Azure.Identity 1.13.1

Describe the bug

Azure.Identity version 1.13.0 and 1.13.1 failing with ChainedTokenCredential

My code is using ChainedTokenCredential with ManagedIdentityCredential for deployed application and VisualStudioCredential for working locally. This has been working fine until 1.12.1 but stopped working in 1.13.0 and 1.13.1
While working locally, it is trying to use the ManagedIdentityCredential first and when it fails, the error is coming out to the surface instead of trying to use the VisualStudioCredential

Working: 1.12.1
Not working: 1.13.0 and 1.13.1

Expected behavior

We should be able to fetch the secret as ChainedTokenCredential should be successful like in version 1.12.1

Actual behavior

Exception:
Azure.Identity.AuthenticationFailedException: 'The ChainedTokenCredential failed due to an unhandled exception: ManagedIdentityCredential authentication failed: [Managed Identity] Authentication unavailable. Either the requested identity has not been assigned to this resource, or other errors could be present. Ensure the identity is correctly assigned and check the inner exception for more details. For more information, visit https://aka.ms/msal-managed-identity.
Status: BadRequest
Content:
{"error":"invalid_request","error_description":"Identity not found"}

Headers:
Server: IMDS/150.870.65.1475
x-ms-request-id: e00d2743-fdbf-4f84-a2f2-763ba9ec69ac
Date: Mon, 11 Nov 2024 06:34:38 GMT

[Managed Identity] Error Code: invalid_request Error Description: Identity not found
See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot'

Reproduction Steps

Create a simple .Net console app.
Add nuget packages:
Azure.Identity
Azure.Core
Azure.Security.KeyVault.Secrets

Add the following code:

// See https://aka.ms/new-console-template for more information
using Azure.Core;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;

Console.WriteLine("Hello, World!");


// Values from app registration
var clientId = "<<ClientID>>";
var tenantId = "<<TenantID>>";
var clientSecret = GetClientSecretFromKeyvault();


// using Azure.Identity;
var options = new ClientSecretCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};

// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
    tenantId, clientId, clientSecret, options);

static TokenCredential GetTokenCredential()
{
    //ManagedIdentityCredential for Azure
    //Visual Studio Credential for local development
    return new ChainedTokenCredential(
        new ManagedIdentityCredential(),
        new VisualStudioCredential()
    );
}

static string GetClientSecretFromKeyvault()
{
    // Create a new secret client using the default credential from Azure.Identity using environment variables previously set,
    // including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
    SecretClient client = GetSecretClient();

    // Retrieve a secret using the secret client.
    var secret = client.GetSecret("HelloSecret");
    return secret.Value.Value;
}

static SecretClient GetSecretClient()
{

    return new SecretClient
        (vaultUri: new Uri("https://<<keyvaultname>>.vault.azure.net/"),
        credential: GetTokenCredential()
    );
}

Environment

Environmet: Local, using visual studio 22 version 17.11.5, using in windows
App Type: .Net 8 Console App

Metadata

Metadata

Assignees

Labels

Azure.IdentityClientThis issue points to a problem in the data-plane of the library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

  • Status

    Untriaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions