Interview Prep/DevSecOps/Cloud identity: IRSA, Workload Identity and CI OIDC

An audit finds an IAM role whose GitHub OIDC trust policy checks only `token.actions.githubusercontent.com:aud = sts.amazonaws.com`

AdvancedTroubleshootingCloud identity: IRSA, Workload Identity and CI OIDC
Answer

Likely causes → Someone copied a minimal example. With no sub condition, any GitHub Actions workflow in any repository in the world can assume the role, because every workflow can get a token with that audience from the same issuer.

Diagnose →

aws iam get-role --role-name gha-deploy --query 'Role.AssumeRolePolicyDocument.Statement[].Condition'
# CloudTrail: check who actually assumed it
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRoleWithWebIdentity \
  --query 'Events[].CloudTrailEvent' --output text | jq -r '.userIdentity.userName // .requestParameters.roleSessionName'

Fix → Add a strict sub condition right away (StringEquals on repo:acme/api:environment:prod). Review CloudTrail for the sub values that have used the role, and treat unknown ones as an incident.

Prevent → An IAM Access Analyzer custom policy check or a Checkov/OPA rule in CI that rejects GitHub OIDC trust policies without a sub condition, or with repo:* wildcards.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Cloud identity: IRSA, Workload Identity and CI OIDC