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
;; Update this when changing the zone:
38
(define lepiller-serial 2022111201)
39
40
(define public-dkim
41
  (apply
42
    string-append
43
    (string-split
44
      (call-with-input-file "/etc/mail/dkim/public.key" get-string-all)
45
      #\newline)))
46
47
(define-zone-entries lepiller.eu.zone
48
;; Name         TTL Class Type Data
49
  ("ene"        ""  "IN"  "A"     ene-toulouse-ip4)
50
  ("ene"        ""  "IN"  "AAAA"  ene-toulouse-ip6)
51
  ("hermes"     ""  "IN"  "A"     hermes-ip4)
52
  ("hermes"     ""  "IN"  "AAAA"  hermes-ip6)
53
  ("xana"       ""  "IN"  "A"     xana-ip4)
54
  ("dark"       ""  "IN"  "A"     dark-ip4)
55
  ("nono"       ""  "IN"  "A"     nono-ip4)
56
  ("nono"       ""  "IN"  "AAAA"  nono-ip6)
57
  ("@"          ""  "IN"  "A"     hermes-ip4)
58
  ("@"          ""  "IN"  "AAAA"  hermes-ip6)
59
  ("www"        ""  "IN"  "CNAME" "lepiller.eu.")
60
61
  ("avatar"     ""  "IN"  "CNAME" "nono")
62
  ("git"        ""  "IN"  "CNAME" "nono")
63
  ("i18n"       ""  "IN"  "CNAME" "xana")
64
  ("nani"       ""  "IN"  "CNAME" "xana")
65
  ("offlate"    ""  "IN"  "CNAME" "xana")
66
  ("social"     ""  "IN"  "CNAME" "nono")
67
  ("lfs"        ""  "IN"  "CNAME" "dark")
68
69
  ("toulouse"   ""  "IN"  "CNAME" "nono")
70
  
71
  ("@"          ""  "IN"  "NS"    "ns")
72
  ("@"          ""  "IN"  "NS"    "ns2")
73
  ("ns"         ""  "IN"  "A"     hermes-ip4)
74
  ("ns"         ""  "IN"  "AAAA"  hermes-ip6)
75
  ("ns2"        ""  "IN"  "A"     nono-ip4)
76
  ("ns2"        ""  "IN"  "AAAA"  nono-ip6)
77
78
  ("@"          ""  "IN"  "MX"    "10 courriel")
79
  ("@"          ""  "IN"  "MX"    "50 b.courriel")
80
  ("@"          ""  "IN"  "MX"    "20 wio6sja633kwuybkyqex7vvnzqvrhrtzjix6cjhsqi42hx3n2qjfmzid.onion.")
81
  ("@"          ""  "IN"  "MX"    "60 5g33mrv2rp2onyvte2b3ge5a44fxansxwt4sajmmae7lgorxjgz5czad.onion.")
82
  ("b.courriel" ""  "IN"  "A"     hermes-ip4)
83
  ("b.courriel" ""  "IN"  "AAAA"  hermes-ip6)
84
  ("courriel"   ""  "IN"  "A"     nono-ip4)
85
  ("courriel"   ""  "IN"  "AAAA"  nono-ip6)
86
  ("imap"       ""  "IN"  "CNAME" "courriel")
87
  ("smtp"       ""  "IN"  "CNAME" "b.courriel")
88
  ("@"          ""  "IN"  "TXT"   "\"v=spf1 mx a ~all\"")
89
  ("@"          ""  "IN"  "SPF"   "\"v=spf1 mx a ~all\"")
90
  
91
  ("dkim._domainkey" "" "IN" "TXT" (string-append "v=DKIM1\\; p=" public-dkim "\\; s=email\\; t=s"))
92
  ("_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"))
93
94
(define-zone-entries ipv4-reverse.zone
95
  ("@" "" "IN" "PTR" "lepiller.eu.")
96
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
97
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
98
99
(define-zone-entries ipv6-reverse.zone
100
  ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.")
101
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
102
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
103
104
(define ene
105
  (knot-remote-configuration
106
    (id "ene")
107
    (address (list ene-toulouse-ip4 ene-toulouse-ip6))
108
    (key "lepiller-key")))
109
110
(define hermes
111
  (knot-remote-configuration
112
    (id "hermes")
113
    (address (list hermes-ip4 hermes-ip6))
114
    (key "lepiller-key")))
115
116
(define master-acl
117
  (knot-acl-configuration
118
    (id "master-acl")
119
    (address (list ene-toulouse-ip4 ene-toulouse-ip6))
120
    (key '("lepiller-key"))
121
    (action '(transfer))))
122
123
(define slave-acl
124
  (knot-acl-configuration
125
    (id "slave-acl")
126
    (address (list hermes-ip4 hermes-ip6))
127
    (key '("lepiller-key"))
128
    (action '(notify))))
129
130
(define lepiller-master-zone
131
  (knot-zone-configuration
132
    (domain "lepiller.eu")
133
    (notify '("ene"))
134
    (dnssec-policy "default")
135
    (acl '("master-acl"))
136
    (zonefile-load 'difference)
137
    (zone (zone-file
138
            (origin "lepiller.eu")
139
            (entries lepiller.eu.zone)
140
            (serial lepiller-serial)))))
141
142
(define lepiller-slave-zone
143
  (knot-zone-configuration
144
    (domain "lepiller.eu")
145
    (acl '("slave-acl"))
146
    (master '("hermes"))))
147
148
(define ipv6-reverse-master-zone
149
  (let* ((ip6 (string->list (substring (string-delete #\: hermes-ip6) 0 12)))
150
         (rev-ip6-lst (fold (lambda (elem acc)
151
                          (cons* #\. elem acc))
152
                        '()
153
                        ip6))
154
         (rev-ip6 (list->string (cdr rev-ip6-lst)))
155
         (domain (string-append rev-ip6 ".ip6.arpa")))
156
    (knot-zone-configuration
157
      (domain domain)
158
      (zone (zone-file
159
              (origin domain)
160
              (entries ipv6-reverse.zone)
161
              (ns "ns.lepiller.eu.")
162
              (mail "hostmaster.lepiller.eu.")
163
              (serial 1))))))
164
165
(define ipv4-reverse-master-zone
166
  (let ((domain (string-append
167
                  (string-join (reverse (string-split hermes-ip4 #\.)) ".")
168
                  ".in-addr.arpa")))
169
    (knot-zone-configuration
170
      (domain domain)
171
      (zone (zone-file
172
              (origin domain)
173
              (entries ipv4-reverse.zone)
174
              (ns "ns.lepiller.eu.")
175
              (mail "hostmaster.lepiller.eu.")
176
              (serial 1))))))
177