Skip to content

[BUG] Azure.Identity.ManagedIdentitySource throws ArgumentNullException #47844

Closed
@pampua84

Description

@pampua84

Library name and version

Azure.Identity 1.13.2

Describe the bug

In my application, I'm trying to get a certificate from Azure Key Vault using this simple code:

var client = new CertificateClient(new Uri("uri"), new DefaultAzureCredential());
var response = client.GetCertificate("name");

However, I receive a 401 Unauthorized error without content in the Azure HTTP response, which raises the following exception:

Azure.Identity.AuthenticationFailedException: ManagedIdentityCredential authentication failed: Value cannot be null. (Parameter 'bytes')
See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/managedidentitycredential/troubleshoot
---> System.ArgumentNullException: Value cannot be null. (Parameter 'bytes')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Void* argument, String paramName)
at System.Text.Encoding.GetString(Byte* bytes, Int32 byteCount)
at System.BinaryData.ToString()
at Azure.Identity.ManagedIdentitySource.HandleResponseAsync(Boolean async, TokenRequestContext context, HttpMessage message, CancellationToken cancellationToken)
at Azure.Identity.ImdsManagedIdentityProbeSource.HandleResponseAsync(Boolean async, TokenRequestContext context, HttpMessage message, CancellationToken cancellationToken)
at Azure.Identity.ManagedIdentitySource.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.ImdsManagedIdentityProbeSource.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.ManagedIdentityClient.AuthenticateCoreAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.ManagedIdentityClient.AuthenticateAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.ManagedIdentityCredential.GetTokenImplAsync(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)

It seems that the ToString() method is being called on a null Content object inside the library.

Image

Expected behavior

In the case of 401 I expect a speaking message or at least only the value Unauthorized

Actual behavior

Currently the following message is returned:

ManagedIdentityCredential authentication failed: Value cannot be null. (Parameter 'bytes')

Reproduction Steps

Create simple unauthorided client to get certificate from Key Vault

var client = new CertificateClient(new Uri("uri"), new DefaultAzureCredential());
var response = client.GetCertificate("name");

Environment

.NET SDK:
Version: 9.0.101
Commit: eedb237549
Workload version: 9.0.100-manifests.4a280210
MSBuild version: 17.12.12+1cce77968

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.101\

Metadata

Metadata

Assignees

Labels

Azure.IdentityClientThis issue is related to a non-management packagecustomer-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

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions