-
Notifications
You must be signed in to change notification settings - Fork 495
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
networking: Workaround 2693 by ignoring resolv.conf entries starting with dot #2694
Conversation
Can one of the admins verify this patch? |
@cthorn42 any chance you could take a look at this ? |
I don't think this is true. Quoting
Quoting
So on Linux libc can certainly use it.
You could replace it with a native implementation. Quoting
I think that means you can use: Socket.getaddrinfo(Socket.gethostname, nil, nil, nil, nil, Socket::AI_CANONNAME) |
I think most sys admins would expect puppet's fqdn / hostname to return exactly what the This is a quick port of the standard linux hostname C code with the addition of falling back to parsing /etc/resolv.conf. #!/opt/puppetlabs/puppet/bin/ruby
require 'socket'
def fqdn
# Addrinfo.getaddrinfo
result = Addrinfo.getaddrinfo(Socket.gethostname, nil, nil, Socket::SOCK_DGRAM, nil, Socket::AI_CANONNAME)
.map { |a| a.canonname }
.find { |n| !n.nil? and n.include? '.' }
return result if !result.nil?
# Socket.getnameinfo
result = Socket.getifaddrs().filter_map do |ifap|
next unless ifap.addr
next unless (ifap.flags & Socket::IFF_LOOPBACK) == 0
next if (ifap.flags & Socket::IFF_UP) == 0
family = ifap.addr.afamily
next unless (family == Socket::AF_INET || family == Socket::AF_INET6)
next if family == Socket::AF_INET6 && ifap.addr.ipv6_linklocal?
n = Socket.getnameinfo(ifap.addr, Socket::NI_NAMEREQD)
n[0] if n and !n[0].nil? and n[0].include? '.'
end.first
return result if !result.nil?
# Fallback to parsing /etc/resolv.conf
content = File.read('/etc/resolv.conf', chomp: true)
domain = if content =~ /^domain\s+(\S+)/
Regexp.last_match[1]
elsif content =~ /^search\s+(\S+)/
Regexp.last_match[1]
end
# strip leading and trailing .
domain.sub!(/^\.?(.*?)\.?$/, '\1') if domain
result = [Socket.gethostname]
result.append(domain) if domain and domain.length > 1
result.join('.')
end |
I think this is definitely true for the search path but i agree using the domain part seems reasonable if there is no better info |
Thanks for your PR @Geod24! I think the "facter has been doing this wrong all this time" issue is valid, but a different issue that would need to be addressed in Facter 5. Thanks @ekohl and @h0tw1r3 for the sample code. Your PR makes sense to me. To get this merged could you:
Note this isn't true for
Could you add a test case for that?
I'd be fine filing a separate issue for this. |
a60d5ac
to
3bffeff
Compare
What is the desired outcome here ? In the meantime, I have rebased the commit and amended the message to remove the aforementioned section. |
Hi @Geod24, thank you for your patience! Regarding your questions:
We should assume the resolver will pick the first entry and should not error out
If the first entry is Let me know if anything is unclear or if you have any other questions, thank you! |
This PR addresses issue #2693. |
dc0056f
to
d337b9c
Compare
d337b9c
to
b8cf55f
Compare
…with dot Currently, systems without a FQDN can be mishandled by facter for certain `/etc/resolv.conf` content. This was initially noticed when systemd-resolved was installed on a host without domain. systemd-resolved stub resolver sets 'search .' as a search domain, which results in the following hostname/domain/fqdn triplet: foo, ., foo... See: https://github.com/systemd/systemd/blob/v255/src/resolve/resolv.conf#L19 This is wrong on multiple levels: first, facter does not seem to handle '.' (the root level) well, and there have been PRs to remove the trailing dot in FQDN as far back as 2012 (PR 200), leaving user with a convenient, but sometimes ambiguous string that is not fully qualified. This commit implements a a middle ground solution to support top-level/domainless servers without making a breaking change. Additionally, it adds more coverage for various search cases.
b8cf55f
to
0181bb7
Compare
Currently, systems without a FQDN can be mishandled by facter for certain
/etc/resolv.conf
content. This was initially noticed when systemd-resolved was installed on a host without domain.systemd-resolved stub resolver sets 'search .' as a search domain, which results in the following hostname/domain/fqdn triplet:
foo
,.
,foo..
. See: https://github.com/systemd/systemd/blob/v255/src/resolve/resolv.conf#L19This is wrong on multiple levels: first, facter does not seem to handle '.' (the root level) well, and there have been PRs to remove the trailing dot in FQDN as far back as 2012 (PR 200), leaving user with a convenient, but sometimes ambiguous string that is not fully qualified.
More fundamentally, facter sould not be using 'search' or 'domain' in resolv.conf to begin with, as those are client resolution options, and usually set for convenience, but are not part of the hostname. However, removing this lookup is much more involved, as facter has been doing this for years.
Hence, this commit implements a a middle ground solution to support top-level/domainless servers without making a breaking change.