feat(security): add balanced kernel and exporter baseline (#365)

This commit is contained in:
ryan4yin | 二花 authored and GitHub committed 2026-10-03 16:33:50 +08:00
1 parent 3fdeedaa78
commit f03907c6a4
15 files changed
+294 -64

No files matched your search

+31 -6
View File
@@ -1,10 +1,35 @@
{ lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:
{
# Keep this baseline independent of a particular kernel CVE. User namespaces
# remain available for Nix builds, rootless containers and application sandboxes.
# See SECURITY.md for compatibility constraints and post-deployment checks.
boot.kernel.sysctl = {
"kernel.dmesg_restrict" = lib.mkDefault 1;
# NixOS already sets mkDefault 1; use a stronger default, still overridable
# by an ordinary host definition, rather than conflicting at priority 1000.
"kernel.kptr_restrict" = lib.mkOverride 900 2;
# Allow debuggers to trace their own children; unrelated processes need
# CAP_SYS_PTRACE or an explicit PR_SET_PTRACER exception.
"kernel.yama.ptrace_scope" = lib.mkDefault 1;
# Upstream documents >=2 as blocking unprivileged kernel profiling. Do not
# assume distro-specific values 3/4 provide additional upstream protection.
"kernel.perf_event_paranoid" = lib.mkDefault 2;
# 2 disables unprivileged BPF but lets an administrator re-enable it without
# rebooting. Privileged Cilium/observability agents retain their BPF access.
"kernel.unprivileged_bpf_disabled" = lib.mkDefault 2;
# Limit JIT hardening to unprivileged programs: do not impose its overhead
# on privileged Cilium/observability workloads. Userns root is not host root.
"net.core.bpf_jit_harden" = lib.mkDefault 1;
"vm.unprivileged_userfaultfd" = lib.mkDefault 0;
# Symlink/hardlink protection is boolean; FIFO/regular-file protection also
# supports 2, extending protection to group-writable sticky directories.
"fs.protected_symlinks" = lib.mkDefault 1;
"fs.protected_hardlinks" = lib.mkDefault 1;
"fs.protected_fifos" = lib.mkDefault 2;
"fs.protected_regular" = lib.mkDefault 2;
};
# Blacklist unused kernel modules to shrink the attack surface. esp4/esp6/rxrpc
# were the vectors for the Dirty Frag LPE (CVE-2026-43284 / CVE-2026-43500);
# kept as defence in depth even though the upstream fix has long landed, since
@@ -33,6 +33,11 @@ in
# monitoring host.
ip saddr != ${monitoringHost} tcp dport 9633 drop
# Monitoring uses the stable IPv4 address above. Deny IPv6 exporter
# connections before broad LAN/tailnet/container trust can accept them;
# this does not restrict other IPv6 services or loopback access.
meta nfproto ipv6 tcp dport { 9100, 9835, 9633 } drop
# The local container bridge and the tailnet have the same access as the
# LAN. Kept after the drop above so neither can reach node_exporter.
iifname "podman0" accept
+1
View File
@@ -8,6 +8,7 @@
../base/btop.nix
../base/core.nix
../base/i18n.nix
../base/kernel-hardening.nix
../base/monitoring.nix
../base/nix.nix
../base/packages.nix
+1
View File
@@ -8,6 +8,7 @@
../base/btop.nix
../base/core.nix
../base/i18n.nix
../base/kernel-hardening.nix
../base/monitoring.nix
../base/nix.nix
../base/packages.nix