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
cannot authenticate through cli, with no error to debug on dnf(linux) based system #4083
@ideepika Hi, this error is a generic network connectivity error. I don't think the gh process can provide you with any more detailed information. From the machine where you are running gh from, can you verify that networking is set up correctly? You can perhaps use curl https://api.github.com to see if you can make requests to GitHub.
@ideepika Setting DEBUG=api environment variable will print detailed information about HTTPS requests. This looks like a DNS error, meaning that gh was not able to resolve the hostname github.com. I cannot think of a reason why that would be.
❯ DEBUG=api gh auth login -w
* Request at 2021-08-05 05:02:31.59816361 +0530 IST m=+0.021690287
* Request to https://api.github.com/repos/cli/cli/releases/latest
> GET /repos/cli/cli/releases/latest HTTP/1.1
> Host: api.github.com
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.13.1
* dial tcp: lookup api.github.com on 127.0.0.1:53: server misbehaving
* Request took 2.654105ms
* Request at 2021-08-05 05:02:31.60151682 +0530 IST m=+0.025043535
* Request to https://github.com/login/device/code
> POST /login/device/code HTTP/1.1
> Host: github.com
> Content-Type: application/x-www-form-urlencoded
* dial tcp: lookup github.com on 127.0.0.1:53: server misbehaving
* Request took 643.855µs
error connecting to github.com
lookup github.com on 127.0.0.1:53: server misbehaving
check your internet connection or githubstatus.com
@ideepika Thanks for sharing! I can't tell from over here why there would be a "server misbehaving" error message. Do you have a proxy set via https_proxy/HTTPS_PROXY environment variables or custom DNS server on this network? You can check DNS resolution with nslookup github.com or dig github.com. Also take a peek at /etc/resolv.conf.
I'm sorry, but people who don't have access to your computer are not very well positioned to debug this issue. I think you might be able to get to the bottom of it after some digging, but I'm pretty sure that this is not a bug caused by gh. Closing until there is evidence that gh itself is broken.
I ran into this issue on Arch Linux. I had an empty /etc/resolv.conf, but dns lookups still worked across the system because it used systemd for dns resolution via nss. Go must not use the nss facility, so adding nameserver 1.1.1.1 to /etc/resolv.conf fixed the issue.
Reacted by Alexander Weaver, czaplicki, Viktor Varland, Thomas Lagies, Fredrik Lanker, valentino-sm, kcx1, xleph, s0bby, Charbel Nicolas and 32 more
Reacted by Kay Gosho, Andrei and SqueakyMonjuer
Reacted by Viktor Varland, kcx1, Roberto Previdi, Kay Gosho, ProMix, Andrei, Drew Deleón-Zemke and SqueakyMonjuer
Reacted by czaplicki, Viktor Varland, Thomas Lagies, Daniel Farrell, Ethan Moss, kcx1, Davide Bassi, Isaac McQuaide, josimarcamilo, Kay Gosho and 7 more
I ran into this issue on Arch Linux. I had an empty /etc/resolv.conf, but dns lookups still worked across the system because it used systemd for dns resolution via nss. Go must not use the nss facility, so adding nameserver 1.1.1.1 to /etc/resolv.conf fixed the issue.
I ran into this issue on Arch Linux. I had an empty /etc/resolv.conf, but dns lookups still worked across the system because it used systemd for dns resolution via nss. Go must not use the nss facility, so adding nameserver 1.1.1.1 to /etc/resolv.conf fixed the issue.
What is the root cause? Is the Go runtime not using the Name Service Switch? The standard API to resolve a domain name on Linux is gethostbyname(3), which should automatically use the Name Service Switch.
I quickly looked at the go source. It looks like it depends on how the binary is compiled. I think the pure go network stack simply reads and parses resolv.conf. There is a separate network stack that uses getaddrinfo which should use nss if compiled with build tag cgo. As best I can tell it will use the pure go stack if the build tag netgo is used or cgo is not used. I'm on my phone so I can't test anything to confirm.
@drewkett Thanks for that analysis. We do set CGO_ENABLED=0 in our official binary/packages, effectively disabling cgo for cross-compiled binaries, so gh compiled on the host system might behave differently than gh downloaded from our official binaries.
Indeed, when I directly make after cloning the repo, I can authenticate to GitHub with the binary. I see that the Arch Linux package did disable cgo. What’s the recommendation for Linux distribution packages? If I understand correctly, it might make sense for the official build to disable cgo for better compatibility, but if we know that cgo works on a distribution (e.g. Arch Linux), maybe we should enable cgo instead?
I can try later enabling cgo in the Arch Linux package metadata, and build the package to see whether this is the only problem. Is there a way to “log out” of the CLI, so that I can try the authentication workflow again? I assume, by deleting some “cookies” file?
@FranklinYu You could try to reach out to Arch linux package maintainers to see if they would enable cgo. I'm not familiar with Arch, but I know that for Ubuntu for example, a build with cgo enabled would work for one Ubuntu version but could fail on a different version. The solution, of course, would be that we offer a different gh build for each Ubuntu version, but as we currently cannot commit to that, our official Linux builds disable cgo to increase portability.
If I build a new gh and want to test the authentication, what’s the best way? Do I simply remove ~/.config/gh/hosts.yml and try gh auth login again? Or does gh auth login accept any flag to specify the configuration root?
I figured it out for Arch Linux! I was using systemd-resolved for name resolution. I should have followed Arch Wiki to set up systemd-resolved to use the “stub mode”, in other words
I figured it out for Arch Linux! I was using systemd-resolved for name resolution. I should have followed Arch Wiki to set up systemd-resolved to use the “stub mode”, in other words
Software that relies on glibc's getaddrinfo(3) (or similar) will work out of the box, since, by default, /etc/nsswitch.conf is configured to use nss-resolve(8) if it is available.
To provide domain name resolution for software that reads /etc/resolv.conf directly, such as web browsers and GnuPG, systemd-resolved has four different modes for handling the file—stub, static, uplink and foreign. They are described in systemd-resolved(8) § /ETC/RESOLV.CONF. We will focus here only on the recommended mode, i.e. the stub mode which uses /run/systemd/resolve/stub-resolv.conf.
/run/systemd/resolve/stub-resolv.conf contains the local stub 127.0.0.53 as the only DNS server and a list of search domains. This is the recommended mode of operation that propagates the systemd-resolved managed configuration to all clients.
Activity
mislav commentedon Aug 4, 2021
@ideepika Hi, this error is a generic network connectivity error. I don't think the gh process can provide you with any more detailed information. From the machine where you are running
ghfrom, can you verify that networking is set up correctly? You can perhaps usecurl https://api.github.comto see if you can make requests to GitHub.ideepika commentedon Aug 4, 2021
@mislav seems to work fine:
mislav commentedon Aug 4, 2021
@ideepika So strange; thanks for checking. How did you install gh on your system?
ideepika commentedon Aug 4, 2021
using dnf, but IIRC the nature remains same with other modes of installation.
ideepika commentedon Aug 4, 2021
@mislav Aren't there ways to look into failure debug logs?
mislav commentedon Aug 4, 2021
@ideepika Setting
DEBUG=apienvironment variable will print detailed information about HTTPS requests. This looks like a DNS error, meaning thatghwas not able to resolve the hostnamegithub.com. I cannot think of a reason why that would be.ideepika commentedon Aug 4, 2021
@mislav
mislav commentedon Aug 5, 2021
@ideepika Thanks for sharing! I can't tell from over here why there would be a "server misbehaving" error message. Do you have a proxy set via
https_proxy/HTTPS_PROXYenvironment variables or custom DNS server on this network? You can check DNS resolution withnslookup github.comordig github.com. Also take a peek at/etc/resolv.conf.I'm sorry, but people who don't have access to your computer are not very well positioned to debug this issue. I think you might be able to get to the bottom of it after some digging, but I'm pretty sure that this is not a bug caused by gh. Closing until there is evidence that gh itself is broken.
0xjas0 commentedon Aug 21, 2021
Run below commands to fix this:
unset HTTP_PROXYunset HTTPS_PROXYunset http_proxyunset https_proxydrewkett commentedon Feb 17, 2022
I ran into this issue on Arch Linux. I had an empty
/etc/resolv.conf, but dns lookups still worked across the system because it used systemd for dns resolution via nss. Go must not use the nss facility, so addingnameserver 1.1.1.1to/etc/resolv.conffixed the issue.charbelnicolas commentedon Jul 9, 2022
I'm on Arch too and this fixed it, thanks!
aureliolk commentedon Jan 10, 2023
Very Thanks !!
FranklinYu commentedon Jan 20, 2023
What is the root cause? Is the Go runtime not using the Name Service Switch? The standard API to resolve a domain name on Linux is
gethostbyname(3), which should automatically use the Name Service Switch.FranklinYu commentedon Jan 20, 2023
I tried this on Arch Linux:
It gives me “200 Ok” as expected, so this do seem like an issue specific to GitHub-CLI. Shall we re-open?
mislav commentedon Jan 23, 2023
@FranklinYu If your simple program works, can you see if you can reproduce the original issue by compiling gh from source?
It should be easy: just clone this repo, run
make, and trybin/gh.drewkett commentedon Jan 23, 2023
I quickly looked at the go source. It looks like it depends on how the binary is compiled. I think the pure go network stack simply reads and parses resolv.conf. There is a separate network stack that uses getaddrinfo which should use nss if compiled with build tag cgo. As best I can tell it will use the pure go stack if the build tag netgo is used or cgo is not used. I'm on my phone so I can't test anything to confirm.
mislav commentedon Jan 23, 2023
@drewkett Thanks for that analysis. We do set
CGO_ENABLED=0in our official binary/packages, effectively disabling cgo for cross-compiled binaries, soghcompiled on the host system might behave differently thanghdownloaded from our official binaries.FranklinYu commentedon Jan 28, 2023
Indeed, when I directly
makeafter cloning the repo, I can authenticate to GitHub with the binary. I see that the Arch Linux package did disable cgo. What’s the recommendation for Linux distribution packages? If I understand correctly, it might make sense for the official build to disable cgo for better compatibility, but if we know that cgo works on a distribution (e.g. Arch Linux), maybe we should enable cgo instead?I can try later enabling cgo in the Arch Linux package metadata, and build the package to see whether this is the only problem. Is there a way to “log out” of the CLI, so that I can try the authentication workflow again? I assume, by deleting some “cookies” file?
mislav commentedon Jan 30, 2023
@FranklinYu You could try to reach out to Arch linux package maintainers to see if they would enable cgo. I'm not familiar with Arch, but I know that for Ubuntu for example, a build with cgo enabled would work for one Ubuntu version but could fail on a different version. The solution, of course, would be that we offer a different
ghbuild for each Ubuntu version, but as we currently cannot commit to that, our official Linux builds disable cgo to increase portability.FranklinYu commentedon Feb 17, 2023
If I build a new
ghand want to test the authentication, what’s the best way? Do I simply remove~/.config/gh/hosts.ymland trygh auth loginagain? Or doesgh auth loginaccept any flag to specify the configuration root?FranklinYu commentedon Feb 17, 2023
I figured it out for Arch Linux! I was using
systemd-resolvedfor name resolution. I should have followed Arch Wiki to set upsystemd-resolvedto use the “stub mode”, in other wordsCompiling with cgo was rejected in https://bugs.archlinux.org/task/77057. Thank Mislav for help!
miakuon commentedon Mar 1, 2023
Very Thanks! That helped a lot
freddiehaddad commentedon Jun 5, 2023
This issue is discussed in detail here: https://wiki.archlinux.org/title/Systemd-resolved#DNS
TLDR; Not all programs use systemd's resolved service and instead rely on /etc/resolv.conf.
The fix:
# ln -rsf /run/systemd/resolve/stub-resolv.conf /etc/resolv.confDNS
Software that relies on glibc's getaddrinfo(3) (or similar) will work out of the box, since, by default, /etc/nsswitch.conf is configured to use nss-resolve(8) if it is available.
To provide domain name resolution for software that reads /etc/resolv.conf directly, such as web browsers and GnuPG, systemd-resolved has four different modes for handling the file—stub, static, uplink and foreign. They are described in systemd-resolved(8) § /ETC/RESOLV.CONF. We will focus here only on the recommended mode, i.e. the stub mode which uses /run/systemd/resolve/stub-resolv.conf.
/run/systemd/resolve/stub-resolv.conf contains the local stub 127.0.0.53 as the only DNS server and a list of search domains. This is the recommended mode of operation that propagates the systemd-resolved managed configuration to all clients.