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

feat: Add --oauth-force-oob CLI option #667

Merged
merged 15 commits into from
Jun 9, 2023

Conversation

laurentsimon
Copy link
Contributor

Adresses comment #665 (comment)

Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
sigstore/_utils.py Outdated Show resolved Hide resolved
Signed-off-by: laurentsimon <laurentsimon@google.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.

Thanks for adding this! A couple of nitpicks 🙂

sigstore/_cli.py Outdated
@@ -221,6 +221,12 @@ def _add_shared_oidc_options(
default=os.getenv("SIGSTORE_OIDC_ISSUER", DEFAULT_OAUTH_ISSUER_URL),
help="The OpenID Connect issuer to use (conflicts with --staging)",
)
group.add_argument(
"--oidc-disable-default-browser",
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 flag name might be a little ambiguous: what it's doing is forcing the OOB flow, which is conceptually untied to the "default" browser. It's also doing an OAuth2 flow, so I think we should emphasize that rather than OIDC (OIDC refers to the "shape" of the claims that come out of the flow).

What do you think about --oauth-no-browser or --oauth-force-oob?

Copy link
Member

Choose a reason for hiding this comment

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

(I have a slight preference for the latter, since it'll be consistent with the environment suggestion below. But either is fine IMO; your call.)

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 renamed --oauth-force-oob, even though I think prepending --oidc-xxx wold be more consistent with other commands if it's under the oidc group. Lmk

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's a little inconsistent, but IMO it's worth it for the compatibility/symmetry with the existing flag.

There might be a better section to put this under; I'll take a look.

sigstore/_cli.py Outdated Show resolved Hide resolved
sigstore/oidc.py Show resolved Hide resolved
@woodruffw
Copy link
Member

JFYI: This will also require a CHANGELOG.md entry and updates to the --help outputs in the README.md. But we can do that as the last step.

Signed-off-by: laurentsimon <laurentsimon@google.com>
Signed-off-by: laurentsimon <laurentsimon@google.com>
@woodruffw
Copy link
Member

/gcbrun

@woodruffw
Copy link
Member

LGTM behaviorally!

check-readme is unhappy, but I'll fix that:

# sigstore --help
# sigstore sign --help
4,5c4,5
<                      [--no-default-files] [--signature FILE]
make: *** [Makefile:[12](https://github.com/sigstore/sigstore-python/actions/runs/5158329157/jobs/9292054589?pr=667#step:5:13)3: check-readme] Error 1
<                      [--certificate FILE] [--bundle FILE]
---
>                      [--oauth-force-oob] [--no-default-files]
>                      [--signature FILE] [--certificate FILE] [--bundle FILE]
30c30,32
<   --oauth-force-oob     Force an out-of-band OAuth flow and do not automatically start the default web browser (default: False)
---
>   --oauth-force-oob     Force an out-of-band OAuth flow and do not
>                         automatically start the default web browser (default:
>                         False)

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

/gcbrun

woodruffw
woodruffw previously approved these changes Jun 2, 2023
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 @laurentsimon!

I need one of the other maintainers to approve as well, but this will be included in the 2.0 series.

@woodruffw woodruffw added this to the 2.0 milestone Jun 2, 2023
@woodruffw woodruffw requested review from di and tetsuo-cpp June 2, 2023 18:21
@di di changed the title feat: Add --oidc-disable-default-browser CLI option feat: Add --oauth-force-oob CLI option Jun 5, 2023
@woodruffw woodruffw enabled auto-merge (squash) June 6, 2023 00:22
@woodruffw
Copy link
Member

/gcbrun

@woodruffw
Copy link
Member

/gcbrun

@woodruffw
Copy link
Member

/gcbrun

@woodruffw woodruffw requested a review from di June 7, 2023 20:48
@woodruffw
Copy link
Member

/gcbrun

di
di previously approved these changes Jun 7, 2023
tetsuo-cpp
tetsuo-cpp previously approved these changes Jun 8, 2023
@woodruffw
Copy link
Member

I have no clue why the macOS and Windows CIs are getting stuck here. Maybe some kind of bad runner state? Nothing in this PR itself should vary between platforms.

@woodruffw
Copy link
Member

Weirdly, both seem to hang at around the same test:

Windows:

2023-06-08T20:15:13.5528997Z test/unit/internal/oidc/test_issuer.py::test_fail_init_url PASSED        [ 75%]
2023-06-08T20:15:13.6085787Z test/unit/internal/oidc/test_issuer.py::test_init_url PASSED             [ 75%]
2023-06-08T20:22:23.5095829Z ##[error]The operation was canceled.
2023-06-08T20:22:23.6691779Z Post job cleanup.
2023-06-08T20:22:24.0268157Z [command]"C:\Program Files\Git\bin\git.exe" version

macOS:

2023-06-08T20:15:08.1732720Z test/unit/internal/oidc/test_issuer.py::test_fail_init_url PASSED        [ 75%]
2023-06-08T20:15:08.1998280Z test/unit/internal/oidc/test_issuer.py::test_init_url PASSED             [ 75%]
2023-06-08T20:22:31.5320710Z ##[error]The operation was canceled.
2023-06-08T20:22:31.5554660Z Post job cleanup.
2023-06-08T20:22:32.1636730Z [command]/usr/local/bin/git version
2023-06-08T20:22:32.2323580Z git version 2.40.1

I'll do some more digging later.

@di
Copy link
Member

di commented Jun 8, 2023

I wonder if these are waiting for user input... perhaps we need to add a reasonable timeout around any flows that wait for user input?

@woodruffw
Copy link
Member

I wonder if these are waiting for user input... perhaps we need to add a reasonable timeout around any flows that wait for user input?

Yeah, that was my guess, although it's a mystery to me why they'd block on these platforms and not on the Linux CI.

I think a timeout around user input makes sense, in places we can enforce it (e.g. stdin and not the browser) -- I'll look into that as well.

@woodruffw
Copy link
Member

This was indeed a silly blocking thing; should be fixed with d6052c9.

Signed-off-by: William Woodruff <william@trailofbits.com>
@woodruffw woodruffw dismissed stale reviews from tetsuo-cpp, di, and themself via d66733d June 8, 2023 21:05
@woodruffw
Copy link
Member

/gcbrun

@woodruffw woodruffw requested review from di and tetsuo-cpp June 8, 2023 21:06
@woodruffw woodruffw added component:cli CLI components component:signing Core signing functionality component:api Public APIs labels Jun 8, 2023
@di
Copy link
Member

di commented Jun 8, 2023

@woodruffw
Copy link
Member

I think it probably passed because we're not being specific enough about which IdentityError is being caught in the test.

Looking at it more closely, I'm not 100% sure what branch this test was originally intended to cover -- @jleightcap do you remember what your intent with this was?

@woodruffw
Copy link
Member

It looks like it was probably meant to catch this:

try:
resp.raise_for_status()
except requests.HTTPError as http_error:
raise IdentityError from http_error

I'll add a proper exception message there and assert on it. My guess is that the Linux CI was passing because webbrowser.open() failed on it and pushed it into the OOB flow, even without force_oob.

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

/gcbrun

@woodruffw
Copy link
Member

Tests are passing with the new match, so that confirms that the Linux CI was coincidentally entering the OOB flow (whereas Windows and macOS weren't, probably because both have a browser installed).

@woodruffw woodruffw merged commit 814af38 into sigstore:main Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:api Public APIs component:cli CLI components component:signing Core signing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants