Skip to content

Commit

Permalink
Validate named.conf and zones.conf using named-checkconf
Browse files Browse the repository at this point in the history
Make use of the `validate_cmd` parameter in concat to run
named-checkconf on the target file. This way the validity of to-be-updated
configuration files named.conf or zones.conf is checked before actually
writing the new configuration and restarting the named service. This
prevents named from loading invalid configuration settings that would
result in named failing to start.

The file named.conf.options itself cannot be checked with
named-checkconf because its content is only valid inside the
"options { };" directive.
  • Loading branch information
antaflos committed May 8, 2019
1 parent 1ff131b commit c88f5ec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
20 changes: 16 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
}

concat { $dns::publicviewpath:
owner => root,
group => $dns::params::group,
mode => '0640',
owner => root,
group => $dns::params::group,
mode => '0640',
validate_cmd => "${dns::params::named_checkconf} %",
}

if $dns::enable_views {
Expand All @@ -19,13 +20,24 @@
mode => '0755',
}
}

concat::fragment { 'dns_zones+01-header.dns':
target => $dns::publicviewpath,
content => ' ',
order => '01',
}

concat { [$dns::namedconf_path, $dns::optionspath]:
concat { $dns::namedconf_path:
owner => root,
group => $dns::params::group,
mode => '0640',
require => Concat[$dns::optionspath],
validate_cmd => "${dns::params::named_checkconf} %",
}

# This file cannot be checked by named-checkconf because its content is only
# valid inside an "options { };" directive.
concat { $dns::optionspath:
owner => root,
group => $dns::params::group,
mode => '0640',
Expand Down
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$user = 'bind'
$group = 'bind'
$rndcconfgen = '/usr/sbin/rndc-confgen'
$named_checkconf = '/usr/sbin/named-checkconf'
}
'RedHat': {
$dnsdir = '/etc'
Expand All @@ -31,6 +32,7 @@
$user = 'named'
$group = 'named'
$rndcconfgen = '/usr/sbin/rndc-confgen'
$named_checkconf = '/usr/sbin/named-checkconf'
}
/^(FreeBSD|DragonFly)$/: {
$dnsdir = '/usr/local/etc/namedb'
Expand All @@ -46,6 +48,7 @@
$user = 'bind'
$group = 'bind'
$rndcconfgen = '/usr/local/sbin/rndc-confgen'
$named_checkconf = '/usr/local/sbin/named-checkconf'
}
'Archlinux': {
$dnsdir = '/etc'
Expand All @@ -61,6 +64,7 @@
$user = 'named'
$group = 'named'
$rndcconfgen = '/usr/sbin/rndc-confgen'
$named_checkconf = '/usr/sbin/named-checkconf'
}
default: {
fail ("Unsupported operating system family ${facts['osfamily']}")
Expand Down
1 change: 1 addition & 0 deletions manifests/view.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
group => $dns::params::group,
mode => '0640',
notify => Service[$dns::namedservicename],
before => Concat[$dns::publicviewpath],
}

concat::fragment { "dns_view_header_${title}.dns":
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/dns_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
'allow-recursion { localnets; localhost; };'
])}

it { should contain_concat('/etc/named.conf') }
it { should contain_concat('/etc/named/zones.conf').with_validate_cmd('/usr/sbin/named-checkconf %') }
it { should contain_concat('/etc/named.conf').with_validate_cmd('/usr/sbin/named-checkconf %') }
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/etc/rndc.key";',
Expand Down Expand Up @@ -281,7 +282,8 @@
'allow-recursion { localnets; localhost; };'
])}

it { should contain_concat('/usr/local/etc/namedb/named.conf') }
it { should contain_concat('/usr/local/etc/namedb/zones.conf').with_validate_cmd('/usr/local/sbin/named-checkconf %') }
it { should contain_concat('/usr/local/etc/namedb/named.conf').with_validate_cmd('/usr/local/sbin/named-checkconf %') }
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/usr/local/etc/namedb/rndc.key";',
Expand Down

0 comments on commit c88f5ec

Please sign in to comment.