Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 30Security · Containers

How to scan a container image for vulnerabilities

Every image contains an OS and libraries — and some of them have known vulnerabilities (CVEs). Trivy finds them in seconds: in images, folders, Git repos, IaC files and Kubernetes. The hard part is not the scan, it is acting on the results: what to fix first, how to stop bad images in CI without blocking everything, and how to accept a risk in a documented way. This how-to covers the scan and the workflow around it.

  • 5 Lessen
  • 3 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

30.1

The quick answer

trivy image nginx:1.27
trivy image --severity HIGH,CRITICAL --ignore-unfixed registry.example.com/shop/api:1.4.2
trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed registry.example.com/shop/api:1.4.2
trivy fs --scanners vuln,secret,misconfig .

The first run downloads the vulnerability database. Install Trivy from the official repository (see the full guide).

Commando's in deze les

30.2

Step by step

  1. Read the result table:
trivy image --severity HIGH,CRITICAL shop/api:1.4.2
shop/api:1.4.2 (debian 12.8)
Total: 3 (HIGH: 2, CRITICAL: 1)
┌──────────┬────────────────┬──────────┬────────┬───────────────────┬───────────────────┐
│ Library  │ Vulnerability  │ Severity │ Status │ Installed Version │ Fixed Version     │
├──────────┼────────────────┼──────────┼────────┼───────────────────┼───────────────────┤
│ libssl3  │ CVE-2026-12345 │ CRITICAL │ fixed  │ 3.0.15-1~deb12u1  │ 3.0.17-1~deb12u1  │
└──────────┴────────────────┴──────────┴────────┴───────────────────┴───────────────────┘

The two most useful columns: Status (fixed = an update exists) and Fixed Version.

  1. Fix in this order:
FindingUsual fix
OS package, fixedRebuild on a newer base image tag (docker build --pull).
App library (pip, npm, Maven, Go)Update the dependency in your lock file.
Many findings from tools you do not needSmaller base: slim, distroless, multi-stage.
affected / will_not_fix (no fix yet)Check if the code path is used; document; watch for a fix.
  1. Gate the pipeline — fail only on what you can act on, so the team does not ignore the gate:
trivy image --exit-code 1 --severity CRITICAL,HIGH --ignore-unfixed --no-progress registry.example.com/shop/api:1.4.2

Exit code 1 stops the CI job. Start with CRITICAL only, then add HIGH.

  1. Accept a risk in a documented way — a .trivyignore file in the repo, with a reason and a date:
.trivyignore
# CVE in a parser we do not call; review again 2027-01-15 (ticket SEC-142)
CVE-2026-12345
  1. More than images:
trivy fs --scanners secret .
trivy config ./terraform
trivy image --format cyclonedx -o sbom.cdx.json registry.example.com/shop/api:1.4.2
trivy k8s --report summary

Secrets in code, misconfigured Terraform/Kubernetes files, an SBOM for the image, and the whole cluster.

  1. Scan again regularly — new CVEs are found every day in images that did not change. Rescan the images you run (daily in CI, or in the registry: Harbor scans on push and on a schedule).

30.3

Check that it worked

After the rebuild with the newer base image, the same command shows fewer findings (Total: goes down), and the pipeline gate passes with exit code 0:

trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed shop/api:1.4.3 && echo "gate passed"

30.4

Common problems

ProblemCauseFix
Hundreds of findings, team gives upBig base image, all severities shown.Slim base; gate on CRITICAL,HIGH with --ignore-unfixed; fix in batches.
Rebuild did not reduce findingsThe old base image was cached.docker build --pull --no-cache; use a newer base tag.
CI fails with TOOMANYREQUESTS / DB download errorsRate limits on the DB download.Cache the DB between jobs, or use a mirror (--db-repository).
Same CVE found again and again with no fixUpstream has no fix yet.--ignore-unfixed in the gate; a dated .trivyignore entry.
A secret is reported in the imageA key or .env was copied in.Remove it, rotate the secret, add .dockerignore.
A pinned GitHub Action or Trivy version changed behaviourSecurity tools are supply-chain targets too.Install from the official repo; pin actions by commit SHA; read release notes.

30.5

Go further

1What does --ignore-unfixed do, and why use it in a CI gate?

It hides findings with no fixed version yet, so the gate fails only on things the team can fix now.

2Your image did not change for months. Why scan it again?

New CVEs are published every day; old images get new findings.

Alle commando's in dit hoofdstuk