Skip to content

_cli: add sigstore verify identity - #379

Merged
woodruffw merged 12 commits into
mainfrom
ww/subcommand-refactor
Jan 4, 2023
Merged

woodruffw merged 12 commits into
mainfrom
ww/subcommand-refactor

Conversation

@woodruffw

Copy link
Copy Markdown
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 [email protected]

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 <[email protected]>
@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 requested review from di and tetsuo-cpp January 3, 2023 19:04
@woodruffw woodruffw self-assigned this Jan 3, 2023
@woodruffw

Copy link
Copy Markdown
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
Copy Markdown
Member Author

/gcbrun

@woodruffw

Copy link
Copy Markdown
Member Author

/gcbrun

@woodruffw

Copy link
Copy Markdown
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 <[email protected]>
@woodruffw

Copy link
Copy Markdown
Member Author

/gcbrun

Signed-off-by: William Woodruff <[email protected]>
@woodruffw

Copy link
Copy Markdown
Member Author

/gcbrun

Signed-off-by: William Woodruff <[email protected]>
@woodruffw

Copy link
Copy Markdown
Member Author

/gcbrun

@woodruffw

Copy link
Copy Markdown
Member Author

Confirmed that each of the following work with these changes:

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

$ sigstore verify README.md --cert-identity '[email protected]' --cert-oidc-issuer 'https://github.com/login/oauth' --staging

$ sigstore verify identity README.md --cert-identity '[email protected]' --cert-oidc-issuer 'https://github.com/login/oauth' --staging

@woodruffw

Copy link
Copy Markdown
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 <[email protected]>
Comment thread sigstore/_cli.py
for arg in sys.argv[1:]:
if arg in ["-h", "--help"]: # global help if no subparser
break
else:

Copy link
Copy Markdown
Contributor

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.

Comment thread sigstore/_cli.py
# 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)

@tetsuo-cpp tetsuo-cpp Jan 4, 2023 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@woodruffw
woodruffw force-pushed the ww/subcommand-refactor branch from a2589d5 to 088714b Compare January 4, 2023 02:32
@woodruffw
woodruffw requested a review from tetsuo-cpp January 4, 2023 02:34

@tetsuo-cpp tetsuo-cpp left a comment

Copy link
Copy Markdown
Contributor

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.

2 participants