0

I am trying to connect to an Azure Blob Storage account from my VM using Managed Identity in Java. Below is the code I have implemented to establish the connection. I have made all the required configurations between the VM and the Blob Storage account, including assigning the "Storage Blob Data Contributor" role to the VM. Despite this, I am still unable to connect to Blob Storage and receiving the following error details.

Java Class:

package com.function;

import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.storage.blob.*;
import com.azure.storage.blob.models.*;

public class AzureBlobStorageTest {
    public static void main(String[] args) {
        String endpoint = "https://s*****ev01.blob.core.windows.net";
        String containerName = "test";
        String blobName = "sample.csv";
        String clientId = "619515b1-****-4437-8c09-9eca28338716"; // User-assigned Managed Identity Client ID

        try {
            // Build credential with client ID
            TokenCredential credential = new DefaultAzureCredentialBuilder()
                    .managedIdentityClientId(clientId)
                    .build();

            BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
                    .endpoint(endpoint)
                    .credential(credential)
                    .buildClient();

            BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);
            BlobClient blobClient = containerClient.getBlobClient(blobName);

            System.out.println("Connected to Blob: " + blobClient.getBlobUrl());

            // Check if blob exists
            if (blobClient.exists()) {
                System.out.println("Blob exists");
            }
        } catch (Exception e) {
            System.err.println("Error accessing blob storage: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

ERRORS:

03:52:25.652 [main] INFO com.azure.core.http.netty.implementation.NettyUtility -- {"az.sdk.message":"The following Netty versions were found on the classpath and have a mismatch with the versions used by azure-core-http-netty. If your application runs without issue this message can be ignored, otherwise please align 
the Netty versions used in your application. For more information, see https://aka.ms/azsdk/java/dependency/troubleshoot.","azure-netty-version":"4.1.126.Final","azure-netty-native-version":"2.0.73.Final","classpath-netty-version-io.netty:netty-common":"4.2.6.Final","classpath-netty-version-io.netty:netty-handler":"4.2.6.Final","classpath-netty-version-io.netty:netty-handler-proxy":"4.2.6.Final","classpath-netty-version-io.netty:netty-buffer":"4.2.6.Final","classpath-netty-version-io.netty:netty-codec":"4.2.6.Final","classpath-netty-version-io.netty:netty-codec-http":"4.2.6.Final","classpath-netty-version-io.netty:netty-codec-http2":"4.2.6.Final","classpath-netty-version-io.netty:netty-transport-native-unix-common":"4.2.6.Final","classpath-netty-version-io.netty:netty-transport-native-epoll":"4.2.6.Final","classpath-netty-version-io.netty:netty-transport-native-kqueue":"4.2.6.Final","classpath-native-netty-version-io.netty:netty-tcnative-boringssl-static":"2.0.73.Final"}
Connected to Blob: https://s*****ev01.blob.core.windows.net/test/sample.csv
03:52:27.415 [main] INFO com.azure.identity.ChainedTokenCredential -- Azure Identity => Attempted credential EnvironmentCredential is unavailable.
03:52:27.419 [main] INFO com.azure.identity.ChainedTokenCredential -- Azure Identity => Attempted credential WorkloadIdentityCredential is unavailable.
03:52:27.486 [main] INFO com.azure.identity.ManagedIdentityCredential -- User-assigned Managed Identity ID: 619515b1-7a16-****-8c09-9eca28338716
03:52:27.554 [main] INFO com.azure.identity.ChainedTokenCredential -- Azure Identity => Attempted credential ManagedIdentityCredential is unavailable.
03:52:27.572 [main] INFO com.azure.identity.ChainedTokenCredential -- Azure Identity => Attempted credential IntelliJCredential is unavailable.
03:52:27.575 [main] INFO com.azure.identity.ChainedTokenCredential -- Azure Identity => Attempted credential VisualStudioCodeCredential is unavailable.
03:52:27.668 [main] INFO com.azure.identity.ChainedTokenCredential -- Azure Identity => Attempted credential AzureCliCredential is unavailable.
03:52:27.696 [main] ERROR com.azure.identity.implementation.PowershellManager -- PowerShell command failure.

Managed Identity Cofiguration: Screenshot

Dependencies:

        <!-- https://mvnrepository.com/artifact/com.azure/azure-storage-blob -->
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-storage-blob</artifactId>
            <version>12.31.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.azure/azure-identity -->
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-identity</artifactId>
            <version>1.18.1</version>
            <scope>compile</scope>
        </dependency>

FYI, I have successfully tested the Managed Identity configuration between the VM and the Storage Account using PowerShell scripts, where I'm able to download files. However, I am facing issues specifically when trying to perform this operation in Java using this calss: BlobServiceClient.

Can anyone help me identify what might be wrong with the Java implementation that is preventing the connection to Azure Blob Storage using Managed Identity?

Thankyou!

1
  • Have you tried using ManagedIdentityCredential directly instead of DefaultAzureCredential? Commented Oct 20 at 17:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.