Hardening CI/CD Pipelines: A Practical Checklist

Your build system holds the keys to production. A field-tested checklist for locking down CI/CD: secrets, runners, dependencies, permissions and the logs that show when someone gets in.

2 min readIntermediate

Attackers have noticed what defenders sometimes forget: a CI/CD system is a privileged automation platform with credentials for source code, cloud accounts, package registries and production. Compromise the pipeline and you don't need to break into production. The pipeline deploys for you.

This checklist is ordered by impact. Work top-down.

1. Credentials: short-lived and scoped

  • Replace long-lived cloud keys with OIDC federation. GitHub Actions, GitLab and most CI platforms can exchange a signed job token for short-lived cloud credentials. No static secret to steal.
  • Scope every credential to one job and one environment. The test job should never hold production deploy rights.
  • Restrict who can trigger privileged workflows. Production deploys should require protected branches and environment approvals.
yaml
# GitHub Actions: least-privilege token + OIDC for cloud access
permissions:
  contents: read
  id-token: write   # only for the job that exchanges OIDC for cloud credentials

jobs:
  deploy:
    environment: production   # requires approval, holds production-only secrets
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/deploy-prod
          aws-region: ap-south-1

2. Untrusted code must not reach secrets

  • Never run code from forks with access to secrets. Avoid pull_request_target workflows that check out the PR's code.
  • Treat PR titles, branch names and issue text as untrusted input. Don't interpolate them directly into shell commands. Pass them through environment variables instead.
  • Separate build from release. Build untrusted code in an unprivileged job, and release only signed artifacts from a protected one.

3. Dependencies and third-party actions

  • Pin third-party actions to a full commit SHA, not a tag that can be moved.
  • Use lockfiles and verify integrity (npm ci, pip install --require-hashes).
  • Run dependency and secret scanning on every PR, and block merges on critical findings.
  • Review new dependencies like you review code: who maintains it, how widely is it used, does it run install scripts?

4. Runners

  • Prefer ephemeral runners that are destroyed after each job, so nothing persists between builds.
  • Self-hosted runners must not serve public repositories. A malicious PR becomes code execution on your network.
  • Isolate runners by trust level, and restrict their network egress to what builds actually need.

5. Artifacts and provenance

  • Sign build artifacts and container images (for example with Sigstore cosign) and verify signatures before deploy.
  • Generate an SBOM for each release, so you can answer "are we affected?" in minutes when the next big library vulnerability lands.
  • Produce build provenance (SLSA) so you can prove an artifact came from your pipeline and your source.

6. Logging and detection

Forward CI platform audit logs to your SIEM and alert on:

  • changes to workflow files on protected branches
  • new or modified repository and organisation secrets
  • new self-hosted runners or runner group changes
  • disabled branch protection or required reviews
  • deploy jobs triggered outside normal patterns (unusual time, user or branch)

Quick audit

Check Good looks like
Cloud credentials OIDC, no static keys in secrets
Default token permissions Read-only, elevated per job
Third-party actions Pinned to commit SHA
Fork PRs No access to secrets
Runners Ephemeral, no self-hosted for public repos
Artifacts Signed, with SBOM and provenance
Audit logs In the SIEM, with alerts on the events above

Further reading

HackersRoot Research · Research team

The HackersRoot research team investigates attack techniques across AI systems, cloud and identity, and enterprise networks, then publishes the detections and hardening guidance that stop them.

More from HackersRoot →

Related research