Opscraft
AWS IAM & multi-account security · Lesson 3 of 7 · 4 min read

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).
Enlarge diagramTask execution roleTask roleUsed by the ECS agentPull the image from ECRRead secrets to inject, write logsUsed by your application codee.g. read the orders S3 bucketLeast privilege per service
Figure 1. Two different roles in ECS: the execution role lets the platform start your task; the task role is what your code uses.
Swipe sideways to see all of it, or tap to open it full screen.

EKS: IRSA and Pod Identity

IRSA (IAM Roles for Service Accounts):

  1. Cluster has an OIDC issuer; create an IAM OIDC provider for it.
  2. Role trust policy allows sts:AssumeRoleWithWebIdentity from that provider, conditioned on sub = system:serviceaccount:<ns>:<sa> and aud = sts.amazonaws.com.
  3. Annotate the ServiceAccount: eks.amazonaws.com/role-arn: arn:aws:iam::...:role/orders-s3.
  4. The pod identity webhook injects AWS_ROLE_ARN and AWS_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.

Enlarge diagramPodServiceAccountordersEKS OIDCissuersigns tokensAWS STSRoleorders-s3trusts sa orderssigned tokenAssumeRoleWithWebIdentity + tokencheck trust: issuer, sub, audtemporary credentialsSDK uses themautomatically
Figure 2. IRSA end to end: the pod gets a signed token, IAM trusts tokens from the cluster for one ServiceAccount, and STS returns temporary credentials.
Swipe sideways to see all of it, or tap to open it full screen.

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.)

Enlarge diagramGitHub Actionsjobrepo acme/orders,branch mainOIDC tokensigned by GitHubIAM role trustonly acme/orderson maintemporarycredentialsabout 1 hour
Figure 3. CI without stored keys: GitHub Actions presents a signed token describing the repo and branch; the role only trusts that exact repo and branch.
Swipe sideways to see all of it, or tap to open it full screen.

Cross-account deploy roles

Pattern: a tooling/CI account whose role assumes deploy roles in dev/staging/prod accounts:

Enlarge diagramtooling accountCI roledev accountrole deploy (trusts the CI role)staging accountrole deploy (trusts the CI role)prod accountrole deploy (trusts the CI role)AssumeRole
Figure 4. The cross-account deploy pattern: a CI role in the tooling account assumes a deploy role in each target account.
Swipe sideways to see all of it, or tap to open it full screen.
{
  "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.