summaryrefslogtreecommitdiffstats
path: root/configs/sshd.nix
blob: cb6d8a636c7d5f8dff19a289008a3530debf1baf (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
{ config, lib, ... }: let
  cfg.host = config.krebs.build.host;
  nets =
    lib.optional (cfg.host.nets?mycelium) cfg.host.nets.mycelium ++
    lib.optional (cfg.host.nets?retiolum) cfg.host.nets.retiolum ++
    lib.optional (cfg.host.nets?wiregrill) cfg.host.nets.wiregrill;

  cfg.ssh.port = 11423;
in {
  services.openssh = {
    enable = true;
  };
  hrm.nftables.input.internet.tcp = [ "ssh" ];
  hrm.nftables.tables.nat.chains = {
    # Port 22 is only reachable on the host's own network addresses; on
    # other addresses, port 22 goes nowhere and cfg.ssh.port leads to sshd.
    prerouting.rules = {
      ssh-own-addresses = {
        order = 900;
        daddr =
          map (net: net.ip4.addr) (builtins.filter (net: net.ip4 != null) nets) ++
          map (net: net.ip6.addr) (builtins.filter (net: net.ip6 != null) nets);
        tcp.dport = [ 22 ];
        verdict = "accept";
      };
      ssh-hide = {
        tcp.dport = [ 22 ];
        verdict = "redirect to :0";
      };
      ssh-port = {
        tcp.dport = [ cfg.ssh.port ];
        verdict = "redirect to :22";
      };
    };
    output.rules.ssh-port = {
      oifname = "lo";
      tcp.dport = [ cfg.ssh.port ];
      verdict = "redirect to :22";
    };
  };
}
[cgit] Unable to lock slot /tmp/cgit/ad100000.lock: Permission denied (13)