-
Notifications
You must be signed in to change notification settings - Fork 0
feat(matic): add filesystem hardening and immutable root protection #1251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,14 @@ inputs.nixpkgs.lib.nixosSystem { | |
| # Pin kernel to 6.18 for CrowdStrike Falcon compatibility (RFM on 6.19) | ||
| boot.kernelPackages = pkgs.linuxPackages_6_18; | ||
|
|
||
| # Filesystem hardening | ||
| boot.kernel.sysctl = { | ||
| "fs.protected_regular" = 2; | ||
| "fs.protected_fifos" = 2; | ||
| "fs.protected_symlinks" = 1; | ||
| "fs.protected_hardlinks" = 1; | ||
| }; | ||
|
|
||
| # AMD power management kernel params | ||
| boot.kernelParams = [ | ||
| "amdgpu.abmlevel=3" # auto backlight management | ||
|
|
@@ -88,6 +96,18 @@ inputs.nixpkgs.lib.nixosSystem { | |
| virtualisation.docker.enable = true; | ||
|
|
||
| security.sudo.wheelNeedsPassword = false; | ||
|
|
||
| # Immutable root — prevents rm -rf / by blocking top-level entry removal | ||
| systemd.services.immutable-root = { | ||
| description = "Set immutable flag on /"; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| serviceConfig = { | ||
| Type = "oneshot"; | ||
| RemainAfterExit = true; | ||
| ExecStart = "${pkgs.e2fsprogs}/bin/chattr +i /"; | ||
| ExecStop = "${pkgs.e2fsprogs}/bin/chattr -i /"; | ||
| }; | ||
|
Comment on lines
+101
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Yes, a systemd service with only WantedBy=multi-user.target and no After= (or other ordering dependencies like Before=) can start in parallel with other units that are also wanted by multi-user.target. Systemd activates all units wanted by a target (via Wants= or WantedBy=) when the target is reached. Without explicit ordering dependencies (After=/Before=), these units have no required sequence and are scheduled as parallel jobs. Systemd's design emphasizes parallel activation to speed up boot, as confirmed in official documentation: "NB: ordering and requirement dependencies are orthogonal. If only a requirement dependency exists between two units (e.g. foo.service requires bar.service), but no ordering dependency (e.g. foo.service after bar.service) and both are requested to start, they will be started in parallel." (systemd(1) man page). Units wanted by multi-user.target typically share common implicit or default dependencies (e.g., After=local-fs.target), but among themselves, without After=, they activate concurrently. Citations:
Add explicit The 🤖 Prompt for AI Agents
Comment on lines
+101
to
+109
|
||
| }; | ||
|
Comment on lines
+100
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation using a systemd service to make the root filesystem immutable will break the standard NixOS update process ( A more idiomatic and robust approach in NixOS is to use |
||
| # Keyd configuration (Linux desktop only) | ||
| services.keyd.enable = true; | ||
| users.groups.keyd = { }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment/PR intent says this “prevents rm -rf /”, but
chattr +i /only prevents creating/removing top-level entries under/(e.g.,/etcitself). It does not prevent deletion of contents inside existing directories (e.g.,rm -rf --no-preserve-root /etc/*would still succeed), so this provides a false sense of protection. Please either (a) reword the comment (and PR description/test plan) to match the actual behavior, or (b) change the approach if the goal is to prevent destructive recursive deletion of the filesystem contents.