Skip to content

Commit a60d5ac

Browse files
committed
networking: Workaround 2693 by ignoring resolv.conf entries starting 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. 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.
1 parent 7bfd75b commit a60d5ac

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/facter/resolvers/hostname.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def hostname_and_no_domain?(hostname, domain)
6363

6464
def read_domain
6565
file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
66-
if file_content =~ /^domain\s+(\S+)/
66+
if file_content =~ /^domain\s+([^.]\S+)/
6767
Regexp.last_match(1)
68-
elsif file_content =~ /^search\s+(\S+)/
68+
elsif file_content =~ /^search\s+([^.]\S+)/
6969
Regexp.last_match(1)
7070
end
7171
end

lib/facter/resolvers/linux/hostname.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def hostname_and_no_domain?(hostname, domain)
9696

9797
def read_domain
9898
file_content = Facter::Util::FileHelper.safe_read('/etc/resolv.conf')
99-
if file_content =~ /^domain\s+(\S+)/
99+
if file_content =~ /^domain\s+([^.]\S+)/
100100
Regexp.last_match(1)
101-
elsif file_content =~ /^search\s+(\S+)/
101+
elsif file_content =~ /^search\s+([^.]\S+)/
102102
Regexp.last_match(1)
103103
end
104104
end

spec/facter/resolvers/linux/hostname_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@
8282

8383
it_behaves_like 'detects values'
8484
end
85+
86+
context 'when /etc/resolv.conf has "search ."' do
87+
let(:resolv_conf) { "search .\n" }
88+
let(:domain) { nil }
89+
let(:fqdn) { hostname }
90+
91+
it_behaves_like 'detects values'
92+
end
8593
end
8694

8795
context 'when FFI is not installed' do

0 commit comments

Comments
 (0)