Skip to main content

Verifies pypi-attestations in a build pipeline

Project description

pypi-verify-now

This is a trust-on-first-use (TOFU) solution to the problem of verifying the build provenance of packages downloaded from PyPI, that is usable now for brave and/or impatient users that want to experiment with this immediately or even sooner.

Pre-abandonware

This tool is intended to never reach version 1.0. Instead, whenever Pip starts verifying signatures client-side, this tool will go to version 99.9 and be end-of-lifed.

How-to and security considerations

First run the tool in TOFU mode with arguments supported by pip lock -- the arguments will be passed on as-is to pip-lock, so you can use -r to process a requirements file, or --group to verify packages specified by a PEP735 dependency group, or any other mechanism supported by pip as long as it generates a lock file:

TOFU=1 python -m pypi_verify_now --group build

This generates a file called .provenance.txt, which for each package lists the repository URL that's expected to have signed it. If a package is signed, but its originating repository URL is not recorded here, the package signature will not be considered valid. The file is expected to be committed to source control, and any changes to be reviewed.

After this, for example in a CI pipeline, create a build step that runs without TOFU:

python -m pypi_verify_now --group build

If this ever fails the build, one of the following things happened:

  1. A package is being signed from a different URL
  2. A package has started uploading signatures to PyPI, but the repo URL isn't yet known
  3. A package is no longer signed, but was expected to be signed in .provenance.txt
  4. A malicious package was somehow uploaded to PyPI

All of these will fail the build. The .provenance.txt will need to be updated in some way. Removing failing packages from .provenance.txt and re-running with TOFU=1 will make the tool happy, but ONLY the user can review the validity of the resulting changes to .provenance.txt. If this manual review doesn't happen, I'm don't think the resulting security posture is meaningfully better.

Configuration

Three settings can be configured through passing in environment variables:

  • TOFU=1 (default 0): set to '1' to generate an updated version of the provenance file
  • STRICT=1 (default 0): set to '1' to fail if any package is missing a signature (unlikely to be usable currently in 2025Q3)
  • FILENAME=... (default .provenance.txt): path to file where for each dependency originating repository URL is configured

Security warning

For my use case, today, I think this is good enough, or at least better than no signature verification. My understanding of security, OIDC and SigStore is more than zero, but still limited. See the license text; "PROVIDED AS-IS" etc.

I expect the PyPA/pip developers to spend a lot more time thinking about this problem and tackle nuances that I haven't thought about, and that this process understandably takes longer than the few hours I spent banging out this script, so it's advisable to evaluate risks accordingly.

TOC/TOU

Now that pip provisionally supports installing from pylock.toml using the --requirements/-r flag, it's possible to avoid a Time-of-check/Time-of-use (TOC/TOU) race by first generating a lock file, verifying that lock file using --lock-file/-L, and then installing from that same lock file.

Links

Talk from PyCon 2025:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypi_verify_now-0.8.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypi_verify_now-0.8-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pypi_verify_now-0.8.tar.gz.

File metadata

  • Download URL: pypi_verify_now-0.8.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for pypi_verify_now-0.8.tar.gz
Algorithm Hash digest
SHA256 e284cfd8e3c490f625495a9b07d915aa18c391f6564783f75ee231d97c574428
MD5 98c0ec2785fbe0d104a31ecb8c2cbb5a
BLAKE2b-256 42d4761ed237beca5632daff8190c43795cf216d838e5838e187e5b25babd06d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypi_verify_now-0.8.tar.gz:

Publisher: .gitlab-ci.yml on j0057-git/python/pypi-verify-now

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypi_verify_now-0.8-py3-none-any.whl.

File metadata

  • Download URL: pypi_verify_now-0.8-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for pypi_verify_now-0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fee590ebdecb7deaa27d3b4499718a6bba688c2fb4b2c08d24857bd575e83794
MD5 fb173b1bf2a5b42415b54cd7f5d6a371
BLAKE2b-256 09db3164e14dbeed9a56bb97cebb871ffa2dabe58959eafcea5a1c7d48052226

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypi_verify_now-0.8-py3-none-any.whl:

Publisher: .gitlab-ci.yml on j0057-git/python/pypi-verify-now

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page