Foreman-Proxy DCHP ISC - DNS Search

**Problem: **
DHCP Settings for multiple search domains not being populated.

**Expected outcome: **
Client using DHCP from Foreman will have full DNS search domains set.

**Foreman and Proxy versions: **
1.16.2-1.el7

Foreman and Proxy plugin versions:

Other relevant data:
Post won’t let me put in dhcp.conf or resolv.conf --> New user limited to 5 links even though no links were in post. Can’t upload.

# dhcpd.conf
omapi-port 7911;

default-lease-time 43200;
max-lease-time 86400;

ddns-update-style none;

option domain-name "mydomain.dick.jane.com";
option domain-name-servers 1.2.3.4,5.6.7.8
option ntp-servers none;

allow booting;
allow bootp;

option fqdn.no-client-update    on;  # set the "O" and "S" flag bits
option fqdn.rcode2            255;
option pxegrub code 150 = text ;


# Bootfile Handoff
next-server 10.118.97.156;
option architecture code 93 = unsigned integer 16 ;
if option architecture = 00:06 {
  filename "grub2/shim.efi";
} elsif option architecture = 00:07 {
  filename "grub2/shim.efi";
} elsif option architecture = 00:09 {
  filename "grub2/shim.efi";
} else {
  filename "pxelinux.0";
}

log-facility local7;

include "/etc/dhcp/dhcpd.hosts";
# mydomain.dick.jane.com
subnet 10.118.97.0 netmask 255.255.255.0 {
  pool
  {
    range 10.118.97.180 10.118.97.189;
  }

  option subnet-mask 255.255.255.0;
  option routers 10.118.97.1;
  option domain-search "mydomain.dick.jane.com,dick.net,jane.com";
}

regarding the link limit, if you mark the text as preformatted (using the ‘</>’ icon in the edit menu), it will both not count them as links and make it easier to read. I have edited your comment to set that. Sorry for the limiter, it is meant to prevent spammers from abusing the board by posting multiple links.

1 Like

From net references and my own testing, it looks like there is a bug in how Foreman-installer is handling the dhcpd.conf setup for dns-search.

It should be setting

option domain-search "mydomain.dick.jane.com","dick.net","jane.com"

in the /etc/dhcp/dhcpd.conf.

Instead the foreman-installer is setting it as:

option domain-search "mydomain.dick.jane.com,dick.net,jane.com"

which causes the dhcpclient process to throw an error and ignore these settings.

Here is a brief version of the foreman-installer run where I try to set the dns-search.

Foreman Installer Run to set
foreman-installer --foreman-proxy-dhcp-search-domains "mydomain.dick.jane.com","dick.net","jane.com" --verbose
...
Running installer with args [["--foreman-proxy-dhcp-search-domains", "mydomain.dick.jane.com,dick.net,jane.com", "--verbose"]]
...
[ WARN 2018-07-02 12:34:51 verbose] /Stage[main]/Dhcp/Concat[/etc/dhcp/dhcpd.conf]/File[/etc/dhcp/dhcpd.conf]/content:
...
[ WARN 2018-07-02 12:34:51 verbose] + option domain-search "mydomain.dick.jane.com,dick.net,jane.com";

/etc/dhcp/dhcpd.conf

option domain-search "cbs.ad.cbs.net,cbs.net,cbs.com";


When I set the following in dhcpd.conf manually and restart dhcpd the client gets set correctly as shown in /var/log/messages

Jul 2 12:53:15 tlistmrsnd32 NetworkManager[824]: <info> [1530550395.7266] dhcp4 (eno16777984): domain name 'mydomain.dick.jane.net'
Jul 2 12:53:15 tlistmrsnd32 NetworkManager[824]: <info> [1530550395.7266] dhcp (eno16777984): domain search 'mydomain.dick.jane.net'
Jul 2 12:53:15 tlistmrsnd32 NetworkManager[824]: <info> [1530550395.7266] dhcp (eno16777984): domain search 'dick.net.'
Jul 2 12:53:15 tlistmrsnd32 NetworkManager[824]: <info> [1530550395.7266] dhcp (eno16777984): domain search 'jane.com.'

/etc/dhcp/dhcpd.conf modified outside of Foreman
...
option domain-search "mydomain.dick.jane.com","dick.net","dick.com";
...

Resolv.conf on client

# Generated by NetworkManager
search mydomain.dick.jane.com dick.net jane.com
nameserver 1.2.3.4
nameserver 5.6.7.8

OS: CentOS Linux release 7.5.1804 (Core)

I have installed the latest available patches as part of this troubleshooting.

I did further digging and found that the /usr/share/foreman-installer/modules/dhcp/templates/dhcpd.pool.erb block of code works. Still digging into where it is getting corrupted to be “mydomain.dick.jane.com,dick.net,jane.com”.

<% if @search_domains and @search_domains.is_a? Array -%>
option domain-search "<%= @search_domains.sort.join('", "') %>";
<% elsif @search_domains -%>
option domain-search "<%= @search_domains.split(/[, ]+/).join('", "') %>";
<% end -%>

From IRB

irb(main):014:0> search_domains = ['mydomain.dick.jane.com','dick.net','jane.com'] => ["mydomain.dick.jane.com", "dick.net", "jane.com"]
irb(main):016:0> p search_domains.sort.join('", "')
"dick.net\", \"jane.com\", \"mydomain.dick.jane.com"
=> "dick.net\", \"jane.com\", \"mydomain.dick.jane.com"

irb(main):017:0> search_domains = "mydomain.dick.jane.com dick.net jane.com" => "mydomain.dick.jane.com dick.net jane.com"
irb(main):018:0> p search_domains.split(/[, ]+/).join('", "') "mydomain.dick.jane.com\", \"dick.net\", \"jane.com" => "mydomain.dick.jane.com\", \"dick.net\", \"jane.com"

With either an array or a string the settings to domain-search are correct at this stage exactly as expected. As I’m not great a tracing foreman code as it executes I could use some assistance nailing this down so it can be put into a bug report / fixed.

I don’t think that’s how we specify arrays in our installer. Can you try with foreman-installer --foreman-proxy-dhcp-search-domains mydomain.dick.jane.com --foreman-proxy-dhcp-search-domains dick.net --foreman-proxy-dhcp-search-domains jane.com and see if that works?

Didn’t work, but… It seems I can almost guess that is it happening when the foreman-installer is parsing the command line options:

foreman-installer --noop --verbose --foreman-proxy-dhcp-search-domains "mydomain.dick.jane.com","dick.net","jane.com"
...
[ INFO 2018-07-05 08:39:13 verbose] Running installer with args [["--noop", "--verbose", "--foreman-proxy-dhcp-search-domains", "mydomain.dick.jane.com,dick.net,jane.com"]]

[ WARN 2018-07-05 08:39:38 verbose] - option domain-search "mydomain.dick.jane.com","dick.net","jane.com";
[ WARN 2018-07-05 08:39:38 verbose] + option domain-search "mydomain.dick.jane.com,dick.net,jane.com";

Oddly, though, when I run this through IRB it still comes with correct output, so somewhere along the line it is pointing back to the wrong data.

irb(main):006:0> search_domains = 'mydomain.dick.jane.com,dick.net,jane.com'
=> "mydomain.dick.jane.com,dick.net,jane.com"

irb(main):007:0> p search_domains.split(/[, ]+/).join('", "')
"mydomain.dick.jane.com\", \"dick.net\", \"jane.com"
=> "mydomain.dick.jane.com\", \"dick.net\", \"jane.com"