Sub topic 13
Workload Identity on AKS
This chapter assumes you know how projected service account tokens work, how a cluster publishes an OIDC issuer, and how a cloud provider trusts a token by checking its issuer, subject, and audience. If those ideas are new, read the earlier chapters on bound tokens and the federation model first.
How AKS fits the federation model
Microsoft Entra Workload ID uses the same exchange you have already seen on EKS and GKE. A Pod presents a Kubernetes-signed token to Microsoft Entra ID. Entra checks the token against a trust rule you created, then returns an Entra access token for a specific identity.
The pieces are:
- An AKS cluster with the OIDC issuer enabled and the workload identity feature turned on.
- An Entra application or user-assigned managed identity, which is the cloud identity the Pod will act as.
- A federated identity credential on that identity. It names the cluster's issuer, the subject, and the audience that Entra should accept.
- A Kubernetes ServiceAccount that carries the identity's client ID.
- A Pod that opts in with a label.
Configuring the ServiceAccount and Pod
The ServiceAccount carries the client ID of the Entra identity. The Pod label azure.workload.identity/use: "true" tells the workload identity webhook to modify that Pod.
apiVersion: v1
kind: ServiceAccount
metadata:
name: app-reader
namespace: demo
annotations:
azure.workload.identity/client-id: 00000000-0000-0000-0000-000000000000
---
apiVersion: v1
kind: Pod
metadata:
name: aks-demo
namespace: demo
labels:
azure.workload.identity/use: "true"
spec:
serviceAccountName: app-reader
containers:
- name: app
image: registry.example.com/app:1.0When the Pod is created, the webhook adds a projected token volume and sets environment variables such as AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE, and AZURE_AUTHORITY_HOST. Recent Azure SDKs read these variables through their default credential chain, so the application code needs no secret. The token's audience defaults to api://AzureADTokenExchange.
Creating the trust rule
The trust lives in Azure, not in Kubernetes. A federated identity credential for the managed identity needs these values:
| Field | Value for this example |
|---|---|
| Issuer | The cluster's OIDC issuer URL |
| Subject | `system:serviceaccount:demo:app-reader` |
| Audience | `api://AzureADTokenExchange` |
With the Azure CLI, you can read the issuer from the cluster and create the credential:
ISSUER=$(az aks show -g my-rg -n my-cluster \
--query "oidcIssuerProfile.issuerUrl" -o tsv)
az identity federated-credential create \
--name app-reader-fc \
--identity-name app-identity \
--resource-group my-rg \
--issuer "$ISSUER" \
--subject system:serviceaccount:demo:app-reader \
--audiences api://AzureADTokenExchangeThis is the same scoping idea as the sub condition in an AWS trust policy. Only a token for the app-reader ServiceAccount in the demo namespace can use this identity. Grant the identity only the Azure role assignments the application needs.
Common failures
- The Pod has no
azure.workload.identity/use: "true"label, so no token or environment variables are injected. - The
client-idannotation holds the wrong value, or the object ID was used instead of the client ID. - The issuer in the federated credential differs from the cluster's current issuer URL.
- The subject or audience does not match the token, which Entra reports as an invalid client assertion.
- The ServiceAccount was changed after the Pod started. Restart the Pod so the webhook runs again.
Exercise
A Pod on AKS fails to get an Entra token, and the Pod has no AZUREFEDERATEDTOKEN_FILE environment variable. The ServiceAccount has the correct client-id annotation. What is the most likely cause, and what check confirms it?
Show answer
The Pod is probably missing the label azure.workload.identity/use: "true", so the webhook did not modify it. Run kubectl get pod aks-demo -n demo -o yaml and check for the label, the projected token volume, and the injected environment variables. Add the label and recreate the Pod.