]> Git — Sourcephile - sourcephile-nix.git/blob - servers/losurdo/acme/sourcephile.fr.nix
fail2ban: enable sshd and postgresql on losurdo
[sourcephile-nix.git] / servers / losurdo / acme / sourcephile.fr.nix
1 { pkgs, lib, config, servers, ... }:
2 let
3 domain = "sourcephile.fr";
4 domainID = lib.replaceStrings ["."] ["_"] domain;
5 credentialsFile = "/var/lib/acme/.lego/${domain}/rfc2136";
6 inherit (config.users) users groups;
7 in
8 {
9 systemd.services."acme-${domain}".after = [
10 "unbound.service"
11 ];
12 services.shorewall.configs.rules = ''
13 # for lego to update ACME DNS-01 challenge
14 DNS(ACCEPT) $FW net:${servers.mermet.ipv4}
15 # for lego to check DNS propagation on ns6.gandi.net
16 DNS(ACCEPT) $FW net:217.70.177.40 {user=${users.root.name}}
17 '';
18 networking.nftables.ruleset = ''
19 # for lego to update ACME DNS-01 challenge
20 add rule inet filter fw2net tcp dport 53 ip daddr ${servers.mermet.ipv4} counter accept comment "DNS"
21 add rule inet filter fw2net udp dport 53 ip daddr ${servers.mermet.ipv4} counter accept comment "DNS"
22 # for lego to check DNS propagation on ns6.gandi.net
23 add rule inet filter fw2net ip daddr 217.70.177.40 tcp dport 53 skuid ${users.root.name} counter accept comment "DNS gandi"
24 add rule inet filter fw2net ip daddr 217.70.177.40 udp dport 53 skuid ${users.root.name} counter accept comment "DNS gandi"
25 '';
26 security.acme.certs."${domain}" = {
27 email = "root+letsencrypt@${domain}";
28 extraDomains = {
29 "*.${domain}" = null;
30 };
31 user = users.root.name;
32 group = groups.acme.name;
33 allowKeysForGroup = true;
34 keyType = "rsa4096";
35 dnsProvider = "rfc2136";
36 # ns6.gandi.net takes roughly 5min to update
37 # hence lego's RFC2136_PROPAGATION_TIMEOUT=1000
38 #dnsPropagationCheck = false;
39 inherit credentialsFile;
40 };
41 install.shellHook = ''
42 {
43 cat <<-EOF
44 RFC2136_NAMESERVER=ns.${domain}:53
45 RFC2136_TSIG_ALGORITHM=hmac-sha256.
46 RFC2136_TSIG_KEY=acme_${domainID}
47 RFC2136_PROPAGATION_TIMEOUT=1000
48 RFC2136_POLLING_INTERVAL=30
49 RFC2136_SEQUENCE_INTERVAL=30
50 RFC2136_DNS_TIMEOUT=1000
51 RFC2136_TTL=1
52 EOF
53 pass "servers/losurdo/lego/${domain}/rfc2136"
54 } |
55 ssh "$target" install -D -m 0400 -o root -g root /dev/stdin \
56 ${credentialsFile}
57 '';
58 }