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