Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for uploading attestations in legacy API #15952

Merged
merged 9 commits into from
Jul 11, 2024

Conversation

facutuesca
Copy link
Contributor

@facutuesca facutuesca commented May 13, 2024

Description

Add support for uploading PEP 740 attestations along with distribution files. Part of #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:

  1. Check if the session is authenticated using Trusted Publishing (and GHA). If not, fail.
  2. Parse the attestations using pypi-attestations.
  3. Get the verification policy corresponding to the current Trusted Publisher (for now, always GitHub) .
  4. Verify the attestations using sigstore with 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@....)
  • OIDCSourceRepositoryDigest (the commit SHA corresponding to the version of the repo used)

See here for the definition of each claim.

cc @woodruffw @di

@facutuesca facutuesca requested a review from a team as a code owner May 13, 2024 16:56
@facutuesca facutuesca marked this pull request as draft May 13, 2024 16:57
warehouse/forklift/legacy.py Outdated Show resolved Hide resolved
warehouse/forklift/legacy.py Outdated Show resolved Hide resolved
warehouse/oidc/models/github.py Show resolved Hide resolved
requirements/dev.txt Outdated Show resolved Hide resolved
@facutuesca facutuesca force-pushed the upload-attestations branch 2 times, most recently from 9afeac1 to 7214138 Compare June 17, 2024 09:25
@facutuesca facutuesca marked this pull request as ready for review June 17, 2024 09:49
Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, nice work @facutuesca!

Note for other reviewers: this PR intentionally discards the attestations after verifying them, both for an initial testing period and to keep the changeset small. We'll follow up with another PR to persist the attestations 🙂

@facutuesca facutuesca force-pushed the upload-attestations branch 2 times, most recently from 45819f3 to 50a69a9 Compare June 20, 2024 20:26
Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @facutuesca!

(Needs another dependency deconflict.)

@facutuesca facutuesca force-pushed the upload-attestations branch 5 times, most recently from b4ba06f to 6d8a0ab Compare June 26, 2024 14:54
@facutuesca
Copy link
Contributor Author

facutuesca commented Jun 26, 2024

The CI / Dependencies failure is also happening in other PRs: #16172 (failure)

@facutuesca facutuesca force-pushed the upload-attestations branch 2 times, most recently from f01e393 to 9345a6f Compare July 1, 2024 11:44
Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks that I'll address today!

warehouse/forklift/legacy.py Outdated Show resolved Hide resolved
warehouse/forklift/legacy.py Outdated Show resolved Hide resolved
warehouse/forklift/legacy.py Outdated Show resolved Hide resolved
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Copy link
Member

@di di left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@di di enabled auto-merge (squash) July 11, 2024 18:41
@di di merged commit 8630bd9 into pypi:main Jul 11, 2024
17 checks passed
@di di deleted the upload-attestations branch July 11, 2024 18:55
@DarkaMaul DarkaMaul mentioned this pull request Jul 18, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants