A scanner that prints a pass/fail verdict gives you nothing to hand an auditor six months later, and nothing to compare against when a base-image bump quietly swaps out forty packages. The fix is to split the job in two: Syft catalogs the image once and writes a software bill of materials, and Grype matches that SBOM against a vulnerability database on every pipeline run. By the end of this article you’ll have a committed SBOM artifact per image tag, a CVE gate that fails a build on high severity, an ignore file that records why each accepted finding is accepted, a vulnerability database that stays fresh (including in an air-gapped runner), and a two-command diff that shows exactly what changed between two tags.
What you’ll accomplish
- A reproducible SBOM per image tag in SPDX and CycloneDX JSON, produced once at build time and stored beside the image.
- A CVE gate that reads the SBOM artifact — no registry pull, no layer extraction — and exits non-zero at a severity threshold you choose.
- A
.grype.yamlignore file that carries a written reason for every accepted or unfixable finding, so exceptions are reviewable instead of invisible. - A vulnerability database refresh strategy that works both in a networked CI runner and in an air-gapped one.
- A package-level diff between two image tags that answers “what did that base bump actually change?” without reading a Dockerfile.
Prerequisites
- Syft v1.x and Grype v0.8x or newer. Both are single Go binaries. On macOS,
brew install syft grype; on Linux, take the release binaries from the Syft and Grype GitHub Releases pages, or install them from your distribution’s packaging if it carries recent versions. - Access to the image: either a local Docker or Podman daemon, or credentials for the registry. Syft can read from a daemon, directly from a registry, or from a
docker savetarball. jqand a Bash shell for the diff and report-parsing steps. Thecommandcutinvocations below are POSIX; the process-substitution form is Bash-only.- Outbound HTTPS from the runner for the first
grype db update, or a mirrored database archive if the runner is isolated. - Command and flag names have been stable for a long time, but the exact wording of progress lines and the
grype db statusoutput has changed across database schema versions. Match on the fields, not on the literal strings.
How it works
Syft mounts each layer of the image, runs a set of catalogers over the resulting filesystem, and records every package it can identify with a package URL and, where possible, a CPE. There is a cataloger per ecosystem: apk for Alpine, dpkg for Debian and Ubuntu, rpm for the RHEL family, plus language catalogers for npm, Python, Go modules, Java archives, Rust crates and more. The output is a list of names, versions, types and file locations — a dependency inventory, not a verdict.
Grype does the second half. It downloads a vulnerability database assembled from distribution security trackers, the GitHub Advisory Database, NVD and language-ecosystem feeds, then matches each package in the SBOM against the right namespace. Alpine’s libcrypto3 is matched against Alpine’s advisories, not against the upstream OpenSSL CPE range, which is why distribution metadata in the SBOM matters so much.
Scanning the SBOM rather than the image is the load-bearing choice. The image is immutable, so cataloging it twice produces the same answer at real cost — pulling layers, extracting them, walking a filesystem. What actually changes between Tuesday and Wednesday is the vulnerability database. Separating the two means the expensive half runs once per build, the cheap half runs as often as you like (nightly against every shipped tag, for instance), and the inventory you scanned is a file you can attach to a release and re-examine later.
Step-by-step
1. Confirm the versions you’re working with. Flag behaviour and database schema both move, so record what produced a given SBOM.
syft version
grype version
Application: syft
Version: 1.20.0
GitDescription: v1.20.0
Platform: linux/amd64
GoVersion: go1.23.4
Grype prints its own version plus the Syft version it embeds and the database schema it expects. If those two Syft versions differ wildly, prefer generating the SBOM with the standalone Syft binary so the artifact is the one you control.
2. Catalog the image once, in more than one format. Syft accepts repeated -o flags with a format=path target, so a single pass writes every representation you need.
syft scan ghcr.io/example/web:1.42.0 \
-o syft-json=sbom.syft.json \
-o spdx-json=sbom.spdx.json \
-o cyclonedx-json=sbom.cdx.json
✔ Loaded image ghcr.io/example/web:1.42.0
✔ Parsed image sha256:6b1c...
✔ Cataloged contents a4f9e2...
├── ✔ Packages [187 packages]
├── ✔ File digests [1,203 files]
└── ✔ Executables [312 executables]
Three files, three audiences. syft-json is the richest and is what you feed back to Grype. spdx-json is what a customer’s compliance team will ask for. cyclonedx-json is what most security platforms ingest. Confirm they are non-empty:
jq '.artifacts | length' sbom.syft.json
jq '.packages | length' sbom.spdx.json
187
187
If the counts diverge sharply, the SPDX conversion dropped something — see Troubleshooting.
3. Scan the SBOM artifact. The sbom: scheme tells Grype the argument is a file, not an image reference.
grype sbom:./sbom.syft.json
✔ Vulnerability DB [no update available]
✔ Scanned for vulnerabilities [14 vulnerability matches]
├── by severity: 1 critical, 3 high, 7 medium, 3 low
└── by status: 9 fixed, 5 not-fixed
NAME INSTALLED FIXED-IN TYPE VULNERABILITY SEVERITY
libcrypto3 3.1.4-r5 3.1.4-r6 apk CVE-2024-2511 Medium
libexpat 2.6.0-r0 2.6.2-r0 apk CVE-2024-28757 High
Note that this ran without touching the registry. On a runner with no image pulled and no daemon, it still works.
4. Turn it into a gate. --fail-on sets the severity at which Grype exits non-zero. Write a machine-readable report at the same time so the failure is diagnosable after the fact.
grype sbom:./sbom.syft.json --fail-on high -o table -o json=grype.json
echo "exit status: $?"
exit status: 1
Exit 0 means nothing at or above high was found. Accepted values are negligible, low, medium, high and critical; the environment-variable form is GRYPE_FAIL_ON_SEVERITY. To see only findings someone can actually act on today, add --only-fixed, which drops matches with no released fix.
5. Record exceptions in .grype.yaml. Some findings are genuinely not applicable, and some have no fix. Suppressing them silently in a shell pipeline is how a real vulnerability gets lost. Put them in a file, with reasons, and review that file the way you review code.
ignore:
- vulnerability: CVE-2024-2511
package:
name: libcrypto3
version: 3.1.4-r5
reason: "Session-cache DoS; TLS terminates at the edge proxy, not in this image."
- vulnerability: CVE-2023-45853
package:
name: zlib
reason: "Affects MiniZip only, which is not compiled into this build."
- vulnerability: GHSA-jrf7-7mfx-3v4v
reason: "Test-only dependency; not present in the runtime layer."
Grype reads .grype.yaml from the working directory, or ~/.grype.yaml, or a path you pass with -c. Prove the rules took effect rather than assuming:
grype sbom:./sbom.syft.json --show-suppressed -c ./.grype.yaml
NAME INSTALLED FIXED-IN TYPE VULNERABILITY SEVERITY
libcrypto3 3.1.4-r5 3.1.4-r6 apk CVE-2024-2511 Medium (suppressed)
A rule with only vulnerability: and no package: block suppresses that CVE across every package in every image you scan from this directory. Scope by package name, and by version where the reason is version-specific, so the exception expires naturally on the next upgrade.
6. Keep the database fresh — deliberately. By default Grype checks for a newer database on every run, which is fine locally and awkward in CI: it adds latency to every job and it means an outage upstream can break a build. Update it once per job, or once per runner, and cache the directory.
grype db status
grype db update
Path: /home/runner/.cache/grype/db/6
Schema: 6.0.0
Built: 2026-08-03T01:24:31Z
Status: valid
Cache ~/.cache/grype/db between pipeline runs, or set GRYPE_DB_CACHE_DIR to a persistent path. In an air-gapped runner, mirror the database archive out of band and pin the tool:
export GRYPE_DB_AUTO_UPDATE=false
export GRYPE_DB_CACHE_DIR=/opt/grype-db
grype db import /opt/grype-db-archives/vulnerability-db.tar.zst
grype sbom:./sbom.syft.json --fail-on high
Grype refuses a database older than a built-in age limit — five days by default — and reports it as an error rather than an empty result, which is the correct behaviour. Air-gapped setups need GRYPE_DB_MAX_ALLOWED_BUILT_AGE raised to match the real mirroring cadence, and a monitor on the mirror job. A stale database that silently reports zero findings is worse than no scanner.
7. Diff two SBOMs to see what a base bump changed. Syft has no diff subcommand; jq plus comm does the job, and the tab-separated form survives package names containing an @.
syft scan ghcr.io/example/web:1.42.0 -o syft-json=sbom-1.42.0.json
syft scan ghcr.io/example/web:1.43.0 -o syft-json=sbom-1.43.0.json
jq -r '.artifacts[] | [.name, .version] | @tsv' sbom-1.42.0.json | sort -u > pkgs-1.42.0.tsv
jq -r '.artifacts[] | [.name, .version] | @tsv' sbom-1.43.0.json | sort -u > pkgs-1.43.0.tsv
comm -13 pkgs-1.42.0.tsv pkgs-1.43.0.tsv
comm -23 pkgs-1.42.0.tsv pkgs-1.43.0.tsv
The first comm lists what appears only in the newer tag, the second what disappeared. A package that was upgraded shows up in both, so to separate genuine additions from version bumps, compare on names alone:
cut -f1 pkgs-1.42.0.tsv | sort -u > names-1.42.0.txt
cut -f1 pkgs-1.43.0.tsv | sort -u > names-1.43.0.txt
comm -13 names-1.42.0.txt names-1.43.0.txt
brotli-libs
ca-certificates
libexpat
sqlite-libs
This is the artifact worth attaching to a base-image upgrade pull request. “Bumped Alpine 3.19 to 3.20” tells a reviewer nothing; four new packages, seven removed and twenty-three upgraded tells them exactly how much surface moved.
8. Attach the SBOM to the image. An SBOM sitting in a build workspace disappears with the runner. Store it as a signed attestation so it travels with the digest — the same Cosign key you already use for images will do, and the mechanics are covered in signing and verifying container images with Cosign.
cosign attest --predicate sbom.spdx.json --type spdxjson \
ghcr.io/example/web@sha256:6b1c...
Validate it works
Run the whole chain from a clean directory against a tag you have never scanned, and check three things: the SBOM is populated, the gate’s exit code matches the findings, and the database that produced the result is recorded.
rm -f sbom.syft.json grype.json
syft scan ghcr.io/example/web:1.42.0 -o syft-json=sbom.syft.json
jq '.artifacts | length' sbom.syft.json
grype sbom:./sbom.syft.json --fail-on high -o json=grype.json
echo "gate exit: $?"
jq '.matches | length, (.ignoredMatches | length)' grype.json
jq '[.matches[] | select(.vulnerability.severity == "High" or .vulnerability.severity == "Critical")] | length' grype.json
jq '.descriptor.db' grype.json
The count of high and critical matches should be zero exactly when the gate exit code is 0. If the counts say zero but the exit code is 1, Grype failed for a reason other than a finding — read stderr. .descriptor.db carries the database build timestamp; log it with every gate result so a “we were clean on Tuesday” claim is checkable.
For a second opinion on the same SBOM, most scanners accept one as input, which is a cheap way to sanity-check coverage — see Docker image security scanning with Trivy and Grype.
Troubleshooting
- The SPDX SBOM finds fewer OS packages than the Syft SBOM. Grype needs to know the distribution to pick the right advisory namespace, and that metadata survives a round-trip through
syft-jsonmore reliably than through the interchange formats. Comparegrype sbom:./sbom.syft.json -o json | jq '.matches | length'against the same command on the SPDX file. If they differ, keepsyft-jsonas the artifact you scan and publish SPDX and CycloneDX for external consumers. Both come out of the samesyft scaninvocation, so this costs nothing. grype sbom:./file.jsonerrors out with an unrecognised format. You almost certainly passed a Grype report rather than a Syft SBOM — the two are both JSON and easy to swap.jq 'keys' file.jsonsettles it: an SBOM hasartifacts(Syft) orpackages(SPDX) orcomponents(CycloneDX); a Grype report hasmatchesanddescriptor.- Exit code 1 is ambiguous. Grype exits 1 both for “policy threshold met” and for “the run failed”. If you need to tell them apart, drop
--fail-on, write-o json=grype.json, and evaluate the report yourself withjq, controlling the exit status in your own script. A missing or unparseable report file then means a tool failure, not a finding. - An ignore rule has no effect. Grype only auto-loads
.grype.yamlfrom the current working directory or your home directory, and CI jobs often run from somewhere else. Pass-c ./.grype.yamlexplicitly and confirm with--show-suppressed; a suppressed match is listed with that marker, an unmatched rule leaves the finding in place unchanged. - The first scan on every CI job takes a minute longer than expected. That is the database download. Cache
~/.cache/grype/db(orGRYPE_DB_CACHE_DIR) as a pipeline cache keyed on the date, and rungrype db updatein a single dedicated step rather than letting every parallel job fetch it. - The same image reports different CVE counts on two consecutive days with no rebuild. That is the system working. The SBOM is identical; the database moved. This is exactly why the SBOM is stored — you can prove the inventory didn’t change and the knowledge did.
When this is the wrong approach
An SBOM records what is installed, not what is reachable or running. Grype will flag a vulnerable library that no code path in your application ever calls, and it has no way to know the difference. If your backlog is dominated by findings nobody can act on, the next tool is not a better scanner — it is reachability analysis, exploit-prediction scoring, or a VEX document from the vendor stating the component is not affected.
Catalogers depend on package metadata being present. Statically linked C binaries, vendored source trees copied in with no manifest, and anything installed by make install will not appear. Go binaries are an exception because the toolchain embeds build information, but you should not assume an empty SBOM section means an empty risk section — check what percentage of the image the package count plausibly accounts for.
If what you need is misconfiguration checks, secret detection, Kubernetes manifest linting or infrastructure-as-code scanning, this pipeline does none of it. Reach for a scanner with those modes instead of stretching Syft and Grype into a role they were not built for.
And if you are one engineer scanning one image on a laptop, grype ghcr.io/example/web:1.42.0 is one command and it is the right one. The SBOM-first split earns its keep when you have many images, a compliance obligation, or a need to answer questions about a build that shipped last quarter.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.