Chapter 88: Amazon EKS for DevOps
88.4 IAM — IRSA for pods
Story. Carlos in Austin stored AWS keys in a Kubernetes Secret for an S3 uploader. The Secret leaked in a support ticket. The blast radius was the whole account key. Meera in Pune replaced it with IRSA — IAM Roles for Service Accounts. The pod assumes a role limited to one S3 prefix. No long-lived access key in the cluster. Interviewers love this answer.
Why
Long-lived keys in Secrets are stolen once and reused forever. IRSA gives each workload a short-lived role session.
What
- IRSA — IAM Roles for Service Accounts on EKS.
- OIDC provider — EKS cluster OIDC issuer trusted by IAM.
- ServiceAccount annotation —
eks.amazonaws.com/role-arnpoints at the IAM role. - Least privilege — Role policy allows only the actions and resources that pod needs.
How
- Associate an IAM OIDC provider with the cluster (eksctl or Terraform can do this).
- Create an IAM role with a trust policy for that OIDC issuer and ServiceAccount.
- Annotate the ServiceAccount with the role ARN.
- Mount nothing secret for AWS keys — the AWS SDK uses the projected token automatically.
Example 1: Annotate ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
name: s3-uploader
namespace: shop
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/shop-s3-uploader
What it shows: Pods using serviceAccountName: s3-uploader can assume that IAM role. Replace the account id with yours. Never commit real keys.
Example 2: Verify identity from a debug pod (shape)
kubectl -n shop exec -it deploy/s3-uploader -- aws sts get-caller-identity
Output
{
"UserId": "AROA...:botocore-session-...",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/shop-s3-uploader/..."
}
What it shows: The pod identity is the IAM role, not a static user access key.
Ravindra Bagale's Tip
Prefer IRSA over access keys in Secrets. Scope the role to one bucket prefix, not s3:.
Secrets मधील access keys पेक्षा IRSA. Role एक bucket prefix पर्यंत मर्यादित ठेवा — s3: नको.
Secrets में access keys से बेहतर IRSA. Role एक bucket prefix तक सीमित रखें — s3:* नहीं.
Quick quiz
Q1. What does IRSA stand for?
IAM Roles for Service Accounts.
Q2. What annotation links a ServiceAccount to a role?
eks.amazonaws.com/role-arn with the IAM role ARN.
Q3. Why is IRSA safer than a static key in a Secret?
It uses short-lived role sessions and avoids long-lived keys in the cluster.
Did you understand? Let us try it once more.