fix(systemd): sandbox privileged hardware oneshots

Assisted-by: DeepSeek Harness (deepseek-flash)
This commit is contained in:
Ryan Yin committed 2026-11-01 20:49:51 +08:00
1 parent e0cb3eab75
commit a97400df69
6 files changed
+82 -3

No files matched your search

@@ -9,6 +9,17 @@ let
"~@clock @cpu-emulation @debug @module @mount @obsolete @privileged @raw-io @reboot @swap"
];
};
privilegedOneshot = {
CapabilityBoundingSet = "";
DeviceAllow = null;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateNetwork = true;
ProtectKernelTunables = null;
ProtectSystem = "strict";
RestrictAddressFamilies = [ "AF_UNIX" ];
};
in
{
# Only 80/443.
@@ -21,4 +32,13 @@ in
whisper-asr = sandbox // {
PrivateDevices = false;
};
privilegedOneshot = {
amdgpu-power-cap = privilegedOneshot;
hdd-no-spindown = privilegedOneshot // {
CapabilityBoundingSet = [ "CAP_SYS_RAWIO" ];
DeviceAllow = [ "block-sd rw" ];
PrivateDevices = false;
};
};
}
@@ -12,6 +12,23 @@ let
lib.genAttrs names (
n: lib.getAttrs keys outputs.nixosConfigurations.${host}.config.systemd.services.${n}.serviceConfig
);
privilegedKeys = [
"CapabilityBoundingSet"
"DeviceAllow"
"NoNewPrivileges"
"PrivateDevices"
"PrivateNetwork"
"ProtectKernelTunables"
"ProtectSystem"
"RestrictAddressFamilies"
];
privilegedUnit =
host: name:
let
cfg = outputs.nixosConfigurations.${host}.config.systemd.services.${name}.serviceConfig;
in
lib.genAttrs privilegedKeys (key: cfg.${key} or null);
in
units "youko" [
"caddy"
@@ -19,3 +36,9 @@ units "youko" [
"vmalert-homelab"
]
// units "aquamarine" [ "whisper-asr" ]
// {
privilegedOneshot = {
amdgpu-power-cap = privilegedUnit "aquamarine" "amdgpu-power-cap";
hdd-no-spindown = privilegedUnit "youko" "hdd-no-spindown";
};
}