AKS Unable to Access IMDS

Ivan Webber 20 Reputation points Microsoft Employee
2025-03-19T00:44:36.25+00:00

I have a simple FastAPI mock service deployed on an old AKS cluster setup a few years ago that uses the Python Azure SDK to access azure storage. It uses MI with Storage Blob Data Contributor with client_id specified via environment variable. It's based on the Azure documentation tutorials.

E.g.:


    try:
        print(os.environ.get("AZURE_CLIENT_ID"))
        client_identity = BlobServiceClient(
            account_url=account_url,
            credential=ManagedIdentityCredential(
                # must be in kwargs passed to IMDS
                client_id=os.environ.get("AZURE_CLIENT_ID")
            )
        )
        containers = client_identity.list_containers()
        print("Connect to Azure Storage succeeded. Find {} containers".format(len(list(containers))), file=sys.stderr)
    except Exception as e:
        print("Connect to Azure Storage failed: {}".format(e), file=sys.stderr)

This was working, but I wanted to improve security and have dedicated resources for this new service, so I made a new resource group and AKS cluster with the following differences:

  1. I chose to use a vnet so that I would be able to create NSG and rules to control ingress and egress. I plan to use an internal load balancer and vnet peering. Unlike the workload of the old cluster, I don't want this one accessible from the internet.
  2. I chose "private cluster" instead of "public cluster".
  3. I decided to use a system-assigned MI because it would be only used for this one thing.
  4. I used separate agentpool and userpool whereas the older cluster had only agentpool.

However, I am now getting the following error:

ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no response from the IMDS endpoint. invalid_request

I tried ensuring there was an allow rule to IMDS, but I got the same response. I'm very new to networking, but I'm wondering if one of the other differences is to blame for the error. I appreciate the help.

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,317 questions
{count} votes

Accepted answer
  1. Mounika Reddy Anumandla 3,300 Reputation points Microsoft External Staff
    2025-03-20T03:09:12.5033333+00:00

    Hi Ivan Webber,

    We noticed your feedback that the above answer was not helpful. Thank you for taking time to share feedback.

    Your understanding is spot on—the old cluster most likely used Pod Identity, which is why authentication worked without additional configuration. The new cluster follows Workload Identity, which requires explicit configuration in the deployment YAML.

    Old Cluster (Using Pod Identity)

    1. A few years ago, Azure AD Pod Identity was the recommended way to assign Managed Identities to pods.https://github.com/Azure/aad-pod-identity
    2. It worked by deploying an agent (DaemonSet) in AKS that:
      • Intercepted requests to IMDS (Instance Metadata Service).
      • Redirected them to use a Kubernetes-assigned identity.
    3. The FastAPI app in the old cluster relied on this Pod Identity mechanism to authenticate without needing Service Connector or extra annotations.

    New Cluster (Using Workload Identity) workload-identity

    1. Microsoft deprecated Pod Identity and replaced it with Azure Workload Identity for better performance and security.
    2. IMDS is no longer needed for authentication in Workload Identity.
    3. Instead, authentication now works by:

    Workload Identity requires explicitly linking the Kubernetes Service Account to the Managed Identity.

    The additional YAML keys (azure.workload.identity/use: "true" and serviceAccountName) were needed to enable Workload Identity authentication.

    As per my understanding, your resolution follows Microsoft's recommended approach for enabling Workload Identity without code changes.

    On a cluster that is already running a pod-managed identity, you can configure it to use workload identity one of two ways. The first option allows you to use the same configuration that you've implemented for pod-managed identity. You can annotate the service account within the namespace with the identity to enable Microsoft Entra Workload ID and inject the annotations into the pods.

    https://learn.microsoft.com/en-us/azure/aks/workload-identity-overview?tabs=dotnet#how-to-migrate-to-microsoft-entra-workload-id

    Hope this helps!

    Let me know if you have any further queries!

    If you find the answer heplful, please consider Accepting answer and upvote.

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.