Interview Prep/Terraform/Secrets Provisioners and Policy as Code

Pipeline needs AWS access without storing access keys in GitHub.

IntermediateScenarioSecrets Provisioners and Policy as Code
Answer

Situation read → Long-lived keys in CI secrets are a liability.

What I'd do →

  1. Create an IAM OIDC identity provider for token.actions.githubusercontent.com.
  2. Create a role whose trust policy restricts sub to repo:acme/infra:ref:refs/heads/main.
  3. Use aws-actions/configure-aws-credentials with role-to-assume.
permissions:
  id-token: write
  contents: read
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123456789012:role/gha-terraform-apply
      aws-region: ap-south-1

Why → Tokens are short-lived and bound to repo and branch; nothing to leak or rotate.

Interview tip → Always constrain the sub claim, or any repo could assume the role.

All Terraform questions

More on Secrets Provisioners and Policy as Code