15 KiB
type, status, project, date, tags
| type | status | project | date | tags | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| decision | accepted | homelab-core | 2026-10-07 |
|
ADR 0002: Homelab Operational Control Plane & Deployment Model Architecture
Context and Problem Statement
Homelab Core historically relied on appctl as a procedural Bash CLI wrapper (scripts/appctl) coupled with a Python metadata helper (scripts/appctl_engine.py). Operational commands (up, down, restart, update, logs, config, sync) executed as local subprocesses in the operator's shell session, sourcing environment files directly from /run/secrets/ and $APP_DIR/.env.
As the platform matured and AI coding agents began operating inside developer SSH sessions, this script-based model exposed five architectural and security liabilities:
- Conflated Host & Control Plane Authority: Entering the server via SSH granted full operational mutation authority. Any unprivileged process or AI coding agent running under the operator's UID could invoke
appctlto mutate containers, inspect secrets, or alter routing with zero authentication. - Duplicated Execution & Pre-Flight Drift: The local CLI (
scripts/appctl) and the GitOps webhook worker (scripts/gitops_dispatcher.py) maintained separate implementations ofgit pullanddocker compose, with the CLI path bypassing Compose AST security validation and sourcing.envfiles via shellsource. - Absence of Tamper-Evident Auditability: Operational actions produced only ephemeral terminal output with no centralized, append-only audit log recording principal identity, transport, origin, target revision, and outcome.
- Secret Lifecycle Coupling: Workload secrets were broadly sourced into parent shell environments or coupled to static SOPS rebuilds rather than resolved via scoped references.
- Manual Workload Authoring Friction: Onboarding workloads required handwriting boilerplate descriptors without a structured boundary separating AI-generated proposals (
DeploymentProposal) from human-approved declarative intent (DeploymentModel).
The central architectural question is: How should Homelab Core transition appctl into an authoritative, fail-closed operational control plane with strict privilege isolation, unified execution, mandatory token authorization, and safe deployment authoring without introducing distributed cloud complexity?
Decision Drivers
- Control Plane Centralization: Exactly one authoritative execution pipeline for all workload and platform operations across CLI, GitOps, and future web clients.
- Host Access Does Not Confer Mutation Authority: Entering the host via SSH must not bypass control-plane authentication. Every mutating action and sensitive read requires cryptographic token verification.
- OS Privilege Isolation: The control plane daemon, token store, and audit log must be isolated under a dedicated system identity (
homelab-appctl) inaccessible to unprivileged operator shell processes and AI sessions. - Unified Pre-Flight & Inert Environment Assembly: Eliminate shell
evalandsource; enforce Pydantic v2 schema validation (ADR-0003) and Compose AST security checks before every Compose invocation. - Declarative Git Ground Truth & AI Boundary: Git remains the sole authoritative source of deployment state; AI agents act strictly as upstream proposal generators (
DeploymentProposal) with zero execution authority. - KISS Primitives: Preserve synchronous, linear execution using local
flockserialization and HTTP/1.1 without external message brokers or databases.
Considered Options
- Option 1: Status Quo with Modernized Local CLI: Modernize
appctl_engine.pyinto a type-safe Python CLI while keeping execution in-process inside the caller's SSH session. - Option 2: Cloud-Native Micro-Platform (Kubernetes / Nomad / ArgoCD): Replace
appctland Docker Compose with enterprise cluster orchestration and distributed control loops. - Option 3: Authoritative
homelab-appctl.serviceDaemon with Single Command Router & Stable Deployment Model (Adopted): Evolveappctlinto an isolated systemd daemon exposing one logical HTTP/1.1 command API (POST /v1/operations) across Unix domain socket and TCP, backed by mandatory Bearer token auth, 3-role RBAC, fail-closed audit logging, and a 5-stageDeploymentModellifecycle.
Decision Outcome
Chosen option: Option 3: Authoritative homelab-appctl.service Daemon with Single Command Router & Stable Deployment Model, because it enforces an OS-level security boundary between operator sessions and platform execution, unifies CLI and GitOps codepaths behind a single fail-closed pipeline, and establishes a clean roadmap for directory-backed identity (P5) and human-gated AI deployment authoring (P6).
Summary of Architectural Commitments (Reconciled with Pre-P4 Locked Decisions DEC-01–DEC-05)
Clients (CLI / GitOps Worker / Future Web UI)
│
POST /v1/operations + GET /v1/health
(One Logical HTTP/1.1 Command Contract)
│
┌─────────────────────┴─────────────────────┐
▼ ▼
Unix Domain Socket (/run/homelab/appctl.sock) HTTP Listener (127.0.0.1:9001)
mode 0660 (homelab-appctl:homelab-operators) (Loopback in P4)
│ │
└─────────────────────┬─────────────────────┘
▼
┌───────────────────────────────────────────────┐
│ Unified Fail-Closed Pipeline (homelab-appctl)│
│ 1. Pydantic v2 Validator (extra="forbid", 64K)│
│ 2. Auth & 3-Role RBAC Gate (Bearer / PeerCred)│
│ 3. Per-Target flock (/var/lib/homelab/appctl) │
│ 4. Pre-Exec Audit Disk Guard (DISPATCHED) │
│ 5. Pre-Flight (Manifest + Compose AST + .env) │
│ 6. Subprocess Execution (Fixed argv, 256K cap)│
│ 7. Post-Exec Audit Record (COMPLETED / FAILED)│
└───────────────────────────────────────────────┘
1. One Logical Command API Across Dual Transports (DEC-01)
appctlruns as a dedicated systemd daemon (homelab-appctl.service) speaking standard HTTP/1.1 over both a local Unix Domain Socket (/run/homelab/appctl.sock) and a TCP listener (127.0.0.1:9001in P4).- All 13 canonical domain operations (
workload.list,workload.get,workload.resolve,platform.ssl,platform.health,workload.config,workload.logs,workload.deploy,workload.stop,workload.restart,workload.pull,workload.update,platform.sync_homepage) dispatch through a single canonical endpoint:POST /v1/operations(plusGET /v1/healthfor liveness). Multi-route REST aliases are rejected. scripts/appctlacts as a thin HTTP/1.1 UDS client with zero local Docker or Git execution logic.
2. Host Access Does Not Confer Mutation Authority & 3-Role RBAC (DEC-02)
- Entering via SSH confers zero control-plane mutation authority. Every mutating operation, every sensitive read (
workload.config,workload.logs), and every HTTP request requires an explicit Bearer token validated via constant-time SHA-256 comparison (hmac.compare_digest) against/run/secrets/appctl/tokens.json(0400). - UDS
SO_PEERCREDViewer Fallback: Unauthenticated local Unix socket calls extract kernel peer credentials (SO_PEERCRED) and fall back strictly tohomelab-viewerprivileges for non-sensitive reads (list,get,resolve,ssl,health), preserving zero-friction CLI inspection and shell tab-completion while blocking all mutations and secret dumps (401/403). - 3-Role Authorization Hierarchy:
homelab-admin: Full access acrosscore,core_service, and all valid~/Sites/<app>workloads.homelab-operator: Mutations and sensitive reads strictly restricted to workloads admitted inCore/config/deployments.yaml(used bygitops-dispatcher). Denied (403) oncore,core_service, and unregistered Sites directories.homelab-viewer: Non-sensitive read-only operations only.
- (Milestone P5 expands this gate with LLDAP directory group mapping and authenticated Traefik/Authelia ForwardAuth proxy headers).
3. Dedicated Service Identity, OS Isolation & Fail-Closed Audit Guard (DEC-03)
- The daemon executes as system user
homelab-appctl(Group = "homelab-operators",SupplementaryGroups = [ "docker" ]), with declarative recursive POSIX ACLs (systemd.tmpfiles.rules) granting shared read/write access on~/Sites,~/var/lib/homelab, and~/Core/config/homepage. - Append-Only Audit Telemetry (
/var/log/homelab/appctl/audit.jsonl, mode0600): RecordsDISPATCHED,COMPLETED,FAILED, andDENIEDlifecycle events withprincipal,action,target,transport,origin,client,timestamp,commit_sha, and secret-redactedparameters/result. - Fail-Closed Disk Guard: Mutating operations must write and flush a
DISPATCHEDaudit record before invoking any Docker or Git subprocess. If the audit write fails (OSError), the mutation aborts immediately with500 ERR_EXECUTION_FAILED.
4. GitOps Execution Unification (DEC-04)
scripts/gitops_dispatcher.pyretains webhook HTTP ingress (port 9000), HMAC-SHA256 verification,config/deployments.yamladmission, and the commit-superseding.pending.jsonqueue.- The background worker delegates deployment execution to the daemon's
workload.updateoperation over/run/homelab/appctl.sockusing itshomelab-operatorBearer token, eliminating duplicatedgit pullanddocker composeexecution codepaths.
5. Unified Pre-Flight & Pure-Python Environment Assembly (DEC-05)
- Shell
evalandsourceare completely eliminated. Subprocess environments are assembled in memory via an inert pure-PythonKEY=VALUEreader enforcingENV_KEY_RE,RESERVED_ENV_KEYS, and canonical domain precedence (HOMELAB_DOMAIN\toDOMAIN_SUFFIX\toDOMAIN). - Every workload mutation and
workload.configcall enforces path containment,core_manifest.parse_manifest(), andvalidate_compose_security()pre-flight inspection before invoking Docker Compose.
6. Declarative Git Truth, Five-Stage Deployment Model & AI Boundary (P5–P7 Trajectory)
- Git is Authoritative: Approved deployment definitions are versioned in Git;
appctlreconciles desired Git state into running containers. - Five-Stage Model Lifecycle (P6):
\text{Repository} \xrightarrow{\text{Investigation}} \text{Application Profile} \xrightarrow{\text{Proposal}} \text{DeploymentProposal} \xrightarrow{\text{Human Selection}} \text{DeploymentModel (Git)} \xrightarrow{\text{appctl Materialize}} \text{Deployment Definition} \xrightarrow{\text{Reconcile}} \text{Containers} - AI Authoring Boundary (P6): AI agents act strictly as upstream
DeploymentProposalgenerators with zero execution or mutation authority. - Secret Reference Invariant (P5): Manifests reference secrets by key (
secretKeyRef) resolved at runtime viaSecretProvider, never storing plaintext credentials in Git. - Client Decoupling (P7): Homepage remains a read-only status portal; interactive web management belongs to a dedicated Operations UI client consuming
POST /v1/operations.
Pros and Cons of the Options
Option 1: Status Quo with Local CLI Modernization
- Good, because it requires no background daemon or socket listener.
- Bad, because every process running under the operator's SSH UID retains full unauthenticated mutation authority over containers and secrets.
- Bad, because CLI and GitOps execution remain split across separate processes without unified lock management or tamper-evident auditing.
Option 2: Cloud-Native Micro-Platform
- Good, because Kubernetes/ArgoCD provide built-in API servers and RBAC.
- Bad, because cluster control planes impose heavy resource and operational complexity disproportionate to a single-node NixOS appliance.
Option 3: Authoritative homelab-appctl.service Daemon (Adopted)
- Good, because it isolates operational authority, secrets (
/run/secrets/appctl/tokens.json), and audit logs (/var/log/homelab/appctl/audit.jsonl) underhomelab-appctl. - Good, because
POST /v1/operationsguarantees 100% contract parity across UDS and HTTP transports. - Good, because
SO_PEERCREDviewer fallback preserves ergonomic local read commands (appctl list,appctl info) while requiring tokens for mutations and secret reads. - Bad, because it introduces a core systemd daemon and requires provisioning SOPS-managed API tokens for mutating CLI and GitOps operations.
Consequences
Positive Consequences
- Defense-in-Depth Against Session Compromise: Unprivileged scripts or AI coding agents in the operator's shell cannot mutate infrastructure, read
tokens.json, or alteraudit.jsonl. - Single Execution Truth: Interactive CLI commands and automated GitOps webhooks execute through the exact same pre-flight validator, lock manager, and environment builder.
- Deterministic Concurrency: Per-target non-blocking
flocklocks (/var/lib/homelab/appctl/locks/<target>.lock) prevent overlapping mutations (409 ERR_CONCURRENT_MUTATION).
Negative Consequences & Accepted Trade-offs
- Daemon Dependency: Normal operational commands depend on
homelab-appctl.serviceavailability (emergency host recovery remains possible for human administrators viasudo). - Token Provisioning: Mutating CLI invocations require
APPCTL_TOKEN/ token configuration rather than relying on ambient SSH user identity.
More Information
- P4 Readiness & Boundary Specification:
docs/plans/p4-readiness-plan.md - Companion ADRs:
- Governing Roadmap:
ROADMAP.md(Milestones P4–P7)