summaryrefslogtreecommitdiff
path: root/hosts/surtr/dns/default.nix
blob: 5d55c8156f85925a437ae534ae60952d25b1a4d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
{ config, pkgs, lib, ... }:

with lib;

let
  acmeChallengeZonefile = domain: let
    reverseDomain = concatStringsSep "." (reverseList (["_acme-challenge"] ++ splitString "." domain));
  in pkgs.writeText "${reverseDomain}.zone" ''
    $ORIGIN _acme-challenge.${domain}.
    $TTL 3600
    @ IN SOA ns.yggdrasil.li. root.yggdrasil.li. 2022022103 10800 3600 604800 30

      IN NS  ns.yggdrasil.li.
  '';
in {
  config = {
    fileSystems."/var/lib/knot" =
      { device = "surtr/safe/var-lib-knot";
        fsType = "zfs";
      };

    systemd.services.knot.unitConfig.RequiresMountsFor = [ "/var/lib/knot" ];
    
    services.knot = {
      enable = true;
      keyFiles = [
        config.sops.secrets."rheperire.org_acme_key.yaml".path
        config.sops.secrets."webdav.141.li_acme_key.yaml".path
        config.sops.secrets."knot_local_key.yaml".path
      ];
      extraConfig = ''
        server:
          listen: 127.0.0.1@53
          listen: ::1@53
          listen: 202.61.241.61@53
          listen: 2a03:4000:52:ada::@53

        remote:
          - id: inwx_notify
            address: 185.181.104.96@53
          - id: recursive
            address: ::1@5353
          - id: local
            address: ::1@53
            key: local_key

        acl:
          - id: inwx_acl
            address: 185.181.104.96
            action: transfer
          - id: rheperire.org_acme_acl
            key: rheperire.org_acme_key
            action: update
          - id: webdav.141.li_acme_acl
            key: webdav.141.li_acme_key
            action: update
          - id: local_acl
            key: local_key
            action: update
            update-type: DS

        mod-rrl:
          - id: default
            rate-limit: 200
            slip: 2

        mod-cookies:
          - id: default
            secret-lifetime: 4h
            badcookie-slip: 1

        submission:
          - id: validating-resolver
            parent: recursive
            check-interval: 5m

        policy:
          - id: rsa2048
            algorithm: rsasha256
            ksk-size: 4096
            zsk-size: 2048
            zsk-lifetime: 30d
            ksk-submission: validating-resolver
          - id: ed25519
            algorithm: ed25519
            nsec3: on
            nsec3-iterations: 0
            ksk-lifetime: 360d
            signing-threads: 2
            ksk-submission: validating-resolver
          - id: ed25519_local-push
            algorithm: ed25519
            nsec3: on
            nsec3-iterations: 0
            ksk-lifetime: 360d
            signing-threads: 2
            ksk-submission: validating-resolver
            cds-cdnskey-publish: double-ds
            propagation-delay: 0
            ds-push: [local]

        template:
          - id: default
            global-module: [mod-cookies/default, mod-rrl/default]
          - id: inwx_zone
            storage: /var/lib/knot
            zonefile-sync: -1
            zonefile-load: difference-no-serial
            serial-policy: dateserial
            journal-content: all
            semantic-checks: on
            dnssec-signing: on
            dnssec-policy: ed25519
            notify: [inwx_notify]
            acl: [inwx_acl]
          - id: acme_zone
            storage: /var/lib/knot
            zonefile-sync: -1
            zonefile-load: difference-no-serial
            serial-policy: dateserial
            journal-content: all
            semantic-checks: on
            dnssec-signing: on
            dnssec-policy: ed25519_local-push

        zone:
          - domain: yggdrasil.li
            template: inwx_zone
            file: ${./zones/li.yggdrasil.soa}

          - domain: nights.email
            template: inwx_zone
            file: ${./zones/email.nights.soa}

          - domain: 141.li
            template: inwx_zone
            acl: [local_acl, inwx_acl]
            file: ${./zones/li.141.soa}
          - domain: _acme-challenge.webdav.141.li
            template: acme_zone
            acl: [webdav.141.li_acme_acl]
            file: ${acmeChallengeZonefile "webdav.141.li"}

          - domain: kleen.li
            template: inwx_zone
            file: ${./zones/li.kleen.soa}

          - domain: xmpp.li
            template: inwx_zone
            file: ${./zones/li.xmpp.soa}

          - domain: dirty-haskell.org
            template: inwx_zone
            file: ${./zones/org.dirty-haskell.soa}

          - domain: praseodym.org
            template: inwx_zone
            file: ${./zones/org.praseodym.soa}

          - domain: rheperire.org
            template: inwx_zone
            acl: [local_acl, inwx_acl]
            file: ${./zones/org.rheperire.soa}
          - domain: _acme-challenge.rheperire.org
            template: acme_zone
            acl: [rheperire.org_acme_acl]
            file: ${acmeChallengeZonefile "rheperire.org"}
      '';
    };

    sops.secrets = {
      "rheperire.org_acme_key.yaml" = {
        format = "binary";
        owner = "knot";
        sopsFile = ./keys/rheperire.org_acme.yaml;
      };
      "webdav.141.li_acme_key.yaml" = {
        format = "binary";
        owner = "knot";
        sopsFile = ./keys/webdav.141.li_acme.yaml;
      };
      "knot_local_key.yaml" = {
        format = "binary";
        owner = "knot";
        sopsFile = ./keys/local_key.yaml;
      };
    };


    fileSystems."/var/lib/unbound" =
      { device = "surtr/local/var-lib-unbound";
        fsType = "zfs";
      };

    systemd.services.unbound.unitConfig.RequiresMountsFor = [ "/var/lib/unbound" ];

    services.unbound = {
      enable = true;
      resolveLocalQueries = false;
      stateDir = "/var/lib/unbound";
      localControlSocketPath = "/run/unbound/unbound.ctl";

      settings = {
        server = {
          interface = ["127.0.0.1@5353" "::1@5353"];
          access-control = ["127.0.0.0/8 allow" "::1/128 allow"];
          root-hints = "${pkgs.dns-root-data}/root.hints";

          num-threads = 12;
          so-reuseport = true;
          msg-cache-slabs = 16;
          rrset-cache-slabs = 16;
          infra-cache-slabs = 16;
          key-cache-slabs = 16;

          rrset-cache-size = "100m";
          msg-cache-size = "50m";
          outgoing-range = 8192;
          num-queries-per-thread = 4096;

          so-rcvbuf = "4m";
          so-sndbuf = "4m";

          # serve-expired = true;
          # serve-expired-ttl = 86400;
          # serve-expired-reply-ttl = 0;

          prefetch = true;
          prefetch-key = true;

          minimal-responses = false;

          extended-statistics = true;

          rrset-roundrobin = true;
          use-caps-for-id = true;
        };
      };
    };
  };
}