Skip to content

Commit 20d6009

Browse files
committed
Add per-zone allow_transfer for primary zones
1 parent 49e9791 commit 20d6009

4 files changed

Lines changed: 109 additions & 12 deletions

File tree

REFERENCE.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,16 @@ bind::zone::primary { 'example.com':
24722472
}
24732473
```
24742474

2475+
##### Restrict zone transfers for a primary zone
2476+
2477+
```puppet
2478+
2479+
bind::zone::primary { 'example.com':
2480+
source => 'puppet:///modules/profile/example.com.zone',
2481+
allow_transfer => ['192.0.2.42'],
2482+
}
2483+
```
2484+
24752485
##### Use DNSSEC signing for a primary zone using a DNSSEC policy
24762486

24772487
```puppet
@@ -2499,6 +2509,7 @@ bind::zone::primary { '_acme-challenge.example.com':
24992509
The following parameters are available in the `bind::zone::primary` defined type:
25002510

25012511
* [`also_notify`](#-bind--zone--primary--also_notify)
2512+
* [`allow_transfer`](#-bind--zone--primary--allow_transfer)
25022513
* [`update_policy`](#-bind--zone--primary--update_policy)
25032514
* [`dnssec_enable`](#-bind--zone--primary--dnssec_enable)
25042515
* [`dnssec_dnskey_kskonly`](#-bind--zone--primary--dnssec_dnskey_kskonly)
@@ -2530,6 +2541,15 @@ nameservers that are listed in the zone file.
25302541

25312542
Default value: `[]`
25322543

2544+
##### <a name="-bind--zone--primary--allow_transfer"></a>`allow_transfer`
2545+
2546+
Data type: `Array[String]`
2547+
2548+
An array of ACL names or networks that are allowed to transfer zone
2549+
information for this zone.
2550+
2551+
Default value: `[]`
2552+
25332553
##### <a name="-bind--zone--primary--update_policy"></a>`update_policy`
25342554

25352555
Data type: `Variant[Enum['local'],Array[String]]`
@@ -3372,4 +3392,3 @@ Alias of `Enum['critical', 'error', 'warning', 'notice', 'info', 'debug', 'dynam
33723392
Type to match allowed values for the zone class
33733393

33743394
Alias of `Enum['IN', 'HS', 'CH']`
3375-

manifests/zone/primary.pp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
# source => 'puppet:///modules/profile/example.com.zone',
1414
# }
1515
#
16+
# @example Restrict zone transfers for a primary zone
17+
#
18+
# bind::zone::primary { 'example.com':
19+
# source => 'puppet:///modules/profile/example.com.zone',
20+
# allow_transfer => ['192.0.2.42'],
21+
# }
22+
#
1623
# @example Use DNSSEC signing for a primary zone using a DNSSEC policy
1724
#
1825
# bind::zone::primary { 'example.com':
@@ -33,6 +40,10 @@
3340
# Secondary servers that should be notified in addition to the
3441
# nameservers that are listed in the zone file.
3542
#
43+
# @param allow_transfer
44+
# An array of ACL names or networks that are allowed to transfer zone
45+
# information for this zone.
46+
#
3647
# @param update_policy
3748
# Enable dynamic updates for the zone and define the update policy. This
3849
# can either be the string `local` or an array of strings. Using the string
@@ -124,6 +135,7 @@
124135
#
125136
define bind::zone::primary (
126137
Array[String] $also_notify = [],
138+
Array[String] $allow_transfer = [],
127139
Variant[Enum['local'],Array[String]] $update_policy = [],
128140
Optional[Boolean] $dnssec_enable = undef,
129141
Optional[Boolean] $dnssec_dnskey_kskonly = undef,
@@ -257,17 +269,18 @@
257269
}
258270

259271
$params = {
260-
'zone' => $zone,
261-
'file' => $zonefile,
262-
'also_notify' => $also_notify,
263-
'notify' => $notify_secondaries,
264-
'statistics' => $zone_statistics,
265-
'update_policy' => $update_policy,
266-
'class' => $class,
267-
'comment' => $comment,
268-
'indent' => bool2str($bind::views_enable, ' ', ''),
269-
'zone_in_view' => ($view =~ NotUndef),
270-
'dnssec_params' => !empty(delete_undef_values($params_dnssec)),
272+
'zone' => $zone,
273+
'file' => $zonefile,
274+
'also_notify' => $also_notify,
275+
'allow_transfer' => $allow_transfer,
276+
'notify' => $notify_secondaries,
277+
'statistics' => $zone_statistics,
278+
'update_policy' => $update_policy,
279+
'class' => $class,
280+
'comment' => $comment,
281+
'indent' => bool2str($bind::views_enable, ' ', ''),
282+
'zone_in_view' => ($view =~ NotUndef),
283+
'dnssec_params' => !empty(delete_undef_values($params_dnssec)),
271284
}
272285

273286
if $bind::views_enable {

spec/defines/zone/primary_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,44 @@
375375
}
376376
end
377377

378+
context 'with source => "/file", allow_transfer => ["any"]' do
379+
let(:params) do
380+
{ source: '/file', allow_transfer: ['any'] }
381+
end
382+
383+
it {
384+
is_expected.to contain_file('/var/lib/bind/primary/com')
385+
is_expected.to contain_file('/var/lib/bind/primary/com/example')
386+
is_expected.to contain_file('/var/lib/bind/primary/com/example/db.example.com')
387+
388+
is_expected.to contain_exec('bind::reload::example.com')
389+
390+
is_expected.to contain_concat__fragment('named.conf.zones-example.com')
391+
.with_target('named.conf.zones')
392+
.with_order('20')
393+
.with_content(%r{allow-transfer {\n\s+any;\n\s+};})
394+
}
395+
end
396+
397+
context 'with source => "/file", allow_transfer => ["acl1", "192.0.2.42"]' do
398+
let(:params) do
399+
{ source: '/file', allow_transfer: ['acl1', '192.0.2.42'] }
400+
end
401+
402+
it {
403+
is_expected.to contain_file('/var/lib/bind/primary/com')
404+
is_expected.to contain_file('/var/lib/bind/primary/com/example')
405+
is_expected.to contain_file('/var/lib/bind/primary/com/example/db.example.com')
406+
407+
is_expected.to contain_exec('bind::reload::example.com')
408+
409+
is_expected.to contain_concat__fragment('named.conf.zones-example.com')
410+
.with_target('named.conf.zones')
411+
.with_order('20')
412+
.with_content(%r{allow-transfer {\n\s+acl1;\n\s+192.0.2.42;\n\s+};})
413+
}
414+
end
415+
378416
context 'with source => "/file", zone_statistics => true' do
379417
let(:params) do
380418
{ source: '/file', zone_statistics: true }
@@ -815,6 +853,25 @@
815853
}
816854
end
817855

856+
context 'with view => "internal", source => "/file", allow_transfer => ["any"]' do
857+
let(:params) do
858+
{ view: 'internal', source: '/file', allow_transfer: ['any'] }
859+
end
860+
861+
it {
862+
is_expected.to contain_file('/var/lib/bind/primary/com')
863+
is_expected.to contain_file('/var/lib/bind/primary/com/example')
864+
is_expected.to contain_file('/var/lib/bind/primary/com/example/db.example.com')
865+
866+
is_expected.to contain_exec('bind::reload::internal::example.com')
867+
868+
is_expected.to contain_concat__fragment('named.conf.views-internal-50-example.com')
869+
.with_target('named.conf.views')
870+
.with_order('10')
871+
.with_content(%r{allow-transfer {\n \s+any;\n \s+};})
872+
}
873+
end
874+
818875
context 'with view => "internal", source => "/file", zone_statistics => true' do
819876
let(:params) do
820877
{ view: 'internal', source: '/file', zone_statistics: true }

templates/zone-primary.epp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
<% } -%>
3030
<%= $indent %> };
3131
<% } -%>
32+
<% unless empty($allow_transfer) { -%>
33+
34+
<%= $indent %> allow-transfer {
35+
<% $allow_transfer.each |$item| { -%>
36+
<%= $indent %> <%= $item -%>;
37+
<% } -%>
38+
<%= $indent %> };
39+
<% } -%>
3240
<% if $dnssec_params { -%>
3341

3442
<% if $dnssec_enable =~ NotUndef { -%>

0 commit comments

Comments
 (0)