DevSecOps: Shift-Left Security in CI/CD
On this page
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
| Check | Finds | Tools |
|---|---|---|
| Secret scanning | Keys and passwords committed to code | gitleaks, GitHub secret scanning with push protection, TruffleHog |
| SAST (static analysis) | Insecure code patterns: injection, unsafe deserialization | Semgrep, CodeQL, SonarQube |
| SCA (dependency scanning) | Libraries with known vulnerabilities (CVEs) | npm audit, Dependabot, Renovate, OSV-Scanner, Snyk |
| Image scanning | Vulnerable OS packages in container images | Trivy, Grype, registry scanning |
| IaC scanning | Insecure Terraform, Kubernetes, Dockerfiles | Checkov, Trivy, tflint, hadolint |
| DAST (dynamic) | Vulnerabilities in the running app | OWASP 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.
A security scanning workflow
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:
RuleID: stripe-access-token
File: config.js
Line: 1
Commit: 7363c8e0ec9395e36213c18d563617716138aa12
WRN leaks found: 1The 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.