TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › Syft: Directories, Lockfiles & Images

Syft: Directories, Lockfiles & Images

Syft (Anchore, Apache-2.0) generates SBOMs from almost anything: a source directory, a single lockfile, an image in a registry, a saved image tarball, a file system of a VM. Grype uses the same library internally, so what Syft finds is what Grype scans.

text
syft scan [SOURCE] [-o FORMAT[=FILE]]...
Source Scheme Typical use
a directory dir:path (default for paths) source checkout in CI, before building
a single file file:path one lockfile or binary
an image in a registry registry:host/repo:tag after pushing; no Docker daemon needed
an image in the local Docker daemon docker:repo:tag on a developer machine
an image tarball docker-archive:app.tar output of docker save or crane pull
an OCI layout directory oci-dir:path output of crane pull --format oci, skopeo copy

Without a scheme, Syft guesses: an existing path is a directory or file, anything else is tried as an image.

A directory and a lockfile

Syft's catalogers each understand one kind of evidence: package-lock.json, requirements.txt, go.mod, installed Python METADATA files, JAR manifests, the Alpine package database, Go build info inside binaries, and so on. A directory scan runs every cataloger that applies to source trees.

bash · try it yourself
cp -r /opt/samples/node-app /opt/samples/python-app /opt/samples/go-app .
echo "--- directory with package-lock.json"; syft scan dir:node-app -q
echo "--- one file";                        syft scan file:python-app/requirements.txt -q
echo "--- go module";                        syft scan go-app -q
--- directory with package-lock.json
NAME      VERSION  TYPE
lodash    4.17.15  npm
minimist  1.2.5    npm
node-app  1.0.0    npm
--- one file
NAME      VERSION  TYPE
jinja2    2.11.2   python
requests  2.25.0   python
urllib3   1.26.4   python
--- go module
NAME               VERSION  TYPE
golang.org/x/text  v0.3.5   go-module

The table is Syft's default syft-table output, handy for humans. Note what each source can and can't tell you:

  • requirements.txt has exact pins here (==), so the versions are real. With ranges (requests>=2.0) Syft reports no version, because nothing was resolved yet. Scan the lockfile or the installed environment instead.
  • go.mod lists requirements, which under minimal version selection are the selected versions for the main module; a compiled Go binary carries the exact versions in its build info, and Syft reads those too.

An image

For images, Syft unpacks the layers and runs the image catalogers: OS package databases (apk, dpkg, rpm) plus language packages installed in the image. Here is the sample Alpine 3.18.0 image three ways: as an OCI layout directory, as a tarball, and from the local registry.

bash · try it yourself
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/demo/alpine:3.18.0 > /dev/null 2>&1
for src in oci-dir:/opt/samples/images/alpine-3.18.0 docker-archive:/opt/samples/images/alpine-3.18.0.tar registry:localhost:5000/demo/alpine:3.18.0; do
  printf '%-60s %s packages\n' "$src" "$(syft scan "$src" -q -o json | jq '.artifacts | length')"
done
syft scan registry:localhost:5000/demo/alpine:3.18.0 -q -o json \
  | jq -r '.artifacts[] | select(.name | test("^(busybox|musl|libssl3)
quot;)) | "\(.name) \(.version) \(.purl)"'
oci-dir:/opt/samples/images/alpine-3.18.0                    15 packages
docker-archive:/opt/samples/images/alpine-3.18.0.tar         15 packages
registry:localhost:5000/demo/alpine:3.18.0                   15 packages
busybox 1.36.0-r9  pkg:apk/alpine/busybox@1.36.0-r9?arch=x86_64&distro=alpine-3.18.0
libssl3 3.1.0-r4  pkg:apk/alpine/libssl3@3.1.0-r4?arch=x86_64&distro=alpine-3.18.0&upstream=openssl
musl 1.2.4-r0  pkg:apk/alpine/musl@1.2.4-r0?arch=x86_64&distro=alpine-3.18.0

The same image gives the same 15 packages from every source, and the purls carry the distribution (distro=alpine-3.18.0), which is what lets a scanner use Alpine's own security database instead of upstream advisories.

Where each package came from

The JSON output (-o syft-json, or just json) is Syft's richest format: for each package it records the locations (file and layer) that proved it exists. Use it to answer "why is this in my image?".

bash · try it yourself
syft scan /opt/samples/images/alpine-3.18.0.tar -q -o json \
  | jq -r '.artifacts[] | select(.name == "ssl_client") | .locations[] | "\(.path)  layer \(.layerID[7:19])"'
/lib/apk/db/installed  layer bb01bd7e32b5

ssl_client is an Alpine package, so its evidence is the apk database, /lib/apk/db/installed, in the image's only layer. For a language package the location is its lockfile or its installed metadata, for example /usr/lib/python3.12/site-packages/requests-2.32.3.dist-info/METADATA.

Naming the subject

When you scan a directory, the SBOM's subject is just ., as the SPDX vs CycloneDX session showed. Name it so that stored SBOMs can be found later:

bash · try it yourself
cp -r /opt/samples/node-app . && cd node-app
syft scan . -q --source-name shop-web --source-version 1.4.2 -o cyclonedx-json | jq '.metadata.component | {type, name, version}'
{
  "type": "file",
  "name": "shop-web",
  "version": "1.4.2"
}

Choosing catalogers

--select-catalogers adds, removes or filters catalogers by name or tag. Filtering is useful when a directory contains test fixtures you don't ship:

bash · try it yourself
mkdir mixed && cp /opt/samples/node-app/package-lock.json /opt/samples/python-app/requirements.txt mixed/
echo "--- all";            syft scan mixed -q
echo "--- javascript only"; syft scan mixed -q --select-catalogers javascript
--- all
NAME      VERSION  TYPE
jinja2    2.11.2   python
lodash    4.17.15  npm
minimist  1.2.5    npm
node-app  1.0.0    npm
requests  2.25.0   python
urllib3   1.26.4   python
--- javascript only
NAME      VERSION  TYPE
lodash    4.17.15  npm
minimist  1.2.5    npm
node-app  1.0.0    npm

syft cataloger list prints every cataloger with its tags (directory, image, package, language names), and --exclude './test/**' skips paths.

Test yourself

Which source scheme scans an image straight from a registry without a Docker daemon?

  1. docker:
  2. registry:
  3. dir:
  4. oci-dir:

Why can Syft report no version for requests>=2.0 in requirements.txt?

  1. Syft doesn't support Python
  2. A range isn't a resolved version; nothing has picked one yet
  3. The DB is frozen
  4. PyPI is offline

Which Syft output format records the file and layer each package was found in?

  1. syft-table
  2. syft-json (and the location data carried into other formats)
  3. purls
  4. spdx-tag-value only