mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-11-13 12:13:46 +01:00
The homelab hosts accept root SSH with long-lived file keys, run several exposed services with almost no systemd sandboxing, and keep no audit trail of privileged actions. Close those three gaps, weighing each measure against its cost instead of adopting a policy wholesale. SSH - Turn off KbdInteractiveAuthentication: nixpkgs defaults it to true and PAM then still accepts the Unix password despite PasswordAuthentication = false. - authorizedKeysInHomedir = false: only keys declared in Nix take effect; youko keeps Gitea's forced-command file through `Match User gitea`. - Pin aquamarine's passphrase-free remote-builder keys to `restrict,command="nix-daemon --stdio --store daemon"`, so builds run in the system daemon instead of an audited root login session. systemd sandboxing - Add the mylib.systemdHardening preset and apply it to the exposed, weakly sandboxed services: caddy 7.8 -> 1.5, vmalert 8.2 -> 1.4, rustfs 6.6 -> 1.4, whisper-asr 7.7 -> 1.6. An eval test pins the key restrictions. - Rejected: a global all-keys policy (<=0.2 score gains on services nixpkgs already sandboxes) and per-service confinement (bind paths to maintain). auditd on all four hosts, reusing nixpkgs' loader and unit - Audit login sessions only: a first `-a never,task -F auid=unset` rule keeps services out of the per-syscall audit path. A compromised service is therefore unrecorded until it opens a session. - Record root commands, credential and host-key access, writes to SSH, account, PAM, Nix-trust and audit configuration, module loads and session denials. - Rejected: global denial logging, service-UID watches and --loginuid-immutable (the kernel already records loginuid changes). Verified on all four hosts after deployment: zero failed units, k3s 6/6 Ready, and the exposed services healthy. Assisted-by: Claude Code (claude-opus-5-5)
38 lines
1.6 KiB
Nix
38 lines
1.6 KiB
Nix
{ lib, pkgs, ... }:
|
|
{
|
|
# Secure by default: firewall ON everywhere. Servers run the same shared
|
|
# firewall (modules/nixos/base/networking/firewall.nix) as every other host,
|
|
# as defence in depth behind the router.
|
|
networking.firewall.enable = lib.mkDefault true;
|
|
# Enable the OpenSSH daemon.
|
|
services.openssh = {
|
|
enable = true;
|
|
settings = {
|
|
# Secure by default: X11 forwarding off everywhere; desktops re-enable it
|
|
# in modules/nixos/desktop/ssh.nix (needed for GUI forwarding).
|
|
X11Forwarding = lib.mkDefault false;
|
|
# root login stays available for Colmena/MicroVM deployment, keys only
|
|
PermitRootLogin = lib.mkDefault "prohibit-password";
|
|
PasswordAuthentication = false; # disable password login
|
|
# nixpkgs defaults it to true, and PAM then still accepts the Unix password
|
|
KbdInteractiveAuthentication = false;
|
|
};
|
|
openFirewall = true;
|
|
# Only keys declared in Nix log in; a hand- or intruder-added key is ignored
|
|
authorizedKeysInHomedir = false;
|
|
};
|
|
|
|
# NixOS appends an `Include` of systemd's ssh_config.d drop-in to
|
|
# /etc/ssh/ssh_config, and OpenSSH re-applies SSHCONF_CHECKPERM to included
|
|
# files. A bubblewrap sandbox (`--unshare-user`) exposes root-owned store
|
|
# files as `nobody`, which would abort ssh there. We do not use
|
|
# systemd-ssh-proxy (.host, machine/*, unix/*, vsock/*).
|
|
programs.ssh.systemd-ssh-proxy.enable = false;
|
|
|
|
# Terminfo for the terminals we use, so `$TERM` resolves on hosts we SSH into.
|
|
environment.systemPackages = [
|
|
pkgs.ghostty.terminfo
|
|
pkgs.kitty.terminfo
|
|
];
|
|
}
|