Try to avoid reserved site keyword
[mirror/dsa-puppet.git] / modules / unbound / manifests / init.pp
index 03ae86c..840cfff 100644 (file)
@@ -1,52 +1,89 @@
-class unbouned {
-    package {
-        unbound: ensure => installed;
-    }
+# = Class: unbound
+#
+# This class installs and configures unbound
+#
+# == Sample Usage:
+#
+#   include unbound
+#
+class unbound {
+       include stdlib
 
-    exec {
-        "unbound restart":
-            path        => "/etc/init.d:/usr/bin:/usr/sbin:/bin:/sbin",
-            refreshonly => true,
-            ;
-    }
-    file {
-        "/var/lib/unbound":
-            ensure  => directory,
-            owner   => unbound,
-            group   => unbound,
-            mode    => 775,
-            ;
-        "/var/lib/unbound/root.key":
-            ensure  => present,
-            replace => false,
-            owner   => unbound,
-            group   => unbound,
-            mode    => 644,
-            # IANA root trust anchor, valid from 2010-07-15T00:00:00+00:00
-            # downloaded from https://data.iana.org/root-anchors/root-anchors.xml
-            content => ". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5\n",
-            notify  => Exec["unbound restart"],
-            ;
-        "/var/lib/unbound/debian.org.key":
-            ensure  => present,
-            replace => false,
-            owner   => unbound,
-            group   => unbound,
-            mode    => 644,
-            # debian.org DS record, July 2010'
-            content => "debian.org. IN DS 5283 7 2 3DC987A633914C195D03EA129E92327630D3428E92884A5E97829A55701F9E8A\n",
-            notify  => Exec["unbound restart"],
-            ;
-        "/etc/unbound/unbound.conf":
-            content => template("unbound/unbound.conf.erb"),
-            require => Package["unbound"],
-            notify  => Exec["unbound restart"],
-            owner   => root,
-            group   => root,
-            ;
-    }
-}
+       $is_recursor   = getfromhash($deprecated::nodeinfo, 'misc', 'resolver-recursive')
+       $client_ranges = hiera('allow_dns_query')
+       $firewall_blocks_dns = hiera('firewall_blocks_dns', false)
+       $empty_client_range = empty($client_ranges)
+       $ns            = hiera('resolv::nameservers')
+
+       package { 'unbound':
+               ensure => installed
+       }
+
+       service { 'unbound':
+               ensure => running,
+               hasstatus => false,
+               pattern   => 'unbound',
+       }
 
-# vim:set et:
-# vim:set sts=4 ts=4:
-# vim:set shiftwidth=4:
+       file { '/etc/init.d/unbound':
+               source => 'puppet:///modules/unbound/unbound.init',
+               mode   => '0555',
+               notify => Exec['systemctl daemon-reload'],
+       }
+       file { '/var/lib/unbound':
+               ensure  => directory,
+               owner   => unbound,
+               group   => unbound,
+               require => Package['unbound'],
+               mode    => '0775',
+       }
+       file { '/var/lib/unbound/root.key':
+               ensure  => present,
+               replace => false,
+               owner   => unbound,
+               group   => unbound,
+               mode    => '0644',
+               source  => 'puppet:///modules/unbound/root.key',
+               notify  => Service['unbound']
+       }
+       file { '/var/lib/unbound/debian.org.key':
+               ensure  => present,
+               replace => false,
+               owner   => unbound,
+               group   => unbound,
+               mode    => '0644',
+               source  => 'puppet:///modules/unbound/debian.org.key',
+               notify  => Service['unbound']
+       }
+       file { '/var/lib/unbound/29.172.in-addr.arpa.key':
+               ensure  => $firewall_blocks_dns ? { true  => 'absent', default => 'present' },
+               replace => $firewall_blocks_dns ? { true  => true, default => false },
+               owner   => unbound,
+               group   => unbound,
+               mode    => '0644',
+               source  => 'puppet:///modules/unbound/29.172.in-addr.arpa.key',
+               notify  => Service['unbound']
+       }
+       file { '/etc/unbound/unbound.conf':
+               content => template('unbound/unbound.conf.erb'),
+               require => [
+                       Package['unbound'],
+                       File['/var/lib/unbound/root.key'],
+                       File['/var/lib/unbound/debian.org.key']
+               ],
+               notify  => Service['unbound']
+       }
+
+       if ($is_recursor and !$empty_client_range) { 
+               ferm::rule { 'dsa-dns':
+                       domain      => 'ip',
+                       description => 'Allow nameserver access',
+                       rule        => sprintf('&TCP_UDP_SERVICE_RANGE(53, (%s))', join_spc(filter_ipv4($client_ranges))),
+               }
+               ferm::rule { 'dsa-dns6':
+                       domain      => 'ip6',
+                       description => 'Allow nameserver access',
+                       rule        => sprintf('&TCP_UDP_SERVICE_RANGE(53, (%s))', join_spc(filter_ipv6($client_ranges))),
+               }
+       }
+}