Scanning with Grype
Grype (Anchore, Apache-2.0) is Syft's partner: it catalogs a target with Syft's library (or reads an SBOM you already have) and matches every package against its vulnerability database.
grype [SOURCE] [flags] # same source schemes as syft: dir:, registry:, docker-archive:, oci-dir:, sbom:Three targets
The same tool scans an image, a source directory and a stored SBOM. In CI you usually scan the SBOM you already generated: it's faster, and it guarantees that the scan and the published SBOM describe the same thing.
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/demo/alpine:3.18.0 > /dev/null 2>&1
summary() { jq -r '[.matches[].vulnerability.severity] | group_by(.) | map("\(.[0]): \(length)") | join(", ")'; }
echo "image: $(grype registry:localhost:5000/demo/alpine:3.18.0 -q -o json | summary)"
echo "dir: $(grype dir:/opt/samples/python-app -q -o json | summary)"
syft scan /opt/samples/node-app -q -o cyclonedx-json=node-app.cdx.json
echo "sbom: $(grype sbom:node-app.cdx.json -q -o json | summary)"image: Critical: 5, High: 10, Low: 6, Medium: 42
dir: High: 8, Medium: 12
sbom: Critical: 1, High: 3, Medium: 3
These counts are what the database contained when this course's image was built; run the same commands next month against a fresh database and they will be higher. Don't hard-code them anywhere.
The table
The default output is a table sorted by risk (Grype's combination of severity, EPSS and KEV), so the top rows are where to start:
grype /opt/samples/images/alpine-3.18.0.tar -q | head -8NAME INSTALLED FIXED IN TYPE VULNERABILITY SEVERITY EPSS RISK
libcrypto3 3.1.0-r4 3.1.7-r0 apk CVE-2024-6119 High 66.6% (99th) 49.9
libssl3 3.1.0-r4 3.1.7-r0 apk CVE-2024-6119 High 66.6% (99th) 49.9
libcrypto3 3.1.0-r4 3.1.1-r0 apk CVE-2023-2650 Medium 75.4% (99th) 43.3
libssl3 3.1.0-r4 3.1.1-r0 apk CVE-2023-2650 Medium 75.4% (99th) 43.3
libcrypto3 3.1.0-r4 3.1.4-r6 apk CVE-2024-2511 Medium 52.4% (98th) 28.6
libssl3 3.1.0-r4 3.1.4-r6 apk CVE-2024-2511 Medium 52.4% (98th) 28.6
libcrypto3 3.1.0-r4 3.1.6-r0 apk CVE-2024-5535 Critical 5.6% (92nd) 5.1
Read one row: package libcrypto3 version 3.1.0-r4 is installed, Alpine fixed the vulnerability in 3.1.7-r0, the type apk means the match used Alpine's security data, and the EPSS column shows the probability and its percentile. Note that libcrypto3 and libssl3 appear as a pair for every OpenSSL CVE: both binary packages come from the same source package, and you fix them with one upgrade.
Only what you can fix
--only-fixed hides findings without a fixed version. It is a triage filter, not a risk statement: an unfixed critical vulnerability is still there, you just can't upgrade your way out of it.
img=/opt/samples/images/alpine-3.18.0.tar
echo "all: $(grype $img -q -o json | jq '.matches | length')"
echo "only fixed: $(grype $img -q -o json --only-fixed | jq '.matches | length')"
echo "packages to upgrade:"
grype $img -q -o json --only-fixed \
| jq -r '[.matches[] | {p: .artifact.name, f: .vulnerability.fix.versions[0]}] | group_by(.p)[] | " \(.[0].p) -> \(map(.f) | max)"'all: 63
only fixed: 49
packages to upgrade:
busybox -> 1.36.1-r7
busybox-binsh -> 1.36.1-r7
libcrypto3 -> 3.1.8-r0
libssl3 -> 3.1.8-r0
musl -> 1.2.4-r3
musl-utils -> 1.2.4-r3
ssl_client -> 1.36.1-r7
The last list is the useful one: for each package, the highest fixed version among its findings is the upgrade that clears all of them. (jq's max compares strings, which happens to work for these versions but is exactly the bug shown in Vulnerability Data; a real tool compares versions with the ecosystem's rules.) For an image, that usually means "rebuild on a newer base", here Alpine 3.18.x's latest patch release or a newer Alpine.
Output formats
-o |
Use |
|---|---|
table (default) |
humans |
json |
scripts and jq; the richest format |
cyclonedx-json / cyclonedx |
an SBOM with a vulnerabilities section (a VDR) |
sarif |
GitHub code scanning and other SARIF viewers |
template -t file.tmpl |
your own text format, with Go templates |
cat > short.tmpl <<'TMPL'
{{- range .Matches }}{{ .Vulnerability.Severity }} {{ .Artifact.Name }}@{{ .Artifact.Version }} {{ .Vulnerability.ID }} (fix: {{ .Vulnerability.Fix.Versions }})
{{ end -}}
TMPL
grype /opt/samples/node-app -q -o template -t short.tmpl | sortCritical minimist@1.2.5 GHSA-xvch-5gv4-984h (fix: [1.2.6])
High lodash@4.17.15 GHSA-35jh-r3h4-6jhm (fix: [4.17.21])
High lodash@4.17.15 GHSA-p6mc-m468-83gw (fix: [4.17.19])
High lodash@4.17.15 GHSA-r5fr-rjxr-66jc (fix: [4.18.0])
Medium lodash@4.17.15 GHSA-29mw-wpgm-hmr9 (fix: [4.17.21])
Medium lodash@4.17.15 GHSA-f23m-r3pf-42rh (fix: [4.18.0])
Medium lodash@4.17.15 GHSA-xxjr-mmjv-4gpg (fix: [4.17.23])
Database status
Grype refuses to run on a database older than five days unless told otherwise (GRYPE_DB_MAX_ALLOWED_BUILT_AGE); this course's image disables that check because its database is frozen on purpose. In CI, print the status so a report always says what data it used:
grype db status | grep -E '^(Schema|Built|Status)'Schema: v6.1.10
Built: 2026-10-23T06:30:15Z
Status: valid
Layers and scope
By default Grype (like Syft) scans the squashed file system: what a container would see. A package installed in one layer and deleted in a later one isn't reported. --scope all-layers reports it too, which matters when you publish images whose lower layers can be extracted (anyone can pull every layer of a public image).
Test yourself
Why scan the stored SBOM (grype sbom:app.cdx.json) in CI rather than the image again?
- SBOM scans find more vulnerabilities
- It is faster and guarantees the scan matches the SBOM you publish
- Grype can't scan images
- Images have no packages
What does --only-fixed do?
- Fixes vulnerabilities
- Hides findings that have no fixed version
- Shows only critical findings
- Updates the database
Why do libssl3 and libcrypto3 show the same CVEs?
- Grype duplicates results
- Both are built from the OpenSSL source package
- They share a purl
- It's a false positive