docs(adr): resolve Stage 7 critic findings in ADR-0005 and README
- Close user: primary GID, device_cgroup_rules:, and network_mode: container:* bypasses - Specify post-interpolation validation, long/short volume syntax, :ro, and :rwm mknod ban - Reconcile absent vs unreadable/malformed grants.json behavior and permissions checks - Add Consequences and More Information sections; sync docs/decisions/README.md
This commit is contained in:
1 parent
f326b11986
commit
37d529848a
2 files changed
+49
-33
No files matched your search
@@ -11,37 +11,37 @@ amends: 0002-appctl-control-plane-architecture.md
|
||||
|
||||
## Context and Problem Statement
|
||||
|
||||
Under [ADR-0001](0001-3tier-architecture-and-provenance.md), [ADR-0002](0002-appctl-control-plane-architecture.md) (`DEC-04`, `DEC-05`), and [ADR-0004](0004-unified-workloads-monorepo.md), `validate_compose_security()` in `scripts/gitops_dispatcher.py` enforces a uniform deny-all pre-flight policy on Tier 2 workload `docker-compose.yml` files:
|
||||
Under [ADR-0001](0001-3tier-architecture-and-provenance.md), [ADR-0002](0002-appctl-control-plane-architecture.md) (`DEC-04`, `DEC-05`), and [ADR-0004](0004-unified-workloads-monorepo.md), `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:
|
||||
|
||||
* 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.
|
||||
* `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 creates real friction for legitimate single-operator capability classes:
|
||||
While this prevents a Tier 2 `git push` from escalating privileges on the host, it blocks required single-operator capability classes:
|
||||
|
||||
1. **Hardware-Accelerated & External-Storage Workloads**: Media transcoding or compute workloads requiring an integrated GPU (`/dev/dri`) must mount host device nodes, pass a supplementary device group (such as `render` / GID `303`), and read an external read-only storage partition (`/media:ro`). Currently, `devices:` and external bind mounts are completely blocked, while `group_add:` is unconstrained (risking arbitrary host GID elevation to groups like `docker` or `wheel` unless strictly governed).
|
||||
2. **LAN Broadcast / Peer-Discovery Services**: Workloads that send Wake-on-LAN magic packets or discover LAN peers struggle across Docker bridge boundaries, prompting requests for `network_mode: host`. However, blanket host networking collapses network namespace isolation, exposing loopback control services (such as `homelab-appctl.service` on `127.0.0.1:9001`) and bypassing proxy network segmentation.
|
||||
3. **Host-Agnostic Core Boundary**: Hardcoding `/dev/dri`, `/media`, or specific workload names inside `nixos-core` violates platform genericism and couples Core to one machine's hardware and app catalog.
|
||||
1. **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 as `render` / GID `303`), and read an external read-only storage partition (`/media:ro`). Currently, `devices:` and external bind mounts are blocked, while `group_add:` and `user:` primary GIDs are unconstrained (risking arbitrary host GID elevation to groups such as `docker` or `wheel` unless constrained).
|
||||
2. **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 as `homelab-appctl.service` on `127.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.
|
||||
3. **Host-Agnostic Core Boundary**: Hardcoding `/dev/dri`, `/media`, or specific workload names inside `nixos-core` violates 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 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?**
|
||||
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 be able to grant itself root-equivalent host access; capability grants must originate from root-level Tier 3 NixOS host configuration (`nixos-rebuild switch`).
|
||||
* **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-core` Generic**: Core defines the capability schema and enforcement logic only, with zero hardcoded personal app names, device nodes, or media paths.
|
||||
* **Keep `app.yaml` Free of Host Paths**: Workload manifests remain declarative routing/provenance metadata; `docker-compose.yml` already declares the requested `devices`, `volumes`, `group_add`, and `network_mode`.
|
||||
* **Documented Instance Schema**: Provide a tracked `nixos/instance.example.nix` template so new hosts (or a future setup wizard) can configure `homelab.domain`, `homelab.operatorUser`, and `homelab.workloadGrants` cleanly in `/etc/nixos/homelab-instance.nix` (or gitignored `nixos/instance.nix`).
|
||||
* **Fail-Closed Validation**: Absent, unreadable, or malformed grant configuration must default to zero grants (identical to today's strict baseline), and `privileged: true` and `/var/run/docker.sock` mounts remain permanently prohibited for all workloads.
|
||||
* **Keep `app.yaml` Free of Host Paths**: Workload manifests remain declarative routing/provenance metadata; `docker-compose.yml` already declares requested `devices`, `volumes`, `group_add`, and `user`.
|
||||
* **Documented Instance Schema**: Provide a tracked `nixos/instance.example.nix` template so new hosts can configure `homelab.domain`, `homelab.operatorUser`, and `homelab.workloadGrants` in `/etc/nixos/homelab-instance.nix` (or gitignored `nixos/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/dri` and arbitrary `:ro` paths for all workloads.
|
||||
* **Option 2: Store Grants in `~/Workloads/grants.yaml`**: Allow `canopy-workloads` to declare its own exceptions alongside `deployments.yaml`.
|
||||
* **Option 3: "Compose Requests, Nix Grants" via `homelab.workloadGrants` (Adopted)**: Define a typed `homelab.workloadGrants` option in `nixos-core` rendered to root-owned `/etc/homelab/grants.json`, validated with Pydantic v2 (`extra="forbid"`), and checked by `validate_compose_security()`.
|
||||
* **Option 3: "Compose Requests, Nix Grants" via `homelab.workloadGrants` (Adopted)**: Define a typed `homelab.workloadGrants` option in `nixos-core` rendered to root-owned `/etc/homelab/grants.json`, validated with Pydantic v2 (`extra="forbid"`), and enforced by `validate_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`.
|
||||
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
|
||||
|
||||
@@ -49,37 +49,53 @@ This ADR formally amends [ADR-0002](0002-appctl-control-plane-architecture.md) (
|
||||
|
||||
1. **Typed Host Grant Schema (`homelab.workloadGrants`)**:
|
||||
* `nixos/modules/homeserver.nix` defines `homelab.workloadGrants` as 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 in `group_add`, such as `"303"` or `"render"`).
|
||||
* `readOnlyPaths` (list of host directories permitted for `:ro` bind mounts only).
|
||||
* Note on `network_mode: host`: To preserve the `127.0.0.1:9001` daemon boundary and Traefik reverse-proxy segmentation, host networking is rejected and excluded from `workloadGrants`. 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.
|
||||
* `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 in `group_add` and `user:`, such as `"render"` or `"303"`; privileged host groups `0`/`root`, `wheel`, and `docker` are 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.
|
||||
|
||||
2. **Immutable Host Projection (`/etc/homelab/grants.json`)**:
|
||||
* NixOS generates `/etc/homelab/grants.json` (`root`-owned, group-owned by `homelab-operators` with mode `0640`, granting read access to both `homelab-appctl` and `operator` without POSIX ACLs; configurable via `HOMELAB_GRANTS_FILE` for testing).
|
||||
* If the grants file is absent, `validate_compose_security()` defaults to zero grants. If present but malformed, validation fails closed.
|
||||
* NixOS generates `/etc/homelab/grants.json` (`root`-owned, group-owned by `homelab-operators` with mode `0640`, granting read access to both `homelab-appctl` and `operator` without POSIX ACLs; overridable via `HOMELAB_GRANTS_FILE`, which is reserved in `RESERVED_ENV_KEYS` so workload `.env` / `app.yaml` cannot override it).
|
||||
* In production, the loader verifies regular-file (non-symlink), root-owned, non-world/group-writable permissions before parsing.
|
||||
* If `/etc/homelab/grants.json` is **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.
|
||||
|
||||
3. **Exact-Match Pre-Flight Enforcement**:
|
||||
* Every capability requested in `<app>/docker-compose.yml` must match an explicit grant for `<app>` in `/etc/homelab/grants.json`:
|
||||
* `devices` entries must have their host path resolve canonically strictly within the granted device node or directory, strictly disallowing directory traversal (`..`) or symlink escapes.
|
||||
* `groups` entries are canonicalized bidirectionally between group names and integer GIDs via the host group database (so a grant of `"render"` or `"303"` accepts either representation in `group_add`, while unknown or ungranted groups fail closed).
|
||||
* `readOnlyPaths` grants permit mounts **only** when `:ro` mode 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.
|
||||
* `validate_compose_security()` evaluates resolved values (post-6-layer env assembly, or rejects uninterpolated `${...}` in `devices`, `volumes`, `group_add`, and `user`). When `app_name` is `None` or unknown, zero grants apply.
|
||||
* Every capability requested in `<app>/docker-compose.yml` must match an explicit grant for `<app>`:
|
||||
* `devices` entries support `host:container[:perms]`, forbid `m` (`mknod`) in permissions, and require canonical host path resolution (`strict=True` existence check) within the granted device node or directory, disallowing `..` traversal or symlink escapes.
|
||||
* `group_add` transitions from unconstrained to **default-deny** when no `groups` grant exists; `groups` entries canonicalize bidirectionally between group names and integer GIDs via the host group database (requiring `homelab-appctl.service` to retain `/etc/group` access without `PrivateUsers=true`, and supporting test injection). `user:` primary GIDs must also fall within granted `groups` (or standard unprivileged non-host-group UID/GID policy).
|
||||
* `readOnlyPaths` validates both short (`host:container:ro[,opts]`) and long (`type: bind`, `read_only: true`) volume syntax, rejects unsafe bind propagation, and requires canonical host path containment (`strict=True`) within the granted directory.
|
||||
|
||||
4. **Tracked Instance Template (`nixos/instance.example.nix`)**:
|
||||
* `nixos-core` tracks `nixos/instance.example.nix` documenting `homelab.domain`, `homelab.operatorUser`, and `homelab.workloadGrants`.
|
||||
* Live hosts keep their concrete configuration in `/etc/nixos/homelab-instance.nix` (loaded via `--impure` flake evaluation) or gitignored `nixos/instance.nix` without build-time file translation between the two.
|
||||
* Live hosts keep concrete values in `/etc/nixos/homelab-instance.nix` (loaded via `--impure` flake evaluation, taking precedence over gitignored `nixos/instance.nix` if both exist). Both paths remain optional so pure `nix flake check` CI 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-core` and cannot safely express `network_mode: host`.
|
||||
* Bad, because it hardcodes host hardware assumptions into `nixos-core` and 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-core` stays generic, `canopy-workloads` stays clean, and privilege elevation requires explicit host-level `nixos-rebuild switch`.
|
||||
* Bad, because adding a new privileged capability for a workload requires editing `/etc/nixos/homelab-instance.nix` and rebuilding NixOS before `appctl up`.
|
||||
* Good, because `nixos-core` stays generic, `canopy-workloads` remains free of host-privilege grants, and privilege elevation requires explicit host-level `nixos-rebuild switch`.
|
||||
* Bad, because adding a new privileged capability requires editing `/etc/nixos/homelab-instance.nix` and rebuilding NixOS before `appctl up`.
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive Consequences
|
||||
* **Hardware & Media Operability**: Workloads can use GPU acceleration and external `:ro` storage cleanly via standard `docker-compose.yml` syntax once authorized by the host.
|
||||
* **Closed GID & Namespace Loopholes**: Transitions `group_add:`, `user:` primary GIDs, `device_cgroup_rules:`, and `network_mode: container:*` to fail-closed enforcement.
|
||||
* **CI Compatibility**: Pure `nix flake check` evaluates 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 switch` fails closed at pre-flight (surfaced clearly via a distinct capability-denial error/audit signal such as `ERR_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](0002-appctl-control-plane-architecture.md) (`DEC-04`, `DEC-05`).
|
||||
* Related specifications: [docs/architecture.md](../architecture.md), [docs/appctl.md](../appctl.md), [docs/secrets-and-state.md](../secrets-and-state.md).
|
||||
@@ -10,7 +10,7 @@ Repository-level architectural decisions are recorded in `docs/decisions/` using
|
||||
|
||||
| Decision Record | Status | Date | Scope & One-Line Purpose |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| [**ADR-0005: Host-Granted Workload Capabilities**](0005-workload-capability-grants.md) | `accepted` | 2026-11-20 | Amends ADR-0002 to introduce `homelab.workloadGrants` (`/etc/homelab/grants.json`) and `nixos/instance.example.nix` so NixOS hosts explicitly authorize `devices`, `groups`, `readOnlyPaths`, and `hostNetwork` per workload. |
|
||||
| [**ADR-0005: Host-Granted Workload Capabilities**](0005-workload-capability-grants.md) | `accepted` | 2026-11-20 | Amends ADR-0002 to introduce `homelab.workloadGrants` (`/etc/homelab/grants.json`) and `nixos/instance.example.nix` so NixOS hosts explicitly authorize `devices`, `groups`, and `readOnlyPaths` per workload while keeping host/container networking prohibited. |
|
||||
| [**ADR-0004: Unified ~/Workloads Monorepo & State Isolation**](0004-unified-workloads-monorepo.md) | `accepted` | 2026-11-16 | Amends ADR-0001 to adopt the unified `~/Workloads` Tier 2 monorepo (`canopy-workloads`), rename `~/Sites` to `~/Workloads` with `WORKLOADS_DIR` fallback, and enforce `~/var/lib/homelab/<app>/` state isolation. |
|
||||
| [**ADR-0003: Centralized Runtime Validation & Serialization via Pydantic v2**](0003-pydantic-v2-runtime-validation.md) | `accepted` | 2026-10-15 | Adopts Pydantic v2 as the single runtime schema and validation authority across workload manifests and daemon API to enforce fail-closed type safety, strict schema-based boundaries, and secret-safe serialization. |
|
||||
| [**ADR-0002: Homelab Operational Control Plane & Deployment Model Architecture**](0002-appctl-control-plane-architecture.md) | `accepted` | 2026-10-07 | Establishes `homelab-appctl.service` as the central operational control plane daemon, one logical command API (`POST /v1/operations`) across dual transports (UDS and HTTP), mandatory token auth with UDS `SO_PEERCRED` viewer fallback, dedicated service isolation, fail-closed audit logging, GitOps worker unification, and deterministic Git-backed declarative deployment state. |
|
||||
@@ -24,7 +24,7 @@ Repository-level architectural decisions are recorded in `docs/decisions/` using
|
||||
* **Canonical Document**: [`0005-workload-capability-grants.md`](0005-workload-capability-grants.md)
|
||||
* **Status**: `accepted` (Active — Amends ADR-0002)
|
||||
* **Core Commitments**:
|
||||
1. **Typed Host Grant Schema (`homelab.workloadGrants`)**: NixOS exposes per-workload `devices`, `groups`, `readOnlyPaths`, and `hostNetwork` grants while keeping `privileged: true`, `docker.sock`, and `cap_add` permanently forbidden.
|
||||
1. **Typed Host Grant Schema (`homelab.workloadGrants`)**: NixOS exposes per-workload `devices`, `groups`, and `readOnlyPaths` grants while keeping `privileged: true`, `docker.sock`, `cap_add`, `device_cgroup_rules`, and host/container namespace sharing permanently forbidden.
|
||||
2. **Immutable Host Projection (`/etc/homelab/grants.json`)**: Projected root-owned at rebuild time; absent file defaults to zero grants, malformed file fails closed.
|
||||
3. **Exact-Match Pre-Flight Enforcement**: `validate_compose_security()` allows requested capabilities only when canonically matched against the workload's Nix grant (and `:ro` for `readOnlyPaths`).
|
||||
4. **Tracked Instance Template (`nixos/instance.example.nix`)**: Documents `homelab.domain`, `homelab.operatorUser`, and `homelab.workloadGrants` for `/etc/nixos/homelab-instance.nix`.
|
||||
|
||||
Reference in new issue
Block a user