Interview Prep/GitHub Actions/OIDC & Cloud Authentication

After assuming the role, `aws ecr get-login-password` works but push fails: `denied: User: arn:aws:sts::111122223333:assumed-role/gha-ecr-push/gha-123 is not authorized to perform: ecr:InitiateLayerUpload on resource: arn:aws:ecr:ap-south-1:111122223333:repository/shack-api`

IntermediateTroubleshootingOIDC & Cloud Authentication
Answer

Likely causes → The role's permission policy lacks push actions on that repository ARN (or the region or repo name differs).

Diagnose →

aws iam list-attached-role-policies --role-name gha-ecr-push
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::111122223333:role/gha-ecr-push \
  --action-names ecr:InitiateLayerUpload --resource-arns arn:aws:ecr:ap-south-1:111122223333:repository/shack-api

Fix → Allow ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImage, ecr:BatchGetImage on the repo ARN, and ecr:GetAuthorizationToken on *.

Prevent → Keep a reviewed push-policy module.

All GitHub Actions questions Roadmap: GitHub Actions

More on OIDC & Cloud Authentication