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
Unable to retrieve username during multi-account migration due to invalid/expired token #8441
I have some Windows machines that have an old version of %APPDATA%\GitHub CLI\config.yml and %APPDATA%\GitHub CLI\hosts.yml that breaks all invocations of the cli with the following error:
failed to migrate configuration: failed to migrate config: cowardly refusing to continue with multi account migration: couldn't get user name for "github.com": non-200 OK status code: 401 Unauthorized body: "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\"}"
If I remove all files, the problem will be resolved.
If I remove the hosts.yml file, the config.yml file is changed by adding a line with version: "1", and the problem is resolved.
I can even restore the old hosts.yml once the config.yml has been updated and the cli will continue to run.
I am running version 2.40.0.
Steps to reproduce the behavior
Type this gh config list (all commands I have tried fail, even help)
View the output failed to migrate configuration: failed to migrate config... (see above)
See error
Expected vs actual behavior
I am not clear what the migration code attempts to achieve, but it fails on some cases as described above.
The migration exists to support multi account. We're failing the migration because we're unable to resolve a username for some token that we found because the server is returning 401. The idea here was that we wanted to err on the side of caution and have people take remediation rather than migrate data we didn't have confidence in. In retrospect, I'm not 100% sure this was the right choice here but we'll talk about it as a team on Monday.
I can even restore the old hosts.yml once the config.yml has been updated and the cli will continue to run.
It will continue to run but later if you log into another account on any host you will replace your current user rather than it being an additive operation the first time. After that things should work as expected. This may not be a big issue for you.
To help us get confidence in this diagnosis, I would love to know the output of gh auth status.
After removing the config files and executing gh auth login, the output of gh auth status is:
github.com
✓ Logged in to github.com account jcasale (keyring)
- Active account: true
- Git operations protocol: https
- Token: gho_************************************
- Token scopes: 'gist', 'read:org', 'repo'
If I misunderstood what you needed, please forgive me and straighten me out.
I am not sure if it matters, but these hosts previously may have had gh auth login executed for troubleshooting purposes, but they all run with the GH_TOKEN environment variable set.
The gh auth status command fails to run with the old files in place:
failed to migrate configuration: failed to migrate config: cowardly refusing to continue with multi account migration: couldn't get user name for "github.com": non-200 OK status code: 401 Unauthorized body: "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/graphql\"}"
Just to be thorough in case I still misunderstood, I tried the following:
Haha sorry it's late here and I wasn't clear at all. You would need to run gh auth status with a version earlier than v2.40.0 if you copy the old config.yml back in place. I think it should work with v2.40.0 if you only copy the hosts.yml back.
C:\>gh.exe --version
gh version 2.39.2 (2023-11-27)
https://github.com/cli/cli/releases/tag/v2.39.2
C:\>gh.exe auth status
github.com
X github.com: authentication failed
- The github.com token in C:\Users\***\AppData\Roaming\GitHub CLI\hosts.yml is invalid.
- To re-authenticate, run: gh auth login -h github.com
- To forget about this host, run: gh auth logout -h github.com
Which is not surprising, the token is 15 months old.
Yep that all makes sense. So what I think happened is that at some point you logged in using gh auth login --with-token and we wrote an entry with just an oauth_token and no user field. For example, I just picked v2.10.0 since it was about 15 months old, we can see that happen here.
Then in the migration code if there is no user entry in the config we try to fetch a username with the token. Obviously since the token is not valid we blow up.
Like I said above, we cowardly fail here because we weren't sure about migrating data that we didn't have full confidence in but maybe that was the wrong choice here. Need to think about it some more on Monday.
Thank you for your help triaging this, it was extremely useful!
changed the title [-]Invalid `%APPDATA%\GitHub CLI\config.yml` and `%APPDATA%\GitHub CLI\hosts.yml` file breaks cli[/-][+]Unable to retrieve username during multi-account migration due to invalid/expired token[/+]on Dec 11, 2023
I'm getting this message for all gh commands, on Ubuntu linux:
failed to migrate config: cowardly refusing to continue with multi account migration: couldn't migrate oauth token for "github.com": timeout while trying to set secret in keyring
Reacted by 0xdavinchee, Mike iLL Kilmer, Ben Lawson, Tyson Jones, Terry Blain, Scott Giminiani, chck, Brandon Fredericksen, Hubert Slojewski, Anderson Grüdtner Martins and 2 more
Reacted by 0xdavinchee, Udaya Prakash and Tyson Jones
Reacted by 0xdavinchee, Udaya Prakash and Tyson Jones
Activity
williammartin commentedon Dec 9, 2023
Hey @jcasale, sorry for the inconvenience.
The migration exists to support multi account. We're failing the migration because we're unable to resolve a username for some token that we found because the server is returning
401. The idea here was that we wanted to err on the side of caution and have people take remediation rather than migrate data we didn't have confidence in. In retrospect, I'm not 100% sure this was the right choice here but we'll talk about it as a team on Monday.It will continue to run but later if you log into another account on any host you will replace your current user rather than it being an additive operation the first time. After that things should work as expected. This may not be a big issue for you.
To help us get confidence in this diagnosis, I would love to know the output of
gh auth status.jcasale commentedon Dec 9, 2023
Hi @williammartin no worries, the tool is brilliant ;)
After removing the config files and executing
gh auth login, the output ofgh auth statusis:If I misunderstood what you needed, please forgive me and straighten me out.
I am not sure if it matters, but these hosts previously may have had
gh auth loginexecuted for troubleshooting purposes, but they all run with theGH_TOKENenvironment variable set.The broken
hosts.ymlfile is:and the new
hosts.ymlfile created above is:williammartin commentedon Dec 9, 2023
Thanks! We try our best not to break but in this case, the multi-account feature work was so large I'm not surprised we overlooked something.
I'd love to see
gh auth statusfor the old hosts.yml, I suspect it will say something likeThe github.com token in .config/gh/hosts.yml is invalidjcasale commentedon Dec 9, 2023
The
gh auth statuscommand fails to run with the old files in place:Just to be thorough in case I still misunderstood, I tried the following:
gh auth login.gh auth status.gh auth statusagain.williammartin commentedon Dec 9, 2023
Haha sorry it's late here and I wasn't clear at all. You would need to run
gh auth statuswith a version earlier thanv2.40.0if you copy the oldconfig.ymlback in place. I think it should work withv2.40.0if you only copy thehosts.ymlback.jcasale commentedon Dec 9, 2023
lol, well now that makes sense;)
Which is not surprising, the token is 15 months old.
williammartin commentedon Dec 9, 2023
Yep that all makes sense. So what I think happened is that at some point you logged in using
gh auth login --with-tokenand we wrote an entry with just anoauth_tokenand nouserfield. For example, I just pickedv2.10.0since it was about 15 months old, we can see that happen here.Then in the migration code if there is no
userentry in the config we try to fetch a username with the token. Obviously since the token is not valid we blow up.Like I said above, we cowardly fail here because we weren't sure about migrating data that we didn't have full confidence in but maybe that was the wrong choice here. Need to think about it some more on Monday.
Thank you for your help triaging this, it was extremely useful!
[-]Invalid `%APPDATA%\GitHub CLI\config.yml` and `%APPDATA%\GitHub CLI\hosts.yml` file breaks cli[/-][+]Unable to retrieve username during multi-account migration due to invalid/expired token[/+]Deleplace commentedon Dec 27, 2023
I'm getting this message for all
ghcommands, on Ubuntu linux:Deleplace commentedon Dec 27, 2023
It got better after
rm ~/.config/gh/*kdere commentedon Mar 8, 2024
that also worked for me
fix(devcontainer): disable gh config mount to avoid migration bug
Reduce GitHub API dependency and fix two real-world blockers