I have the code from below that works fine. My service and the storage are in the same environment in agent. Is there a way to write the credentials without having to provide a key, hence they are in the same environment in agent ?
StorageSharedKeyCredential credential =
new StorageSharedKeyCredential(accountName, **accountKey**);
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(endpoint)
.credential(credential)
.buildClient();
To avoid key credential, I agree with @NotFound that you can use
Tokencredentialwith the DefaultAzureCredential method.You need to assign RBAC roles to your storage account for accessing blob storage through identity, The roles are:-
Go to portal -> storage accounts -> Access Control (IAM) ->Add -> Add role assignments -> storage-blob-contributor or storage-blob-owner role to the storage account.
Portal:
I tried with sample code to upload a file from the local path to azure blob storage using identity it uploaded successfully.
Code:
Console:
Portal: