Azure Workload Identities
This guide covers creating and configuring managed identities for Kubernetes workloads running on AKS. Workload Identity enables your pods to securely access Azure services without managing static credentials.
How Workload Identity Works
Azure Workload Identity uses federated identity credentials to allow Kubernetes service accounts to authenticate as Azure AD applications:
AKS issues OIDC tokens for service accounts
Azure AD trusts tokens from the AKS OIDC issuer
Pods exchange service account tokens for Azure AD tokens
Azure resources validate the Azure AD token and grant access
This eliminates the need for client secrets and provides fine-grained, pod-level access control.
Prerequisites
AKS cluster with OIDC issuer and Workload Identity enabled
Permissions to create managed identities and role assignments
Your cluster's OIDC issuer URL (found in the AKS portal or via Azure CLI)
Creating a Managed Identity
Step 1: Get Your AKS OIDC Issuer URL
Step 2: Create the Managed Identity
Step 3: Create the Federated Credential
Link the managed identity to your Kubernetes service account:
💡 Multiple Service Accounts
You can create multiple federated credentials for the same managed identity if different service accounts need the same permissions:
Step 4: Assign Azure Roles
Grant the managed identity access to Azure resources:
Step 5: Configure Your Application
Add the identity annotations to your ServiceAccount configuration:
Common Azure Role Assignments
Key Vault Secrets User
For applications using External Secrets to fetch secrets from Key Vault:
Storage Blob Data Reader
For applications that need to read from Azure Blob Storage:
Storage Blob Data Contributor
For applications that need to read and write to Azure Blob Storage:
Service Bus Data Receiver
For ScaledJobs processing Service Bus messages:
Service Bus Data Sender
For applications that need to send messages to Service Bus:
Cosmos DB Data Contributor
For applications using Cosmos DB:
🔒 Least Privilege
Always assign roles at the most specific scope possible (e.g., specific Key Vault or storage account rather than resource group or subscription level).
Terraform Example
If you manage infrastructure with Terraform, here's a complete example:
Troubleshooting
Authentication Failures
Error: AADSTS70021: No matching federated identity record found
Verify the federated credential subject matches exactly:
system:serviceaccount:<namespace>:<service-account-name>Check the OIDC issuer URL in the federated credential matches your AKS cluster
Ensure the audience is set to
api://AzureADTokenExchange
Access Denied to Azure Resources
Error: AuthorizationFailed or 403 Forbidden
Verify the role assignment exists and is at the correct scope
Check that the role includes the required permissions
Ensure the role assignment has had time to propagate (can take a few minutes)
Token Exchange Failures
Error: Failed to exchange token
Verify the managed identity exists and hasn't been deleted
Check that Workload Identity is enabled on your AKS cluster
Ensure the pod has the
azure.workload.identity/use: "true"label
Debugging in Argo CD
Check Pod Logs:
Navigate to your application in the Argo CD UI
Expand the application tree to find your Pod
Click on the Pod resource
Select the Logs tab to view container output
Look for Azure SDK errors or authentication failures (e.g.,
AADSTSerror codes)
Check ServiceAccount Configuration:
In the application tree, click on the ServiceAccount resource
Select the Live Manifest tab
Verify the
azure.workload.identity/client-idandazure.workload.identity/tenant-idannotations are present and correct
Check Pod Labels and Environment:
Click on the Pod resource
Select the Live Manifest tab
Verify the
azure.workload.identity/use: "true"label is present undermetadata.labelsCheck for the
AZURE_CLIENT_ID,AZURE_TENANT_ID, andAZURE_FEDERATED_TOKEN_FILEenvironment variables (injected automatically)Verify the projected service account token volume is mounted
Check Events:
Click on the Pod or Deployment resource
Select the Events tab
Look for warnings related to service account tokens or Azure authentication
Best Practices
🔒 Security Recommendations
One identity per application: Create dedicated managed identities for each workload to isolate permissions
Use specific scopes: Assign roles at the resource level, not resource group or subscription
Namespace scoping: Include the namespace in federated credential subjects
Regular audits: Review and remove unused identities and role assignments
Use built-in roles: Prefer Azure built-in roles over custom role definitions where possible
Tag resources: Tag managed identities with application and team identifiers for cost allocation and auditing
Related Documentation
PGT Application Deployment - ServiceAccount configuration
PGT Secrets - Using Workload Identity with External Secrets
PGT CronJob - ServiceAccount for scheduled jobs
PGT ScaledJob - ServiceAccount for event-driven jobs
AWS IAM Roles (IRSA) - AWS equivalent
Last updated
Was this helpful?
