-
Notifications
You must be signed in to change notification settings - Fork 935
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
base: main
Are you sure you want to change the base?
Conversation
expected_build_configs = [ | ||
OIDCBuildConfigURI(f"https://github.com/{self.job_workflow_ref}@{claim}") | ||
for claim in [ref, sha] | ||
if claim is not None | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I might be mistaken, but in practice this should only be ref
, not sha
. With that being said, we can probably use OIDCSourceRepositoryDigest
to enforce that the sha
also matches 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trusted publisher claim verification attempts both though:
warehouse/warehouse/oidc/models/github.py
Lines 56 to 62 in 784f446
ref = all_signed_claims.get("ref") | |
sha = all_signed_claims.get("sha") | |
if not (ref or sha): | |
raise InvalidPublisherError("The ref and sha claims are empty") | |
expected = {f"{ground_truth}@{_ref}" for _ref in [ref, sha] if _ref} | |
if signed_claim not in expected: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, hmm. Maybe we observed GitHub's IdP doing both at different points...
This is fine for now, then! IMO we could also add the OIDCSourceRepositoryDigest
for good measure 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this further, the current claims (plus the Digest one you suggested above) are:
- OIDCBuildConfigURI (e.g: https://github.com/org/repo/.github/workflows/workflow.yml@$REF/$SHA)
- OIDCSourceRepositoryURI (e.g: https://github.com/org/repo/)
- OIDCSourceRepositoryDigest (the commit SHA)
I think we could remove the repo URI (2), since it's included in the build config URI (1). WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tying things together: #14335 is where checking both the ref
and the sha
was introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a PR that adds a comment explaining why we check for both: #15967
@@ -235,6 +241,25 @@ def publisher_url(self, claims=None): | |||
return f"{base}/commit/{sha}" | |||
return base | |||
|
|||
def publisher_verification_policy(self, claims): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: docstring explaining the exact inner policy being constructed would be good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
af6432f
to
784f446
Compare
warehouse/forklift/legacy.py
Outdated
except (ValidationError, InvalidAttestationError) as e: | ||
raise _exc_with_message( | ||
HTTPBadRequest, | ||
f"Error while decoding the included attestation: {e}", | ||
) | ||
except VerificationError as e: | ||
raise _exc_with_message( | ||
HTTPBadRequest, | ||
f"Could not verify the uploaded artifact using the included " | ||
f"attestation: {e}", | ||
) | ||
except Exception as e: | ||
raise _exc_with_message( | ||
HTTPBadRequest, | ||
f"Unknown error while trying to verify included attestations: {e}", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to have some metrics/Sentry handlers for these different cases, to help us debug/triage as this gets rolled out 🙂
(See metrics
and sentry_sdk
uses in the codebase for some examples)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I added metrics for warehouse.upload.attestations.ok
(successful upload), warehouse.upload.attestations.malformed
(error decoding/parsing the attestation) and warehouse.upload.attestations.failed_verify
(error verifying the attestation).
I also added a Sentry message for unknown/unexpected errors
warehouse/forklift/legacy.py
Outdated
verification_policy = publisher.publisher_verification_policy( | ||
request.oidc_claims | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this can be moved out of the loop, to avoid re-building the policy each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, fixed!
expected_build_configs = [ | ||
OIDCBuildConfigURI(f"https://github.com/{self.job_workflow_ref}@{claim}") | ||
for claim in [ref, sha] | ||
if claim is not None | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, hmm. Maybe we observed GitHub's IdP doing both at different points...
This is fine for now, then! IMO we could also add the OIDCSourceRepositoryDigest
for good measure 🙂
784f446
to
e0b9a33
Compare
@@ -3,4 +3,6 @@ hupper>=1.9 | |||
pip-tools>=1.0 | |||
pyramid_debugtoolbar>=2.5 | |||
pip-api | |||
repository-service-tuf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now solved with the new releases of RSTUF that support tuf 4.0.0 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new release has another conflict with warehouse
. See: #15958 (comment)
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:pypi-attestation-models
.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:https://github.com/org/repo/.github/workflows/workflow.yml@....
)https://github.com/org/repo/
)See here for the definition of each claim.
TODO before merging:
repository-service-tuf
torequirements/dev.txt
once they release a new version. The current version pinstuf==3.1.0
, which conflicts withsigstore
who depends ontuf==4.0.0
.cc @woodruffw @di