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

Impossible to set permissions for view annotations, for gh run watch #8842

Closed
bendavies opened this issue Mar 19, 2024 · 13 comments · Fixed by #9113
Closed

Impossible to set permissions for view annotations, for gh run watch #8842

bendavies opened this issue Mar 19, 2024 · 13 comments · Fixed by #9113
Assignees
Labels
gh-run relating to the gh run command help wanted Contributions welcome needs-design An engineering task needs design to proceed p2 Affects more than a few users but doesn't prevent core functions platform Problems with the GitHub platform rather than the CLI client

Comments

@bendavies
Copy link

bendavies commented Mar 19, 2024

Describe the bug

When using a Fine Grained Token, it seems impossible to use gh run watch, as this requires permissions to view annotations.

It doesn't seem possible to grant checks:read with Fine Grained Tokens, unless i'm missing something.

Steps to reproduce the behavior

  1. Type this gh run watch $id
  2. View the output

failed to get annotations: HTTP 403: Resource not accessible by personal access token (https://api.github.com/repos/org/repo/check-runs/id/annotations)'

@bendavies bendavies added the bug Something isn't working label Mar 19, 2024
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Mar 19, 2024
@williammartin
Copy link
Member

Hey @bendavies, off the top of my head I'm not sure. In the meantime, what permissions do you have on your fine grained PAT, then we can try to reproduce?

@williammartin williammartin added needs-user-input gh-run relating to the gh run command labels Mar 19, 2024
@bendavies
Copy link
Author

bendavies commented Mar 19, 2024

@williammartin i added Read on EVERYTHING, to test that checks:read wasn't hidden away somewhere in another option.

@williammartin williammartin added p2 Affects more than a few users but doesn't prevent core functions platform Problems with the GitHub platform rather than the CLI client blocked and removed bug Something isn't working needs-user-input needs-triage needs to be reviewed labels Mar 19, 2024
@williammartin
Copy link
Member

I was able to recreate this also with gh run view:

➜  gh run view 8099062527
⣾failed to get annotations: HTTP 403: Resource not accessible by personal access token (https://api.github.com/repos/williammartin-test-org/test-repo/check-runs/22133946540/annotations)

I checked this out internally and unfortunately the platform doesn't support adding checks permissions to a Fine Grained PAT right now, so this is blocked. I've left a comment on the internal issue to here to aid in prioritisation.

I've created #8843 in the meantime to document this more clearly in the CLI.

Is it a requirement for you to use fine grained PATs for these commands? We could consider the addition of a flag to skip annotations if that is the only bit that is currently failing, though I'd prefer not to add permanent flags for temporary situations if possible.

@bendavies
Copy link
Author

Thanks for the investigation.

Is it a requirement for you to use fine grained PATs for these commands?

well, they are nice in that they allow scoping to an org, so i prefer to use them.

You could also gracefully skip over annotations if they 403, while still showing the run, informing the user that there were no permissions for annotations.

@williammartin
Copy link
Member

That's an interesting idea and I'm leaning in favour of it. My only concern is whether we want to try and be smart about the type of token in use. For example, if it were a legacy PAT would we error, would we be more informative, or would we just have a generalised error message to help differentiate the steps (or lack of) that a user could take to fix it.

@00ber
Copy link

00ber commented Mar 21, 2024

Affected by this as well. Hoping for a solution 🙏

@williammartin
Copy link
Member

Labelling this help wanted if someone would like to do some design work around #8842 (comment). There's other interesting questions like "what should the exit code be" if there is only partial success. I'm not sure we have a pattern for this anywhere in the CLI yet.

@williammartin williammartin added help wanted Contributions welcome needs-design An engineering task needs design to proceed and removed blocked labels Mar 21, 2024
@wingleung
Copy link
Contributor

the platform already does error handling with informative error messaging so I'm not sure we should introduce some custom error handling in the cli.

as is: failed to get annotations: HTTP 403: Resource not accessible by personal access token

  • failed to get annotations: : cli hints at what part went wrong
  • HTTP 403: Resource not accessible by personal access token: platform error hints at my access token, this could be more verbose

to me it's clear something is wrong with my access token so I need to debug my access token against the annotations endpoint.

the platform could add more info as to why it fails for example HTTP 403: Resource not accessible by personal access token. Annotations are not supported yet in Fine Grained Tokens (https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens).

This way we don't need to duplicate error messaging logic, the platform is the single source of truth and the client, in this case the cli, just throws the error or handles the error however it likes.

optional error suppression

I follow @bendavies in evaluating certain flows and suppressing some errors when it's not the critical data needed for a command.

for the run watch and run view command we fetch 3 endpoints, depending on the endpoint we suppress the error we receive from the platform

  • GET run: most important data 👉 throw error
  • GET jobs: needed for the command to be useful 👉 throw error
  • GET annotations: useful but when unavailable shouldn't block us from seeing the jobs 👉 suppress error, show warning

exit codes

strictly speaking, when we cannot access a resource that requires permission we should exit with 2. But I think in the case were we would optionally depend on annotations, I think 0 is more appropriate because the most important data is there, given there is also a warning about the missing data.

ultimately, when the platform adds support for annotations in FGT the warning will be gone and the platform possibly doesn't need to provide extra info about the error which makes it more security by obscurity

@williammartin
Copy link
Member

Thanks @wingleung, your write up makes sense to me! I don't know how easy it is to change the platform error message in this case as I believe there is a lot of 🌈 magic 🌈 in the authorization code. That said, it seems like if we choose to suppress the error on GET annotations and provide our own warning, then that change has less value for us in the CLI.

I agree with your statement about exit codes.

Would you be interested in opening a PR for this?

@wingleung
Copy link
Contributor

indeed, it would be more for debugging faster why I couldn't fetch the annotations with my token. and I would also understand if platform people don't want this level of detail in their error messaging.

I can take a look later this week 🙏

@williammartin
Copy link
Member

Looking at this a bit closer, presumably this is also an issue for gh run view which also render annotations?

var annotations []shared.Annotation
for _, job := range jobs {
as, err := shared.GetAnnotations(client, repo, job)
if err != nil {
return fmt.Errorf("failed to get annotations: %w", err)
}
annotations = append(annotations, as...)
}

@wingleung
Copy link
Contributor

@williammartin thanks for the heads up! PR updated with changes to the view command as well

@williammartin
Copy link
Member

@bendavies this should go out in the next release but if you'd like to try it now and provide feedback then you can build from source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gh-run relating to the gh run command help wanted Contributions welcome needs-design An engineering task needs design to proceed p2 Affects more than a few users but doesn't prevent core functions platform Problems with the GitHub platform rather than the CLI client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants