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

_cli: add sigstore verify identity #379

Merged
merged 12 commits into from
Jan 4, 2023
Merged

_cli: add sigstore verify identity #379

merged 12 commits into from
Jan 4, 2023

Conversation

woodruffw
Copy link
Member

This adds sigstore verify identity, which is aliased (through some argparse hackery) back to sigstore verify.

This allows us to remain compatible with the existing CLI, while also giving us the flexibility we need to extend verification (e.g. sigstore verify github).

See #322.

Signed-off-by: William Woodruff william@trailofbits.com

This adds `sigstore verify identity`, which is aliased
(through some `argparse` hackery) back to `sigstore verify`.

This allows us to remain compatible with the existing CLI,
while also giving us the flexibility we need to extend verification
(e.g. `sigstore verify github`).

Signed-off-by: William Woodruff <william@trailofbits.com>
@woodruffw woodruffw added component:cli CLI components refactoring Refactoring tasks. labels Jan 3, 2023
@woodruffw woodruffw added this to the Stable release (1.0) milestone Jan 3, 2023
@woodruffw woodruffw self-assigned this Jan 3, 2023
@woodruffw
Copy link
Member Author

NB: This PR doesn't add sigstore verify github, since I want to keep it small. I'll do that in a follow-up, once we're happy with the approach here 🙂

@woodruffw
Copy link
Member Author

/gcbrun

Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
Signed-off-by: William Woodruff <william@trailofbits.com>
@woodruffw
Copy link
Member Author

/gcbrun

@woodruffw
Copy link
Member Author

Hmm, this doesn't quite work yet:

$ sigstore verify README.mdusage: sigstore verify [-h] {identity} ...
sigstore verify: error: argument verify_subcommand: invalid choice: 'README.md' (choose from 'identity')

Signed-off-by: William Woodruff <william@trailofbits.com>
@woodruffw
Copy link
Member Author

/gcbrun

Signed-off-by: William Woodruff <william@trailofbits.com>
@woodruffw
Copy link
Member Author

/gcbrun

Signed-off-by: William Woodruff <william@trailofbits.com>
@woodruffw
Copy link
Member Author

/gcbrun

@woodruffw
Copy link
Member Author

Confirmed that each of the following work with these changes:

$ sigstore sign --staging README.md --overwrite

$ sigstore verify README.md --cert-identity 'william@yossarian.net' --cert-oidc-issuer 'https://github.com/login/oauth' --staging

$ sigstore verify identity README.md --cert-identity 'william@yossarian.net' --cert-oidc-issuer 'https://github.com/login/oauth' --staging

@woodruffw
Copy link
Member Author

Implementation details: we do a little bit of argparse patching via _set_default_verify_subparser, which does the following:

  1. Nothing if the arguments look like help arguments (e.g. --help)
  2. Scans the subparsers for the parser it was run against, looking for the default subparser (identity in our case)
    1. If identity is present, there's nothing to be done
    2. If identity is not present, it looks for the index of verify in sys.argv (as in sigstore verify ... and inserts it immediately afterwards, normalizing the command to sigstore verify identity ....
      1. If verify itself is not present, there's nothing to be done (since we're in another sigstore top-level subcommand)

Signed-off-by: William Woodruff <william@trailofbits.com>
for arg in sys.argv[1:]:
if arg in ["-h", "--help"]: # global help if no subparser
break
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoa... how did I not know that this exists.

# within `sys.argv`. To do that, we get the index of the `verify`
# subcommand, and insert it directly after it.
verify_idx = sys.argv.index("verify")
sys.argv.insert(verify_idx + 1, name)
Copy link
Collaborator

@tetsuo-cpp tetsuo-cpp Jan 4, 2023

Choose a reason for hiding this comment

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

Can we maybe log a warning here? I realise we don't want to make a breaking change but perhaps we can at least mark it as deprecated and slate it for future removal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, a log sounds good. I'll do that in a moment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Signed-off-by: William Woodruff <william@yossarian.net>
Copy link
Collaborator

@tetsuo-cpp tetsuo-cpp left a comment

Choose a reason for hiding this comment

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

LGTM!

@woodruffw woodruffw merged commit 5ef5b23 into main Jan 4, 2023
@woodruffw woodruffw deleted the ww/subcommand-refactor branch January 4, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:cli CLI components refactoring Refactoring tasks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants