Skip to content

Commit e0b9a33

Browse files
committed
Address review comments
1 parent 8fc3533 commit e0b9a33

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

warehouse/forklift/legacy.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,28 +1087,37 @@ def file_upload(request):
10871087
attestations = TypeAdapter(list[Attestation]).validate_json(
10881088
request.POST["attestations"]
10891089
)
1090+
verification_policy = publisher.publisher_verification_policy(
1091+
request.oidc_claims
1092+
)
10901093
for attestation_model in attestations:
10911094
# For now, attestations are not stored, just verified
1092-
verification_policy = publisher.publisher_verification_policy(
1093-
request.oidc_claims
1094-
)
10951095
attestation_model.verify(
10961096
Verifier.production(),
10971097
verification_policy,
10981098
Path(temporary_filename),
10991099
)
1100+
# Log successful attestation upload
1101+
metrics.increment("warehouse.upload.attestations.ok")
11001102
except (ValidationError, InvalidAttestationError) as e:
1103+
# Log invalid (malformed) attestation upload
1104+
metrics.increment("warehouse.upload.attestations.malformed")
11011105
raise _exc_with_message(
11021106
HTTPBadRequest,
11031107
f"Error while decoding the included attestation: {e}",
11041108
)
11051109
except VerificationError as e:
1110+
# Log invalid (failed verification) attestation upload
1111+
metrics.increment("warehouse.upload.attestations.failed_verify")
11061112
raise _exc_with_message(
11071113
HTTPBadRequest,
11081114
f"Could not verify the uploaded artifact using the included "
11091115
f"attestation: {e}",
11101116
)
11111117
except Exception as e:
1118+
sentry_sdk.capture_message(
1119+
f"Unexpected error while verifying attestation: {e}"
1120+
)
11121121
raise _exc_with_message(
11131122
HTTPBadRequest,
11141123
f"Unknown error while trying to verify included attestations: {e}",

warehouse/oidc/models/github.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
AllOf,
1717
AnyOf,
1818
OIDCBuildConfigURI,
19-
OIDCSourceRepositoryURI,
19+
OIDCSourceRepositoryDigest,
2020
)
2121
from sqlalchemy import ForeignKey, String, UniqueConstraint
2222
from sqlalchemy.dialects.postgresql import UUID
@@ -242,6 +242,20 @@ def publisher_url(self, claims=None):
242242
return base
243243

244244
def publisher_verification_policy(self, claims):
245+
"""
246+
Get the policy used to verify attestations signed with GitHub Actions.
247+
248+
This policy checks the certificate in an attestation against the following
249+
claims:
250+
- OIDCBuildConfigURI (e.g:
251+
https://github.com/org/repo/.github/workflows/workflow.yml@REF})
252+
- OIDCSourceRepositoryDigest (the commit SHA corresponding to the version of
253+
the repo used)
254+
255+
Note: the Build Config URI might end with either a ref (i.e: refs/heads/main)
256+
or with a commit SHA, so we allow either by using the `AnyOf` policy and
257+
grouping both possibilities together.
258+
"""
245259
sha = claims.get("sha") if claims else None
246260
ref = claims.get("ref") if claims else None
247261
if not (ref or sha):
@@ -255,7 +269,7 @@ def publisher_verification_policy(self, claims):
255269

256270
return AllOf(
257271
[
258-
OIDCSourceRepositoryURI(f"https://github.com/{self.repository}"),
272+
OIDCSourceRepositoryDigest(sha),
259273
AnyOf(expected_build_configs),
260274
],
261275
)

0 commit comments

Comments
 (0)