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

net: myhostname nss module doesn't work if hostname contains dots #17967

Closed
dcbw opened this issue Nov 17, 2016 · 4 comments

Comments

Projects
None yet
6 participants
@dcbw
Copy link

commented Nov 17, 2016

222 if src.source == "myhostname" {
223 if hostname == "" || hasDot {
224 continue
225 }
226 return fallbackOrder
227 }

The intent of this block appears to be that for a non-dotted name (which presumably is the local hostname) the fallback should be performed to allow nss-myhostname to attempt resolution of the name as a local hostname.

Unfortunately many installations, including cloud-based hosts, use fully qualified domain names as their hostname. hostname(1) on Linux even says:

   /etc/hostname  Historically  this  file  was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at
   boot time by the system initialization scripts to set the hostname.

It doesn't look like anywhere else in the Go resolver has special logic for handling the local hostname, so if your system hostname is an FQDN, go appears to bypass nss-myhostname. If your upstream DNS server cannot resolve the local hostname FQDN, and the hostname is not listed in /etc/hosts, then resolution will fail. But that's precisely what nss-myhostname was created to avoid, yet Go will ignore it.

Not sure what the best option here is, except that if myhostname is in nsswitch.conf, then either the Go resolver should attempt to do the mapping between local hostname and hostname internally, or it should pass the lookup off to netdns=cgo after trying its internal dns+files and getting failure from both of those?

@dustymabe

This comment has been minimized.

Copy link

commented Nov 17, 2016

Here is an example of this behavior on ec2:

[fedora@ip-10-0-110-213 ~]$ hostname
ip-10-0-110-213.ec2.internal
[fedora@ip-10-0-110-213 ~]$ go version
go version go1.7.3 linux/amd64
[fedora@ip-10-0-110-213 ~]$ cat dig.go 
package main

import "fmt"
import "net"
import "os"


func main() {
    a, _ := net.LookupHost(os.Args[1])
    fmt.Println(a)
}
[fedora@ip-10-0-110-213 ~]$ go run dig.go ip-10-0-110-213.ec2.internal
[]
[fedora@ip-10-0-110-213 ~]$ GODEBUG=netdns=cgo+1 go run dig.go ip-10-0-110-213.ec2.internal
go package net: using cgo DNS resolver
[fe80::10b8:58ff:feb4:cccc%eth0 10.0.110.213]

@quentinmit quentinmit added the NeedsFix label Nov 18, 2016

@quentinmit quentinmit changed the title net/conf.go::hostLookupOrder() should not ignore myhostname for dotted hostnames net: myhostname nss module doesn't work if hostname contains dots Nov 18, 2016

@quentinmit quentinmit added this to the Go1.8Maybe milestone Nov 18, 2016

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Nov 18, 2016

This is getting late for 1.8 but if the patch is really simple it could go in.

@danp

This comment has been minimized.

Copy link
Contributor

commented Nov 23, 2016

CL incoming for this. I went ahead and added support for other special names per the man page but happy to back that out.

@gopherbot

This comment has been minimized.

Copy link

commented Nov 23, 2016

CL https://golang.org/cl/33550 mentions this issue.

@gopherbot gopherbot closed this in 4bd9570 Nov 29, 2016

@golang golang locked and limited conversation to collaborators Nov 29, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.