Skip to content

IRSA

AWS binds a Kubernetes service account to an IAM role with a pair: a trust policy on the role, and a role-ARN annotation on the service account. The bundle renders both, already filled in.

The cluster side

apiVersion: v1
kind: ServiceAccount
metadata:
  name: xratud
  namespace: dp-eu-west1
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::<aws-account-id>:role/dp-eu-west1-runtime
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: builder
  namespace: xratu-build-bootstrap
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::<aws-account-id>:role/dp-eu-west1-build

The ARN is built from account_id and the role name derived from dp_install, so it is known at render time and requires no editing.

The cloud side

    condition {
      test     = "StringEquals"
      variable = "oidc.eks.<region>.amazonaws.com/id/<cluster-oidc-id>:sub"
      values   = ["system:serviceaccount:dp-eu-west1:xratud"]
    }

How the two meet

flowchart LR
  KSA["KSA xratud<br/>namespace dp-eu-west1"] -->|"role-arn annotation"| ROLE["IAM role<br/>dp-eu-west1-runtime"]
  ROLE -->|"trust policy pins<br/>system:serviceaccount:dp-eu-west1:xratud"| KSA
  ROLE --> ECR["ECR"]
  ROLE --> S3["S3 bucket"]

Both halves name the same namespace and service account, which is why they are generated together from one spec. See One bundle, two layers.

Prerequisites on the cluster

The EKS cluster needs an IAM OIDC provider associated with it, and the pod identity webhook that EKS runs by default injects the token and environment variables. The bundle renders the role and the annotation; associating the provider is yours, once per cluster.

Verifying

The annotation:

kubectl -n dp-eu-west1 get serviceaccount xratud \
  -o jsonpath='{.metadata.annotations}'

The trust policy:

aws iam get-role --role-name dp-eu-west1-runtime \
  --query "Role.AssumeRolePolicyDocument"

That the pod actually assumed it:

kubectl -n dp-eu-west1 exec dp-eu-west1-0 -c xratud -- env | grep AWS_ROLE_ARN

A pod with no AWS_ROLE_ARN in its environment means the annotation did not reach the service account, or the webhook did not act on it.