Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

Scanning Kubernetes images with Grype, Trivy and CVEs

By updated

Improve this page

Scanning container images before you deploy them is an essential control, but it is only one link in supply chain security. A scanner compares the components of an image with CVE databases to identify known flaws, but it proves neither the integrity, the provenance nor the compliance of the image.

This guide shows the commands and concepts of vulnerability scanning in the Kubernetes ecosystem. It recommends Grype as the main production scanner, because of the incident that hit the Trivy ecosystem in March 2026. The Trivy commands stay in: the tool is still widespread in existing pipelines and in CKS exam preparation.

In March 2026, the Trivy ecosystem suffered a major compromise: a malicious binary was published, GitHub Actions tags were rewritten en masse and Docker Hub images were compromised, all from stolen credentials. Aqua published the details and the remediations in the security advisory GHSA-69fq-xp46-6x23 (CVE-2026-33634). The advisory names binary version 0.69.4 as malicious, and versions 0.69.2 and 0.69.3 as clean.

I no longer recommend Trivy as the main scanner in production. Its commands are here to help you read existing pipelines, but the recommended path now goes through Grype. A supply chain security tool is part of that chain, and it can be compromised like everything else.

What you will learn

  • Read a scan report and sort it with CVSS, EPSS and FIXED-IN
  • Install Grype from a verified binary and block a pipeline with --fail-on
  • Separate the inventory (SBOM with Syft) from the analysis, and rescan without the image
  • Read the Trivy commands you will meet in existing pipelines
  • Explain why two scanners do not return the same result
  • Say what a scan does not prove
  • Prove, unaided, that you can ship a verified image with the module challenge, graded on the state of the cluster

Prerequisites

  • Docker or containerd installed
  • Access to images to scan
  • Security basics: notions of CVE, CVSS, EPSS (→ CVE guide)

Understanding a CVE

Before you scan, you need to know how to read the results. A CVE (Common Vulnerabilities and Exposures) is a unique identifier for a known security flaw. Format: CVE-YEAR-NUMBER.

The CVSS v3 severity scores rank each flaw on a scale from 0 to 10, and most scanners derive the displayed level from them:

ScoreSeverityRecommended action
9.0 – 10.0CRITICALFix immediately, block the deployment
7.0 – 8.9HIGHHandle as a priority, within 48h
4.0 – 6.9MEDIUMPlan for the next sprint
0.1 – 3.9LOWBacklog, fix during regular updates

Grype, my main choice for scanning image vulnerabilities

Grype is developed by Anchore. I favor it for scanning images and SBOMs, for its integration with Syft, and because it takes EPSS, KEV and OpenVEX into account: in other words, it prioritizes the risk that is actually exploited.

Installation

Install Grype from an official binary verified by its SHA256 digest, never with a curl | sh script: fetch the archive and the checksums from the GitHub Releases, check the digest, then extract the binary.

Terminal window
GRYPE_VERSION=0.118.0
cd /tmp
base="https://github.com/anchore/grype/releases/download/v${GRYPE_VERSION}"
curl -sSfLO "${base}/grype_${GRYPE_VERSION}_linux_amd64.tar.gz"
curl -sSfLO "${base}/grype_${GRYPE_VERSION}_checksums.txt"
grep "grype_${GRYPE_VERSION}_linux_amd64.tar.gz" "grype_${GRYPE_VERSION}_checksums.txt" | sha256sum -c -
sudo tar -C /usr/local/bin -xzf "grype_${GRYPE_VERSION}_linux_amd64.tar.gz" grype
grype version

Essential commands

Grype takes an image reference, a local path or an SBOM as its argument, and picks its analysis source from the prefix you use. With no option, it prints every vulnerability it finds and exits with return code 0: it is --fail-on that turns the scan into a pipeline lock. The example image for this whole guide is nginx:1.25.3, deliberately old, and pinned by its digest so that your numbers are comparable with mine.

Terminal window
IMG=nginx:1.25.3@sha256:c7a6ad68be85142c7fe1089e48faa1e7c7166a194caa9180ddea66345876b9d2
# Scan an image from a registry
grype "$IMG"
# Show only the CVEs that have a fix available
grype "$IMG" --only-fixed
# Fail if a CRITICAL CVE is detected (CI/CD)
grype "$IMG" --fail-on critical
# JSON output for parsing
grype "$IMG" -o json > report.json
# From a Syft SBOM
grype sbom:/path/to/sbom.json

What a real report contains

The numbers below come from a scan of this image on 5 October 2026 with grype 0.118.0. They move with every update of the vulnerability database, and they do not hold for yours, but their proportions show up everywhere.

SeverityCount
Critical47
High262
Medium265
Low46
Negligible129
Unknown19
Total768

Seven hundred and sixty-eight lines, and nobody will work through them. The number that makes the report actionable is elsewhere, behind a single option:

Terminal window
grype "$IMG" --only-fixed

355 vulnerabilities out of 768, or 46%, have a fix available. The other four hundred or so cannot be settled by bumping a version: there is nothing to bump to. Starting with --only-fixed therefore sorts what you can act on today from what you will have to track or accept.

The exit code is 2, not 1

A detail that breaks a pipeline written from memory, measured on the same image with grype 0.118.0:

CommandExit code
grype "$IMG"0
grype "$IMG" --fail-on critical2

Without --fail-on, grype succeeds whatever the number of vulnerabilities found: a job that just runs the command will always pass. With the option, the code is 2. A test written as if [ $? -eq 1 ] will therefore never trigger; test for a non-zero value instead.

Example output

The default output is a table, with one line per package and vulnerability pair. The same identifier therefore appears several times if it affects several packages of the image, like CVE-2024-0727 below on libssl3 and openssl.

NAME INSTALLED FIXED-IN TYPE VULNERABILITY SEVERITY
libssl3 3.0.11 3.0.13 deb CVE-2024-0727 MEDIUM
openssl 3.0.11 3.0.13 deb CVE-2024-0727 MEDIUM
expat 2.5.0 (none) deb CVE-2023-52425 MEDIUM
zlib1g 1:1.2.13 (none) deb CVE-2023-45853 MEDIUM

The FIXED-IN column is the most important one: when it is empty, it means that no fix is referenced for that package in the scanner's sources. You then have to decide: update the application, change the base image, remove the component, or accept the risk, documented and dated.

SBOM + Grype workflow

Separating the inventory from the analysis changes the way you work: Syft produces the list of components once and for all, and Grype checks it against the vulnerability databases of the day. The image no longer needs to exist or to be downloaded for you to reassess it six months later.

Terminal window
IMG=nginx:1.25.3@sha256:c7a6ad68be85142c7fe1089e48faa1e7c7166a194caa9180ddea66345876b9d2
# 1. Generate the inventory (SBOM)
syft "$IMG" -o cyclonedx-json > sbom.json
# 2. Scan the SBOM for CVEs
grype sbom:sbom.json --fail-on high
# Advantage: the SBOM can be archived and rescanned every time
# new CVEs are published, without rebuilding the image

This detour costs nothing in completeness, and that is what had to be checked before recommending it. On the same image, the direct scan and the SBOM scan return exactly the same number of matches, 768. The SBOM produced by syft inventories 3,863 components for about 1.3 MB of JSON: a modest artifact, archivable with the version, and rescannable in six months without the image still existing.

→ See the full SBOM guide and the Syft guide (in French).

Trivy, a tool found everywhere in the ecosystem, that I no longer use as the main scanner

Trivy, from Aqua Security, is a tool that is very common in CKS preparation and in the literature around the exam. I keep its commands for general culture and for reading existing pipelines. For a new production pipeline, however, I now prefer Grype for scanning image vulnerabilities.

Installation

Installation goes through Aqua's signed APT repository: the public key is converted into a binary keyring in /usr/share/keyrings/, then referenced by signed-by= in the source. This mechanism limits the trust placed in that key to the Trivy repository alone, unlike the old apt-key add, which authorized it for every repository on the system.

Terminal window
# Debian/Ubuntu
sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update && sudo apt-get install trivy

Essential CKS commands

Trivy is organized by subcommands according to the target: image for a container, fs for a code directory, config for a manifest. The CKS exam mostly expects you to master filtering by severity and --exit-code, which decides whether the scan blocks the chain or not.

Terminal window
IMG=nginx:1.25.3@sha256:c7a6ad68be85142c7fe1089e48faa1e7c7166a194caa9180ddea66345876b9d2
# Scan an image
trivy image "$IMG"
# Ignore CVEs with no fix available
trivy image --ignore-unfixed "$IMG"
# Filter by severity
trivy image --severity CRITICAL,HIGH "$IMG"
# Exit code 1 on a critical CVE (CI/CD)
trivy image --exit-code 1 --severity CRITICAL "$IMG"
# Generate a CycloneDX SBOM
trivy image --format cyclonedx "$IMG" > sbom.json
# Scan the local filesystem (application dependencies)
trivy fs --scanners vuln .
# Scan a Kubernetes manifest
trivy config deployment.yaml

Comparing Grype vs Trivy

Both tools do the same basic job, so the comparison is about their scope and how they rank the results. Trivy covers more types of targets (configuration, IaC, cluster), while Grype focuses on images and SBOMs and pushes prioritization by real exploitation risk further. Use the table below to decide according to what you have to cover, not to name an absolute winner.

CriterionGrypeTrivy
Main targetImages, file systems, SBOMsImages + config/IaC + Kubernetes + SBOMs
EPSS / prioritizationStrong emphasis: EPSS, KEV, risk score, OpenVEXBroader coverage, prioritization less prominent
SBOMScans existing SBOMsNative generation and use
Kubernetes nativeNo equivalent official operatorTrivy Operator
Position in this guideMy main choice for productionKept for ecosystem culture / exam preparation

Trivy Operator, continuous scanning in Kubernetes

The Trivy Operator installs CRDs in the cluster and automatically scans all the images at a regular interval. The results are stored as Kubernetes resources, which kubectl reads like any other object. The chart is pinned to a precise version: 0.36.0 ships operator 0.34.0.

Terminal window
# Install with Helm, chart pinned
helm repo add aquasecurity https://aquasecurity.github.io/helm-charts/
helm install trivy-operator aquasecurity/trivy-operator \
--namespace trivy-system \
--create-namespace \
--version 0.36.0 \
--set trivy.ignoreUnfixed=true
# List the vulnerability reports
kubectl get vulnerabilityreports -A
# Detail of one report
kubectl describe vulnerabilityreport <name> -n <namespace>

CI/CD integration

A scan only has an effect if it can stop the chain. The principle is the same on every platform: build the image, scan it, and let the scanner's non-zero exit code fail the job. What remains is deciding on the blocking threshold, knowing that a --fail-on critical that is too strict on an old base image blocks everyone from day one.

The examples that follow show the minimal mechanics of a scan, not a production pipeline. The difference comes down to one point: do not download your scanner from the Internet on every run. That is exactly the path by which the March 2026 incident spread. Build an internal job image, versioned and validated, that embeds the scanner and its databases.

GitHub Actions

The checkout action is pinned by SHA rather than by tag, which protects against the rewriting of a Git tag in the action's repository, exactly the method observed during the March 2026 incident. The workflow's permissions: {} removes every default right from the GITHUB_TOKEN, and the job takes back only read access to the repository. The built image is tagged with the commit SHA: a unique identifier per build, which has no registry digest yet since it has not been pushed.

.github/workflows/scan.yml
name: scan-image
on: [push]
permissions: {}
jobs:
scan:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Build image
run: docker build -t myapp:${{ github.sha }} .
- name: Scan with Grype
run: |
GRYPE_VERSION=0.118.0
base="https://github.com/anchore/grype/releases/download/v${GRYPE_VERSION}"
curl -sSfLO "${base}/grype_${GRYPE_VERSION}_linux_amd64.tar.gz"
curl -sSfLO "${base}/grype_${GRYPE_VERSION}_checksums.txt"
grep "grype_${GRYPE_VERSION}_linux_amd64.tar.gz" "grype_${GRYPE_VERSION}_checksums.txt" | sha256sum -c -
sudo tar -C /usr/local/bin -xzf "grype_${GRYPE_VERSION}_linux_amd64.tar.gz" grype
grype myapp:${{ github.sha }} --fail-on critical

GitLab CI

The job downloads the Grype archive and its checksums file, and checks the digest with sha256sum -c before extracting anything. This sequence is the bare minimum for a binary fetched from the Internet, and it fails loudly if the archive has been tampered with. The two docker images carry the same digest: in the official image, the bare tag 29.8.2 is an alias of 29.8.2-dind, so this is not a copy error.

.gitlab-ci.yml
scan:
stage: test
image: docker:29.8.2@sha256:7dcdfc4a20246236f558175182ccace1eb15a41bd3eb119dd2284f393498b7c1
services:
- docker:29.8.2-dind@sha256:7dcdfc4a20246236f558175182ccace1eb15a41bd3eb119dd2284f393498b7c1
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- apk add --no-cache curl tar
- |
GRYPE_VERSION=0.118.0
base="https://github.com/anchore/grype/releases/download/v${GRYPE_VERSION}"
curl -sSfLO "${base}/grype_${GRYPE_VERSION}_linux_amd64.tar.gz"
curl -sSfLO "${base}/grype_${GRYPE_VERSION}_checksums.txt"
grep "grype_${GRYPE_VERSION}_linux_amd64.tar.gz" "grype_${GRYPE_VERSION}_checksums.txt" | sha256sum -c -
tar -C /usr/local/bin -xzf "grype_${GRYPE_VERSION}_linux_amd64.tar.gz" grype
grype $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --fail-on critical

Troubleshooting

The difficulty of scanning is almost never technical: it comes from the volume of results and their interpretation. A first scan of an application image commonly returns several hundred lines, most of them with no fix available and no exploitability in your context. The symptoms below cover the cases met during setup, from the initial noise to the differences between tools.

SymptomLikely causeSolution
Too many MEDIUM/LOW CVEsNo filteringTrivy: --severity HIGH,CRITICAL. Grype: --only-fixed, and --fail-on high to block
CVE with no FIXED-INNo fix referencedWeigh the alternatives: application update, base change, removing the component
Repeated false positivesCVE not applicable to your contextCreate .grype.yaml with ignore: or formalize with OpenVEX
Trivy DB outdatedLocal database expiredtrivy image --download-db-only
Slow scan in CI/CDDatabase downloaded on every runCache the database in the pipeline
Distroless / Wolfi imageFewer OS packagesScan anyway, application libraries remain visible
Different results between two scannersDifferent sources and matching rulesNormal, define a reference scanner and document the differences
CVE not exploitable in your contextContextual false positiveFormalize the risk acceptance with OpenVEX or .grype.yaml

Two scanners do not return the same result, and that is normal

The gap is measurable, on the same day and the same digest. On nginx:1.25.3, grype 0.118.0 and Trivy 0.74.0 return 476 and 498 distinct CVEs respectively, of which 473 are common. Three appear only with grype, twenty-five only with Trivy.

That is 95% overlap, and about thirty divergences. Neither is wrong: the databases, the matching rules and the package metadata differ. The practical consequence is that you must pick a reference scanner and stick to it, otherwise every change of tool produces a wave of new alerts that matches no change in your images. And document the exceptions against that scanner, not in the absolute.

Ignoring false positives with Grype

The .grype.yaml file placed at the root of the project removes from the results the vulnerabilities listed under ignore:. Each exception must carry a written reason: an exclusion with no justification becomes unverifiable as soon as its author leaves the team, and nobody dares remove it any more.

.grype.yaml
ignore:
# CVE does not apply to our build (Java not used)
- vulnerability: CVE-2023-XXXXX
reason: "Not applicable - Java runtime not present"
# All CVEs without a fix for this package
- package:
name: libcurl
fix-state: not-fixed
reason: "No fix published, risk accepted and reviewed at every base image update"

The second rule is broader than the first: it hides every CVE without a fix for a package, including those that will be published tomorrow. An exception of that scope is justified in writing and reviewed on a fixed date, for example at every base image update, otherwise it hides indefinitely flaws that you should have re-examined.

Limits of vulnerability scanning

A scanner answers a single question: do the components present in this image appear in a database of known vulnerabilities? It says nothing about what the code does, nor about who built it, nor about what the image will run once deployed. Confusing the absence of critical CVEs with the safety of the image is a common mistake, and the March 2026 Trivy incident gives a direct example.

The most important limit to remember from this guide: an image with no known CVE is not a safe image. It may have been tampered with, come from a compromised source, or carry malicious code that no vulnerability database references. The Trivy incident is itself the demonstration.

The scan covers one question, "which known flaws does this image contain", and only that one. Four other mechanisms answer the neighboring questions: the signature with Cosign establishes integrity, provenance in the SLSA sense establishes the origin of the build, the admission policy decides what enters the cluster, and runtime monitoring detects what departs from the expected behavior. None replaces the others.

Put it into practice

Replacing a vulnerable image requires proving that the replacement is better, not that it is newer. This lab has you scan with Trivy, the tool expected at the CKS exam, an image three years old, choose its replacement, and the validation scans both and requires strictly fewer critical flaws than the original.

Challenge: let only verified images in

The challenge is the unaided proof of the module "Supply chain", and it is graded on the state of the cluster you leave behind, not on the commands you typed. Today the cluster runs only images that are neither pinned, nor scanned, nor signed. You pin a Deployment to its digest, you clear a Dockerfile of the static analysis findings, you sign an image and publish its public key, you replace a vulnerable image, then you make the cluster refuse, at creation, any image whose signature does not verify. No procedure is given.

The validation reads ten states, with no solution or value to copy. It asks the node's runtime what is really running, reruns the static analysis and the vulnerability scans, verifies the signatures with the key published in the cluster, then submits two Pods to admission without creating them.

Passing takes 70 points out of 100, and there are no hints. Three states are blocking and must pass whatever the total: the declared digest is the one the node runs, with both replicas running; the new image carries strictly fewer critical flaws than the old one; the cluster refuses an unsigned image while accepting the signed image.

dsoxlab check lists the states that are not satisfied, without saying how to fix them: the lesson to go back to is the one that teaches that state. The challenge draws on this lesson, on Kubernetes supply chain security, on Signing and verifying an image and on Kyverno.

Key points

  • Grype: my main choice for scanning images and SBOMs in production, with a focus on EPSS, KEV and OpenVEX
  • Trivy: a tool that is still very well known and functionally broad, which I no longer keep as the main scanner after the March 2026 incident
  • An image scan is not enough: complement it with signing, provenance, admission policies and runtime controls
  • EPSS + CVSS: cross the two signals to prioritize, EPSS alone is not enough
  • --fail-on returns 2, not 1: test for a non-zero code, and without the option the scan always succeeds
  • In CI/CD: avoid downloading scanners on the fly; prefer internal, frozen job images
  • Empty FIXED-IN: no fix referenced at this point in time, weigh the alternatives rather than wait
  • SBOM: generate with Syft, scan with Grype = a clean separation of responsibilities, same number of matches

Knowledge check

The questions cover what has just been explained: reading a scan result, prioritisation with CVSS and EPSS, and the exact scope of what a scanner proves.

Knowledge check

Check what you have learned with this interactive quiz

7 questions
8 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer