Skip to main content
How to Secure Your CI/CD Pipeline (DevSecOps)

How to Secure Your CI/CD Pipeline (DevSecOps)

KU
· Founder & Chief Editor
• 8 min read•Updated •29 views

Your pipeline holds the keys to production and signs off on everything you ship, so harden both the pipeline itself and the artifacts it builds.

Key takeaways

  • Secure a CI/CD pipeline by removing long-lived cloud keys with OIDC federation, adding dependency and image scans that fail the build on high and critical findings, and pinning every third-party action to a full commit SHA.
  • Then add SBOMs, keyless signing, and a deploy step that refuses anything unsigned.

Secure a CI/CD pipeline in three moves first: replace static cloud keys with OIDC federation, add dependency and image scans that fail the build on high and critical findings, and pin every third-party action to a full commit SHA. Then prove what you ship with SBOMs, signing, and verify-before-deploy.

Verified against

aws-actions/configure-aws-credentials v6.3.0, aquasecurity/trivy-action v0.36.0, against the GitHub Actions secure-use and OpenID Connect docs and the AWS IAM OIDC identity provider docs. Checked October 2026.

Your pipeline is the most privileged thing in your engineering org. It holds credentials to production, runs code from every branch and pull request, and signs off on the artifacts your users trust. Compromise it and an attacker skips every other control. So securing CI/CD is two jobs: locking down the pipeline, and vouching for what it ships. Below, both, ordered by impact.

Start here

Three changes stop the majority of real-world pipeline attacks, and none of them take a week:

  1. Kill long-lived cloud keys. Replace static AWS_ACCESS_KEY_ID secrets with OIDC federation so jobs assume a role at runtime.
  2. Add SCA and image scan gates that fail the build. Most breaches ride in through a known-vulnerable dependency or base image, not novel exploits.
  3. Pin every third-party action to a commit SHA. A tag like @v6 is mutable; a SHA is not.

Everything after this matters, but these three come first.

Secrets: stop shipping credentials into the pipeline

The worst secret is the one that never expires.

Use OpenID Connect (OIDC) so your runner exchanges a short-lived signed token for a scoped cloud role. No static keys live in CI at all. Here is the GitHub Actions to AWS pattern:

YAML
# .github/workflows/deploy.yml
permissions:
  id-token: write   # required to request the OIDC token
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
        with:
          role-to-assume: arn:aws:iam::123456789012:role/ci-deploy
          aws-region: us-east-1
          role-session-name: gha-${{ github.run_id }}

On the AWS side, the trust policy restricts which repo and branch can assume that role, so a token minted for another repo is useless. The credentials it hands back last minutes, not months.

For the secrets you still genuinely need (a third-party API token, a signing key), keep them scoped and short-lived, pull them from a vault at job time, and never echo them into logs. Then add secret scanning (Gitleaks, TruffleHog, or your platform's native scanner) on every push and pull request. Treat any hit as a rotation event, not a code-review comment. The secret is already in git history.

Least privilege for the runner and its jobs

Default pipeline permissions are almost always too broad. Set the top-level token to read-only and grant write only on the specific jobs that need it. On GitHub that means permissions: contents: read at the workflow level, elevated per job. Give each job the narrowest cloud role it can do its work with, and separate build credentials from deploy credentials so a compromised test step cannot push to production.

Pull requests from forks are the classic poisoning vector. A fork can propose a workflow change or a malicious build script that runs with your secrets if you let it. Use pull_request (not pull_request_target) for untrusted contributions so the run executes without access to secrets, require manual approval for first-time contributors, and never let fork code reach a job that holds deploy credentials.

Pin third-party actions to a full commit SHA, not a tag or branch. Tags are mutable, and a maintainer compromise or a malicious retag turns @v3 into arbitrary code inside your privileged runner. This is not hypothetical: in March 2026 Aqua Security responded to a supply-chain attack on aquasecurity/trivy-action by re-issuing its releases under new v-prefixed tags. A workflow pinned to a SHA it had reviewed keeps running that exact code whatever happens to the tags; a workflow pinned to a tag runs whatever the tag points at today. GitHub's secure-use guide now also points to workflow dependency lockfiles as the successor to SHA pinning where you can adopt them (more in our GitHub Actions security hardening guide). Use Dependabot or Renovate to keep those SHAs current so pinning does not rot into stale, vulnerable versions.

Security gates in the pipeline

Gates are where DevSecOps stops being a slogan. Each runs in CI and fails the build on findings above your threshold. Wire them so high and critical severities break the pipeline; leave medium and low as reported-but-passing so you do not train everyone to ignore red.

  • SAST: Semgrep or CodeQL scans your own source for injection, auth, and unsafe-API bugs.
  • SCA / dependency scanning: the highest-yield gate, since most exploited vulnerabilities live in your dependencies, not your code. See our dependency and SCA scanning guide for how to tune it.
  • Container image scanning: scan the built image and its base layers before you push. Details in container vulnerability scanning.
  • DAST: exercise the running app (OWASP ZAP against a staging deploy) to catch what static analysis misses.
  • IaC scanning: tfsec or Checkov on your Terraform and Kubernetes manifests to catch open security groups, public buckets, and missing encryption before they ship.

A scan-and-fail gate looks like this:

YAML
# .github/workflows/build.yml (job step)
      - name: Scan image, fail on high/critical
        uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
        with:
          image-ref: ${{ env.IMAGE }}:${{ github.sha }}
          severity: HIGH,CRITICAL
          exit-code: '1'          # non-zero exit stops the pipeline
          ignore-unfixed: true    # don't block on CVEs with no fix yet

The exit-code: '1' is what turns a report into a gate. Without it, the scan is decoration.

Supply-chain integrity: prove what you shipped

Passing gates tells you the artifact was clean when it was built. Supply-chain integrity lets you prove, at deploy time, that the thing you are about to run is exactly that artifact.

  • SBOM: generate a software bill of materials (Syft, or native build-tool support) for every build. When the next big CVE lands, you answer "are we affected" in minutes instead of days. See supply-chain security with SBOMs.
  • Artifact signing: sign images and artifacts with Sigstore's cosign, ideally keyless via OIDC so there is no signing key to steal.
  • Provenance and SLSA: emit signed provenance recording how and where the artifact was built, moving you up the SLSA levels.
  • Verify before deploy: the step teams skip. Have your deploy step, and ideally a cluster admission controller, verify the signature and provenance and refuse anything unsigned. Signing without verification protects no one.

Protect the artifact, the registry, and the repo

Lock down where artifacts live. Require authentication and least-privilege access on your registry, enable immutable tags so a pushed digest cannot be silently replaced, and restrict who can publish.

On the source side, turn on branch protection for your main branches: required status checks (your gates above), required reviews, and no direct or force-pushes. Require signed commits where you can. Finally, keep audit logs for the pipeline, the registry, and cloud role assumptions, and ship them somewhere an attacker who owns the pipeline cannot edit.

For the application code flowing through all of this, our application security best practices guide covers the vulnerability classes your SAST and DAST gates are looking for.

Questions people ask

What is the most important CI/CD security control?

Removing long-lived credentials. A static cloud key in a CI secret works for anyone who steals it, until someone notices. OIDC federation lets each job exchange a short-lived token, scoped by a trust policy to a specific repository and branch, for cloud credentials that are valid only for that job. With nothing standing to steal, a leaked log or a malicious dependency has far less to exfiltrate.

Should I pin GitHub Actions to a commit SHA or a version tag?

A full commit SHA. GitHub's own secure-use guidance says to pin actions to a commit SHA, because tags can be moved to point at different code after a maintainer or repository compromise. Add the version as a trailing comment for readability, and let Dependabot or Renovate open pull requests that bump the SHA. Repositories that can adopt workflow dependency lockfiles get the same guarantee with less manual churn.

Is pull_request_target safe to use?

Only if the workflow never checks out or runs code from the pull request. pull_request_target runs in the context of the base repository with access to secrets and a writable token, so building fork code there hands an attacker your credentials. GitHub recommends avoiding it unless necessary and using pull_request for untrusted contributions, or workflow_run to separate the unprivileged build from a privileged follow-up job.

The call we'd make

If you are starting from a typical pipeline with static keys and no gates, spend your first week here: move to OIDC, add SCA and image scanning as build-breaking gates, and pin your actions to SHAs. That combination removes the credentials worth stealing, blocks the vulnerabilities most likely to be exploited, and closes the action-poisoning path.

Then invest in supply-chain integrity: SBOMs, cosign signing, and verify-before-deploy. It pays off later, during the incident where you need to prove exactly what ran in production. A pipeline that mints short-lived credentials, fails loudly on known-vulnerable dependencies, and refuses to deploy anything it cannot verify is a genuinely hard target.

Sources

Explore topics:CI/CDSecurityDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). How to Secure Your CI/CD Pipeline (DevSecOps). DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/secure-cicd-pipeline

Markdown

[How to Secure Your CI/CD Pipeline (DevSecOps)](https://www.devopsness.com/blog/secure-cicd-pipeline) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.