Video in progress

How do you give a CI pipeline access to the cloud and the registry? What do you use instead of static access keys?

Instead of keeping long-lived keys in CI secrets, I use OIDC federation: on every run the pipeline gets a short-lived token, and the cloud checks it by repo, branch and environment. Permissions are minimal and split by stage.

📖 Answer

The classic situation: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets in CI, created three years ago, with admin rights. Anyone who can edit the workflow file can send the key out. It has never been rotated, because "nobody knows what would break".

With OIDC (using GitHub Actions as the example):

permissions:
  id-token: write      # to request an OIDC token
  contents: read
jobs:
  deploy:
    environment: prod
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/ci-orders-prod
          aws-region: eu-central-1

The CI provider issues a signed JWT for this job, with the repo, branch and environment written in it. On the cloud side the role trusts only the subject repo:company/orders:environment:prod. The token dies in an hour, and there is no stored key. GitLab, GCP Workload Identity Federation and Azure use the same model.

Design rules:

  • Split into stages: the PR build only runs tests and has no prod rights at all. Image push comes only from main. A prod deploy goes through a protected environment, with an approval.
  • Fork PRs: code from an outside fork must not reach the secrets or the OIDC role. Be careful with pull_request_target: it runs with secrets, and if you check out fork code inside it, that code can reach the secrets too.
  • GitOps: CI does not need cluster rights at all. It only pushes to the registry and commits to Git, and Argo CD pulls into the cluster itself.
  • Registry pull: nodes sign in with their own cloud identity, not with a static password in imagePullSecrets.

For the static secrets that remain (tokens for external SaaS), set an owner, an expiry and automatic rotation. Do not fully trust masking in CI logs: a secret printed in base64 or in pieces slips past the mask.