Skip to content

[Bug] AZURE_POD_IDENTITY_AUTHORITY_HOST env not used correctly #1037

Description

@alar0046

Library version used

1.23.1

Java version

Java 25

Scenario

ManagedIdentityClient - managed identity

Is this a new or an existing app?

None

Issue description and reproduction steps

When setting the environment variable AZURE_POD_IDENTITY_AUTHORITY_HOST to a custom url, e.g. http://127.0.0.1:80 the full imds endpoint is not built correctly.

The bug is in the constructor of class com.microsoft.aad.msal4j.IMDSManagedIdentitySource. The class contains a variable IMDS_TOKEN_PATH that is set to /metadata/identity/oauth2/token. When AZURE_POD_IDENTITY_AUTHORITY_HOST is set, the endpoint is built with the following code:

StringBuilder builder = new StringBuilder(environmentVariables.getEnvironmentVariable(Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST));
builder.append("/" + IMDS_TOKEN_PATH);

This causes the imdsEndpoint to contain an extra /, thus the endpoint becomes http://127.0.0.1:80//metadata/identity/oauth2/token which causes a resource not found exception from Azure.

Relevant code snippets

Expected behavior

For the imds endpoint to be built correctly without a double /

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

The fix is to remove the extra /.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working, needs an investigation and a fixP2Normal priority items, should be done after P1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions