- Drop hostNetwork grant from workloadGrants to protect 127.0.0.1:9001 appctl boundary - Explicitly motivate groups grant by detailing jellyfin GID 303 (render) requirement - Elevate enforcement specifications to architectural invariants - Acknowledge host-path coupling trade-off
7.9 KiB
type, status, project, date, tags, amends
| type | status | project | date | tags | amends | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| decision | accepted | homelab-core | 2026-11-20 |
|
0002-appctl-control-plane-architecture.md |
ADR 0005: Host-Granted Workload Capabilities ("Compose Requests, Nix Grants")
Context and Problem Statement
Under ADR-0002 (DEC-04, DEC-05) and ADR-0004, validate_compose_security() in scripts/gitops_dispatcher.py enforces a uniform deny-all pre-flight policy on Tier 2 workload docker-compose.yml files:
- All
devices:mounts are unconditionally blocked. - All host bind mounts outside
~/Workloads/<app>and~/var/lib/homelab/<app>are blocked. - All host namespace sharing (
network_mode: host, etc.) is blocked.
While this prevents a Tier 2 git push from escalating privileges on the host, it creates real friction for legitimate single-operator workloads:
- Hardware Acceleration & Media Access (
jellyfin): Using an integrated GPU (/dev/dri) for VAAPI transcoding requires mounting host device nodes, passing supplementary groups (group_add: ["303"]/render), and reading a dedicated media partition (/media:ro). Currently,devices:and arbitrary bind mounts are completely blocked, whilegroup_add:is unconstrained (risking arbitrary host GID elevation to groups likedockerorwheelunless strictly governed). - LAN Broadcast / Peer Services (e.g.,
lg-smtv-mcp): Workloads that send Wake-on-LAN broadcasts or discover LAN peers may struggle across Docker bridge boundaries, prompting requests fornetwork_mode: host. However, blanket host networking collapses network namespace isolation, exposing loopback control services (such ashomelab-appctl.serviceon127.0.0.1:9001) and bypassing proxy network segmentation. - Host-Agnostic Core Boundary: Hardcoding
/dev/dri,/media, or specific workload names insidenixos-coreviolates platform genericism and couples Core to one machine's hardware and app catalog.
The central architectural question is: How should Canopy NixOS Core permit hardware devices, supplementary groups, and external read-only storage paths for specific workloads without hardcoding personal infrastructure into nixos-core or weakening the Tier 2 -> Tier 3 trust boundary?
Decision Drivers
- Preserve the Trust Split: A push to Tier 2 (
canopy-workloads) must never be able to grant itself root-equivalent host access; capability grants must originate from root-level Tier 3 NixOS host configuration (nixos-rebuild switch). - Keep
nixos-coreGeneric: Core defines the capability schema and enforcement logic only, with zero hardcoded personal app names, device nodes, or media paths. - Keep
app.yamlFree of Host Paths: Workload manifests remain declarative routing/provenance metadata;docker-compose.ymlalready declares the requesteddevices,volumes,group_add, andnetwork_mode. - Documented Instance Schema: Provide a tracked
nixos/instance.example.nixtemplate so new hosts (or a future setup wizard) can configurehomelab.domain,homelab.operatorUser, andhomelab.workloadGrantscleanly in/etc/nixos/homelab-instance.nix(or gitignorednixos/instance.nix). - Fail-Closed Validation: Absent, unreadable, or malformed grant configuration must default to zero grants (identical to today's strict baseline), and
privileged: trueand/var/run/docker.sockmounts remain permanently prohibited for all workloads.
Considered Options
- Option 1: Relax
validate_compose_security()Globally: Allow/dev/driand arbitrary:ropaths for all workloads. - Option 2: Store Grants in
~/Workloads/grants.yaml: Allowcanopy-workloadsto declare its own exceptions alongsidedeployments.yaml. - Option 3: "Compose Requests, Nix Grants" via
homelab.workloadGrants(Adopted): Define a typedhomelab.workloadGrantsoption innixos-corerendered to root-owned/etc/homelab/grants.json, validated with Pydantic v2 (extra="forbid"), and checked byvalidate_compose_security().
Decision Outcome
Chosen option: Option 3: "Compose Requests, Nix Grants" via homelab.workloadGrants, because it keeps nixos-core 100% hardware- and workload-agnostic while preserving the security boundary between Tier 2 Git pushes and Tier 3 sudo nixos-rebuild switch.
Summary of Architectural Commitments
This ADR formally amends ADR-0002 (DEC-04, DEC-05) with the following commitments:
-
Typed Host Grant Schema (
homelab.workloadGrants):nixos/modules/homeserver.nixdefineshomelab.workloadGrantsas an attribute set keyed by workload name, supporting three explicit grant fields:devices(list of exact device paths, e.g."/dev/dri"or"/dev/dri/renderD128").groups(list of supplementary group names/GIDs permitted ingroup_add, such as"303"or"render").readOnlyPaths(list of host directories permitted for:robind mounts only).
- Note on
network_mode: host: To preserve the127.0.0.1:9001daemon boundary and Traefik reverse-proxy segmentation, host networking is rejected and excluded fromworkloadGrants. Workloads requiring L2 broadcast/discovery should be provisioned on dedicated isolated Docker networks (macvlan/ipvlan) or host-side intermediaries. privileged: true,/var/run/docker.sock,cap_add, and host namespaces (pid,ipc,uts,userns_mode,network_mode: host) remain permanently prohibited and are not grantable.
-
Immutable Host Projection (
/etc/homelab/grants.json):- NixOS generates
/etc/homelab/grants.json(root-owned, readable byhomelab-appctlandhomelab-gitops, configurable viaHOMELAB_GRANTS_FILEfor testing). - If the grants file is absent,
validate_compose_security()defaults to zero grants. If present but malformed, validation fails closed.
- NixOS generates
-
Exact-Match Pre-Flight Enforcement:
- Every capability requested in
<app>/docker-compose.ymlmust match an explicit grant for<app>in/etc/homelab/grants.json:devicesentries must have their host path resolve canonically strictly within the granted device node or directory, strictly disallowing directory traversal (..) or symlink escapes.groupsentries must match allowlisted GIDs or group names granted to that specific workload.readOnlyPathsgrants permit mounts only when:romode is specified and the canonical host path resolves strictly within the granted directory.
- Trade-off (Host Path Coupling): Workload Compose definitions declare physical host paths matching host grants; logical capability aliasing via environment variable injection remains an optional future refinement.
- Every capability requested in
-
Tracked Instance Template (
nixos/instance.example.nix):nixos-coretracksnixos/instance.example.nixdocumentinghomelab.domain,homelab.operatorUser, andhomelab.workloadGrants.- Live hosts keep their concrete configuration in
/etc/nixos/homelab-instance.nix(or gitignorednixos/instance.nix) without build-time file translation between the two.
Pros and Cons of the Options
Option 1: Relax validate_compose_security() Globally
- Good, because it requires minimal code.
- Bad, because it hardcodes host hardware assumptions into
nixos-coreand cannot safely expressnetwork_mode: host.
Option 2: Store Grants in ~/Workloads/grants.yaml
- Good, because grants live next to
deployments.yaml. - Bad, because Tier 2 would self-authorize Tier 3 host privileges on a single
git push.
Option 3: "Compose Requests, Nix Grants" via homelab.workloadGrants (Adopted)
- Good, because
nixos-corestays generic,canopy-workloadsstays clean, and privilege elevation requires explicit host-levelnixos-rebuild switch. - Bad, because adding a new privileged capability for a workload requires editing
/etc/nixos/homelab-instance.nixand rebuilding NixOS beforeappctl up.