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

sigstore: extract LogEntry conversions to their own functions #992

Conversation

facutuesca
Copy link
Contributor

This moves the logic that converts between rekor_v1.TransparencyLogEntry and sigstore.models.LogEntry to their own separate functions:

    @classmethod
    def _from_dict_rekor(cls, dict_: dict[str, Any]) -> LogEntry:
    ...

    def _to_dict_rekor(self, is_message_signature: bool) -> dict[str, Any]:
    ...

The motivation for having these available is PEP 740, which defines an attestation format for PyPI artifacts. This PEP doesn't define a specific transparency log entry format, rather it leaves the choice to the implementation. In practice, it makes sense to use the exact same structure as a rekor_v1.TransparencyLogEntry for these entries. Using a different structure is not necessary and would introduce another format conversion to keep track of.

This means that at some point, in order to verify artifacts using the PEP 740 attestation format, we will have to convert it (back) to a Sigstore bundle. The only API to construct a Bundle other than Bundle.from_json is Bundle.from_parts:

    def from_parts(cls, cert: Certificate, sig: bytes, log_entry: LogEntry) -> Bundle:

But since it requires an already constructed LogEntry, it can't be used unless you already have one.

The new methods would allow a user of sigstore-python to create a LogEntry from an existing rekor_v1.TransparencyLogEntry without exposing the actual type, just a dict[str, Any]. This would look something like:

def pypi_to_sigstore(pypi_attestation: Attestation) -> Bundle:
    ....
    tlog_entry = pypi_attestation.verification_material.transparency_entries[0]

    return Bundle.from_parts(..., log_entry = LogEntry._from_dict_rekor(pypi_attestation....))

cc @woodruffw

Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
@woodruffw woodruffw self-requested a review April 29, 2024 21:45
@woodruffw woodruffw added the enhancement New feature or request label Apr 29, 2024
@woodruffw
Copy link
Member

Thanks @facutuesca! Could you add a round-trip test for these? Something simple where we ensure that entry == from_dict(to_dict(entry)) works would be perfect 🙂

@woodruffw
Copy link
Member

(Test failures are OK; expected as part of ongoing flakiness from staging.)

Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
@facutuesca
Copy link
Contributor Author

Thanks @facutuesca! Could you add a round-trip test for these? Something simple where we ensure that entry == from_dict(to_dict(entry)) works would be perfect 🙂

done!

sigstore/models.py Outdated Show resolved Hide resolved
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
sigstore/models.py Outdated Show resolved Hide resolved
Co-authored-by: William Woodruff <william@yossarian.net>
Signed-off-by: Facundo Tuesca <facu@tuesca.com>
sigstore/models.py Outdated Show resolved Hide resolved
Co-authored-by: William Woodruff <william@yossarian.net>
Signed-off-by: Facundo Tuesca <facu@tuesca.com>
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!

@woodruffw woodruffw marked this pull request as ready for review April 30, 2024 14:57
@woodruffw woodruffw merged commit 7583a78 into sigstore:ww/refactor-modules Apr 30, 2024
22 checks passed
@woodruffw woodruffw deleted the logentry-tlog-conversion-api branch April 30, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants