8000 Better messaging for `attestation verify` custom issuer mismatch error by bdehamer · Pull Request #9616 · cli/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Better messaging for attestation verify custom issuer mismatch error #9616

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

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

bdehamer
Copy link
Contributor
@bdehamer bdehamer commented Sep 12, 2024

GH Enterprise customers have the option to customize the issuer claim in their Actions-issued OIDC tokens to include their unique enterprise "slug".

For users who have customized the issuer claim, the attestation verify command is unable to determine to expected issuer value by default -- instead, the user must pass in their customized issuer value using the --cert-oidc-issuer flag. If the user does NOT supply the issuer value, they receive an error message similar to the following:

Error: verifying with issuer "sigstore.dev": failed to verify certificate identity: no matching CertificateIdentity found, last error: 
expected issuer value "https://token.actions.githubusercontent.com", got "https://token.actions.githubusercontent.com/foo-bar"

This change detects the scenario where the expected issuer differs only by the enterprise slug and nudges the user in the right direction by suggesting they use the --cert-oidc-issuer flag with their expected issuer value.

Error: expected issuer to be https://token.actions.githubusercontent.com, got https://token.actions.githubusercontent.com/foo-bar -- if you have customized the issuer for your enterprise try using the --cert-oidc-issuer flag with your expected issuer

See: #9615

@bdehamer bdehamer requested a review from a team as a code owner September 12, 2024 23:03
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Sep 12, 2024
@cliAutomation
Copy link
Collaborator

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

Comment on lines -54 to +53
issuerMatcher, err := verify.NewIssuerMatcher(opts.OIDCIssuer, "")
// Accept any issuer, we will verify the issuer as part of the extension verification
issuerMatcher, err := verify.NewIssuerMatcher("", ".*")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the issuer verification is handled by the sigstore-go verifier . . . however, the existing logic doesn't allow us to properly detect the customized issuer string and alter the error message accordingly.

Instead, we're going to let the verifier accept ANY issuer value and perform the issuer comparison as part of the extension verification done within the verify command itself.

Comment on lines 67 to 73
if !strings.EqualFold(want, certIssuer) {
if strings.Index(certIssuer, want) == 0 {
return fmt.Errorf("expected Issuer to be %s, got %s -- if you have customized the issuer for your enterprise try using the --cert-oidc-issuer flag with your expected issuer", want, certIssuer)
} else {
return fmt.Errorf("expected Issuer to be %s, got %s", want, certIssuer)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the expected value IS NOT an exact match, but IS a substring of the actual value, the user will get the new error message suggesting they use the --cert-oidc-issuer flag.

@@ -151,7 +151,6 @@ func NewVerifyCmd(f *cmdutil.Factory, runF func(*Options) error) *cobra.Command
}
config.TrustDomain = td
opts.Tenant = tenant
opts.OIDCIssuer = fmt.Sprintf(GitHubTenantOIDCIssuer, tenant)
Copy link
Contributor Author
@bdehamer bdehamer Sep 12, 2024

Choose a reason for hiding this comment

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

This defaulting of the tenant-specific issuer string now happens in the VerifyCertExtensions function.

@bdehamer bdehamer force-pushed the bdehamer/custom-issuer-error branch from 6025ed4 to 090d9e1 Compare September 13, 2024 16:26
Copy link
Contributor
@steiza steiza left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor
@phillmv phillmv left a comment

Choose a reason for hiding this comment

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

minor suggestions

if strings.Index(certIssuer, want+"/") == 0 {
return fmt.Errorf("expected Issuer to be %s, got %s -- if you have customized the issuer for your enterprise try using the --cert-oidc-issuer flag with your expected issuer", want, certIssuer)
} else {
return fmt.Errorf("expected Issuer to be %s, got %s", want, certIssuer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we give more of a hint here, too? What if we:

  1. detected https://token.actions.*.ghe.com and prompted to set the tenant correctly (is that the failure condition?)
  2. said something like, attestations must be created inside GitHub Actions otherwise?

Signed-off-by: Brian DeHamer <bdehamer@github.com>
Co-authored-by: Zach Steindler <steiza@github.com>
Co-authored-by: Phill MV <phillmv@github.com>
@bdehamer bdehamer force-pushed the bdehamer/custom-issuer-error branch from 1737473 to 8c8423a Compare September 16, 2024 19:39
@bdehamer bdehamer merged commit 2e13ec5 into trunk Sep 16, 2024
16 checks passed
@bdehamer bdehamer deleted the bdehamer/custom-issuer-error branch September 16, 2024 19:52
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 16, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.57.0` -> `v2.58.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.58.0`](https://github.com/cli/cli/releases/tag/v2.58.0): GitHub CLI 2.58.0

[Compare Source](cli/cli@v2.57.0...v2.58.0)

#### What's Changed

-   Better messaging for `attestation verify` custom issuer mismatch error by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#9616
-   Enhance gh repo create docs, fix random cmd link by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#9630
-   Add HasActiveToken method to AuthConfig to refactor auth check for `attestation trusted-root` command by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#9635
-   Improve the suggested command for creating an issue when an extension doesn't have a binary for your platform by [@&#8203;timrogers](https://github.com/timrogers) in cli/cli#9608
-   Disable auth check for `attestation trusted-root` command by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#9610
-   build(deps): bump github.com/henvic/httpretty from 0.1.3 to 0.1.4 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#9645
-   Fix tenant-awareness for `trusted-root` command by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#9638
-   Replace "GitHub Enterprise Server" option with "other" in gh auth login prompting by [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#9642
-   build(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.4 to 2.0.5 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#9634
-   Add `dnf5` instructions to `docs/install_linux.md` by [@&#8203;its-miroma](https://github.com/its-miroma) in cli/cli#9660
-   build(deps): bump github.com/theupdateframework/go-tuf/v2 from 2.0.0 to 2.0.1 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#9688

#### New Contributors

-   [@&#8203;its-miroma](https://github.com/its-miroma) made their first contribution in cli/cli#9660

**Full Changelog**: cli/cli@v2.57.0...v2.58.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0