DevSecOps Pipeline: Adding Security to CI/CD Without Slowing Down Developers

Posted: | Last updated: | 5 minute read

DevSecOps Pipeline

Security cannot be a gate at the end of the release process. If developers build features for two weeks and then a security team blocks the release for three days of review, everyone loses. DevSecOps shifts security left — integrating automated security checks into every stage of the CI/CD pipeline so vulnerabilities are caught early, when they are cheap and fast to fix.

The DevSecOps Pipeline

┌──────┐   ┌──────┐   ┌──────┐   ┌──────┐   ┌──────┐   ┌──────┐
│ Code │ → │Build │ → │ Test │ → │Scan  │ → │Deploy│ → │ Run  │
│      │   │      │   │      │   │      │   │      │   │      │
│Secret│   │SAST  │   │Unit  │   │Image │   │K8s   │   │DAST  │
│Detect│   │Lint  │   │Integ │   │Scan  │   │Audit │   │WAF   │
│Pre-  │   │SCA   │   │      │   │SBOM  │   │      │   │RASP  │
│commit│   │      │   │      │   │Sign  │   │      │   │      │
└──────┘   └──────┘   └──────┘   └──────┘   └──────┘   └──────┘

Each stage adds a security check. No single check catches everything — the pipeline catches vulnerabilities in layers.

Stage 1: Pre-Commit — Secrets Detection

The most common security mistake: committing secrets (API keys, passwords, tokens) to Git.

Gitleaks (Pre-Commit Hook)

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.18.0
    hooks:
      - id: gitleaks
# Install pre-commit
pip install pre-commit
pre-commit install

Now every git commit scans staged files for secrets. If a secret is found, the commit is blocked.

In CI

# GitHub Actions
- name: Detect secrets
  uses: gitleaks/gitleaks-action@v2
  env:
    GITHUB_TOKEN: $

Stage 2: Build — SAST and Dependency Scanning

SAST (Static Application Security Testing)

SAST analyses source code for vulnerabilities without running the application.

Semgrep (fast, supports 30+ languages):

- name: SAST with Semgrep
  uses: returntocorp/semgrep-action@v1
  with:
    config: >-
      p/owasp-top-ten
      p/nodejs
      p/python

Semgrep rules catch:

  • SQL injection
  • XSS (cross-site scripting)
  • Path traversal
  • Insecure deserialization
  • Hardcoded credentials

Dependency Scanning (SCA)

Third-party dependencies are the biggest attack surface. 80% of application code is open-source libraries.

Trivy for dependencies:

- name: Scan dependencies
  run: trivy fs --scanners vuln --severity HIGH,CRITICAL .

Snyk:

- name: Snyk dependency check
  uses: snyk/actions/node@master
  env:
    SNYK_TOKEN: $
  with:
    args: --severity-threshold=high

npm audit (Node.js):

- name: npm audit
  run: npm audit --audit-level=high

License Compliance

Some open-source licenses (GPL, AGPL) have viral clauses that may be incompatible with your product.

- name: License check
  run: trivy fs --scanners license --severity HIGH .

Stage 3: Test — Security-Focused Tests

Security Unit Tests

# test_security.py
def test_sql_injection_prevention():
    """Ensure parameterized queries are used"""
    response = client.get("/users?id=1' OR '1'='1")
    assert response.status_code == 400

def test_xss_prevention():
    """Ensure HTML is escaped in output"""
    response = client.post("/comments", json={"body": "<script>alert('xss')</script>"})
    assert "<script>" not in response.json()["body"]

def test_auth_required():
    """Ensure protected endpoints require authentication"""
    response = client.get("/admin/users")
    assert response.status_code == 401

Stage 4: Scan — Container Image Security

Image Scanning with Trivy

- name: Build image
  run: docker build -t myapp:$ .

- name: Scan image
  uses: aquasecurity/trivy-action@master
  with:
    image-ref: myapp:$
    format: sarif
    output: trivy-results.sarif
    severity: CRITICAL,HIGH
    exit-code: 1

- name: Upload scan results
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: trivy-results.sarif

Generate SBOM (Software Bill of Materials)

An SBOM lists every component in your software — required by many compliance frameworks and government contracts.

- name: Generate SBOM
  run: trivy image --format cyclonedx --output sbom.json myapp:$

- name: Upload SBOM
  uses: actions/upload-artifact@v4
  with:
    name: sbom
    path: sbom.json

Sign Images with Cosign

- name: Sign image
  run: |
    cosign sign --key env://COSIGN_KEY myregistry/myapp:$
  env:
    COSIGN_KEY: $

Stage 5: Deploy — Kubernetes Security

Kubernetes Manifest Scanning

- name: Scan K8s manifests
  run: trivy config k8s/ --severity HIGH,CRITICAL --exit-code 1

This catches:

  • Containers running as root
  • Missing resource limits
  • Privileged containers
  • Missing security contexts
  • Use of latest tag

OPA/Gatekeeper Policies

# Require non-root containers
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequireNonRoot
metadata:
  name: require-non-root
spec:
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces: ["production"]

Stage 6: Runtime — DAST and Monitoring

DAST (Dynamic Application Security Testing)

DAST tests the running application by sending malicious requests.

OWASP ZAP:

- name: DAST with ZAP
  uses: zaproxy/action-full-scan@v0.10.0
  with:
    target: 'https://staging.example.com'
    rules_file_name: 'zap-rules.tsv'
    cmd_options: '-a'

DAST catches vulnerabilities that SAST misses — runtime configuration issues, authentication bypasses, CORS misconfigurations.

Runtime Protection

Falco for runtime anomaly detection:

  • Shell spawning inside containers
  • Unexpected network connections
  • File access to sensitive paths (/etc/shadow, /proc)
  • Privilege escalation attempts

The Complete GitHub Actions Pipeline

name: DevSecOps Pipeline
on:
  push:
    branches: [main]
  pull_request:

jobs:
  security-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      # Secrets detection
      - name: Detect secrets
        uses: gitleaks/gitleaks-action@v2

      # SAST
      - name: SAST scan
        uses: returntocorp/semgrep-action@v1
        with:
          config: p/owasp-top-ten

      # Dependency scanning
      - name: Dependency scan
        run: trivy fs --scanners vuln --severity HIGH,CRITICAL --exit-code 1 .

      # Build
      - name: Build image
        run: docker build -t myapp:$ .

      # Container scan
      - name: Container scan
        run: trivy image --severity HIGH,CRITICAL --exit-code 1 myapp:$

      # K8s manifest scan
      - name: K8s config scan
        run: trivy config k8s/ --severity HIGH,CRITICAL

      # SBOM
      - name: Generate SBOM
        run: trivy image --format cyclonedx --output sbom.json myapp:$

Handling Findings Without Blocking Developers

The biggest mistake in DevSecOps: blocking every build on every finding. That creates alert fatigue and developers start ignoring security.

Graduated enforcement:

Severity PR Action Main Branch Action
Critical Block merge Block deploy
High Block merge Block deploy
Medium Warning comment Warning in dashboard
Low Informational Log only

Suppression policy:

  • False positives: Suppress with inline comments (# nosemgrep) and document why
  • Accepted risk: Track in a risk register with an owner and review date
  • No blanket suppression: Every suppression requires a justification

Conclusion

DevSecOps is not about adding a security scan at the end of the pipeline. It is about layering security checks at every stage — pre-commit (secrets), build (SAST, SCA), test (security tests), scan (container images, SBOM), deploy (K8s audit), and runtime (DAST, Falco). Each layer catches what the others miss. The goal is not to block developers but to give them fast feedback: “This dependency has a critical CVE” or “This Dockerfile runs as root.” Fix it in the PR, not in a post-mortem.

FAQs

Q: Does DevSecOps slow down CI/CD? The scans add 2-5 minutes to a pipeline. That is far less than the days or weeks a security incident costs. Run scans in parallel with tests to minimise wall-clock time.

Q: Which tool should I start with? Start with three: Gitleaks (secrets), Trivy (dependencies + containers), and Semgrep (SAST). All are free and open source. Add more tools as you mature.

Q: Do I need a dedicated security team? For DevSecOps to work, security must be everyone’s responsibility. A security champion on each team, supported by a central security team that maintains policies and tools, is the most effective model.


Related posts: