Skip to content

Commit 82726fd

Browse files
committed
Add support for inline-signing, see #64 for details
1 parent 6e8652d commit 82726fd

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,5 +1,11 @@
11
{% from "bind/map.jinja" import map with context %}
22
3+
{%- set key_directory = salt['pillar.get']('bind:lookup:key_directory', map.key_directory) %}
4+
{%- set key_algorithm = salt['pillar.get']('bind:lookup:key_algorithm', map.key_algorithm) %}
5+
{%- set key_algorithm_field = salt['pillar.get']('bind:lookup:key_algorithm_field', map.key_algorithm_field) %}
6+
{%- set key_size = salt['pillar.get']('bind:lookup:key_size', map.key_size) %}
7+
{%- set key_flags = {'zsk': 256, 'ksk': 257} %}
8+
39
include:
410
- bind
511
@@ -17,6 +23,7 @@ bind_restart:
1723
- reload: False
1824
- watch:
1925
- file: {{ map.chroot_dir }}{{ map.log_dir }}/query.log
26+
- file: bind_key_directory
2027
2128
{{ map.chroot_dir }}{{ map.log_dir }}/query.log:
2229
file.managed:
@@ -109,6 +116,8 @@ bind_options_config:
109116
- user: {{ salt['pillar.get']('bind:config:user', map.user) }}
110117
- group: {{ salt['pillar.get']('bind:config:group', map.group) }}
111118
- mode: {{ salt['pillar.get']('bind:config:mode', '644') }}
119+
- context:
120+
key_directory: {{ map.key_directory }}
112121
- require:
113122
- pkg: bind
114123
- watch_in:
@@ -201,6 +210,15 @@ zones{{ dash_view }}-{{ zone }}{{ '.include' if serial_auto else ''}}:
201210
- require:
202211
- file: named_directory
203212
213+
{% if zone_data['dnssec'] is defined and zone_data['dnssec'] -%}
214+
signed-{{ zone }}:
215+
cmd.run:
216+
- cwd: {{ map.named_directory }}
217+
- name: zonesigner -zone {{ zone }} {{ file }}
218+
- prereq:
219+
- file: zones-{{ zone }}
220+
{% endif %}
221+
204222
{% if serial_auto %}
205223
zones{{ dash_view }}-{{ zone }}:
206224
module.wait:
@@ -237,7 +255,27 @@ signed{{ dash_view }}-{{ zone }}:
237255
- prereq:
238256
- file: zones{{ dash_view }}-{{ zone }}
239257
{% endif %}
258+
{% endif %}
259+
260+
{% if zone_data['auto-dnssec'] is defined -%}
261+
zsk-{{ zone }}:
262+
cmd.run:
263+
- cwd: {{ key_directory }}
264+
- name: dnssec-keygen -a {{ key_algorithm }} -b {{ key_size }} -n ZONE {{ zone }}
265+
- runas: {{ map.user }}
266+
- unless: "grep {{ key_flags.zsk }} {{ key_directory }}/K{{zone}}.+{{ key_algorithm_field }}+*.key"
267+
- require:
268+
- file: bind_key_directory
240269
270+
ksk-{{ zone }}:
271+
cmd.run:
272+
- cwd: {{ key_directory }}
273+
- name: dnssec-keygen -f KSK -a {{ key_algorithm }} -b {{ key_size }} -n ZONE {{ zone }}
274+
- runas: {{ map.user }}
275+
- unless: "grep {{ key_flags.ksk }} {{ key_directory }}/K{{zone}}.+{{ key_algorithm_field }}+*.key"
276+
- require:
277+
- file: bind_key_directory
241278
{% endif %}
279+
242280
{% endfor %}
243281
{% 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
@@ -221,6 +227,19 @@ bind:
221227
- 1.1.1.1 # notify has been set to no)
222228
- 2.2.2.2
223229

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

0 commit comments

Comments
 (0)