Files
nix-config/hosts/12kingdoms-youko/homelab-services/rustfs.nix
T
Ryan Yin 7dc4e7a39f feat(security): harden homelab SSH, services and audit trail
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)
2026-10-31 01:09:15 +08:00

48 lines
1.8 KiB
Nix

{
config,
mylib,
...
}:
let
inherit (mylib.systemdHardening) mkDefaults service;
in
{
# The service module comes from the default nixpkgs (services.rustfs); it
# creates the rustfs user/group, the data volume via tmpfiles, and a hardened
# systemd unit.
services.rustfs = {
enable = true;
settings = {
# New directory; the old MinIO tree at /data/apps/minio is kept as a
# rollback snapshot and was carried over via an S3-level copy.
RUSTFS_VOLUMES = "/data/apps/rustfs";
# Loopback only; caddy terminates TLS and reverse-proxies 443 -> 9000/9001.
RUSTFS_ADDRESS = "127.0.0.1:9000";
RUSTFS_CONSOLE_ADDRESS = "127.0.0.1:9001";
RUSTFS_CONSOLE_ENABLE = "true";
# Sign/presign against the public hostname, since the public port (443)
# differs from the internal one (9000).
RUSTFS_SERVER_DOMAINS = "s3.writefor.fun";
RUST_LOG = "info";
};
# Root credentials (access key = root "user", secret key = password), as a
# dotenv secret with RUSTFS_ACCESS_KEY / RUSTFS_SECRET_KEY.
environmentFile = config.age.secrets."rustfs.env".path;
};
systemd.services.rustfs = {
# The data volume lives on the encrypted HDD subvolume; wait for its mount.
unitConfig.RequiresMountsFor = "/data/apps";
# Fill the sandboxing the nixpkgs unit leaves out.
serviceConfig = mkDefaults service // {
# ProtectSystem=strict: the data volume is the only writable path.
ReadWritePaths = [ config.services.rustfs.settings.RUSTFS_VOLUMES ];
# Its startup endpoint list enumerates the host's interface addresses.
RestrictAddressFamilies = service.RestrictAddressFamilies ++ [ "AF_NETLINK" ];
# Capacity and observability metrics read host-wide /proc files.
ProcSubset = "all";
};
};
}