Roles for workloads
EC2, Lambda, ECS
- EC2: instance profile wraps a role; credentials delivered via IMDS (require IMDSv2).
- Lambda: execution role (what the function can do) vs resource policy (who can invoke it).
- ECS: task execution role (pull images, read secrets for injection, write logs) vs task role (what the app calls).
EKS: IRSA and Pod Identity
IRSA (IAM Roles for Service Accounts):
- Cluster has an OIDC issuer; create an IAM OIDC provider for it.
- Role trust policy allows
sts:AssumeRoleWithWebIdentityfrom that provider, conditioned onsub = system:serviceaccount:<ns>:<sa>andaud = sts.amazonaws.com. - Annotate the ServiceAccount:
eks.amazonaws.com/role-arn: arn:aws:iam::...:role/orders-s3. - The pod identity webhook injects
AWS_ROLE_ARNandAWS_WEB_IDENTITY_TOKEN_FILE; the SDK exchanges the projected token.
EKS Pod Identity (newer): install the Pod Identity Agent add-on, create a pod identity association (cluster + namespace + service account → role) via the EKS API; the role trusts pods.eks.amazonaws.com. No per-cluster OIDC provider, roles reusable across clusters, session tags (cluster, namespace, SA) enable ABAC.
Either way: block pods from the node role (IMDSv2 hop limit 1 or network policy), one role per workload, least privilege.
CI/CD: OIDC federation
GitHub Actions/GitLab/Jenkins (with OIDC plugins) assume roles with AssumeRoleWithWebIdentity, trust policies pinned to repo + branch/environment via the sub claim. No stored access keys. (Details in the GitHub Actions topic.)
Cross-account deploy roles
Pattern: a tooling/CI account whose role assumes deploy roles in dev/staging/prod accounts:
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:role/ci-runner" },
"Action": "sts:AssumeRole",
"Condition": { "StringEquals": { "sts:ExternalId": "acme-ci" } }
}
External ID is for third parties assuming roles in your account (prevents the confused-deputy problem: a vendor tricked into using your role for another customer). Within your own org, conditions like aws:PrincipalOrgID are more relevant.