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

Key management improvement #936

Conversation

javanlacerda
Copy link
Contributor

@javanlacerda javanlacerda commented Mar 14, 2024

Closes #927

It makes a refactor on code for a better key management. It makes the trusted root fully responsible by the key management, concentrating the responsibilities there.

It also removes the unused flags from the CLI. These properties are already provided by the trusted root.
Removed flags:

  • --certificate-chain
  • --rekor-root-pubkey
  • -ctfe

Summary

It is a refactor to make the code cleaner and cohesive.

Release Note

Documentation

cc @woodruffw @jku

@javanlacerda javanlacerda marked this pull request as draft March 14, 2024 13:43
Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

I left some specific comments in code. The main feedback is that these items from william are the core ones:

  • SigningContext and Verifier should probably take a TrustedRoot directly.
  • RekorClient should have no key material within it at all.

Just to add to those:

  • SigningContext and Verifier could still have staging() and production() helpers to make things easier for API users but the normal constructor call should look something like Verifier(rekor_client, trusted_root)
  • CLI should create the TrustedRoot, and pass it to Verifier and SigningContext
  • the CLI legacy args could be supported by "modifying" the TrustedRoot based on those args
  • Verifier and SigningContext know that their purposes are verifying and signing: this does not need to be an argument in any of their public methods
  • RekorClient should not need a trust root or a purpose

It's a long list of things but I think when we manage that , the code is hopefully significantly easier to understand.

sigstore/_internal/trustroot.py Outdated Show resolved Hide resolved
sigstore/_internal/trustroot.py Outdated Show resolved Hide resolved
sigstore/_internal/trustroot.py Outdated Show resolved Hide resolved
sigstore/_cli.py Show resolved Hide resolved
sigstore/_cli.py Outdated Show resolved Hide resolved
@jku
Copy link
Member

jku commented Mar 15, 2024

I did not address the actual key choices in different situations... It's friday afternoon and I'm pretty sure I'll get it wrong. If you can document in a comment which keys are used in which situations in your PR that would probably be useful.

The basic idea with KeyringPurpose seems good.

@woodruffw
Copy link
Member

Thanks @javanlacerda! I agree with @jku's feedback, and I'll add some of my own in a bit as well.

For deconflicting: this will probably interact a bit with #937. In particular, that changeset may end up removing RekorClient from Verifier, since the Verifier will become totally offline and will only need the Rekor keyring, not Rekor REST APIs.

@javanlacerda javanlacerda force-pushed the javan.ref.internal_key_management_improvement branch from 261457c to 397e166 Compare March 15, 2024 22:46
@javanlacerda javanlacerda marked this pull request as ready for review March 18, 2024 15:12
@javanlacerda javanlacerda force-pushed the javan.ref.internal_key_management_improvement branch from 0b1cb47 to 21eb980 Compare March 18, 2024 15:25
@woodruffw
Copy link
Member

@javanlacerda JFYI: it's easier to review the diffs here if you don't force-push each time -- it's okay to have a messy commit history while the PR is in progress, since we can squash or amend it before merge 🙂

@javanlacerda
Copy link
Contributor Author

@javanlacerda JFYI: it's easier to review the diffs here if you don't force-push each time -- it's okay to have a messy commit history while the PR is in progress, since we can squash or amend it before merge 🙂

I apologize!! I had to do that as I forgot to sign one of the commits in the middle 😞

@woodruffw
Copy link
Member

I apologize!! I had to do that as I forgot to sign one of the commits in the middle 😞

No worries! I personally do alias gc=git commit --signoff, but also don't worry too much about missing ones: I can also fix that during squash.

@woodruffw
Copy link
Member

/gcbrun

@woodruffw
Copy link
Member

This is looking pretty good to me, modulo the design question about the CLI flags. That boils down to whether we want to remove the CLI flags outright (fine by me, personally), or whether we want to keep them around for a bit and internally convert them into a TrustRoot.

I personally lean towards the former: we've been wanting to get rid of them for a while, and doing so will make future improvements much more straightforward. If @jku agrees, I think we can just go ahead and delete all of that 🙂

@woodruffw woodruffw added component:signing Core signing functionality component:verification Core verification functionality labels Mar 18, 2024
@javanlacerda javanlacerda force-pushed the javan.ref.internal_key_management_improvement branch from 9c63913 to ee94ba2 Compare March 18, 2024 19:50
Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

Looks really nice, this seems like the right direction. As for CLI arguments: I think I'm fine with removing them -- we could ping the slack channel with the specific list of arguments we intend to remove to see if anyone complains...

Are we going to lose testing coverage if the arguments are removed? probably not?

I might not have time this week to do proper testing/review but I left some minor comments, generally this looks good. I would really love more "description of changes" (as a simple example, if you move a bunch of code from one file to another, maybe mention if it's a direct copy or somehow modified).

Comment on lines 225 to 228
trusted_root = cls.from_file(path)
trusted_root.args = args
trusted_root.purpose = purpose
return trusted_root
Copy link
Member

@jku jku Mar 19, 2024

Choose a reason for hiding this comment

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

Suggested change
trusted_root = cls.from_file(path)
trusted_root.args = args
trusted_root.purpose = purpose
return trusted_root
return cls.from_file(path, args, purpose)

same suggestion applies to all other helper constructors

Comment on lines 291 to 294
def rekor_keyring(self) -> RekorKeyring:
"""Return public key contents given certificate authorities."""

return RekorKeyring(self._get_rekor_keys())
Copy link
Member

Choose a reason for hiding this comment

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

I believe you can just remove this wrapper method, and change
_get_rekor_keys(self) -> Keyring
into
rekor_keyring(self) -> RekorKeyring
right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it makes sense

Comment on lines 255 to 249
rekor_keyring=trust_root.rekor_keyring(),
ct_keyring=trust_root.ct_keyring(),
)
Copy link
Member

Choose a reason for hiding this comment

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

I was kind of expecting RekorClient to not need at least one of these (that the users of these keyrings actually have access to a proper keyring and should be using these)... but maybe that's fine to leave for future PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just removed any trustedroot and keyring dependency from rekor client :)

@javanlacerda
Copy link
Contributor Author

Looks really nice, this seems like the right direction. As for CLI arguments: I think I'm fine with removing them -- we could ping the slack channel with the specific list of arguments we intend to remove to see if anyone complains...

Are we going to lose testing coverage if the arguments are removed? probably not?

I might not have time this week to do proper testing/review but I left some minor comments, generally this looks good. I would really love more "description of changes" (as a simple example, if you move a bunch of code from one file to another, maybe mention if it's a direct copy or somehow modified).

Awesome! I will start making more comments about decisions.

Do you guys think we should create a different issue/PR for removing the flags? cc @jku @woodruffw

@woodruffw
Copy link
Member

Are we going to lose testing coverage if the arguments are removed? probably not?

I believe not -- we basically don't hit the _cli.py routines at all in tests at the moment.

Do you guys think we should create a different issue/PR for removing the flags?

I'm okay with either way. If we do it in a separate PR, we should merge that one first to ensure we don't have to adapt these changes too much. But if you find it easier to just update this one, I don't mind a larger diff here 🙂

@javanlacerda javanlacerda force-pushed the javan.ref.internal_key_management_improvement branch 2 times, most recently from 4014282 to 28bd775 Compare March 20, 2024 17:09
@javanlacerda
Copy link
Contributor Author

I did these forced push because I just removed a remaining print 😆 @woodruffw

Copy link
Member

Choose a reason for hiding this comment

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

I think this file also needs deletions for the CLI flags themselves: the _parser() function needs to be updated to remove each of the arg definitions that have had their usages removed below.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@javanlacerda javanlacerda changed the title Concentrate keys on trusted root Key management improvement Mar 21, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
@woodruffw
Copy link
Member

/gcbrun

@woodruffw
Copy link
Member

Thanks @javanlacerda, this is looking pretty good! I'm going to give these changes a spin locally and do a final review afterwards, with the goal of merging today.

(Mind updating the branch again?)

@javanlacerda javanlacerda force-pushed the javan.ref.internal_key_management_improvement branch from e6f3e9c to 8d39dff Compare March 21, 2024 16:31
@javanlacerda
Copy link
Contributor Author

Thanks @javanlacerda, this is looking pretty good! I'm going to give these changes a spin locally and do a final review afterwards, with the goal of merging today.

(Mind updating the branch again?)

Done! :)

@woodruffw
Copy link
Member

/gcbrun

javanlacerda and others added 12 commits March 22, 2024 13:57
refactors and adding trusted_root to Verifier and SigningContext

move purpose from rekor client to trusted_root

Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Co-authored-by: William Woodruff <william@yossarian.net>
Signed-off-by: Javan Lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
Signed-off-by: Javan lacerda <javanlacerda@google.com>
@javanlacerda javanlacerda force-pushed the javan.ref.internal_key_management_improvement branch from 8d39dff to ea26820 Compare March 22, 2024 13:57
@jku
Copy link
Member

jku commented Mar 25, 2024

please leave comments about changes (especially when force pushing): even a "rebase, no code changes" is useful.

/gcbrun

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 and didn't observe any breakage in local testing. Thanks @javanlacerda!

@woodruffw woodruffw merged commit e3ec47b into sigstore:main Mar 25, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:signing Core signing functionality component:verification Core verification functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve our internal key management
3 participants