You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh auth login hangs when config.yml is read-only, potentially producing an "auth schism" #8357
bugSomething isn't workingcoreThis issue is not accepting PRs from outside contributorspriority-3Affects a small number of users or is largely cosmetic
When config.yml is read-only, gh auth login hangs indefinitely after having stored the token in secure storage and printing ✓ Authentication complete. This can cause some confusion for users, as described in the linked discussion below.
Yeh the confusion here stems from the fact that ✓ Authentication complete. is printed once the oauth flow is completed (but before we store any configuration changes):
Perhaps the simplest thing to do to remove the confusion is just to move that message out of the login flow and into the login command.
With regards the hang, I need to do some investigation. I'm surprised there is a hang rather than an error? For example, in #7360 there is an EPERM. It would be nice if you could recreate that scenario and maybe get an strace so we can see where it is hanging.
Did more investigation about the hang. When experiencing the hang, I was using the packaged gh binary of my distro, which is v2.29.0 currently. I never tried to re-auth with the current version without setting the custom GH_CONFIG_DIR. I actually mis-read the distro's gh version to be v2.39.0, so I thought I'd only be one point release behind, not ten minor releases 🙈.
I can repro the hang using 2.29.0, with both the distro's binary and the binary provided on the release download page. However, with 2.39.1, I get a proper error message, again both with the distro's unstable binary as well as with the binary from the release page:
$ ./gh auth login? What account do you want to log into? GitHub.com? You're already logged into github.com. Do you want to re-authenticate? Yes? What is your preferred protocol for Git operations? SSH? Generate a new SSH key to add to your GitHub account? No? How would you like to authenticate GitHub CLI? Paste an authentication tokenTip: you can generate a Personal Access Token here https://github.com/settings/tokensThe minimum required scopes are 'repo', 'read:org'.? Paste your authentication token: ****************************************- gh config set -h github.com git_protocol ssh✓ Configured git protocolopen /home/twieczorek/.config/gh/config.yml: read-only file system
I also tried strace, but there's not much enlightening in there, at least not for me. And in the end, the hang is no longer happening in current versions, so it doesn't really matter 🤷 🙂.
strace on v2.29.0 after pasting the token and hitting enter
Thanks for investigation, nothing obvious in the strace as you say. I have some thoughts on how to debug that but since it's not occurring anymore I don't think it's worth us spending the time.
With this new error, it maybe is also clearer that something in fact went wrong even if it says ✓ Authentication complete. so maybe the change isn't necessary. I'm ambivalent.
so maybe the change isn't necessary. I'm ambivalent.
Yeah. The only thing remaining is the weird outcome that gh auth token works (and gh auth login also states "You're already logged into github.com. Do you want to re-authenticate?") while all the other commands ask for auth...
Right, I forgot about that. Would it be possible for you to double check for me if that is still the case in the latest version?
By that I mean, logging out and then going through the log in process again, seeing it fail on config.yml.
I can't quite see how that would happen in the latest as the hosts.yml should be written before config.yml, and that is where the known hosts are enumerated. I'm just a bit concerned that the older version use in the original discussion might have some red herrings.
This can be triggered by simply removing the hosts.yml file (or maybe by just removing the github.com section from it?). I checked and in the current version that's not hanging, gh auth login writes hosts.yml, even in the case when config.yml can't be written to. So there's definitely extra user interaction necessary to trigger this.
$ ./gh versiongh version 2.39.1 (2023-11-14)https://github.com/cli/cli/releases/tag/v2.39.1
$ ./gh auth statusgithub.com ✓ Logged in to github.com as twz123 (keyring) ✓ Git operations for github.com configured to use ssh protocol. ✓ Token: gho_************************************ ✓ Token scopes: gist, read:org, repo
$ mv ~/.config/gh/hosts.yml ~/.config/gh/hosts.yml.foo
$ ./gh auth statusYou are not logged into any GitHub hosts. Run gh auth login to authenticate.
$ ./gh auth login? What account do you want to log into? GitHub.com? You're already logged into github.com. Do you want to re-authenticate? (y/N)^C
$ GH_TOKEN=$(./gh auth token) ./gh auth statusgithub.com ✓ Logged in to github.com as twz123 (GH_TOKEN) ✓ Git operations for github.com configured to use https protocol. ✓ Token: gho_************************************ ✓ Token scopes: gist, read:org, repo
Thanks for the extra investigation, super valuable.
Yeh, I understand how this would occur if the hosts.yml file were deleted. Ultimately, gh expects to own the configuration files and if you go messing around with them you're in for a bad time. I'm not against making changes to make this bifurcation less confusing but I reckon it'd be low priority given the user done goofed (assuming there's no way for this to happen normally in current versions).
bugSomething isn't workingcoreThis issue is not accepting PRs from outside contributorspriority-3Affects a small number of users or is largely cosmetic
Activity
williammartin commentedon Nov 24, 2023
Yeh the confusion here stems from the fact that
✓ Authentication complete.is printed once the oauth flow is completed (but before we store any configuration changes):cli/pkg/cmd/auth/shared/login_flow.go
Line 159 in 06e438b
In the case of
refreshwe actually print this message after the config changes have been made:cli/pkg/cmd/auth/refresh/refresh.go
Line 198 in 06e438b
Perhaps the simplest thing to do to remove the confusion is just to move that message out of the login flow and into the login command.
With regards the hang, I need to do some investigation. I'm surprised there is a hang rather than an error? For example, in #7360 there is an
EPERM. It would be nice if you could recreate that scenario and maybe get anstraceso we can see where it is hanging.twz123 commentedon Nov 24, 2023
Did more investigation about the hang. When experiencing the hang, I was using the packaged
ghbinary of my distro, which is v2.29.0 currently. I never tried to re-auth with the current version without setting the customGH_CONFIG_DIR. I actually mis-read the distro's gh version to be v2.39.0, so I thought I'd only be one point release behind, not ten minor releases 🙈.I can repro the hang using 2.29.0, with both the distro's binary and the binary provided on the release download page. However, with 2.39.1, I get a proper error message, again both with the distro's unstable binary as well as with the binary from the release page:
I also tried strace, but there's not much enlightening in there, at least not for me. And in the end, the hang is no longer happening in current versions, so it doesn't really matter 🤷 🙂.
strace on v2.29.0 after pasting the token and hitting enter
williammartin commentedon Nov 24, 2023
Thanks for investigation, nothing obvious in the
straceas you say. I have some thoughts on how to debug that but since it's not occurring anymore I don't think it's worth us spending the time.With this new error, it maybe is also clearer that something in fact went wrong even if it says
✓ Authentication complete.so maybe the change isn't necessary. I'm ambivalent.twz123 commentedon Nov 24, 2023
Yeah. The only thing remaining is the weird outcome that
gh auth tokenworks (andgh auth loginalso states "You're already logged into github.com. Do you want to re-authenticate?") while all the other commands ask for auth...williammartin commentedon Nov 24, 2023
Right, I forgot about that. Would it be possible for you to double check for me if that is still the case in the latest version?
By that I mean, logging out and then going through the log in process again, seeing it fail on
config.yml.I can't quite see how that would happen in the latest as the
hosts.ymlshould be written beforeconfig.yml, and that is where the known hosts are enumerated. I'm just a bit concerned that the older version use in the original discussion might have some red herrings.twz123 commentedon Nov 24, 2023
This can be triggered by simply removing the
hosts.ymlfile (or maybe by just removing the github.com section from it?). I checked and in the current version that's not hanging,gh auth loginwriteshosts.yml, even in the case whenconfig.ymlcan't be written to. So there's definitely extra user interaction necessary to trigger this.williammartin commentedon Nov 24, 2023
Thanks for the extra investigation, super valuable.
Yeh, I understand how this would occur if the
hosts.ymlfile were deleted. Ultimately,ghexpects to own the configuration files and if you go messing around with them you're in for a bad time. I'm not against making changes to make this bifurcation less confusing but I reckon it'd be low priority given the user done goofed (assuming there's no way for this to happen normally in current versions).Rebuild zsh on antidote, fix gh auth under home-manager, add XDG comp…