Catalog My learning Blog
CI/CD and DevOps Tutorial: Build a Delivery Pipeline · Phase 4 · Lesson 25 · 4 min read

DevSecOps: Shift-Left Security in CI/CD

On this page
  1. What DevSecOps and shift left mean
  2. Security checks in the pipeline: SAST, SCA, DAST and more
  3. A security scanning workflow
  4. Why deleting a committed secret isn't enough
  5. Software supply chain protection
  6. Making security checks stick
  7. Check yourself

What DevSecOps and shift left mean

When security review happens once before a big release, findings arrive weeks after the code was written, pile up, and get waived to hit the date. DevSecOps builds automated security checks into the same pipeline as tests, so each pull request gets security feedback in minutes, when it's cheapest to fix. Moving checks earlier is called shifting left.

Security checks in the pipeline: SAST, SCA, DAST and more

CheckFindsTools
Secret scanningKeys and passwords committed to codegitleaks, GitHub secret scanning with push protection, TruffleHog
SAST (static analysis)Insecure code patterns: injection, unsafe deserializationSemgrep, CodeQL, SonarQube
SCA (dependency scanning)Libraries with known vulnerabilities (CVEs)npm audit, Dependabot, Renovate, OSV-Scanner, Snyk
Image scanningVulnerable OS packages in container imagesTrivy, Grype, registry scanning
IaC scanningInsecure Terraform, Kubernetes, DockerfilesCheckov, Trivy, tflint, hadolint
DAST (dynamic)Vulnerabilities in the running appOWASP ZAP, against staging

Two ideas recur in that table. A CVE is a public ID for one known vulnerability, such as CVE-2021-44228, the Log4Shell flaw in the Log4j library. And static tools read your code without running it, while dynamic tools attack the running application from outside, the way a real attacker would.

Security checks placed along the pipeline: secrets and static analysis on every pull request, dependency and image scans on build, dynamic tests against staging.
Security checks placed along the pipeline: secrets and static analysis on every pull request, dependency and image scans on build, dynamic tests against staging.

A security scanning workflow

YAML
name: Security
on: [pull_request]

permissions:
  contents: read

jobs:
  secrets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - run: docker run --rm -v "$PWD:/repo" zricethezav/gitleaks:latest git /repo --exit-code 1

  sast:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: pipx run semgrep scan --config auto --severity ERROR --error

  dependencies:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with: { node-version: 24, cache: npm }
      - run: npm ci
      - run: npm audit --audit-level=high

  image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: docker build -t app:${{ github.sha }} .
      - run: docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:latest image --severity CRITICAL,HIGH --ignore-unfixed --exit-code 1 app:${{ github.sha }}

Each job fails the build only on serious findings (--severity ERROR, --audit-level=high, CRITICAL,HIGH), and Trivy ignores vulnerabilities with no available fix. Strict but focused gates get fixed; noisy ones get bypassed. Pin scanner image versions in real use rather than latest.

Why deleting a committed secret isn't enough

A key committed and then deleted in the next commit is still in Git history. gitleaks scans history, not just current files. On a test repository where a Stripe-style key was added, then removed:

YAML
RuleID:      stripe-access-token
File:        config.js
Line:        1
Commit:      7363c8e0ec9395e36213c18d563617716138aa12
WRN leaks found: 1

The file no longer exists, but the finding stands, and the command exits with code 1, failing the job. The only real fix for a leaked secret is to revoke and rotate it; rewriting history is secondary, since clones and forks may already have it. Push protection, which blocks the push before the secret lands, is better still.

Software supply chain protection

Attacks increasingly target the build itself: compromised dependencies, malicious packages with names close to popular ones, and hijacked CI actions.

  • Pin dependencies with lockfiles, and pin third-party actions to commit SHAs (Day 11).
  • Automate updates with Dependabot or Renovate, so pinning doesn't mean falling behind.
  • Generate an SBOM (software bill of materials, with Syft or Trivy) for each image, so you can answer "are we affected?" when a new CVE appears.
  • Sign images and attest provenance (Sigstore cosign, GitHub artifact attestations, SLSA), and verify signatures at deploy time.
  • Least-privilege tokens for every workflow (permissions:), and OIDC instead of stored keys.

Making security checks stick

  • Triage findings quickly; track exceptions with an expiry date, not permanent ignores.
  • Rescan images on a schedule: new CVEs appear daily for software that hasn't changed.
  • Security owns the policies and tooling; teams own fixing findings in their code.

Check yourself

The secret remains in Git history, forks, clones and CI caches, and bots scan public repositories within minutes. Revoke and rotate the secret first; cleaning history is optional afterwards.

Gates that block on noise or unfixable findings get bypassed or switched off. Starting with focused, actionable gates builds trust, and thresholds can tighten as the backlog shrinks.

Which of your images or services contain a specific component and version, such as a library with a newly announced vulnerability, in minutes instead of days of searching.

SAST analyzes source code without running it, finding issues early. DAST tests a running application from outside, finding issues like misconfiguration that only show at runtime.

Deployments can verify an image was built by your pipeline and not altered, and admission policies can reject unsigned images.