Sub topic 3
Filtering Container Image Vulnerabilities
Assume you know basic Docker commands, can read a Dockerfile, and understand that an image contains software packages. A scanner reports a vulnerability when a package matches an advisory in its database.
Filter by severity and fix status
Severity helps prioritize work. A high or critical finding usually needs faster attention than a low finding. An unfixed vulnerability has no vendor-provided patched version yet.
trivy image --severity HIGH,CRITICAL --ignore-unfixed python:3.12-slimThis command reports only high and critical findings that have a known fix. Filtering is useful for a release gate, but do not confuse it with a complete inventory. Review all severities regularly.
Export reports and SBOMs
JSON is useful when CI systems or dashboards need structured results. An SBOM, or Software Bill of Materials, is an inventory of packages and their versions.
trivy image --format json --output result.json python:3.12-slim
trivy image --format cyclonedx --output sbom.cdx.json python:3.12-slimCycloneDX is a standard SBOM format. Store scan results with the build so you can investigate which image version introduced a package.
Triage findings
For each finding, check the affected package, severity, exploitability, available fix, and whether the package is reachable at runtime. Document accepted risk rather than hiding it silently.
# .trivyignore
# Accepted until the upstream fix ships; reviewed each sprint.
CVE-2024-00000An ignore file is a temporary exception. Give it an owner, reason, and review date in your project process.
Fix the image
Update the base image and rebuild regularly. A multi-stage build keeps compilers and build tools out of the runtime image.
FROM golang:1.22 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app .
FROM gcr.io/distroless/static-debian12
COPY --from=build /app /app
ENTRYPOINT ["/app"]Gate CI
Use an exit code so CI fails when serious findings exist.
#!/bin/sh
set -e
IMAGE="$1"
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 "$IMAGE"
docker scout cves --only-severity critical,high --exit-code "$IMAGE"Why tools disagree
Docker Scout and Trivy can use different vulnerability databases, package detection methods, severity mappings, and database update times. One tool may identify an operating-system package differently from the other. Compare package versions, advisory IDs, and database timestamps before deciding that a result is incorrect.
| Difference | Possible effect |
|---|---|
| Database or mapping | Different severity or advisory status |
| Package detection | One tool finds a dependency the other misses |
| Update timing | One tool knows about a fix earlier |
Exercise
What does --ignore-unfixed remove from a Trivy report?
Show answer
It removes vulnerabilities for which the scanner has no known fixed version. It does not prove that the remaining image is safe.