0

Using the Azure SDK for Java, I have created a container in my Azure storage account. To control ACL for the newly added container, I must now add the service principle.

Is there a way to use Java to handle ACL and incorporate the service principle?

I have tried azure-document-to-manage-acl , but need more help.

OnkarG
  • 267
  • 1
  • 3
  • 16

1 Answers1

0

I tried to in my environment and got the below results:

You can follow this github link to achieve your requirement by adding service principal to Azure Blob Container by using the below code.

Code:

@GetMapping("/call")
public  void  assignBlob()  throws  IOException  {
TokenCredential  credential  =  new  ClientSecretCredentialBuilder().clientId("client_id").clientSecret("client_secret").tenantId("tenant_id").build();

String  connectionString  =  "DefaultEndpointsProtocol=https;AccountName=<storage_account_name>;AccountKey=<storage_account_key>;EndpointSuffix=core.windows.net";

BlobContainerClient  containerClient  =  new  BlobContainerClientBuilder().credential(credential).connectionString(connectionString).containerName("<conatiner_name>").buildClient();

BlobSignedIdentifier  identifier  =  new  BlobSignedIdentifier().setId("<your_another_service_principal_id>").setAccessPolicy(new  BlobAccessPolicy().setStartsOn(OffsetDateTime.now()).setExpiresOn(OffsetDateTime.now().plusDays(7)).setPermissions("rw"));

// Set the access policy for the container
containerClient.setAccessPolicy(null,  Collections.singletonList(identifier));
}

I have used the below-highlighted service principal id to provide access to my container.

Portal: enter image description here

As it is shown below, I can add a service principal to the Azure Blob container.

Portal:

enter image description here

Venkatesan
  • 3,748
  • 1
  • 3
  • 15