azureopenid-connectazure-managed-identityworkload-identity

Azure Workload Identity Federation and Managed Identity: login.microsoftonline.com returns 401


Given following setup:

Using Maven azure-identity for the ManagedIdentity instance:

<dependency>
  <groupId>com.azure</groupId>
  <artifactId>azure-identity</artifactId>
  <version>1.9.0-beta.3</version>
  <!--      <version>1.7.3</version> tried different versions ... -->
</dependency>

Java snippet:

ManagedIdentityCredential managedIdentityCredential =
  new ManagedIdentityCredentialBuilder()
  .build();
QueueClient queue = new QueueClientBuilder()
  .credential(managedIdentityCredential)
  .endpoint("https://<my-storage-account>.queue.core.windows.net")
  .queueName("test")
  .buildClient();

This results in:

java.io.IOException: Server returned HTTP response code: 401 for URL: https://login.microsoftonline.com/\<my-tenant-id>/oauth2/v2.0/token
...
[ForkJoinPool.commonPool-worker-3] ERROR com.azure.identity.ManagedIdentityCredential - Azure Identity => ERROR in getToken() call for scopes [https://storage.azure.com/.default]: Managed Identity authentication is not available.
[ForkJoinPool.commonPool-worker-3] ERROR com.azure.core.implementation.AccessTokenCache - Failed to acquire a new access token.

Any suggestions what might be missing in the picture? Thx!


Solution

  • There might be many reasons leading to this 401 error. But in my particular case: I had a wrong Kubernetes namespace configuration in the Federated Credential ... maybe this helps somebody else, too.