- Replace strict=True and PrivateUsers=true implementation details with architectural invariants - State unprivileged primary UID/GID rule directly
10 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-0001, ADR-0002 (DEC-04, DEC-05), and ADR-0004, validate_compose_security() (shared pre-flight validator invoked authoritatively by homelab-appctl.service in scripts/appctl_router.py across CLI and GitOps paths) enforces a uniform deny-all policy on Tier 2 workload docker-compose.yml files:
devices:mounts are blocked.- Host bind mounts outside
~/Workloads/<app>and~/var/lib/homelab/<app>are blocked. - Host namespace sharing (
network_mode: host, etc.) is blocked.
While this prevents a Tier 2 git push from escalating privileges on the host, it blocks required single-operator capability classes:
- Hardware-Accelerated & External-Storage Workloads: Media transcoding or compute workloads requiring an integrated GPU (
/dev/dri/renderD128) must mount host device nodes, pass a supplementary device group (such asrender/ GID303), and read an external read-only storage partition (/media:ro). Currently,devices:and external bind mounts are blocked, whilegroup_add:anduser:primary GIDs are unconstrained (risking arbitrary host GID elevation to groups such asdockerorwheelunless constrained). - LAN Broadcast / Peer-Discovery Services (Out of Scope for Host Networking): Workloads that send Wake-on-LAN magic packets or discover LAN peers cannot traverse Docker bridge L2 isolation, prompting requests for
network_mode: host. Because blanket host networking collapses network namespace isolation—exposing loopback control services such ashomelab-appctl.serviceon127.0.0.1:9001—host networking remains out of scope for workload grants and must be handled via isolated L2 Docker networks (macvlan/ipvlan) or host-side intermediaries. - Host-Agnostic Core Boundary: Hardcoding
/dev/dri,/media, or specific workload names insidenixos-coreviolates platform portability 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/primary GIDs, 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 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 requesteddevices,volumes,group_add, anduser. - Documented Instance Schema: Provide a tracked
nixos/instance.example.nixtemplate so new hosts can configurehomelab.domain,homelab.operatorUser, andhomelab.workloadGrantsin/etc/nixos/homelab-instance.nix(or gitignorednixos/instance.nix). - Fail-Closed Validation: An absent grants file defaults to zero grants (current baseline); a present but unreadable, tampered, or malformed grants file fails closed across all workloads.
privileged: true,/var/run/docker.sock,cap_add,device_cgroup_rules:, and host/container namespace sharing remain permanently prohibited.
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 enforced byvalidate_compose_security().
Decision Outcome
Chosen option: Option 3: "Compose Requests, Nix Grants" via homelab.workloadGrants, because it keeps nixos-core 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; prefer specific nodes such as"/dev/dri/renderD128"over whole directories unless display control is required).groups(list of supplementary/primary group names or GIDs permitted ingroup_addanduser:, such as"render"or"303"; privileged host groups0/root,wheel, anddockerare permanently rejected).readOnlyPaths(list of host directories permitted for read-only bind mounts only).
privileged: true,/var/run/docker.sock,cap_add,device_cgroup_rules:, and namespace sharing (network_mode: host,network_mode: container:*,network_mode: service:*,pid,ipc,uts,userns_mode: host) remain permanently prohibited and are not grantable.
-
Immutable Host Projection (
/etc/homelab/grants.json):- NixOS generates
/etc/homelab/grants.json(root-owned, group-owned byhomelab-operatorswith mode0640, granting read access to bothhomelab-appctlandoperatorwithout POSIX ACLs; overridable viaHOMELAB_GRANTS_FILE, which is reserved inRESERVED_ENV_KEYSso workload.env/app.yamlcannot override it). - In production, the loader verifies regular-file (non-symlink), root-owned, non-world/group-writable permissions before parsing.
- If
/etc/homelab/grants.jsonis absent,validate_compose_security()defaults to zero grants. If it is present but unreadable, fails permission checks, or fails Pydantic v2 (extra="forbid") validation, pre-flight fails closed for all workloads.
- NixOS generates
-
Exact-Match Pre-Flight Enforcement:
validate_compose_security()evaluates resolved values (post-6-layer env assembly, or rejects uninterpolated${...}indevices,volumes,group_add, anduser). Whenapp_nameisNoneor unknown, zero grants apply.- Every capability requested in
<app>/docker-compose.ymlmust match an explicit grant for<app>:devicesentries supporthost:container[:perms], forbidm(mknod) in permissions, and require the host path to exist and resolve canonically within the granted device node or directory, disallowing..traversal or symlink escapes.group_addtransitions from unconstrained to default-deny when nogroupsgrant exists;groupsentries canonicalize bidirectionally between group names and integer GIDs via the host group database.user:primary GIDs must either fall within grantedgroupsor be unprivileged numeric IDs that do not map to privileged or host-sensitive groups.readOnlyPathsvalidates both short (host:container:ro[,opts]) and long (type: bind,read_only: true) volume syntax, rejects unsafe bind propagation, and requires the host path to exist and resolve canonically within the granted directory.
-
Tracked Instance Template (
nixos/instance.example.nix):nixos-coretracksnixos/instance.example.nixdocumentinghomelab.domain,homelab.operatorUser, andhomelab.workloadGrants.- Live hosts keep concrete values in
/etc/nixos/homelab-instance.nix(loaded via--impureflake evaluation, taking precedence over gitignorednixos/instance.nixif both exist). Both paths remain optional so purenix flake checkCI passes with defaults.
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 weakens tenant isolation for all workloads.
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-workloadsremains free of host-privilege grants, and privilege elevation requires explicit host-levelnixos-rebuild switch. - Bad, because adding a new privileged capability requires editing
/etc/nixos/homelab-instance.nixand rebuilding NixOS beforeappctl up.
Consequences
Positive Consequences
- Hardware & Media Operability: Workloads can use GPU acceleration and external
:rostorage cleanly via standarddocker-compose.ymlsyntax once authorized by the host. - Closed GID & Namespace Loopholes: Transitions
group_add:,user:primary GIDs,device_cgroup_rules:, andnetwork_mode: container:*to fail-closed enforcement. - CI Compatibility: Pure
nix flake checkevaluates cleanly with empty default grants.
Negative Consequences & Accepted Trade-offs
- Tier 2 / Tier 3 Deployment Ordering: Pushing a Compose file requesting a new capability before running
nixos-rebuild switchfails closed at pre-flight (surfaced clearly via a distinct capability-denial error/audit signal such asERR_CAPABILITY_NOT_GRANTED). - Host Path Coupling: Workload Compose files declare physical host paths matching host grants; logical capability aliasing via environment-variable injection remains an optional future refinement.
More Information
- Amends ADR-0002 (
DEC-04,DEC-05). - Related specifications: docs/architecture.md, docs/appctl.md, docs/secrets-and-state.md.