dotfiles/nixos/security.nix

90 lines
2.8 KiB
Nix
Raw Normal View History

2022-03-10 12:25:23 +00:00
{ config, pkgs, lib, ... }: {
2022-06-03 21:45:58 +01:00
networking.firewall.checkReversePath = "loose";
networking.firewall.enable = true;
2020-05-02 20:20:22 +01:00
nix.allowedUsers = [ "@users" ];
2022-06-03 21:45:58 +01:00
security.apparmor.enable = true;
security.apparmor.killUnconfinedConfinables = true;
security.forcePageTableIsolation = true;
security.lockKernelModules = false;
2020-05-02 20:20:22 +01:00
security.protectKernelImage = true;
security.virtualisation.flushL1DataCache = "always";
2022-01-15 09:38:11 +00:00
services.clamav.daemon.enable = true;
services.clamav.updater.enable = true;
2022-06-03 21:45:58 +01:00
2022-06-04 13:11:55 +01:00
sops.age = {
keyFile = "/var/lib/sops-nix/key.txt";
generateKey = true;
};
2022-03-10 12:25:23 +00:00
boot.kernelParams =
[ "slub_debug=FZP" "page_poison=1" "page_alloc.shuffle=1" ];
2020-05-02 20:20:22 +01:00
boot.blacklistedKernelModules = [
# Obscure network protocols
"ax25"
"netrom"
"rose"
# Old or rare or insufficiently audited filesystems
"adfs"
"affs"
"bfs"
"befs"
"cramfs"
"efs"
"erofs"
"exofs"
"freevxfs"
"f2fs"
"hfs"
"hpfs"
"jfs"
"minix"
"nilfs2"
2022-01-15 10:18:49 +00:00
"omfs"
2020-05-02 20:20:22 +01:00
"qnx4"
"qnx6"
"sysv"
"ufs"
];
2022-01-15 10:18:49 +00:00
# Restrict ptrace() usage to processes with a pre-defined relationship
# (e.g., parent/child)
boot.kernel.sysctl."kernel.yama.ptrace_scope" = lib.mkOverride 500 1;
# Hide kptrs even for processes with CAP_SYSLOG
boot.kernel.sysctl."kernel.kptr_restrict" = lib.mkOverride 500 2;
# Disable bpf() JIT (to eliminate spray attacks)
2020-05-02 20:20:22 +01:00
boot.kernel.sysctl."net.core.bpf_jit_enable" = false;
2022-01-15 10:18:49 +00:00
# Disable ftrace debugging
2020-05-02 20:20:22 +01:00
boot.kernel.sysctl."kernel.ftrace_enabled" = false;
2022-01-15 10:18:49 +00:00
# Enable strict reverse path filtering (that is, do not attempt to route
# packets that "obviously" do not belong to the iface's network; dropped
# packets are logged as martians).
2020-05-02 20:20:22 +01:00
boot.kernel.sysctl."net.ipv4.conf.all.log_martians" = true;
boot.kernel.sysctl."net.ipv4.conf.all.rp_filter" = "1";
boot.kernel.sysctl."net.ipv4.conf.default.log_martians" = true;
2021-11-22 19:32:26 +00:00
boot.kernel.sysctl."net.ipv4.conf.default.rp_filter" = "1";
2022-01-15 10:18:49 +00:00
# Ignore broadcast ICMP (mitigate SMURF)
2021-11-22 19:32:26 +00:00
boot.kernel.sysctl."net.ipv4.icmp_echo_ignore_broadcasts" = true;
2022-01-15 10:18:49 +00:00
# Ignore incoming ICMP redirects (note: default is needed to ensure that the
# setting is applied to interfaces added after the sysctls are set)
2021-11-22 19:32:26 +00:00
boot.kernel.sysctl."net.ipv4.conf.all.accept_redirects" = false;
boot.kernel.sysctl."net.ipv4.conf.all.secure_redirects" = false;
boot.kernel.sysctl."net.ipv4.conf.default.accept_redirects" = false;
boot.kernel.sysctl."net.ipv4.conf.default.secure_redirects" = false;
boot.kernel.sysctl."net.ipv6.conf.all.accept_redirects" = false;
boot.kernel.sysctl."net.ipv6.conf.default.accept_redirects" = false;
2022-01-15 10:18:49 +00:00
# Ignore outgoing ICMP redirects (this is ipv4 only)
2021-11-22 19:32:26 +00:00
boot.kernel.sysctl."net.ipv4.conf.all.send_redirects" = false;
boot.kernel.sysctl."net.ipv4.conf.default.send_redirects" = false;
2020-05-02 20:20:22 +01:00
}