Add support for uploading attestations in legacy API
Description
Add support for uploading PEP 740 attestations along with distribution files. Part of https://github.com/pypi/warehouse/issues/15871.
For now only GHA-signed attestations are supported, but the implementation allows easily adding other publishers by implementing the OIDCPublisherMixin.publisher_verification_policy() method in the corresponding subclass.
Implementation
The core logic is in legacy.py: we check an upload request to see if it includes any attestations. If it does, we:
- Check if the session is authenticated using Trusted Publishing (and GHA). If not, fail.
- Parse the attestations using
pypi-attestation-models. - Get the verification policy corresponding to the current Trusted Publisher (for now, always GitHub) .
- Verify the attestations using
sigstorewith the above verification policy, against the uploaded distribution file.
For now we only verify the attestations. Storing them will be implemented in a later PR.
The GHA verification policy (from step 3) is defined in GitHubPublisherMixin.publisher_verification_policy(), and it checks the certificate in the attestation against the following claims:
- OIDCBuildConfigURI (e.g:
https://github.com/org/repo/.github/workflows/workflow.yml@....) - OIDCSourceRepositoryURI (e.g:
https://github.com/org/repo/)
See here for the definition of each claim.
TODO before merging:
- [ ] Re-add
repository-service-tuftorequirements/dev.txtonce they release a new version. The current version pinstuf==3.1.0, which conflicts withsigstorewho depends ontuf==4.0.0.
cc @woodruffw @di