flakes/modules/system/security.nix

57 lines
1.3 KiB
Nix
Raw Normal View History

2021-05-11 14:32:58 +07:00
{ config, pkgs, ... }: {
networking.firewall =
let
iptables = "${pkgs.iptables}/bin/iptables";
genCmds = type: ''
${iptables} -${type} nixos-fw -p tcp --source 192.168.0.0/16 -j nixos-fw-accept ${if type == "D" then " || true" else ""}
${iptables} -${type} nixos-fw -p udp --source 192.168.0.0/16 -j nixos-fw-accept ${if type == "D" then " || true" else ""}
'';
in {
2021-09-20 13:42:43 +00:00
enable = true;
allowedUDPPortRanges = [ { from = 20000; to = 20100; } ];
allowedTCPPortRanges = [ { from = 20000; to = 20100; } ];
2021-09-20 13:42:43 +00:00
trustedInterfaces = [ "wg0" ];
extraCommands = genCmds "I";
extraStopCommands = genCmds "D";
2021-09-20 13:42:43 +00:00
};
services.openssh = {
enable = true;
2023-06-18 21:31:27 +07:00
settings = {
PermitRootLogin = "no";
PasswordAuthentication = false;
X11Forwarding = true;
};
2021-09-20 18:40:15 +07:00
hostKeys = [
{
bits = 4096;
2022-08-09 15:17:30 +07:00
path = "/persist/ssh_host_rsa_key";
2021-09-20 18:40:15 +07:00
rounds = 100;
type = "rsa";
}
{
2022-08-09 15:17:30 +07:00
path = "/persist/ssh_host_ed25519_key";
2021-09-20 18:40:15 +07:00
rounds = 100;
type = "ed25519";
}
];
};
2021-05-11 14:32:58 +07:00
security = {
polkit.enable = true;
sudo.enable = false;
doas = {
enable = true;
extraRules = [
{
2021-07-15 19:57:49 +07:00
groups = [ "wheel" ];
2021-05-11 14:32:58 +07:00
keepEnv = true;
persist = true;
}
];
};
};
}