system-configuration/modules/config/dns.scm

dns.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
;;
19
;; DNS services
20
;;
21
22
(define-module (config dns)
23
  #:use-module (data dns)
24
  #:use-module (gnu services)
25
  #:use-module (gnu services dns)
26
  #:use-module (srfi srfi-1)
27
  #:use-module (ice-9 textual-ports)
28
  #:export (ipv4-reverse-master-zone
29
            ipv6-reverse-master-zone
30
            lepiller-master-zone
31
            lepiller-slave-zone
32
            master-acl
33
            slave-acl
34
            hermes
35
            ene))
36
37
(define public-dkim
38
  (apply
39
    string-append
40
    (string-split
41
      (call-with-input-file "/etc/mail/dkim/public.key" get-string-all)
42
      #\newline)))
43
44
(define-zone-entries lepiller.eu.zone
45
;; Name         TTL Class Type Data
46
  ("ene"        ""  "IN"  "A"     ene-ip4)
47
  ("hermes"     ""  "IN"  "A"     hermes-ip4)
48
  ("hermes"     ""  "IN"  "AAAA"  hermes-ip6)
49
  ("xana"       ""  "IN"  "A"     xana-ip4)
50
  ("@"          ""  "IN"  "A"     hermes-ip4)
51
  ("@"          ""  "IN"  "AAAA"  hermes-ip6)
52
  ("www"        ""  "IN"  "CNAME" "lepiller.eu.")
53
54
  ("avatar"     ""  "IN"  "CNAME" "ene")
55
  ("i18n"       ""  "IN"  "CNAME" "xana")
56
  ("nani"       ""  "IN"  "CNAME" "xana")
57
  ("offlate"    ""  "IN"  "CNAME" "xana")
58
  ("rennes"     ""  "IN"  "CNAME" "ene")
59
  ("social"     ""  "IN"  "CNAME" "hermes")
60
61
  ("@"          ""  "IN"  "NS"    "ns")
62
  ("@"          ""  "IN"  "NS"    "ns2")
63
  ("ns"         ""  "IN"  "A"     hermes-ip4)
64
  ("ns"         ""  "IN"  "AAAA"  hermes-ip6)
65
  ("ns2"        ""  "IN"  "A"     ene-ip4)
66
67
  ("@"          ""  "IN"  "MX"    "10 courriel")
68
  ("@"          ""  "IN"  "MX"    "50 b.courriel")
69
  ("b.courriel" ""  "IN"  "A"     hermes-ip4)
70
  ("b.courriel" ""  "IN"  "AAAA"  hermes-ip6)
71
  ("courriel"   ""  "IN"  "A"     ene-ip4)
72
  ("imap"       ""  "IN"  "CNAME" "courriel")
73
  ("smtp"       ""  "IN"  "CNAME" "b.courriel")
74
  ("@"          ""  "IN"  "TXT"   "v=spf1 mx a ~all")
75
  ("@"          ""  "IN"  "SPF"   "v=spf1 mx a ~all")
76
  
77
  ("dkim._domainkey" "" "IN" "TXT" (string-append "v=DKIM1\\; p=" public-dkim "\\; s=email\\; t=s"))
78
  ("_dmarc"     ""  "IN"  "TXT"   "v=DMARC1\\; p=none\\; sp=reject\\; rua=mailto:rua@lepiller.eu!10m\\; ruf=mailto:ruf@lepiller.eu!10m\\; rf=afrf\\; pct=100\\; ri=86400"))
79
80
(define-zone-entries ipv4-reverse.zone
81
  ("@" "" "IN" "PTR" "lepiller.eu.")
82
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
83
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
84
85
(define-zone-entries ipv6-reverse.zone
86
  ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.")
87
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
88
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
89
90
(define ene
91
  (knot-remote-configuration
92
    (id "ene")
93
    (address (list ene-ip4))
94
    (key "lepiller-key")))
95
96
(define hermes
97
  (knot-remote-configuration
98
    (id "hermes")
99
    (address (list hermes-ip4 hermes-ip6))
100
    (key "lepiller-key")))
101
102
(define master-acl
103
  (knot-acl-configuration
104
    (id "master-acl")
105
    (address (list hermes-ip4))
106
    (key '("lepiller-key"))
107
    (action '(transfer))))
108
109
(define slave-acl
110
  (knot-acl-configuration
111
    (id "slave-acl")
112
    (address (list ene-ip4))
113
    (key '("lepiller-key"))
114
    (action '(notify))))
115
116
(define lepiller-master-zone
117
  (knot-zone-configuration
118
    (domain "lepiller.eu")
119
    (notify '("hermes"))
120
    (dnssec-policy "default")
121
    (acl '("master-acl"))
122
    (zonefile-load 'difference)
123
    (zone (zone-file
124
            (origin "lepiller.eu")
125
            (entries lepiller.eu.zone)
126
            (serial 2019120701)))))
127
128
(define lepiller-slave-zone
129
  (knot-zone-configuration
130
    (domain "lepiller.eu")
131
    (acl '("slave-acl"))
132
    (master '("ene"))))
133
134
(define ipv6-reverse-master-zone
135
  (let* ((ip6 (string->list (substring (string-delete hermes-ip6 #\:) 0 12)))
136
         (rev-ip6-lst (fold (lambda (elem acc)
137
                          (cons* #\. elem acc))
138
                        '()
139
                        ip6))
140
         (rev-ip6 (list->string (cdr rev-ip6-lst)))
141
         (domain (string-append rev-ip6 ".ip6.arpa")))
142
    (knot-zone-configuration
143
      (domain domain)
144
      (zone (zone-file
145
              (origin domain)
146
              (entries ipv6-reverse.zone)
147
              (ns "ns.lepiller.eu.")
148
              (mail "hostmaster.lepiller.eu.")
149
              (serial 1))))))
150
151
(define ipv4-reverse-master-zone
152
  (let ((domain (string-append
153
                  (string-join (reverse (string-split hermes-ip4 #\.)) ".")
154
                  ".in-addr.arpa")))
155
    (knot-zone-configuration
156
      (domain domain)
157
      (zone (zone-file
158
              (origin domain)
159
              (entries ipv4-reverse.zone)
160
              (ns "ns.lepiller.eu.")
161
              (mail "hostmaster.lepiller.eu.")
162
              (serial 1))))))
163