DevSecOps: Shift Left Security

devops security

Finding a vulnerability in production costs 100x more than finding it in development. DevSecOps—integrating security into the DevOps pipeline—shifts security left.

What is “Shift Left”?

Traditional security:

Code → Build → Test → Deploy → Security Test → Production

                              (Too late, too expensive)

Shift left:

Code → Security Scan → Build → Security Test → Deploy → Production
  ↑                      ↑                        ↑
(Early detection)  (Continuous)              (Defense in depth)

Find issues early. Fix them cheaply.

The DevSecOps Pipeline

Stage 1: Pre-Commit

IDE Integration:

// VS Code settings
{
    "editor.formatOnSave": true,
    "python.linting.banditEnabled": true,
    "eslint.enable": true
}

Pre-commit Hooks:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/PyCQA/bandit
    rev: 1.7.0
    hooks:
      - id: bandit
        args: [-r, src/]
  
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.0.0
    hooks:
      - id: gitleaks

Stage 2: Commit/PR

Static Analysis (SAST):

# GitHub Actions
- name: Run Semgrep
  uses: returntocorp/semgrep-action@v1
  with:
    config: p/python

- name: Run Snyk Code
  uses: snyk/actions/python@master
  env:
    SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

Secret Scanning:

- name: Detect Secrets
  uses: trufflesecurity/trufflehog@main
  with:
    path: ./
    base: main

Stage 3: Build

Dependency Scanning:

- name: Check Dependencies
  run: |
    pip-audit --requirement requirements.txt
    npm audit --audit-level high

Container Scanning:

- name: Scan Container
  uses: aquasecurity/trivy-action@master
  with:
    image-ref: 'myapp:${{ github.sha }}'
    severity: 'CRITICAL,HIGH'

Stage 4: Test

Dynamic Analysis (DAST):

- name: OWASP ZAP Scan
  uses: zaproxy/action-full-scan@v0.4.0
  with:
    target: 'https://staging.example.com'

Infrastructure Scanning:

- name: Scan Terraform
  uses: aquasecurity/tfsec-action@v1.0.0

Stage 5: Deploy

Admission Control:

# Kubernetes admission policy
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sDisallowedTags
metadata:
  name: no-latest-tag
spec:
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
  parameters:
    tags: ["latest"]

Stage 6: Runtime

Runtime Protection:

Essential Tools

Static Analysis (SAST)

LanguageTools
PythonBandit, Semgrep, Snyk
JavaScriptESLint, npm audit, Snyk
Gogosec, staticcheck
JavaSpotBugs, Checkmarx
MultiSonarQube, Veracode

Dependency Scanning

# Python
pip-audit
safety check

# JavaScript
npm audit
yarn audit

# Universal
snyk test

Container Security

# Scan images
trivy image myapp:latest

# Scan Dockerfile
hadolint Dockerfile

# Scan running containers
falco

Infrastructure as Code

# Terraform
tfsec .
checkov -d .

# Kubernetes
kubesec scan deployment.yaml
kube-bench

Implementing DevSecOps

Phase 1: Foundation

  1. Inventory: Know your dependencies, containers, infrastructure
  2. CI/CD pipeline: Automated builds and deployments
  3. Version control: Everything as code

Phase 2: Integration

  1. Add scanning: Start with one tool per category
  2. Gate deployments: Block on critical vulnerabilities
  3. Train developers: Security awareness

Phase 3: Automation

  1. Auto-fix: Dependabot, Renovate for dependency updates
  2. Policy as code: OPA, Gatekeeper for enforcement
  3. Self-service: Security tools accessible to developers

Phase 4: Culture

  1. Security champions: Developers leading security in teams
  2. Blameless postmortems: Learn from incidents
  3. Continuous improvement: Regular security reviews

Common Pitfalls

Too Many Alerts

Start with critical/high severity only:

# Don't do this
- run: trivy --severity CRITICAL,HIGH,MEDIUM,LOW

# Do this
- run: trivy --severity CRITICAL,HIGH

Add more over time as you reduce backlog.

Blocking Everything

Start in report mode, then enforce:

# Week 1-2: Warn
- run: snyk test --severity-threshold=critical || true

# Week 3+: Block
- run: snyk test --severity-threshold=high

Ignoring Developers

Security tools should:

Metrics

Track progress:

Final Thoughts

DevSecOps isn’t about tools—it’s about integrating security into how you build software. The goal is making secure development the path of least resistance.

Start small. Add one security check to your pipeline. Fix what it finds. Iterate.


Security is everyone’s job. Make it easy.

All posts