1

I am updating some legacy code to work with a managed identity instead of an access key.
The code:

  1. Creates a DataLakeServiceClient
  2. Uses that to get a file DataLakeFileSystemClient (var dlfsc = dlsc.GetFileSystemClient(containerName);)
  3. Calls GetAccessPolicyAsync and SetAccessPolicyAsync (var acl = await client.GetAccessPolicyAsync().ConfigureAwait(false);)

When I construct the DataLakeServiceClient using a StorageSharedKeyCredential everything works fine. However, when I construct the DataLakeServiceClient using a ManagedIdentityCredential vai(DefaultAzureCredential), the following exception is thrown:

The specified resource does not exist.
RequestId:f2543e09-a01e-000d-321b-e47741000000
Time:2021-11-28T05:51:15.6906885Z
Status: 404 (The specified resource does not exist.)
ErrorCode: ResourceNotFound

Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.
RequestId:f2543e09-a01e-000d-321b-e57741000000
Time:2021-11-28T05:51:15.6906885Z</Message></Error>

I assume this is coming from when Azure.Identity is trying to obtain a token using the ManagedIdentityCredential?

An important point to note is the DataLakeFileSystemClient ExistsAsync() method is also being called, and works fine in either case.

So my question is, why does the AccessPolicy methods work fine when the DataLakeFileSystemClient has been created using StorageSharedKeyCredential, but not when it is created using ManagedIdentityCredential?

Hoppy
  • 720
  • 2
  • 12
  • 24

1 Answers1

2

So my question is, why does the AccessPolicy methods work fine when the DataLakeFileSystemClient has been created using StorageSharedKeyCredential, but not when it is created using ManagedIdentityCredential?

This is because the access policy operations are only supported with shared access key credentials and not Azure AD credentials which is used when you use Managed Identity.

From this link:

enter image description here

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • That's great - thanks! The link you posted seems broken, though. – Hoppy Nov 28 '21 at 09:22
  • 1
    Sorry, my bad. Edited the answer and provided the correct link: https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-azure-active-directory#permissions-for-blob-service-operations. – Gaurav Mantri Nov 28 '21 at 09:43