Identity & Zero Trust for Platform Engineers›05 · Cloud workload identity

Lesson 05 of 14 · Workload identity

Cloud workload identity

Let pods call cloud APIs with no stored keys: how a Kubernetes ServiceAccount token is exchanged for short-lived cloud credentials on AWS (IRSA and EKS Pod Identity), Azure and GCP, how to scope the trust precisely, and how to stop pods borrowing the node's credentials.

Advanced
Key wordsworkload identityIRSAEKS Pod IdentityAzure Workload IdentityGKE Workload IdentityOIDC federationprojected ServiceAccount tokenAssumeRoleWithWebIdentitytrust policyfederated identity credentialIMDSv2static keys

The problem with keys in Secrets

The old way: create a cloud access key, put it in a Kubernetes Secret, mount it into the pod. Every copy is a long-lived credential that can leak through Git, logs, backups or anyone with get secrets, and rotating it is a manual project.

Workload identity federation removes the stored key. The pod proves who it is with a Kubernetes-issued token, and the cloud exchanges that for short-lived credentials scoped to one role.

Instead of giving every pupil a permanent master key, the school gives them their ID card. When they need the science lab, they show the card at the office and receive a key that only opens the science lab and stops working after an hour.

The common shape

All three clouds use the same idea:

1. The cluster acts as an OIDC issuer: it signs ServiceAccount tokens and publishes its public keys.
2. The cloud is told to trust that issuer, and to map ONE ServiceAccount (namespace + name)
   to ONE cloud identity (IAM role / managed identity / Google service account).
3. The pod gets a projected, short-lived ServiceAccount token with a cloud-specific audience.
4. The cloud SDK sends the token to the cloud's token service, which checks the signature,
   issuer, audience and subject, and returns temporary credentials.
5. The SDK refreshes credentials automatically. No key is ever stored.

AWS: IRSA and EKS Pod Identity

IRSA (IAM Roles for Service Accounts):

apiVersion: v1
kind: ServiceAccount
metadata:
  name: orders
  namespace: shop
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/orders

A webhook injects a projected token (audience sts.amazonaws.com) and the environment variables AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE. The SDK calls AssumeRoleWithWebIdentity. The role's trust policy must pin the exact ServiceAccount:

{
  "Effect": "Allow",
  "Principal": { "Federated": "arn:aws:iam::111122223333:oidc-provider/oidc.eks.eu-west-1.amazonaws.com/id/EXAMPLE" },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": { "StringEquals": {
    "oidc.eks.eu-west-1.amazonaws.com/id/EXAMPLE:sub": "system:serviceaccount:shop:orders",
    "oidc.eks.eu-west-1.amazonaws.com/id/EXAMPLE:aud": "sts.amazonaws.com" } }
}

EKS Pod Identity is the newer, simpler option: an agent DaemonSet hands out credentials, the role trusts the service principal pods.eks.amazonaws.com, and the ServiceAccount-to-role mapping is an association in the EKS API. There is no per-cluster OIDC provider to manage, and one role can be reused across clusters.

Azure Workload Identity

The ServiceAccount is annotated with a managed identity's client ID, pods carry the label azure.workload.identity/use: "true", and the managed identity has a federated identity credential whose issuer is the cluster's OIDC issuer URL and whose subject is system:serviceaccount:shop:orders. The webhook injects AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_FEDERATED_TOKEN_FILE; the Azure SDK exchanges the token with Entra ID.

GKE Workload Identity

The ServiceAccount is linked to a Google service account (annotation iam.gke.io/gcp-service-account) that grants roles/iam.workloadIdentityUser to the member serviceAccount:<project>.svc.id.goog[shop/orders], or IAM grants roles directly to that Kubernetes principal. A GKE metadata server on each node answers the pod's credential requests.

Scope it tightly

  • One cloud identity per service, with permissions limited to its own resources (one bucket, one queue), not *.
  • Pin the subject. Never use wildcards on namespace or ServiceAccount in trust conditions.
  • Protect the bootstrap: anyone who can create a pod with ServiceAccount orders gets the orders role. RBAC on create pods, and separate namespaces for separate trust levels.
  • Block the node's credentials. Pods must not fall back to the node's own role:
  • AWS: IMDSv2 required with hop limit 1, so the metadata service is unreachable from pod network namespaces (or block 169.254.169.254 with network policy).
  • GKE: the metadata server only exposes the pod's own identity once Workload Identity is enabled on the node pool.
  • Audit: cloud logs (CloudTrail, Azure Activity Log, Cloud Audit Logs) show which role was assumed, by which ServiceAccount (it appears in the session name or subject), and what it did.

Classic failure

The pod works in development, where it silently used the node's broad role, and fails in production where IMDS is locked down. Test with node credentials blocked from day one.

Going deeper

Self-managed and on-premises clusters can do the same: publish the cluster's ServiceAccount issuer discovery document and JWKS at a reachable HTTPS URL (the --service-account-issuer and --service-account-jwks-uri flags), register that issuer in the cloud as an OIDC provider, and use the AWS/Azure/GCP SDKs exactly as on a managed cluster. No keys need to reach the data centre.

Try it

On a cluster with IRSA or Pod Identity, create a role that can only s3:ListBucket on one bucket. Bind it to ServiceAccount orders, run aws sts get-caller-identity and aws s3 ls from the pod, then from a pod using default. The second pod must fail. If it succeeds, find out why (node role or IMDS).

Recap

  • Federation exchanges a Kubernetes ServiceAccount token for short-lived cloud credentials: no stored keys.
  • AWS: IRSA (OIDC provider + trust policy) or EKS Pod Identity (associations); Azure: federated identity credentials; GCP: Workload Identity.
  • Pin the exact ServiceAccount, one identity per service, least privilege, and block access to node credentials.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.