diff options
| author | Alejandro Soto <alejandro@34project.org> | 2024-08-03 11:49:59 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2024-08-03 11:51:34 -0600 |
| commit | bd29827fba8aefa978798ad105d8793976f082b4 (patch) | |
| tree | 7359cf79d4aea6036c3fb0e2488854b83a1e76bd /sys/auth/openssh.nix | |
| parent | 43978aaa287f2c0eed643789fc0a70777dda33a2 (diff) | |
sys/auth, sys/[lustrated]: restrict SSH to gate interface
Diffstat (limited to '')
| -rw-r--r-- | sys/auth/openssh.nix | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/sys/auth/openssh.nix b/sys/auth/openssh.nix index 87c6299..161fe6f 100644 --- a/sys/auth/openssh.nix +++ b/sys/auth/openssh.nix @@ -2,6 +2,8 @@ with lib; let cfg = config.local.auth.openssh; withOath = config.local.auth.oath.enable; + + port = if cfg.shiftPortNumber then 2234 else 22; in { options.local.auth.openssh = { @@ -19,6 +21,22 @@ in }; }) [ "ecdsa" "ed25519" "rsa" ]); + restrictListen = mkOption { + default = null; + + type = with types; nullOr (submodule { + options = { + address = mkOption { + type = str; + }; + + interface = mkOption { + type = str; + }; + }; + }); + }; + shiftPortNumber = mkOption { type = types.bool; default = true; @@ -41,26 +59,16 @@ in local.boot.impermanence.files = flatten (map (key: [ key.path "${key.path}.pub" ]) config.services.openssh.hostKeys); + networking.firewall.interfaces = optionalAttrs (cfg.restrictListen != null) { + ${cfg.restrictListen.interface}.allowedTCPPorts = [ port ]; + }; + services.openssh = { enable = true; - openFirewall = true; - ports = mkIf cfg.shiftPortNumber [ 2234 ]; - startWhenNeeded = !config.services.fail2ban.enable; - - hostKeys = map - (name: { - path = "/etc/ssh/ssh_host_${name}_key"; - type = name; - } // optionalAttrs (name == "rsa") { - bits = 4096; - }) - (attrNames (filterAttrs (name: enable: enable) cfg.hostKeys)); - settings = { - X11Forwarding = true; - PermitRootLogin = "prohibit-password"; - PasswordAuthentication = withOath; # Necesario para oath, no reemplaza a oath - }; + ports = [ port ]; + openFirewall = cfg.restrictListen == null; + startWhenNeeded = !config.services.fail2ban.enable; extraConfig = optionalString cfg.tunnel.enable '' # User 'tunnel' has no password. Use PAM OATH @@ -79,6 +87,25 @@ in This is a reverse tunnel ''} ''; + + hostKeys = map + (name: { + path = "/etc/ssh/ssh_host_${name}_key"; + type = name; + } // optionalAttrs (name == "rsa") { + bits = 4096; + }) + (attrNames (filterAttrs (name: enable: enable) cfg.hostKeys)); + + settings = { + X11Forwarding = true; + PermitRootLogin = "prohibit-password"; + PasswordAuthentication = withOath; # Necesario para oath, no reemplaza a oath + }; + + listenAddresses = mkIf (cfg.restrictListen != null) (singleton { + addr = cfg.restrictListen.address; + }); }; users.users = { |
