az aks update --resource-group <RESOURCE_GROUP> --name <CLUSTER_NAME> --enable-oidc-issuer --enable-workload-identity
export AKS_OIDC_ISSUER="$(az aks show --name <CLUSTER_NAME> --resource-group <RESOURCE_GROUP> --query oidcIssuerProfile.issuerUrl --output tsv)"
echo $AKS_OIDC_ISSUER
az identity create -g <RESOURCE_GROUP> -n <USER_ASSIGNED_IDENTITY_NAME>
az identity federated-credential create \
--name <FEDERATED_CREDENTIAL_NAME> \
--identity-name <MANAGED_IDENTITY_NAME> \
--resource-group <RESOURCE_GROUP> \
--issuer <AKS_OIDC_ISSUER_URL> \
--subject system:serviceaccount:<YOUR_NAMESPACE>:workload-identity-sa \
--audiences "api://AzureADTokenExchange"
az keyvault create --name "<your-unique-keyvault-name>" --resource-group "myResourceGroup" --location "EastUS"
az keyvault secret set --vault-name "your-keyvault-name" --name "SampleSecret" --value "MyS3cr3tValue!"
az role assignment create \
--role "Key Vault Secrets User" \
--assignee <managed-identity-ObjectId-or-clientId> \
--scope /subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<key-vault-name>
apiVersion: v1
kind: ServiceAccount
metadata:
name: workload-identity-sa
namespace: <YOUR_NAMESPACE>
annotations:
azure.workload.identity/client-id: "<MANAGED_IDENTITY_CLIENT_ID>"
apiVersion: v1
kind: Pod
metadata:
name: sample-workload-identity-key-vault
namespace: <NAMESPACE>
labels:
azure.workload.identity/use: "true"
spec:
serviceAccountName: <SERVICE_ACCOUNT_NAME>
containers:
- name: oidc
image: ghcr.io/azure/azure-workload-identity/msal-go
env:
- name: KEYVAULT_URL
value: "<https://<KEYVAULT_NAME>.vault.azure.net/>"
- name: SECRET_NAME
value: "<YOUR_SECRET_NAME>"
kubectl describe pod sample-workload-identity-key-vault | grep "SECRET_NAME:"
kubectl logs sample-workload-identity-key-vault
You may also want to check the env variables
kubectl exec -it <POD_NAME> -- sh
env | grep AZURE