How do you avoid static secrets in CI/CD pipelines altogether?

IntermediateConceptGitleaks
Answer

Short answer

Use OIDC federation: the CI platform issues a short-lived identity token for each job, and the cloud (AWS, Azure, GCP) trades it for temporary credentials scoped to that repo/branch. No long-lived access keys are stored in CI, so there's nothing to leak or rotate.

GitHub Actions → AWS

permissions: { id-token: write, contents: read }
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123456789012:role/gha-shop-deploy
      aws-region: ap-south-1
  - run: aws ecr get-login-password | docker login --username AWS --password-stdin $ECR

The IAM role's trust policy only allows repo:org/shop:ref:refs/heads/main.

Same idea elsewhere

GitLab CI id_tokens, Azure DevOps workload identity federation, Jenkins with cloud plugins, and Workload Identity / IRSA for apps in Kubernetes.

What to say in the interview

"With OIDC federation each pipeline job gets a short-lived token that the cloud exchanges for temporary, tightly scoped credentials, so there are no static keys in CI to leak. It's the strongest fix behind secret scanning."

All Security Tools questions Roadmap: Gitleaks — secret scanning

More on Gitleaks