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

GitLab CI to AWS OIDC fails with `InvalidIdentityToken: Incorrect token audience`

IntermediateTroubleshootingCloud identity: IRSA, Workload Identity and CI OIDC
Answer

Likely causes → The aud in the job's id_tokens does not match any client ID on the IAM OIDC provider for gitlab.com (or your self-managed host).

Diagnose →

aws iam get-open-id-connect-provider --open-id-connect-provider-arn <arn> --query ClientIDList

Compare that list with the aud: in .gitlab-ci.yml.

Fix →

deploy:
  id_tokens:
    AWS_TOKEN:
      aud: https://gitlab.com
  script:
    - >
      aws sts assume-role-with-web-identity --role-arn "$ROLE_ARN"
      --role-session-name "gl-$CI_JOB_ID" --web-identity-token "$AWS_TOKEN"

Make the provider's client ID list contain the same value.

Prevent → Restrict the trust policy on gitlab.com:sub (for example project_path:acme/api:ref_type:branch:ref:main) and keep the job template central.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

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