Skip to content

Commit 72ea4cf

Browse files
Merge pull request #98 from aanriot/master
Add support for inline-signing, see #64 for details
2 parents aeeafc3 + 82726fd commit 72ea4cf

File tree

7 files changed

+154
-4
lines changed

7 files changed

+154
-4
lines changed

README.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,61 @@ To use an external tool to manage the <zone> file, simply declare the location
9393
of the zone file in `bind:configured_zones:<zone>:file` and **don't** add any
9494
entry for the <zone> in `bind:available_zones`
9595

96+
DNSSEC
97+
======
98+
99+
The `bind` formula currently support two ways to enable DNSSEC:
100+
101+
* Using the `zonesigner` binary provided by `dnssec-tools` (legacy) ;
102+
* Using internal features of `bind`.
103+
104+
Here is sample pillar entries to use the latter.
105+
106+
On the master server :
107+
108+
.. code:: yaml
109+
110+
bind:
111+
lookup:
112+
key_directory: '/etc/bind/keys'
113+
config:
114+
options:
115+
dnssec-enable: 'yes'
116+
dnssec-validation: 'yes'
117+
configured_acls:
118+
slave_server:
119+
- 192.168.1.2
120+
configured_zones:
121+
domain.tld:
122+
file: "db.domain.tld"
123+
type: master
124+
notify: True
125+
allow-transfer:
126+
- localnets
127+
- localhost
128+
- slave_server
129+
allow-update: 'none'
130+
auto-dnssec: 'maintain'
131+
132+
On the slave server :
133+
134+
.. code:: yaml
135+
136+
bind:
137+
config:
138+
options:
139+
dnssec-enable: 'yes'
140+
dnssec-validation: 'yes'
141+
configured_zones:
142+
domain.tld:
143+
file: "db.domain.tld.signed"
144+
type: slave
145+
masters:
146+
- master_server
147+
configured_masters:
148+
master_server:
149+
- 192.168.1.1
150+
96151
Notes
97152
=====
98153

bind/config.sls

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{% from "bind/map.jinja" import map with context %}
22
{% from "bind/reverse_zone.jinja" import generate_reverse %}
33
4+
{%- set key_directory = salt['pillar.get']('bind:lookup:key_directory', map.key_directory) %}
5+
{%- set key_algorithm = salt['pillar.get']('bind:lookup:key_algorithm', map.key_algorithm) %}
6+
{%- set key_algorithm_field = salt['pillar.get']('bind:lookup:key_algorithm_field', map.key_algorithm_field) %}
7+
{%- set key_size = salt['pillar.get']('bind:lookup:key_size', map.key_size) %}
8+
{%- set key_flags = {'zsk': 256, 'ksk': 257} %}
9+
410
include:
511
- bind
612
@@ -18,6 +24,7 @@ bind_restart:
1824
- reload: False
1925
- watch:
2026
- file: {{ map.chroot_dir }}{{ map.log_dir }}/query.log
27+
- file: bind_key_directory
2128
2229
{{ map.chroot_dir }}{{ map.log_dir }}/query.log:
2330
file.managed:
@@ -110,6 +117,8 @@ bind_options_config:
110117
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
111118
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
112119
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
120+
- context:
121+
key_directory: {{ map.key_directory }}
113122
- require:
114123
- pkg: bind
115124
- watch_in:
@@ -205,6 +214,15 @@ zones{{ dash_view }}-{{ zone }}{{ '.include' if serial_auto else ''}}:
205214
- require:
206215
- file: named_directory
207216
217+
{% if zone_data['dnssec'] is defined and zone_data['dnssec'] -%}
218+
signed-{{ zone }}:
219+
cmd.run:
220+
- cwd: {{ map.named_directory }}
221+
- name: zonesigner -zone {{ zone }} {{ file }}
222+
- prereq:
223+
- file: zones-{{ zone }}
224+
{% endif %}
225+
208226
{% if serial_auto %}
209227
zones{{ dash_view }}-{{ zone }}:
210228
module.wait:
@@ -241,7 +259,27 @@ signed{{ dash_view }}-{{ zone }}:
241259
- prereq:
242260
- file: zones{{ dash_view }}-{{ zone }}
243261
{% endif %}
262+
{% endif %}
263+
264+
{% if zone_data['auto-dnssec'] is defined -%}
265+
zsk-{{ zone }}:
266+
cmd.run:
267+
- cwd: {{ key_directory }}
268+
- name: dnssec-keygen -a {{ key_algorithm }} -b {{ key_size }} -n ZONE {{ zone }}
269+
- runas: {{ map.user }}
270+
- unless: "grep {{ key_flags.zsk }} {{ key_directory }}/K{{zone}}.+{{ key_algorithm_field }}+*.key"
271+
- require:
272+
- file: bind_key_directory
244273
274+
ksk-{{ zone }}:
275+
cmd.run:
276+
- cwd: {{ key_directory }}
277+
- name: dnssec-keygen -f KSK -a {{ key_algorithm }} -b {{ key_size }} -n ZONE {{ zone }}
278+
- runas: {{ map.user }}
279+
- unless: "grep {{ key_flags.ksk }} {{ key_directory }}/K{{zone}}.+{{ key_algorithm_field }}+*.key"
280+
- require:
281+
- file: bind_key_directory
245282
{% endif %}
283+
246284
{% endfor %}
247285
{% endfor %}

bind/files/debian/named.conf.options

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{%- set key_directory = salt['pillar.get']('bind:lookup:key_directory', key_directory) %}
2+
13
options {
24
directory "/var/cache/bind";
35

@@ -20,6 +22,10 @@ options {
2022
listen-on-v6 { {{ salt['pillar.get']('bind:config:ipv6_listen', 'any') }}; };
2123
{%- endif -%}
2224

25+
{%- if key_directory %}
26+
key-directory "{{ key_directory }}";
27+
{%- endif -%}
28+
2329
{#- Allow inclusion of arbitrary statements #}
2430
{%- for statement, value in salt['pillar.get']('bind:config:options', {}).items() -%}
2531
{%- if value is iterable and value is not string %}

bind/files/named.conf.local.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ zone "{{ key }}" {
2525
{% else -%}
2626
file "{{ map.named_directory }}/{{ file }}";
2727
{%- endif %}
28+
{% if args['auto-dnssec'] is defined -%}
29+
auto-dnssec {{ args['auto-dnssec'] }};
30+
inline-signing yes;
31+
{%- endif %}
2832
{%- if args['allow-update'] is defined %}
2933
allow-update { {{args['allow-update']}}; };
3034
{%- endif %}

bind/init.sls

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
{% from "bind/map.jinja" import map with context %}
22
3+
{%- set key_directory = salt['pillar.get']('bind:config:key_directory', map.key_directory) %}
4+
35
bind:
46
pkg.installed:
57
- pkgs: {{ map.pkgs|json }}
68
service.running:
79
- name: {{ map.service }}
810
- enable: True
911
- reload: True
12+
13+
bind_key_directory:
14+
file.directory:
15+
- name: {{ key_directory }}
16+
- require:
17+
- pkg: bind

bind/map.jinja

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
'user': 'bind',
2020
'group': 'bind',
2121
'mode': '644',
22+
'key_directory': '/etc/bind/keys',
23+
'key_algorithm': 'RSASHA256',
24+
'key_algorithm_field': '008',
25+
'key_size': '4096',
2226
'options': {
2327
'querylog': 'no'
2428
}
@@ -38,13 +42,17 @@
3842
'user': 'named',
3943
'group': 'named',
4044
'mode': '640',
45+
'key_directory': '/etc/named.keys',
46+
'key_algorithm': 'RSASHA256',
47+
'key_algorithm_field': '008',
48+
'key_size': '4096',
4149
'options': {
4250
'listen-on': 'port 53 { 127.0.0.1; }',
4351
'listen-on-v6': 'port 53 { ::1; }',
4452
'allow-query': '{ localhost; }',
4553
'recursion': 'yes',
4654
'dnssec-enable': 'yes',
47-
'dnssec-validation': 'yes'
55+
'dnssec-validation': 'yes',
4856
}
4957
},
5058
'Arch': {
@@ -60,7 +68,11 @@
6068
'log_mode': '640',
6169
'user': 'root',
6270
'group': 'named',
63-
'mode': '640'
71+
'mode': '640',
72+
'key_directory': '/etc/named.keys',
73+
'key_algorithm': 'RSASHA256',
74+
'key_algorithm_field': '008',
75+
'key_size': '4096',
6476
},
6577
'FreeBSD': {
6678
'pkgs': ['bind911'],
@@ -75,7 +87,11 @@
7587
'log_mode': '660',
7688
'user': 'root',
7789
'group': 'bind',
78-
'mode': '640'
90+
'mode': '640',
91+
'key_directory': '/usr/local/etc/namedb/keys',
92+
'key_algorithm': 'RSASHA256',
93+
'key_algorithm_field': '008',
94+
'key_size': '4096',
7995
},
8096
'Suse': {
8197
'pkgs': ['bind'],
@@ -92,7 +108,11 @@
92108
'user': 'root',
93109
'group': 'named',
94110
'mode': '640',
95-
},
111+
'key_directory': '/etc/named.keys',
112+
'key_algorithm': 'RSASHA256',
113+
'key_algorithm_field': '008',
114+
'key_size': '4096',
115+
}
96116
}, merge=salt['grains.filter_by']({
97117
}, grain='oscodename', merge=salt['grains.filter_by']({
98118
'Ubuntu': {

pillar.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ bind:
1717

1818
### General config options ###
1919
bind:
20+
lookup:
21+
key_directory: '/etc/bind/keys' # Key directory (needed to use auto-dnssec)
22+
key_algorithm: RSASHA256 # Algorithm when using auto-dnssec
23+
key_algorithm_field: 008 # See http://www.bind9.net/dns-sec-algorithm-numbers
24+
key_size: 4096 # Key size
25+
2026
config:
2127
tmpl: salt://bind/files/debian/named.conf # Template we'd like to use (not implemented?)
2228
user: root # File & Directory user
@@ -227,6 +233,19 @@ bind:
227233
- 1.1.1.1 # notify has been set to no)
228234
- 2.2.2.2
229235

236+
sub.domain2.com: # Domain zone with DNSSEC
237+
type: master # We're the master of this zone
238+
notify: False # Don't notify any NS RRs of any changes to zone
239+
dnssec: True # Create and manage signed zonefile with zonesigner
240+
# You will have to install dnssec-tools by hand
241+
# on many distributions
242+
243+
sub.domain3.com: # Domain zone with DNSSEC
244+
type: master # We're the master of this zone
245+
notify: False # Don't notify any NS RRs of any changes to zone
246+
auto-dnssec: 'maintain' # Bind will create and manage the signed zonefile
247+
# itself, we only have to provide the clear zone
248+
230249
1.168.192.in-addr.arpa: # Reverse lookup for local IPs
231250
type: master # As above
232251
notify: False # As above

0 commit comments

Comments
 (0)