From 18816ca38c3e946b52650db8325562d569a0e088 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 11 Apr 2014 16:18:34 +0200 Subject: [PATCH 01/20] adding a allow forward option to a zone --- manifests/zone.pp | 1 + templates/zone.erb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/manifests/zone.pp b/manifests/zone.pp index 18285801..a6f77c73 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -11,6 +11,7 @@ $reverse = false, $zone_type = 'master', $allow_transfer = [], + $allow_forward = [] $slave_masters = undef, $zone_notify = false, $ensure = present diff --git a/templates/zone.erb b/templates/zone.erb index 75592f13..824707c6 100644 --- a/templates/zone.erb +++ b/templates/zone.erb @@ -14,5 +14,11 @@ zone "<%= @zone %>" { <% end -%> }; <% end -%> +<% if @allow_forward -%> + allow-transfer { +<% @allow_forward.each do |ip| -%> + <%= ip %>; +<% end -%> + }; <% end -%> }; From 069ca05f9bf175b53966351a16f2fee501303061 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 11 Apr 2014 16:31:46 +0200 Subject: [PATCH 02/20] Adding the stdlib dependency This module was already used trough the array_validate in zone.pp. It is now explicitely declared in the Modulefile. --- Modulefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Modulefile b/Modulefile index 67f8dbf4..fb525410 100644 --- a/Modulefile +++ b/Modulefile @@ -6,3 +6,4 @@ author 'Adam Jahn' project_page 'https://github.com/ajjahn/puppet-dns' source 'https://github.com/ajjahn/puppet-dns' dependency 'puppetlabs/concat', '>=1.0.0' +dependency 'puppetlabs/stdlib', '>= 2.4.0' From 69e4f47d05ed1f20d50d3c130cdc165d7865d6c2 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 11 Apr 2014 16:34:26 +0200 Subject: [PATCH 03/20] correcting a typo --- manifests/zone.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index a6f77c73..35ba2433 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -11,7 +11,7 @@ $reverse = false, $zone_type = 'master', $allow_transfer = [], - $allow_forward = [] + $allow_forward = [], $slave_masters = undef, $zone_notify = false, $ensure = present From 1884ccbddbd26a18afdb683e8f728e381052e319 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 11 Apr 2014 17:38:13 +0200 Subject: [PATCH 04/20] correction on the forwarder name --- templates/zone.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/zone.erb b/templates/zone.erb index 824707c6..5278486f 100644 --- a/templates/zone.erb +++ b/templates/zone.erb @@ -15,7 +15,7 @@ zone "<%= @zone %>" { }; <% end -%> <% if @allow_forward -%> - allow-transfer { + allow-forwarder { <% @allow_forward.each do |ip| -%> <%= ip %>; <% end -%> From d5c5ffb18ef5b19fbe8b61e2796e97e5d1a6d197 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 11 Apr 2014 17:38:13 +0200 Subject: [PATCH 05/20] correction on the forwarder name --- templates/zone.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/zone.erb b/templates/zone.erb index 5278486f..5b904270 100644 --- a/templates/zone.erb +++ b/templates/zone.erb @@ -21,4 +21,5 @@ zone "<%= @zone %>" { <% end -%> }; <% end -%> +<% end -%> }; From 1f747e26ba5894d01c035aa99e9b13ffd0688f6e Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 10:46:51 +0200 Subject: [PATCH 06/20] validate the allow forwarder option --- manifests/zone.pp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index 35ba2433..29bef288 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -11,13 +11,18 @@ $reverse = false, $zone_type = 'master', $allow_transfer = [], - $allow_forward = [], + $allow_forwarder = [], $slave_masters = undef, $zone_notify = false, $ensure = present ) { validate_array($allow_transfer) + validate_array($allow_forwarder) + if $dns::options::forwarder and $allow_forwarder { + fatal("You cannot specify a global forwarder and \ + a zone forwarder for zone ${soa}") + } $zone_serial = $serial ? { false => inline_template('<%= Time.now.to_i %>'), From 2d64e830cc04364f4f421276e661af3d9e4dd79e Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 10:50:59 +0200 Subject: [PATCH 07/20] adding test for the forward option --- spec/defines/dns_zone_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index 7a49abc8..14b67766 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -15,7 +15,9 @@ context 'passing an array to data' do let :facts do { :concat_basedir => '/dne', } end let :params do - { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ] } + { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], + :allow_forwarder => ['8.8.8.8', '208.67.222.222'] + } end it 'should pass input validation' do @@ -31,11 +33,21 @@ should contain_concat__fragment('named.conf.local.test.com.include'). with_content(/192\.0\.2\.0/) } + it { should contain_concat__fragment('named.conf.local.test.com.include'). - with_content(/2001:db8::\/32/) + with_content(/allow-forwarder/) + } + + it { + should contain_concat__fragment('named.conf.local.test.com.include'). + with_content(/8.8.8.8/) } + it { + should contain_concat__fragment('named.conf.local.test.com.include'). + with_content(/2001:db8::\/32/) + } end end From f5fc4aa516132c07e047a0c951b884f0acffbf7a Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 11:01:53 +0200 Subject: [PATCH 08/20] tab to space --- spec/defines/dns_zone_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index 14b67766..25180a98 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -16,7 +16,7 @@ let :facts do { :concat_basedir => '/dne', } end let :params do { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], - :allow_forwarder => ['8.8.8.8', '208.67.222.222'] + :allow_forwarder => ['8.8.8.8', '208.67.222.222'] } end From 946c3a36cd87d90d9df6cca512d23dd02395fb54 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 11:06:49 +0200 Subject: [PATCH 09/20] change the variable name accordingly in the template --- templates/zone.erb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/zone.erb b/templates/zone.erb index 5b904270..d88588e7 100644 --- a/templates/zone.erb +++ b/templates/zone.erb @@ -14,9 +14,10 @@ zone "<%= @zone %>" { <% end -%> }; <% end -%> -<% if @allow_forward -%> - allow-forwarder { -<% @allow_forward.each do |ip| -%> +<% if @allow_forwarder -%> + forward <%= @forward_policy %>; + forwarders { +<% @allow_forwarder.each do |ip| -%> <%= ip %>; <% end -%> }; From d6481f881a3bb021c218dcefba64f6e03fa8bdec Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 11:25:57 +0200 Subject: [PATCH 10/20] adding a policy setting for the forwarder --- manifests/zone.pp | 4 ++++ templates/zone.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index 29bef288..48fe7084 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -12,6 +12,7 @@ $zone_type = 'master', $allow_transfer = [], $allow_forwarder = [], + $forward_policy = 'first', $slave_masters = undef, $zone_notify = false, $ensure = present @@ -23,6 +24,9 @@ fatal("You cannot specify a global forwarder and \ a zone forwarder for zone ${soa}") } + if !member(['first', 'only'], $forward_policy) { + fatal('The forward policy can only be set to either first or only') + } $zone_serial = $serial ? { false => inline_template('<%= Time.now.to_i %>'), diff --git a/templates/zone.erb b/templates/zone.erb index d88588e7..a2021b6a 100644 --- a/templates/zone.erb +++ b/templates/zone.erb @@ -13,7 +13,7 @@ zone "<%= @zone %>" { <%= ip %>; <% end -%> }; -<% end -%> +<% end -%> <% if @allow_forwarder -%> forward <%= @forward_policy %>; forwarders { From 2e8242f40e8aaf5a60c5da33083f69fdbd993ef6 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 11:35:46 +0200 Subject: [PATCH 11/20] fixing the forwarders accordingly --- spec/defines/dns_zone_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index 25180a98..bb981b80 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -36,7 +36,7 @@ it { should contain_concat__fragment('named.conf.local.test.com.include'). - with_content(/allow-forwarder/) + with_content(/forwarders/) } it { From 698695350bcf7603dd8988fd9ab7ba3d2249740a Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sat, 12 Apr 2014 11:38:02 +0200 Subject: [PATCH 12/20] correcting the test accordingly to the new options --- spec/defines/dns_zone_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index bb981b80..4432d96f 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -39,6 +39,11 @@ with_content(/forwarders/) } + it { + should contain_concat__fragment('named.conf.local.test.com.include'). + with_content(/forward only;/) + } + it { should contain_concat__fragment('named.conf.local.test.com.include'). with_content(/8.8.8.8/) From 37403d4abab241000cc0698df2f298a16cede4f2 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 12:28:22 +0200 Subject: [PATCH 13/20] adding more test --- spec/defines/dns_zone_spec.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index 4432d96f..3a45361d 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -41,7 +41,7 @@ it { should contain_concat__fragment('named.conf.local.test.com.include'). - with_content(/forward only;/) + with_content(/forward first;/) } it { @@ -55,5 +55,30 @@ } end + context 'when ask to have a only forward policy' do + let :facts do { :concat_basedir => '/dne', } end + let :params do + { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], + :allow_forwarder => ['8.8.8.8', '208.67.222.222'], + :forward_policy => 'only' + } + end + it { + should contains_concat__fragment('named.conf.local.test.com.include') + with_content(/foward only;/) + } + end + context 'when given a bogus forward policy' do + let :facts do { :concat_basedir => '/dne', } end + let :params do + { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], + :allow_forwarder => ['8.8.8.8', '208.67.222.222'], + :forward_policy => 'nonvalidpolicy' + } + end + it { + should fail + } + end end From a2fe3a5235cde245591220071256dbf064001656 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 12:40:35 +0200 Subject: [PATCH 14/20] correcting the test --- spec/defines/dns_zone_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index 3a45361d..f44e9c4b 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -63,10 +63,10 @@ :forward_policy => 'only' } end - it { - should contains_concat__fragment('named.conf.local.test.com.include') + it 'should have a forward only policy' do + should contain_concat__fragment('named.conf.local.test.com.include'). with_content(/foward only;/) - } + end end context 'when given a bogus forward policy' do let :facts do { :concat_basedir => '/dne', } end @@ -76,9 +76,9 @@ :forward_policy => 'nonvalidpolicy' } end - it { + it 'should not validat:' do should fail - } + end end end From 411f11e7bf6a66a5c7e12c4c79d3923563cda301 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 12:58:14 +0200 Subject: [PATCH 15/20] correcting the except --- manifests/zone.pp | 2 +- spec/defines/dns_zone_spec.rb | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/manifests/zone.pp b/manifests/zone.pp index 48fe7084..84de398f 100644 --- a/manifests/zone.pp +++ b/manifests/zone.pp @@ -25,7 +25,7 @@ a zone forwarder for zone ${soa}") } if !member(['first', 'only'], $forward_policy) { - fatal('The forward policy can only be set to either first or only') + error('The forward policy can only be set to either first or only') } $zone_serial = $serial ? { diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index f44e9c4b..2b0a8014 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -65,19 +65,7 @@ end it 'should have a forward only policy' do should contain_concat__fragment('named.conf.local.test.com.include'). - with_content(/foward only;/) - end - end - context 'when given a bogus forward policy' do - let :facts do { :concat_basedir => '/dne', } end - let :params do - { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], - :allow_forwarder => ['8.8.8.8', '208.67.222.222'], - :forward_policy => 'nonvalidpolicy' - } - end - it 'should not validat:' do - should fail + with_content(/forward only;/) end end end From 066a565e3c7afc3ccb60a6d41ef63d2b8177e876 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 13:28:58 +0200 Subject: [PATCH 16/20] empty forwarder --- spec/defines/dns_zone_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index 2b0a8014..bf3b49e2 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -68,5 +68,18 @@ with_content(/forward only;/) end end + + context 'when ask to have a only forward policy' do + let :facts do { :concat_basedir => '/dne', } end + let :params do + { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], + } + end + + it 'should have a forward only policy' do + should_not contain_concat__fragment('named.conf.local.test.com.include'). + with_content(/forward/) + end + end end From b353b8fd5803caa0b72fdfccf6b75120d20f5231 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 13:34:21 +0200 Subject: [PATCH 17/20] fixing the erb template --- templates/zone.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/zone.erb b/templates/zone.erb index a2021b6a..df807750 100644 --- a/templates/zone.erb +++ b/templates/zone.erb @@ -14,7 +14,7 @@ zone "<%= @zone %>" { <% end -%> }; <% end -%> -<% if @allow_forwarder -%> +<% if !@allow_forwarder.empty? -%> forward <%= @forward_policy %>; forwarders { <% @allow_forwarder.each do |ip| -%> From f6be93a9fb4fe60db090b6d3ec4f056e0e9ffa58 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 21:38:36 +0200 Subject: [PATCH 18/20] no forward policy fix --- spec/defines/dns_zone_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index bf3b49e2..fcde389b 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -76,7 +76,7 @@ } end - it 'should have a forward only policy' do + it 'should not have any forwarder configuration' do should_not contain_concat__fragment('named.conf.local.test.com.include'). with_content(/forward/) end From 8c896159f1f57acc62dc4878e3e2bb45c60a7a0a Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 21:39:46 +0200 Subject: [PATCH 19/20] better sentence --- spec/defines/dns_zone_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/defines/dns_zone_spec.rb b/spec/defines/dns_zone_spec.rb index fcde389b..1731576d 100644 --- a/spec/defines/dns_zone_spec.rb +++ b/spec/defines/dns_zone_spec.rb @@ -58,7 +58,7 @@ context 'when ask to have a only forward policy' do let :facts do { :concat_basedir => '/dne', } end let :params do - { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], + { :allow_transfer => [], :allow_forwarder => ['8.8.8.8', '208.67.222.222'], :forward_policy => 'only' } @@ -69,7 +69,7 @@ end end - context 'when ask to have a only forward policy' do + context 'In the default case with no explicit forward policy or forwarder' do let :facts do { :concat_basedir => '/dne', } end let :params do { :allow_transfer => [ '192.0.2.0', '2001:db8::/32' ], From b2ca148ce5a50b718f86db4e7bd296551151da1e Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Sun, 13 Apr 2014 21:42:16 +0200 Subject: [PATCH 20/20] a bit of documentation with an example --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index dc47fecc..56d25c77 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,16 @@ Tweak and add the following to your site manifest: } } +You can also declare forwarders for a specific zone, if you don't have one in the dns::option. + + dns::zone { 'example.com': + soa => "ns1.example.com", + soa_email => 'admin.example.com', + allow_forwarder => ['8.8.8.8'], + forward_policy => 'first' + nameservers => ["ns1"] + } + ### Exported resource patterns node default { # Other nodes export an A record for thier hostname