Sachin Chaurasiya

Secure · Vulnerability & misconfiguration scanner

Trivy

Trivy scans container images, source trees, Kubernetes clusters and SBOMs for vulnerabilities, secrets and misconfigurations. Single binary, fast, and easy to gate a pipeline with.

Stage
Secure
Category
Vulnerability & misconfiguration scanner
Website
trivy.dev
Documentation
Official docs
License
Apache-2.0
On this page

What it does

Trivy detects OS package and language dependency vulnerabilities, embedded secrets and IaC misconfigurations. It can also emit CycloneDX/SPDX SBOMs and scan SBOMs it or other tools produced.

Where it fits

The Secure stage: scan images after build and before push, scan the repository (trivy fs) in merge requests, and re-scan released images on a schedule. It also runs in-cluster (trivy k8s) for a periodic posture check.

Quick start

trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 registry.example.com/app:1.2.3
trivy fs --scanners vuln,secret,misconfig .
trivy image --format cyclonedx --output app.cdx.json registry.example.com/app:1.2.3

Common pitfalls

  • Gating on unfixed CVEs trains people to ignore the gate — use --ignore-unfixed for the blocking scan.
  • Downloading the DB on every CI job hits registry rate limits; cache TRIVY_CACHE_DIR.
  • Exceptions without expiry become permanent. Prefer .trivyignore.yaml with expired_at.

On this site

  • Secrets and Configuration Security: trivy image --scanners secret finding a GitLab token in a copied .env and a Stripe key in the image configuration, and missing the token in a deleted layer.

Hands-on labs using Trivy

Lab

Secure Docker Images with Trivy

Build a deliberately weak image, scan it with Trivy, and rebuild it until the gate for fixable HIGH and CRITICAL findings passes: current base, non-root user, patched packages, no pip in the runtime image.

beginner 30 minutes Trivy · Docker

Articles about Trivy

Security Tools beginner

Container Image Scanning with Trivy

How Trivy finds OS and application vulnerabilities, secrets and misconfigurations in container images, how to make the results actionable, and how to wire it into CI without slowing builds down.

9 min read
CI/CD intermediate

Building a Secure CI/CD Pipeline with Jenkins

A declarative Jenkins pipeline with secrets scanning, SAST, image scanning and least-privilege credential handling — and the agent, plugin and Docker decisions that keep it that way.

9 min read