Security
A Pod gets AWS credentials
Projected tokens and OIDC
The uploader app writes files to an S3 bucket, and nowhere in the cluster is there an AWS access key. Instead the Pod gets a short-lived token from Kubernetes that says which ServiceAccount it runs as, and AWS trades it for temporary credentials, because an IAM role trusts the cluster's token issuer. This is IAM roles for service accounts (IRSA). Follow it from the trust policy to a signed PutObject.
- Pod
- uploader-…-w7r4d · ServiceAccount shop/uploader
- Role
- uploader-s3 · may write to kubelearn-uploads
- Token
- projected · audience sts.amazonaws.com · 24 h
- Credentials
- temporary · 1 h · nothing stored
Read the whole lesson as text
1. The trust
The API server signs ServiceAccount tokens with its own key, and names itself in them as the issuer https://kubelearn-oidc.s3.eu-west-1.amazonaws.com. For AWS to trust those tokens, that issuer publishes an OpenID Connect discovery document and the public keys, here in an S3 bucket, and you register it in IAM as an identity provider. Then you create the role uploader-s3 with a trust policy: tokens from that provider, for audience sts.amazonaws.com, for the subject system:serviceaccount:shop:uploader. Last, the ServiceAccount gets an annotation naming the role.
- You register the cluster's token issuer with IAM as an OpenID Connect provider.
- You create the role uploader-s3, which only this ServiceAccount's tokens may assume.
- You annotate the ServiceAccount with the role's ARN.
2. The webhook
You deploy uploader with serviceAccountName: uploader and nothing about AWS in it. When the ReplicaSet creates the Pod, the API server sends it to the Amazon EKS pod identity webhook, a mutating admission webhook that runs in the cluster. The webhook sees the role annotation on the Pod's ServiceAccount and patches the Pod: a projected volume with a ServiceAccount token for audience sts.amazonaws.com, mounted in every container, and environment variables that tell the AWS SDK where the token and the role are.
- The ReplicaSet creates the uploader Pod, with nothing about AWS in it.
- The API server sends the Pod to the pod identity webhook, which runs on node-1.
- The webhook answers with a patch: a token volume and the variables the SDK reads.
3. The token
node-1's kubelet sets up the Pod's volumes. For the projected token it calls the TokenRequest API: a token for ServiceAccount uploader, for audience sts.amazonaws.com, valid 24 hours, and bound to this Pod. The API server signs a JWT and the kubelet writes it into the volume. Decoded, it says who issued it, who it's about and who may accept it. It's useless once the Pod is deleted, and the kubelet replaces it well before it expires.
- The kubelet asks the API server for a token for this Pod, with the audience STS expects.
- The API server signs the token. The kubelet writes it into the Pod's volume.
4. Assume the role
uploader starts and creates an S3 client. The AWS SDK looks for credentials in a fixed order, and finds AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE in the environment. It reads the token file and calls STS AssumeRoleWithWebIdentity over HTTPS, with the role, a session name and the token. The call carries no AWS signature: the token is the proof. The app's own code never sees any of this.
- The SDK sends the token to STS and asks to become uploader-s3.
5. STS checks
STS doesn't call the cluster. It reads the issuer's discovery document and keys, and caches them, then checks the token's signature with the key named in its header. It checks that iss is the registered provider, that aud is one of its client IDs, that the token hasn't expired, and that sub and aud satisfy the role's trust policy. All pass, so STS returns temporary credentials: an access key ID, a secret key and a session token, valid for an hour.
- STS fetches the issuer's discovery document and public keys.
- Signature, issuer, audience, expiry and the trust policy's conditions all pass.
- STS returns credentials for uploader-s3, valid for one hour.
6. The call
The SDK signs the upload with the temporary secret key, using AWS Signature Version 4, and sends the session token with it. S3 checks the signature and asks IAM whether the assumed role may put objects in kubelearn-uploads. It may. CloudTrail records the role session behind the call, so an audit can trace an upload back to the ServiceAccount. Before the hour is up, the SDK calls STS again with the token file, which the kubelet keeps fresh.
- The SDK uploads the file, signed with the temporary credentials.
- S3 checks the signature and the role's permissions, and stores the file.
7. The alternatives
EKS also offers Pod Identity, which drops the OIDC part: an agent DaemonSet on each node answers credential requests on a link-local address, and roles are linked to ServiceAccounts through the EKS API rather than trust policies naming an issuer. Google Cloud's Workload Identity Federation for GKE and Azure's Workload ID work on the same idea. Compared with an access key in a Secret, every one of them leaves nothing long-lived to leak, rotate or forget.
- An hour later the SDK repeats the exchange with the current token. Nothing was ever stored.
Summary
Nothing in the Pod holds an AWS key. The API server signs a short-lived token that names the Pod's ServiceAccount and is meant for STS, the kubelet keeps it fresh, and a webhook tells the SDK where to find it. AWS trusts it because the cluster's issuer publishes its public keys and an IAM role names exactly which subject may assume it. The credentials that come back last an hour, and the whole exchange repeats on its own.
Next lesson: Kyverno policies