Vulnerability scanning
Enable --scan to gate a generated image using an optional native Grype
0.122.1 executable. No scanner is downloaded or invoked by default; no
runtime dependency, Docker daemon, registry push, or Python SBOM is required.
Install the exact scanner version separately from a trusted upstream release.
Other versions fail closed rather than assuming a compatible JSON contract.
Native windows/amd64 scanner hosts are allowed with Grype 0.122.1.
Other Windows hosts remain rejected before database access or cataloging.
This scans Linux OCI image layouts, not Windows container images. The builder
and scanner must run together on the same host; wrapping a Linux scanner
around a Windows builder is not supported.
Linux/amd64 acceptance passed on 2026-11-22 (details below): a
checksum-verified Grype 0.119.0 scanned generated layouts on an
ubuntu-latest GitHub Actions runner with a SHA-256-pinned database, proving
OS and staged Python findings, deletion/opaque whiteout handling, and real
JSON plus derived SARIF provenance. That historical run used the old pin and
does not validate 0.122.1. Isolated Windows 0.122.1 research also passed
(see below), but is not acceptance evidence for this product revision.
Before merge, real Grype 0.122.1 acceptance must pass on Linux/amd64 and
Windows/amd64 using the same controlled database archive. Record each
host’s on-disk database digest separately. The adapter remains experimental:
macOS and linux/arm64 scanner hosts are unvalidated, other Grype versions
are rejected, and synthetic fixtures do not prove container startup.
Usage and settings
Section titled “Usage and settings”python -m pycontainer.cli build --scan --tag ghcr.io/user/app:v1 --pushpython -m pycontainer.cli build --scan --scan-report-format sarif --scan-report scan.sarifpython -m pycontainer.cli build --scan --scan-threshold critical --scan-unknown ignoreAll options have corresponding [build] TOML keys; explicit CLI values win.
Omitting scanner options preserves file settings.
[build]scan = truescan-executable = "grype"scan-threshold = "high"scan-unknown = "fail"scan-report-format = "json"scan-report = "scan.json"scan-offline = falsescan-db-max-age-hours = 120# scan-db-dir = "C:/scanner-db"| Option | Default / meaning |
|---|---|
--scan |
Disabled; explicit opt-in |
--scan-executable |
grype on PATH, or an executable path |
--scan-threshold |
high; negligible, low, medium, high, critical; inclusive |
--scan-unknown |
fail; ignore explicitly accepts missing/unrecognized severity |
--scan-report-format |
json or sarif |
--scan-report |
<output-dir>/vulnerabilities.json or .sarif |
--scan-offline |
Disabled; use an already imported database without updating |
--scan-db-dir |
~/.pycontainer/grype-db, separate from Grype’s default cache |
--scan-db-max-age-hours |
120; positive integer; measured from DB build timestamp |
Scan settings alone do not enable scanning. Dry-run does not scan or produce vulnerability evidence. Reports cannot overwrite OCI metadata/blobs/tags, the scanner executable, or files in the configured database cache.
Image identity and coverage
Section titled “Image identity and coverage”Build scans after image assembly and before returning success. The builder
creates a private single-manifest OCI layout, copying and streaming-verifying
every referenced manifest, config and layer against its digest and size.
Grype is invoked with oci-dir:, an exact platform and --scope squashed.
The adapter verifies the returned manifest/config bytes, identities, ordered
layers, platform, scanner version and database metadata.
Push scans again, while holding the output lock, and transfers that same private copy. No registry authentication, existence check, blob upload or manifest publication starts until the gate succeeds. This deliberately adds copying, hashing and scan costs to both build and push; source changes cannot substitute bytes between those operations. Base-image pulls needed to build the image still occur normally.
Supported scan targets are limited to linux/amd64 and linux/arm64. The
gate does not support multi-platform indexes: build and scan each platform
separately. Multi-platform builds with scanning enabled are rejected before
assembly, and enabling scanning on an existing index blocks its push.
Python-version matrices with scanning enabled are also rejected; build and
scan each Python version separately.
The scanner catalogs the merged image’s base OS package databases and installed
language package metadata, including staged Python dependencies. Squashed
scope should respect deletion and opaque whiteouts; that behavior requires the
real acceptance test, not an assertion about the Python-only SBOM.
Unknown distribution coverage, package/distro coverage alerts, ignored findings, malformed output and missing metadata are operational failures. No report proves absence of vulnerabilities: uncataloged packages, incomplete database coverage and scanner false negatives remain possible. This is not malware detection, source analysis, cross-compilation or runtime validation.
Database, network and offline policy
Section titled “Database, network and offline policy”Online mode explicitly runs grype db update before status and scan, requiring
successful update checks. Database updates are disabled during the scan to bind
one checked database to one result. The database status must be valid, schema
6, and have a timezone-qualified build timestamp within the configured maximum
age. Future timestamps beyond five minutes fail. The database file’s SHA-256
and size are checked before and after scanning and recorded in the report.
A cache lock serializes pycontainer scanner operations; simultaneous use fails
explicitly. Do not run external Grype database updates against this cache during
the scan.
Offline mode disables updates, application-update checks and external-source lookups. It requires a valid pre-imported database with the same freshness rules. Air-gapped operators may explicitly increase the allowed age; this is a documented policy exception, not an automatic stale-database fallback.
$env:GRYPE_DB_CACHE_DIR = 'C:\scanner-db'grype db import C:\controlled\database.tar.gzRemove-Item Env:GRYPE_DB_CACHE_DIRpython -m pycontainer.cli build --scan --scan-offline --scan-db-dir C:\scanner-dbUse a controlled, independently verified database archive. Importing does not
make an old database fresh. The adapter supplies an explicit configuration,
uses a private working directory and removes inherited GRYPE_* / SYFT_*
overrides so ambient ignores, VEX and filtering cannot silently weaken policy.
Corporate proxy/TLS environment settings remain available; certificate or
network failures must be fixed rather than disabling validation.
Reports and failures
Section titled “Reports and failures”JSON retains validated Grype findings and adds pycontainer provenance. SARIF
2.1.0 is derived from those same findings (not a second scan); package identities
and CVEs are represented without temporary host file locations. Both formats
record manifest digest, platform, scanner version, database digest/build time,
scan timestamp, threshold/unknown/offline policy, pass/fail and coverage limits.
Findings reports are atomically written before a threshold failure is raised.
Before a scan attempt, old evidence is replaced with an incomplete, failed
record for the attempted image digest. An operational failure cannot leave a
previous clean report looking like the current result. An incomplete SARIF run
has executionSuccessful: false; it is not a zero-finding successful scan.
Report-write failure itself fails the operation.
The CLI exits 3 for vulnerability findings and 4 for scan operational
errors. Operational messages distinguish scanner, database, unsupported,
identity and report categories. Library callers receive ScanError with a
category, or its VulnerabilityFoundError subclass. Unsupported versions,
missing tools, timeout/nonzero exit, unavailable/stale/changed DB, invalid
identity and unwritable reports never authorize publication. Each scanner
process has a 300-second limit; each stdout/stderr stream is capped at 32 MiB.
Validation
Section titled “Validation”For paired hosted acceptance, dispatch the existing runtime workflow with
scanner-acceptance=true on the revision to test:
gh workflow run runtime-check.yml --ref <branch> -f scanner-acceptance=trueOnly the scanner matrix runs in this mode (ubuntu-latest and
windows-latest, Python 3.11); ordinary runtime import/startup jobs are skipped.
The scanner job never runs on PRs, pushes or reusable workflow calls. It
downloads Grype 0.122.1, verifies the published release checksum, then imports
the same independently pinned historical database archive on each host.
The archive SHA-256 is
baa591108fd0fafa273503769dea65bf0334ad337e84aeb7f08197849cea9f87,
recorded independently in the #14 research.
This controlled fixture explicitly allows a maximum database age of 8760
hours; it does not change the product’s 120-hour default or refresh the DB.
Each scanner-acceptance-<OS>-<run>-<attempt> artifact retains scanner version
and release checksum, verified source archive digest, host-specific imported
database digest/build time, tested revision/run identity, pytest output/JUnit,
and JSON/SARIF reports. Require both hosts to pass in the same run and
attempt against the same tested revision and archive; a skipped, failed or
incomplete job is not acceptance. Current acceptance evidence is tracked in
#254.
Default tests use a fake executable, synthesized OCI layouts and no real database or registry:
uv run --locked --group test --group build python -m pytest tests -qThe opt-in real-scanner test generates an OCI image with compressed Debian OS
package layers and an actually staged pure-Python requests fixture. A paired
control contains vulnerable urllib3 and jinja2; the whiteout case removes
them using deletion and opaque markers. The controlled database must yield
findings for openssl 3.0.9-1, requests 2.19.1, urllib3 1.24.1 and jinja2 2.10
in the control. The deleted packages must have no findings in the whiteout
case. Synthetic package metadata tests cataloging, not container startup.
Prepare a trusted imported schema-6 database in a dedicated cache and pin the
SHA-256 of 6\vulnerability.db. No network update or registry pull occurs in
this test:
On Linux/WSL:
export PYCONTAINER_GRYPE="$(command -v grype)"export PYCONTAINER_SCAN_DB_DIR="$HOME/controlled-db"export PYCONTAINER_SCAN_DB_SHA256='sha256:<independently-verified-database-digest>'# Only for a deliberate historical controlled database policy:# export PYCONTAINER_SCAN_DB_MAX_AGE_HOURS='8760'uv run --locked --group test --group build python -m pytest -q -o addopts= -m scanner_integrationOn native Windows/amd64, with the exact same independently verified archive imported into a separate cache:
$env:PYCONTAINER_GRYPE = (Get-Command grype).Source$env:PYCONTAINER_SCAN_DB_DIR = 'C:\controlled-db'$env:PYCONTAINER_SCAN_DB_SHA256 = 'sha256:<independently-verified-database-digest>'# Only for a deliberate historical controlled database policy:# $env:PYCONTAINER_SCAN_DB_MAX_AGE_HOURS = '8760'uv run --locked --group test --group build python -m pytest -q -o addopts= -m scanner_integrationUse Grype 0.122.1 on both hosts. Import processing can produce different on-disk database bytes across hosts; pin each host’s resulting file, not the other host’s digest. Preserve the archive digest to establish the shared input.
Explicitly selected integration tests fail if prerequisites are missing.
Default pytest excludes scanner_integration and registry_integration.
Capture scanner version, database digest/build time, platform and test output
with acceptance evidence; fake-scanner results do not substitute for this run.
Observed integration runs (2026-11-22)
Section titled “Observed integration runs (2026-11-22)”All runs used Grype 0.119.0 (Syft v1.52.0) and DB schema v6.1.10 built
2026-11-22T06:19:59Z, database file digest
sha256:0e7c51fa7ca3eb381347a1dc632b2a77be91ba952103431b7fff9b65009accd8.
- Native
windows/amd64: both generated-layout cases failed before cataloging because of invalid cache filenames. The old pin rejected Windows. linux/amd64(GitHub Actionsubuntu-latest, Python 3.11): the release archive was verified against the release checksums file and all threescanner_integrationcases passed offline (Actions run 45074781421). The control found openssl, requests, urllib3 and jinja2 (83 matches); the whiteout case found only openssl and requests (64 matches); SARIF derived the same 83 results. Every report carried the scanned manifest digest, scanner version, database digest/build time, policy andscan_status: complete.
The first Linux runs failed closed and exposed three real report-contract
differences, now validated strictly: source.target.layers lists the
uncompressed diffIDs with cataloged sizes (bound to the attested config’s
ordered rootfs.diff_ids and manifest media types); database metadata is
nested in descriptor.db.status; and Grype injects kernel-header ignore
rules unless match-upstream-kernel-headers is enabled, which the adapter now
sets so the no-filtering check stays exact.
Isolated Windows research (2026-11-24; not product acceptance)
Section titled “Isolated Windows research (2026-11-24; not product acceptance)”The research on #14
used checksum-verified Grype 0.122.1 (Syft v1.57.2) on Windows/amd64 with
the controlled archive SHA-256
baa591108fd0fafa273503769dea65bf0334ad337e84aeb7f08197849cea9f87.
Its imported database digest was
sha256:8c86d7b851cf08c193f18b3329b11c209e695e61d4bb21db39c5971fbf99426d.
Three cases passed (83 control matches, 64 whiteout matches, 83 SARIF results)
in an isolated patched harness, with the Debian 12 fixture corrected to
PYTHON_LIBC=glibc-2.36. Grype 0.119.0 reproduced the cache-path failure
against the same input. The upstream filename fix is included in 0.122.1.
That research did not run this revision, rerun Linux with 0.122.1, exercise a Windows CI runner, or scan the push path with real Grype. Paired acceptance on the final product revision remains required; do not infer missing evidence.