Use Microsoft Entra pod-managed identities in AKS (Preview)

Microsoft Entra pod-managed identities use Azure Kubernetes Service (AKS) primitives to associate managed identities for Azure resources and identities in Microsoft Entra ID with pods. Administrators create identities and bindings as Kubernetes primitives that allow pods to access Azure resources that rely on Microsoft Entra ID as an identity provider.

Microsoft Entra pod-managed identities in AKS have the following limitations:

  • Each cluster supports up to 200 pod-managed identities.
  • Each cluster supports up to 200 pod-managed identity exceptions.
  • Pod-managed identities are supported only on Linux node pools.
  • This feature is supported only on clusters backed by Virtual Machine Scale Sets.

Important

We recommend you review Microsoft Entra Workload ID. This authentication method replaces pod-managed identity (preview), which integrates with the Kubernetes native capabilities to federate with any external identity providers on behalf of the application.

The open source Microsoft Entra pod-managed identity (preview) in Azure Kubernetes Service was deprecated on October 24, 2022, and the project archived in September 2023. For more information, see the deprecation notice. The AKS Pod Identity Managed add-on is patched and supported through September 2025 to allow time for customers to move over to Microsoft Entra Workload ID.

Operation mode options

Microsoft Entra pod-managed identity supports two modes of operation:

  • Standard Mode: In this mode, the following two components are deployed to the AKS cluster:

    • Managed Identity Controller (MIC): An MIC is a Kubernetes controller that watches for changes to pods, AzureIdentity, and AzureIdentityBinding through the Kubernetes API Server. When it detects a relevant change, the MIC adds or deletes AzureAssignedIdentity as needed. Specifically, when a pod is scheduled, the MIC assigns the managed identity on Azure to the underlying Virtual Machine Scale Set used by the node pool during the creation phase. When all pods using the identity are deleted, it removes the identity from the Virtual Machine Scale Set of the node pool, unless the same managed identity is used by other pods. The MIC takes similar actions when AzureIdentity or AzureIdentityBinding are created or deleted.

    • Node Managed Identity (NMI): NMI is a pod that runs as a DaemonSet on each node in the AKS cluster. NMI intercepts security token requests to the Azure Instance Metadata Service on each node. NMI intercepts token requests and redirects them to itself. It then checks if the pod is authorized to access the requested identity and, if so, retrieves the token from the Microsoft Entra tenant on behalf of the application.

  • Managed Mode: This mode offers only NMI. When installed via the AKS cluster add-on, Azure manages creation of Kubernetes primitives (AzureIdentity and AzureIdentityBinding) and identity assignment in response to CLI commands by the user. Otherwise, if installed via Helm chart, the identity needs to be manually assigned and managed per the user. For more information, see Pod identity in managed mode.

When you install the Microsoft Entra pod-managed identity via Helm chart or YAML manifest as shown in the Installation Guide, you can choose between the standard and managed mode. If you instead decide to install the Microsoft Entra pod-managed identity using the AKS cluster add-on as shown in this article, the setup uses the managed mode.

Prerequisites

Your Microsoft Entra pod-managed identities in AKS must meet the following requirements:

  • The Azure CLI version 2.20.0 or later is installed.

  • Your AKS cluster is at version 1.26 or later.

  • You must have the appropriate permissions such as the Owner or Contributor role.

Install the aks-preview Azure CLI extension

Important

AKS preview features are available on a self-service, opt-in basis. Previews are provided "as is" and "as available," and they're excluded from the service-level agreements and limited warranty. AKS previews are partially covered by customer support on a best-effort basis. As such, these features aren't meant for production use. For more information, see the following support articles:

To install the aks-preview extension, run the following command:

az extension add --name aks-preview

Run the following command to update to the latest version of the extension released:

az extension update --name aks-preview

Register the EnablePodIdentityPreview feature flag

Register the EnablePodIdentityPreview feature flag by using the az feature register command as shown in the following example:

az feature register --namespace "Microsoft.ContainerService" --name "EnablePodIdentityPreview"

Tip

To disable the AKS Managed add-on, run the following command:

az feature unregister --namespace "Microsoft.ContainerService" --name "EnablePodIdentityPreview"

It takes a few minutes for the status to show as Registered. Verify the registration status by using the az feature show command:

az feature show --namespace "Microsoft.ContainerService" --name "EnablePodIdentityPreview"

When the status reflects Registered, refresh the registration of the Microsoft.ContainerService resource provider by using the az provider register command:

az provider register --namespace Microsoft.ContainerService

Manage an AKS cluster with pod-managed identities

You can manage your AKS cluster with either the Azure Container Networking Interface (CNI) or Kubenet network plugin when enabling Microsoft Entra pod-managed identities.

  1. Create an AKS cluster with Azure CNI and pod-managed identity enabled with the default recommended configuration. The following commands use az group create to create a resource group named myResourceGroup and the az aks create command to create an AKS cluster named myAKSCluster in the myResourceGroup resource group.

    az group create --name myResourceGroup --location eastus
    az aks create \
        --resource-group myResourceGroup \
        --name myAKSCluster \
        --enable-pod-identity \
        --network-plugin azure \
        --generate-ssh-keys
    
  2. Use az aks get-credentials to sign in to your AKS cluster. This command also downloads and configures the kubectl client certificate on your development computer.

    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
    

When you enable pod-managed identity on your AKS cluster, the system adds an AzurePodIdentityException named aks-addon-exception to the kube-system namespace. An AzurePodIdentityException lets pods with certain labels access the Azure Instance Metadata Service (IMDS) endpoint without interception by the NMI server. The aks-addon-exception allows AKS first-party addons, such as Microsoft Entra pod-managed identity, to operate without requiring you to manually configure an AzurePodIdentityException. Optionally, you can add, remove, and update an AzurePodIdentityException using:

  • az aks pod-identity exception add

  • az aks pod-identity exception delete

  • az aks pod-identity exception update

  • Or kubectl

Update an existing AKS cluster with Azure CNI

To update an existing AKS cluster with Azure CNI to include pod-managed identity, run the following command:

az aks update --resource-group $MY_RESOURCE_GROUP --name $MY_CLUSTER --enable-pod-identity

Create a managed identity

You must have the relevant permissions (for example, Owner) on your subscription to create the identity.

To create an identity to be used by the demo pod with az identity create, set the IDENTITY_CLIENT_ID and IDENTITY_RESOURCE_ID variables, run the following command:

az group create --name myIdentityResourceGroup --location chinaeast2
export IDENTITY_RESOURCE_GROUP="myIdentityResourceGroup"
export IDENTITY_NAME="application-identity"
az identity create --resource-group ${IDENTITY_RESOURCE_GROUP} --name ${IDENTITY_NAME}
export IDENTITY_CLIENT_ID="$(az identity show --resource-group ${IDENTITY_RESOURCE_GROUP} --name ${IDENTITY_NAME} --query clientId -o tsv)"
export IDENTITY_RESOURCE_ID="$(az identity show --resource-group ${IDENTITY_RESOURCE_GROUP} --name ${IDENTITY_NAME} --query id -o tsv)"

Assign permissions for the managed identity

The managed identity assigned to the pod must be granted appropriate permissions based on the operations the pod performs. Ensure that you assign only the minimum required roles to follow security best practices.

To run the demo, the IDENTITY_CLIENT_ID managed identity must have Virtual Machine Contributor permissions in the resource group that contains the Virtual Machine Scale Set of your AKS cluster.

# Obtain the name of the resource group containing the Virtual Machine Scale set of your AKS cluster, commonly called the node resource group
NODE_GROUP=$(az aks show --resource-group myResourceGroup --name myAKSCluster --query nodeResourceGroup -o tsv)

# Obtain the id of the node resource group
NODES_RESOURCE_ID=$(az group show --name $NODE_GROUP -o tsv --query "id")

# Create a role assignment granting your managed identity permissions on the node resource group
az role assignment create --role "Virtual Machine Contributor" --assignee "$IDENTITY_CLIENT_ID" --scope $NODES_RESOURCE_ID

Create a pod-managed identity

To create a pod-managed identity for the cluster using az aks pod-identity add, run the following command:

export POD_IDENTITY_NAME="my-pod-identity"
export POD_IDENTITY_NAMESPACE="my-app"
az aks pod-identity add --resource-group myResourceGroup --cluster-name myAKSCluster --namespace ${POD_IDENTITY_NAMESPACE}  --name ${POD_IDENTITY_NAME} --identity-resource-id ${IDENTITY_RESOURCE_ID}

Note

The "POD_IDENTITY_NAME" has to be a valid Domain Name System (DNS) subdomain name as defined in RFC 1123.

When you assign the pod-managed identity by using pod-identity add, the Azure CLI attempts to grant the Managed Identity Operator role over the pod-managed identity (IDENTITY_RESOURCE_ID) to the cluster identity.

Azure creates an AzureIdentity resource in your cluster representing the identity in Azure, and an AzureIdentityBinding resource that connects the AzureIdentity to a selector. You can view these resources by running the following command:

kubectl get azureidentity -n $POD_IDENTITY_NAMESPACE
kubectl get azureidentitybinding -n $POD_IDENTITY_NAMESPACE

Run a sample application

For a pod to use Microsoft Entra pod-managed identity, the pod needs an aadpodidbinding label with a value that matches a selector from a AzureIdentityBinding. By default, the selector will match the name of the pod-managed identity, but it can also be set using the --binding-selector option when calling az aks pod-identity add.

To run a sample application using Microsoft Entra pod-managed identity, create a demo.yaml file with the following contents. Replace POD_IDENTITY_NAME, IDENTITY_CLIENT_ID, and IDENTITY_RESOURCE_GROUP with the values from the previous steps. Replace SUBSCRIPTION_ID with your subscription ID.

Note

In the previous steps, you created the POD_IDENTITY_NAME, IDENTITY_CLIENT_ID, and IDENTITY_RESOURCE_GROUP variables. You can use a command such as echo to display the value you set for variables, for example echo $POD_IDENTITY_NAME.

apiVersion: v1
kind: Pod
metadata:
  name: demo
  labels:
    aadpodidbinding: $POD_IDENTITY_NAME
spec:
  containers:
  - name: demo
    image: mcr.azk8s.cn/oss/azure/aad-pod-identity/demo:v1.6.3
    args:
      - --subscriptionid=$SUBSCRIPTION_ID
      - --clientid=$IDENTITY_CLIENT_ID
      - --resourcegroup=$IDENTITY_RESOURCE_GROUP
    env:
      - name: MY_POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: MY_POD_NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: MY_POD_IP
        valueFrom:
          fieldRef:
            fieldPath: status.podIP
  nodeSelector:
    kubernetes.io/os: linux

Notice the pod definition has an aadpodidbinding label with a value that matches the name of the pod-managed identity you ran az aks pod-identity add in the previous step.

  1. Deploy the demo.yaml to the same namespace as your pod-managed identity using kubectl apply:

    kubectl apply -f demo.yaml --namespace $POD_IDENTITY_NAMESPACE
    
  2. Verify the sample application successfully runs using kubectl logs:

    kubectl logs demo --follow --namespace $POD_IDENTITY_NAMESPACE
    

    Verify that the logs show a token is successfully acquired and that the HTTP GET request operation is successful.

    ...
    successfully doARMOperations vm count 0
    successfully acquired a token using the MSI, msiEndpoint(http://169.254.169.254/metadata/identity/oauth2/token)
    successfully acquired a token, userAssignedID MSI, msiEndpoint(http://169.254.169.254/metadata/identity/oauth2/token) clientID(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
    successfully made GET on instance metadata
    ...
    

Run an application with multiple identities

To enable an application to use multiple identities, set the --binding-selector to the same selector when creating pod identities:

az aks pod-identity add --resource-group myResourceGroup --cluster-name myAKSCluster --namespace ${POD_IDENTITY_NAMESPACE}  --name ${POD_IDENTITY_NAME_1} --identity-resource-id ${IDENTITY_RESOURCE_ID_1} --binding-selector myMultiIdentitySelector
az aks pod-identity add --resource-group myResourceGroup --cluster-name myAKSCluster --namespace ${POD_IDENTITY_NAMESPACE}  --name ${POD_IDENTITY_NAME_2} --identity-resource-id ${IDENTITY_RESOURCE_ID_2} --binding-selector myMultiIdentitySelector

Then set the aadpodidbinding field in your pod YAML to the binding selector you specified.

apiVersion: v1
kind: Pod
metadata:
  name: demo
  labels:
    aadpodidbinding: myMultiIdentitySelector
...

Disable pod-managed identity on an existing cluster

  1. To disable pod-managed identity on an existing cluster, remove the pod-managed identities from the cluster by running the following command:

    az aks pod-identity delete --name ${POD_IDENTITY_NAME} --namespace ${POD_IDENTITY_NAMESPACE} --resource-group myResourceGroup --cluster-name myAKSCluster
    
  2. Then disable the feature on the cluster by running the following command:

    az aks update --resource-group myResourceGroup --name myAKSCluster --disable-pod-identity
    

Clean up resources

To remove a Microsoft Entra pod-managed identity from your cluster, remove the sample application and the pod-managed identity from the cluster.

kubectl delete pod demo --namespace $POD_IDENTITY_NAMESPACE

Then remove the identity and the role assignment of cluster identity.

az aks pod-identity delete \
  --name ${POD_IDENTITY_NAME} \
  --namespace ${POD_IDENTITY_NAMESPACE} \
  --resource-group myResourceGroup \
  --cluster-name myAKSCluster

az identity delete \
  --resource-group ${IDENTITY_RESOURCE_GROUP} \
  --name ${IDENTITY_NAME}

az role assignment delete \
  --role "Managed Identity Operator" \
  --assignee "$IDENTITY_CLIENT_ID" \
  --scope "$IDENTITY_RESOURCE_ID"

Next steps

For more information on managed identities, see Managed identities for Azure resources.