mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-08-26 21:33:57 +02:00
* security: make firewall secure-by-default, disable explicitly on servers
Flip the base firewall default to ON so new hosts are protected by default. Servers keep the firewall off (trusted internal LAN, WAN protected at the router) via explicit overrides in modules/nixos/server/{server,server-aarch64}.nix. Behavior-preserving for all 18 current hosts; adds a security-firewall eval test guarding the per-host state.
* test: fix security-firewall eval test to scalar per-host values
* security: enable AppArmor (complain) on all Linux hosts
* security: bind aquamarine metrics exporters to loopback
* security: restrict k3s kubeconfig file mode to 600
* security: disable SSH X11 forwarding on servers, keep on desktops
* security: add conservative systemd hardening to aquamarine services
* docs(apparmor): correct FHS-alias comment (nixpkgs has no broad FHS layer)
nixpkgs only creates /run/current-system, /usr/bin/env and /bin/sh; it does not
provide a broad FHS->store alias tree, so FHS-oriented abstractions are incomplete
on NixOS. They are safe only because the profiles run in complain mode.
* fix(aquamarine): scrape same-host exporters over loopback
The v2ray/postgres/sftpgo exporters were bound to 127.0.0.1 but VictoriaMetrics
scraped them via the host's routable IP, so those scrapes refused connections.
Point the three same-host scrape targets at 127.0.0.1 (VM runs on the same host).
node-exporter keeps the host IP since it binds 0.0.0.0.
* Revert "security: add conservative systemd hardening to aquamarine services"
This reverts commit f9cf99dadb.
Linux Hardening
Work in progress.
Goal
- System Level: Protect critical files from being accessed by untrusted applications.
- Such as browser cookies, SSH keys, etc.
- Per-App Level: Prevent untrusted applications(such as closed-source apps) from:
- Accessing files they shouldn't.
- Such as a malicious application accessing your browser's cookies, SSH Keys, etc.
- Accessing the network when they don't need to.
- Accessing hardware devices they don't need.
- Accessing files they shouldn't.
Current Structure
1. System Level
- AppArmor (
apparmor/): AppArmor profiles and configuration - Kernel & System Hardening (
profiles/): System-wide hardening profiles
2. Per-App Level
- Nixpak (
nixpaks/): Bubblewrap-based sandboxing for applications- Firefox configuration
- QQ (Chinese messaging app) configuration
- Modular system with reusable components
- Firejail (legacy): SUID-based sandboxing (not used)
- Bubblewrap (
bwraps/): Direct bubblewrap configurations- WeChat sandboxing configuration
Current Implementation Status
| Component | Status | Notes |
|---|---|---|
| AppArmor Profiles | 🚧 WIP | Basic structure in place |
| Nixpak Firefox | ✅ Active | Firefox sandboxing via nixpak |
| Nixpak QQ | ✅ Active | QQ application sandboxing |
| Bubblewrap WeChat | ✅ Active | WeChat specific sandboxing |
| System Profiles | 🚧 WIP | Hardened system configurations |
Directory Structure
hardening/
├── README.md
├── apparmor/ # AppArmor security profiles
│ └── default.nix
├── bwraps/ # Direct bubblewrap configurations
│ ├── default.nix
│ └── wechat.nix
├── nixpaks/ # Nixpak application sandboxing
│ ├── default.nix
│ ├── firefox.nix
│ ├── qq.nix
│ └── modules/ # Reusable nixpak modules
│ ├── gui-base.nix
│ └── network.nix
└── profiles/ # System hardening profiles
└── default.nix
Kernel Hardening
- NixOS Kernel Config: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/os-specific/linux/kernel/hardened/config.nix
System Hardening
- NixOS Profile: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/profiles/hardened.nix
- Apparmor: roddhjav/apparmor.d
- https://gitlab.com/apparmor/apparmor/-/wikis/Documentation
- AppArmor.d is a set of over 1500 AppArmor profiles whose aim is to confine most Linux based applications and processes.
- But all the profiles of AppArmor assume a FHS filesystem, which caused all apparmor policies takes no effect on NixOS.
- Apparmor on NixOS Roadmap:
- SELinux: too complex, not recommended for personal use.
Application Sandboxing
- Bubblewrap:
nixpak, more secure than firejail, but no batteries included.
- NixOS's FHSEnv is implemented using bubblewrap by default.
- Firejail: A SUID security sandbox with
hundreds of security profiles for many common applications in the default installation.
- https://wiki.nixos.org/wiki/Firejail
- Firejail needs SUID to work, which is considered a security risk - Does firejail improve the security of my system?
- Systemd/Hardening: Systemd also provides some sandboxing features.
NOTE
Running untrusted code is never safe, kernel hardening & sandboxing cannot change this.
If you want to run untrusted code, please use a VM & an isolated network environment, which will provide a much higher level of security.
References
- Harden your NixOS workstation - dataswamp
- Linux Insecurities - Madaidans
- Sandboxing all programs by default - NixOS Discourse
- Paranoid NixOS Setup - xeiaso
- nix-mineral: NixOS module for convenient system hardening.
- apparmor configs:
- Others:
- Directly via
buildFHSUserEnvBubblewrap:
- Directly via