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

Using hub from GitHub Actions #2149

Closed
rtimush opened this issue May 29, 2019 · 7 comments · Fixed by #2198
Closed

Using hub from GitHub Actions #2149

rtimush opened this issue May 29, 2019 · 7 comments · Fixed by #2198
Labels

Comments

@rtimush
Copy link

rtimush commented May 29, 2019

When hub api is called from a GitHub Action with a GITHUB_TOKEN available without any additional configuration it fails with "Bad credentials".

Command:

HUB_VERBOSE=true hub api /repos/rtimush/test/git/refs

Output:

$ git rev-parse -q --git-dir
$ git remote -v
$ git config --get-all hub.host
> GET https://api.github.com/user
> Authorization: token [REDACTED]
> Accept: application/vnd.github.v3+json;charset=utf-8
< HTTP 403
{"message":"Resource not accessible by integration","documentation_url":"https://developer.github.com/v3/users/#get-the-authenticated-user"}
> GET https://api.github.com/repos/rtimush/test/git/refs
> Authorization: token 
> Accept: application/vnd.github.v3+json;charset=utf-8
< HTTP 401
{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}
{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}
@rtimush
Copy link
Author

rtimush commented May 29, 2019

The workaround I found is to write GITHUB_TOKEN to ~/.config/hub and to unset the environment variable. Then hub doesn't call /user API and uses the token directly.

@mislav
Copy link
Owner

mislav commented May 29, 2019

Thank you @rtimush; this is useful information. I was not aware of the "Resource not accessible by integration" API limitation. I shall file this as a bug and will think about how to avoid automatically querying /user when GITHUB_TOKEN is provided. Hub uses this endpoint solely to get the username of the currenly authenticated actor— maybe we can get that information another way?

@mislav mislav added the bug label May 29, 2019
@mislav
Copy link
Owner

mislav commented May 29, 2019

@rtimush For clarity, can you tell us more what kind of action uses hub and how you set it up roughly? Thank you

@rtimush
Copy link
Author

rtimush commented May 29, 2019

The action I'm trying to create is a script that reacts on push events, and issues a couple of hub api calls first creating git references for the already existing commits, and then creating pull requests from them. Basically, I am using hub as a smarter curl.

@ghost
Copy link

ghost commented Jul 18, 2019

I'd like to add that we're running into the same issue.
Specifically we are trying to use hub release to push some artifacts to our releases from our CI during post build steps.
But in testing, it seems any of the hub non-git commands are returning a 403.

$ hub release show v2.60.0
$ git rev-parse -q --git-dir
$ git remote -v
$ git config --get-all hub.host
> GET https://api.github.com/user
> Authorization: token [REDACTED]
> Accept: application/vnd.github.v3+json;charset=utf-8
< HTTP 403
{"message":"Resource not accessible by integration","documentation_url":"https://developer.github.com/v3/users/#get-the-authenticated-user"}
> GET https://api.github.com/repos/.../releases?per_page=100
> Authorization: token
> Accept: application/vnd.github.v3+json;charset=utf-8
< HTTP 401
{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}
Error fetching releases: Unauthorized (HTTP 401)
Bad credentials

It also would be helpful if hub failed on the 403. We were getting just the 401 without setting verbose, which lead us down a hole of checking our token creation and integration permissions.

@mislav
Copy link
Owner

mislav commented Jul 19, 2019

You may now work around this by upgrading hub to v2.12.3 and setting the GITHUB_USER environment variable. This value is seldom used for any command, so you can even set it to a dummy value (the recommended value is the owner of the current repo, even if it's an org).

Let me know how using hub from Actions goes! 🙌

@rtimush
Copy link
Author

rtimush commented Jul 21, 2019

Everything looks good now, thanks!

bors bot pushed a commit to sigp/lighthouse that referenced this issue Feb 15, 2021
## Issue Addressed

Our v1.1.0 automated release failed to upload to Github. The `hub` command failed with a `403`, which seems like this issue: mislav/hub#2149
 
## Proposed Changes

The suggested fix in that issue is to set the `$GITHUB_USER` environment variable. I can't really test this because this hasn't been failing on my fork, but seems low risk



Co-authored-by: realbigsean <seananderson33@gmail.com>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
bors bot pushed a commit to sigp/lighthouse that referenced this issue Feb 15, 2021
## Issue Addressed

Our v1.1.0 automated release failed to upload to Github. The `hub` command failed with a `403`, which seems like this issue: mislav/hub#2149
 
## Proposed Changes

The suggested fix in that issue is to set the `$GITHUB_USER` environment variable. I can't really test this because this hasn't been failing on my fork, but seems low risk



Co-authored-by: realbigsean <seananderson33@gmail.com>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
krassowski added a commit to krassowski/language-packs that referenced this issue Jul 7, 2021
krassowski added a commit to krassowski/language-packs that referenced this issue Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants