Skip to main content

DevSecOps — Shift Security Left Without Slowing Down

· 7 min read
Goel Academy
DevOps & Cloud Learning Hub

The average cost of a data breach hit $4.88 million in 2024, and the average time to detect one was 194 days. DevSecOps aims to flip this by embedding security into every stage of the development lifecycle — not as a gate at the end, but as a continuous practice from the first line of code.

What Is DevSecOps?

DevSecOps integrates security practices into the DevOps workflow. Instead of a separate security review before release (which creates bottlenecks and adversarial relationships), security checks run automatically at every stage:

Traditional Model:
Dev → Build → Test → [Security Review] → Deploy
↑ 2-week bottleneck
↑ Findings are expensive to fix

DevSecOps Model:
[Pre-commit hooks] → [CI Security Gates] → [Runtime Protection]
Secret detection SAST, SCA, DAST WAF, RASP, monitoring
Linting Container scanning Anomaly detection
Local scanning IaC scanning Incident response

The key principle: security findings should reach the developer who wrote the code, in the same PR, within minutes — not weeks later via a PDF report.

The Shift-Left Security Model

"Shift left" means moving security earlier in the development process. The earlier you find a bug, the cheaper it is to fix:

StageCost to FixExample Finding
IDE / Pre-commit$1xHardcoded API key detected
Pull Request / CI$5xSQL injection in new endpoint
Staging / QA$15xMisconfigured S3 bucket in Terraform
Production$100xData breach from unpatched dependency

Security Gates in CI/CD

A mature DevSecOps pipeline has security checks at every stage:

# .github/workflows/devsecops-pipeline.yaml
name: DevSecOps Pipeline

on:
pull_request:
branches: [main]

jobs:
secret-detection:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect secrets with Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Semgrep SAST
uses: semgrep/semgrep-action@v1
with:
config: >-
p/owasp-top-ten
p/nodejs
p/typescript

sca:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Snyk dependency scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high

container-scan:
runs-on: ubuntu-latest
needs: [sast, sca]
steps:
- uses: actions/checkout@v4
- name: Build container image
run: docker build -t app:${{ github.sha }} .
- name: Scan with Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: app:${{ github.sha }}
severity: CRITICAL,HIGH
exit-code: 1
format: sarif
output: trivy-results.sarif
- name: Upload to GitHub Security
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-results.sarif

iac-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Scan Terraform with Checkov
uses: bridgecrewio/checkov-action@v12
with:
directory: terraform/
framework: terraform
soft_fail: false

Security Tools Comparison

Choosing the right tools for each security domain:

CategoryToolTypeLanguage SupportFree TierCI Integration
SASTSemgrepStatic analysis30+ languagesYes (OSS rules)GitHub, GitLab
SASTSonarQubeStatic analysis25+ languagesCommunity EditionAll major CI
SCASnykDependency scanNode, Python, Java, Go200 tests/monthGitHub, GitLab
SCADependabotDependency scanAll GitHub languagesFreeGitHub native
ContainerTrivyImage scannerOS packages + appsFully open sourceAll major CI
ContainerGrypeImage scannerOS packages + appsFully open sourceAll major CI
IaCCheckovIaC scannerTerraform, K8s, CloudFormationOpen sourceAll major CI
IaCtfsecTerraform scannerTerraform onlyOpen sourceAll major CI
DASTOWASP ZAPDynamic scannerAny web appFully open sourceDocker-based
SecretsGitleaksSecret detectionGit reposFully open sourceGitHub Action
SecretsTruffleHogSecret detectionGit repos + moreOpen sourceAll major CI

Secret Detection with Gitleaks

Leaked credentials are the number one cause of breaches. Catch them before they reach the repo:

# Install gitleaks
brew install gitleaks

# Scan current repo for secrets
gitleaks detect --source . --verbose

# Scan only staged changes (pre-commit hook)
gitleaks protect --staged --verbose

# Custom config for your org
# .gitleaks.toml
# .gitleaks.toml — Custom rules
title = "Company Gitleaks Config"

[allowlist]
paths = [
'''(.*?)test(.*?)''',
'''\.gitleaks\.toml''',
]

[[rules]]
id = "internal-api-key"
description = "Internal API Key"
regex = '''ACME_API_KEY_[A-Za-z0-9]{32}'''
tags = ["key", "internal"]

[[rules]]
id = "database-url"
description = "Database Connection String"
regex = '''(postgres|mysql|mongodb)://[^:]+:[^@]+@[^/]+/\w+'''
tags = ["database", "credentials"]

Set up a pre-commit hook so secrets never leave the developer's machine:

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

Dependency Scanning

Over 80% of modern application code comes from open-source dependencies. One vulnerable transitive dependency can compromise your entire application:

# Scan Node.js project with Snyk
snyk test --severity-threshold=high

# Output:
# ✗ High severity: Prototype Pollution
# Package: lodash@4.17.20
# Fix: Upgrade to lodash@4.17.21
# Path: express > lodash
#
# ✗ Critical severity: Remote Code Execution
# Package: log4j-core@2.14.1
# Fix: Upgrade to log4j-core@2.17.1

# Auto-fix where possible
snyk fix

# Monitor continuously (sends alerts for new CVEs)
snyk monitor

Container Image Scanning with Trivy

Containers inherit vulnerabilities from their base images. Scan them in CI:

# Scan a container image
trivy image --severity HIGH,CRITICAL python:3.11-slim

# Scan and fail if critical vulns found
trivy image --exit-code 1 --severity CRITICAL myapp:latest

# Scan a Dockerfile for misconfigurations
trivy config Dockerfile

# Scan a running Kubernetes cluster
trivy k8s --report summary cluster
# Sample Trivy output:
myapp:latest (debian 12.4)
Total: 3 (HIGH: 2, CRITICAL: 1)

┌───────────────┬──────────────┬──────────┬─────────────┬────────────────┐
│ Library │ Vulnerability│ Severity │ Installed │ Fixed │
├───────────────┼──────────────┼──────────┼─────────────┼────────────────┤
│ openssl │ CVE-2024-001 │ CRITICAL │ 3.0.11 │ 3.0.13 │
│ curl │ CVE-2024-002 │ HIGH │ 7.88.1 │ 7.88.2 │
│ libxml2 │ CVE-2024-003 │ HIGH │ 2.9.14 │ 2.9.16 │
└───────────────┴──────────────┴──────────┴─────────────┴────────────────┘

Security Champions Program

Tools alone don't create a security culture. A security champions program embeds security expertise across teams:

Security Champions Model:

Central Security Team (2-3 people)

├── Champion: Payments Team (1 dev)
├── Champion: Search Team (1 dev)
├── Champion: Platform Team (1 dev)
└── Champion: Mobile Team (1 dev)

Champions receive:
- 4 hours/week dedicated to security work
- Advanced security training
- Direct channel to security team
- Authority to approve security exceptions

Champions provide:
- First-pass security reviews for their team
- Threat modeling for new features
- Triage of automated scan findings
- Security awareness within their team

DevSecOps Maturity Model

Assess where your organization stands:

LevelNameCharacteristics
0Ad-hocNo security in pipeline; annual pen test only
1ReactiveSecret scanning and dependency checks in CI
2ProactiveSAST + SCA + container scanning; security gates block PRs
3IntegratedThreat modeling per feature; IaC scanning; DAST in staging
4OptimizedAutomated remediation; security metrics dashboard; champions program
5ContinuousRuntime protection (RASP); continuous compliance; chaos security testing

Most organizations should aim for Level 2-3 within 6 months. Level 4-5 requires organizational commitment and dedicated security engineering resources.

Quick Wins to Start Today

If you're starting from zero, implement these in order:

# Week 1: Enable Dependabot (free, zero config)
# → GitHub repo → Settings → Security → Enable Dependabot alerts

# Week 2: Add secret scanning pre-commit hook
pip install pre-commit
# Add .pre-commit-config.yaml with gitleaks (shown above)
pre-commit install

# Week 3: Add Trivy container scanning to CI
# Add the trivy-action step (shown above) to your pipeline

# Week 4: Add Semgrep SAST to CI
# Add the semgrep-action step (shown above) to your pipeline

# Month 2: Implement IaC scanning with Checkov
pip install checkov
checkov -d terraform/ --framework terraform

Each step takes less than an hour to implement and immediately raises your security posture.

Closing Note

DevSecOps isn't about making developers into security experts — it's about giving them fast, automated feedback so security issues never make it past the PR stage. In the next post, we'll dive deep into Observability — exploring distributed tracing with Jaeger and OpenTelemetry to understand complex system behavior.