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

Support configuration of multiple forward zones #135

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ class { 'powerdns':
}
```

### Recursor forward zones

Multiple forward zones can be configured using `powerdns::forward_zones`.

```puppet
include powerdns::recursor
```

The configuration will be serialized into `forward-zones-file` config file.

```yaml
powerdns::forward_zones:
'example.com': 10.0.0.1
'foo': 192.168.1.1
# recurse queries
'+.': 1.1.1.1;8.8.8.8;8.8.4.4
```

### Backends

The default backend is MySQL. It also comes with support for PostgreSQL, Bind,
Expand Down
7 changes: 6 additions & 1 deletion manifests/authoritative.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# powerdns::authoritative
class powerdns::authoritative ($package_ensure = $powerdns::params::default_package_ensure) inherits powerdns {
class powerdns::authoritative (
$package_ensure = $powerdns::params::default_package_ensure,
Optional[Array[String]] $install_packages = $powerdns::install_packages,
) inherits powerdns {
# install the powerdns package
package { $::powerdns::params::authoritative_package:
ensure => $package_ensure,
}

ensure_packages($install_packages)

# install the right backend
case $::powerdns::backend {
'mysql': {
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
Pattern[/4\.[0-9]+/] $version = $::powerdns::params::version,
String[1] $mysql_schema_file = $::powerdns::params::mysql_schema_file,
String[1] $pgsql_schema_file = $::powerdns::params::pgsql_schema_file,
Hash $forward_zones = {},
) inherits powerdns::params {

# Do some additional checks. In certain cases, some parameters are no longer optional.
if $authoritative {
if ($::powerdns::backend != 'bind') and ($::powerdns::backend != 'ldap') and ($::powerdns::backend != 'sqlite') {
Expand Down
37 changes: 34 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
$authoritative_configdir = '/etc/pdns'
$recursor_package = 'pdns-recursor'
$recursor_service = 'pdns-recursor'
$recursor_config = '/etc/pdns-recursor/recursor.conf'
$recursor_dir = '/etc/pdns-recursor'
$recursor_config = "${recursor_dir}/recursor.conf"
$install_packages = []
}
'Debian': {
$authoritative_package = 'pdns-server'
Expand All @@ -61,7 +63,34 @@
$authoritative_configdir = '/etc/powerdns'
$recursor_package = 'pdns-recursor'
$recursor_service = 'pdns-recursor'
$recursor_config = '/etc/powerdns/recursor.conf'
$recursor_dir = '/etc/powerdns'
$recursor_config = "${recursor_dir}/recursor.conf"

case $facts['os']['name'] {
'Debian': {
case $facts['os']['release']['major'] {
'8': {
$install_packages = []
}
default: {
$install_packages = ['dirmngr']
}
}
}
'Ubuntu': {
case $facts['os']['release']['major'] {
'16.04': {
$install_packages = []
}
default: {
$install_packages = ['dirmngr']
}
}
}
default: {
$install_packages = []
}
}
}
'FreeBSD': {
$authoritative_package = 'powerdns'
Expand All @@ -82,7 +111,9 @@
$authoritative_configdir = '/usr/local/etc/pdns'
$recursor_package = 'powerdns-recursor'
$recursor_service = 'pdns-recursor'
$recursor_config = '/usr/local/etc/pdns/recursor.conf'
$recursor_dir = '/usr/local/etc/pdns'
$recursor_config = "${recursor_dir}/recursor.conf"
$install_packages = []
}
default: {
fail("${facts['os']['family']} is not supported yet.")
Expand Down
39 changes: 33 additions & 6 deletions manifests/recursor.pp
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
# the powerdns recursor
class powerdns::recursor ($package_ensure = $powerdns::params::default_package_ensure) inherits powerdns {
package { $::powerdns::params::recursor_package:
# @summary powerdns recursor

# @param package_ensure
# @param forward_zones
# Hash containing zone => dns servers pairs
# @param recursor_dir
# Configuration directory for recursor
#
class powerdns::recursor (
String $package_ensure = $powerdns::params::default_package_ensure,
Hash $forward_zones = $powerdns::forward_zones,
String $recursor_dir = $powerdns::recursor_dir,
) inherits powerdns {
package { $powerdns::recursor_package:
ensure => $package_ensure,
}

if !empty($forward_zones) {
$zone_config = "${recursor_dir}/forward_zones.conf"
file { $zone_config:
ensure => file,
owner => 'root',
group => 'root',
content => template('powerdns/forward_zones.conf.erb'),
notify => Service['pdns-recursor'],
}

powerdns::config { 'forward-zones-file':
value => $zone_config,
type => 'recursor',
}
}

service { 'pdns-recursor':
ensure => running,
name => $::powerdns::params::recursor_service,
name => $powerdns::params::recursor_service,
enable => true,
provider => [$::powerdns::params::service_provider],
require => Package[$::powerdns::params::recursor_package],
provider => [$powerdns::params::service_provider],
require => Package[$powerdns::params::recursor_package],
}
}
35 changes: 35 additions & 0 deletions spec/classes/powerdns_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,41 @@

it { is_expected.to contain_package(authoritative_package_name).with('ensure' => 'installed') }
end

context 'powerdns class with the recursor with forward zones' do
let(:params) do
{
recursor: true,
authoritative: false,
forward_zones: {
'example.com': '1.1.1.1',
'+.': '8.8.8.8'
}
}
end

case facts[:osfamily]
when 'RedHat'
recursor_dir = '/etc/pdns-recursor'
when 'Debian'
recursor_dir = '/etc/powerdns'
end

it { is_expected.to compile.with_all_deps }

# Check the authoritative server
it { is_expected.to contain_class('powerdns::recursor') }
it { is_expected.to contain_file("#{recursor_dir}/forward_zones.conf").with_ensure('file') }
it {
is_expected.to contain_powerdns__config('forward-zones-file') \
.with(value: "#{recursor_dir}/forward_zones.conf")
}

it {
is_expected.to contain_file("#{recursor_dir}/forward_zones.conf") \
.with_content(/^example.com=1.1.1.1/)
}
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions templates/forward_zones.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% @forward_zones.sort.each do |key, value| -%>
<%= key %>=<%= value %>
<% end -%>