How can I access a storage container from within an AKS pod?

Tom 0 Reputation points
2025-01-17T13:09:58.7366667+00:00

I have an AKS cluster that runs a Python application on a pod. The code attempts to list files in a storage container via the Azure SDK. It fails due to lack of permissions and I cannot figure out how to make it work.

I am well-versed in AWS but new to Azure, so please forgive me if I have this wrong. My understanding is that the AKS cluster has a managed identity. So I have assigned roles to that identity with various scopes (tried, subscription, resource group, storage account, etc.). My thought was if I do this, and use ManagedIdentityCredential in my code, it should "see" the files automatically. And it fails. I've tried everything, assigned dozens of roles and scopes. It I just get:

azure.core.exceptions.HttpResponseError: This request is not authorized to perform this operation using this permission.

If I try this from a VM, all is fine. It is like the pod doesn't know how to read the identity. In AWS, I would assign an IAM role to my EKS worker nodes and any pod running AWS SDK code would just "See" it and work. I'm trying to emulate that here. I've spent many hours googling this, going in hallucinated circles via AI and trying everything. I just don't get it. Will be glad to post any logs/output/additional information!

Thanks.

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,236 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Manu Philip 18,961 Reputation points MVP
    2025-01-17T20:36:03.0933333+00:00

    Hi Tom

    When you wanted to use Managed Identity to connect to Azure Storage, make sure that your cluster is configured to use Managed Identity and linked to your storage account.

    An example given below:

    az aks create --resource-group <rg-name> --name <aks-name> --enable-managed-identity
    

    Azure Storage account should have the access from the Managed Identity associated with your AKS cluster.

    Following is the sample command to use

    az role assignment create --assignee <principal-object-id> --role "Storage Blob Data Contributor" --scope /subscriptions/<subscription-id>/resourceGroups/<rg-name>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>
    

    An example as below:

    User's image Hope this helps.


    --please don't forget to upvote and Accept as answer if the reply is helpful--


  2. Bruce (SqlWork.com) 69,976 Reputation points
    2025-01-20T20:38:36.79+00:00

    There is no default managed identity, you need to setup

    https://learn.microsoft.com/en-us/azure/aks/use-managed-identity

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.