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