惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
J
Java Code Geeks
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
腾讯CDC
博客园 - 司徒正美
B
Blog RSS Feed
博客园 - 三生石上(FineUI控件)
I
InfoQ
N
Netflix TechBlog - Medium
L
LangChain Blog
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
美团技术团队
The Cloudflare Blog
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
H
Help Net Security
Martin Fowler
Martin Fowler
V
Visual Studio Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
DevSecOps in Practice: Tools That Actually Catch Vulnerab...
Hariharan · 2026-04-26 · via DEV Community

Hariharan

The previous parts secured the code and the infrastructure. This part secures the container image — the thing that actually runs in production.
When you build a Docker image, you're not just shipping your application.
You're shipping the entire base image underneath it — the OS, the system
libraries, the package manager, all of it. Every CVE in those packages is
now your problem.

Code repo: https://github.com/pkkht/devsecops-demo/

What container scanning is
Container scanning analyses a built Docker image for known vulnerabilities. It inspects the OS layer, every installed package, and the application dependencies, then cross-references each one against public CVE databases. The key insight: most of the vulnerabilities in a container image come from the base image, not from the application code. Choosing an old or full base image can introduce hundreds of vulnerabilities before you've written a single line of your own code.

The tool: Trivy
Trivy is an open source vulnerability scanner from Aqua Security. It scans container images, filesystems, git repositories, Kubernetes clusters, and more. It queries multiple vulnerability databases including the NVD, GitHub Advisory Database, and OS-specific advisories. It's free, fast, and requires no account or API key.

The demo Dockerfile
The Dockerfile in the repo has two intentional issues:

# ISSUE 1: Using python:3.8 (not slim, not alpine)
# An older, full base image with many OS-level packages = more CVE surface.
# The fix: use python:3.11-slim or python:3.11-alpine.
FROM python:3.8

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .

# ISSUE 2: No USER directive — container runs as root
# Running as root means if the app is compromised, the attacker
# has root inside the container.
# The fix:
#   RUN adduser --disabled-password --gecos '' appuser
#   USER appuser

EXPOSE 5000
CMD ["python", "app.py"]

Enter fullscreen mode Exit fullscreen mode

python:3.8 is a full Debian-based image. It includes everything — compilers, build tools, image processing libraries, the lot. Most of it is unnecessary for running a Flask API, but all of it adds CVE surface.

GitHub Actions workflow
Create .github/workflows/container-scan.yml:

name: Container Scan - Trivy

on:
  push:
    branches: ["**"]
  pull_request:
    branches: ["**"]

jobs:
  trivy:
    name: Trivy Container Scan
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build Docker image
        run: docker build -t devsecops-demo:${{ github.sha }} .

      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: devsecops-demo:${{ github.sha }}
          format: json
          output: trivy-report.json
          severity: CRITICAL,HIGH
          exit-code: 1

      - name: Upload Trivy Report
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: trivy-report
          path: trivy-report.json

Enter fullscreen mode Exit fullscreen mode

severity: CRITICAL,HIGH tells Trivy to only report and gate on CRITICAL and HIGH findings — ignoring MEDIUM and LOW keeps the noise manageable.
exit-code: 1 fails the build when findings are found.

What the pipeline found

The pipeline failed immediately.

The trivy-report.json artifact from the Actions run tells the full story.
Total: 1,747 vulnerabilities
OS layer (Debian 12.7): 1,736 vulnerabilities
CRITICAL: 185
HIGH: 1,551

Python packages: 11 vulnerabilities
HIGH: 11

OS layer findings
The python:3.8 base image ships with ImageMagick, which alone accounts for
185 CRITICAL findings. ImageMagick is an image processing library with a long history of CVEs. You almost certainly don't need it in a Flask API container, but because python:3.8 is a full Debian image, it's there anyway.

Python package findings
The application dependencies contributed 11 HIGH severity findings:

These overlap with what pip-audit found in Part 4 — Trivy is scanning the same packages but from inside the built image rather than from
requirements.txt. Both tools catching the same issues is a good sign.

A sample finding from the JSON report

{
  "VulnerabilityID": "CVE-2023-30861",
  "PkgName": "Flask",
  "InstalledVersion": "1.1.2",
  "FixedVersion": "2.2.5, 2.3.2",
  "Severity": "HIGH",
  "Title": "Flask vulnerable to possible disclosure of permanent session cookie"
}

Enter fullscreen mode Exit fullscreen mode

The fix is simple

Both issues in the Dockerfile have straightforward fixes:
Switch to a slim base image:

# Before
FROM python:3.8

# After
FROM python:3.11-slim

Enter fullscreen mode Exit fullscreen mode

python:3.11-slim is a minimal Debian image — no ImageMagick, no compilers, no build tools. The CVE count drops dramatically.

Add a non-root user:

RUN adduser --disabled-password --gecos '' appuser
USER appuser

Enter fullscreen mode Exit fullscreen mode

The container no longer runs as root.
These two changes would eliminate the vast majority of the 1747 findings.
They are intentionally left in the demo so the pipeline has something real
to catch.

What we've built so far
Six layers now in place:

  • Gitleaks pre-commit — blocks secrets at commit time
  • Gitleaks GitHub Actions — catches secrets at push time
  • Bandit GitHub Actions — catches code vulnerabilities, gates on HIGH
  • pip-audit GitHub Actions — catches vulnerable dependencies
  • Checkov GitHub Actions — catches Terraform misconfigurations
  • Trivy GitHub Actions — catches CVEs in the container image