-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net: Go DNS resolver does not read /etc/hosts #22846
Comments
Reading the source of // glibc says the default is "dns [!UNAVAIL=return] files"
// http://www.gnu.org/software/libc/manual/html_node/Notes-on-NSS-Configuration-File.html. It turns out that file does not exist in the container. If I create it with the following contents:
I get the expected result. |
Thanks a ton! |
Docker container with a cgo-disabled Go binary that needs to resolves a host defined in the /etc/hosts file but wasn't working |
Hi, how to fix the problems in mac osx? I can not create the |
As this is a common deployment method with golang and k8s with minimal images, this has very unexpected results. Can we fix this to function as expected in a minimal environment? |
Ping |
The golang resolver uses `/etc/nsswitch.conf` if it exists. See golang/go#22846 Resolves jumanjihouse#64
The golang resolver uses `/etc/nsswitch.conf` if it exists. See golang/go#22846 Resolves jumanjihouse#64
The golang resolver uses `/etc/nsswitch.conf` if it exists. See golang/go#22846 Resolves jumanjihouse#64
another reason could be the permission ot '/etc/hosts', it should be 644 when user is not root |
@panamafrancis it is common to use alpine as a base image as its size is small. it uses a non glibc implementation and does not contain nsswitch.conf. The distro assumes nonglibc behavior as its not glibc based, and behaves well in the absence of nsswitch.conf. golang chose to implement glibc's failback behaviour in the absence of nsswitch.conf, which IMO is a bad default. etc/hosts should be honored by default in the absence of nsswitch.conf. Alpine is not going away any time soon, and convincing folks not to use alpine is going to be a hard sell. I'd suggest golang change its default to a safer one, ie honor etc/hosts first, in light of this. This would be the least surprise option as well as one that hardens security. |
Ok... just hit this again when switching to k8s 1.12. |
As a result, /etc/hosts will be prioritized over DNS queries This resolves the conflict between: * fluxd using netgo for static compilation. netgo reads nsswitch.conf to mimic glibc, defaulting to prioritize DNS queries over /etc/hosts if nsswitch.conf is missing: golang/go#22846 * Alpine not including a nsswitch.conf file. Since Alpine doesn't use glibc (it uses musl), maintainers argue that the need of nsswitch.conf is a Go bug: gliderlabs/docker-alpine#367 (comment)
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
What did you do?
The following script creates a Docker container with a cgo-disabled Go binary that resolves a host defined in the /etc/hosts file.
What did you expect to see?
Go's DNS resolver resolve the address that is contained in /etc/hosts.
Output:
What did you see instead?
An external DNS lookup was performed.
(This may be the same issue that was happening here #14170)
The text was updated successfully, but these errors were encountered: