Skip to content

✨ feat(zipapp): publish an SBOM for the zipapp - #3310

Merged
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:feat/zipapp-sbom
Sep 23, 2026
Merged

gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:feat/zipapp-sbom

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

virtualenv.pyz ships on GitHub Releases and at https://bootstrap.pypa.io/virtualenv.pyz with build provenance but no SBOM, and it bundles more than the wheel does: distlib, filelock, platformdirs, python-discovery and typing-extensions, in different versions per Python, next to the embedded pip and setuptools wheels. The wheel's SBOM declares those dependencies without versions because pip resolves them at install time, so it cannot describe the zipapp. 📦

tasks/zipapp_sbom.py reads the built archive and writes a CycloneDX 1.6 document from what it finds there. virtualenv and each bundled distribution come from their METADATA, each bundled distribution records the Python versions that load it (from the zipapp's distributions.json), each embedded wheel carries the SHA-256 of its bytes, and every other member gets its own file entry and hash. I reuse the helpers in hatch_build.py (made public for that) so both SBOMs share the serial number namespace, the supplier, the SOURCE_DATE_EPOCH timestamp and the build tool records. I identify the zipapp as pkg:generic/virtualenv.pyz, the product id #3308's VEX uses for it, and its embedded wheels carry the same purls and hashes that VEX names. The script writes virtualenv.pyz.cdx.json next to the zipapp and adds the same file to the archive root, next to __main__.py, so a copy fetched from bootstrap.pypa.io carries its own inventory.

tox r -e zipapp now builds the zipapp, writes the SBOM and runs tasks/validate_sbom.py on it: the CycloneDX 1.6 schema, the serial number actions/attest needs, the reference checks the wheel SBOM gets, and a comparison of every archive member and its SHA-256 with the document. The env pins Python 3.14 because the validator imports spdx-tools. The release workflow attests the SBOM against virtualenv.pyz, attaches it in the single gh release create call that immutable releases require, and the verify job checks that the asset matches both the copy inside the published zipapp and the attested predicate.

The zipapp's dependencies are unpinned today, so two builds of one commit can bundle different versions; #3306 pins them by hash, which makes the SBOM content reproducible too. This PR leaves tasks/make_zipapp.py untouched, so the two merge in either order. This PR and #3308 both edit the gh release create line and tasks/validate_sbom.py, so the second to merge needs a rebase.

@gaborbernat gaborbernat added enhancement security Fixes a vulnerability or hardens the supply chain, CI or release labels Sep 23, 2026
@gaborbernat
gaborbernat force-pushed the feat/zipapp-sbom branch 2 times, most recently from 27d0fbe to 3725b16 Compare September 23, 2026 00:29
The zipapp bundles more than the wheel: distlib, filelock,
platformdirs, python-discovery and the per-Python backports next to the
embedded pip and setuptools wheels. Only its build provenance was
published, so scanners had no inventory for it.

Describe the built archive from its own content, reusing hatch_build's
SBOM helpers so both documents share the namespace, supplier and build
tool records. The SBOM goes into the archive root and next to it,
tox validates that it lists every member with its hash, and the release
attests it against virtualenv.pyz and attaches it in the single gh
release create call.
@gaborbernat
gaborbernat merged commit 7af56ff into pypa:main Sep 23, 2026
64 of 65 checks passed
@gaborbernat
gaborbernat deleted the feat/zipapp-sbom branch October 3, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement security Fixes a vulnerability or hardens the supply chain, CI or release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant