docs(p4): reconcile operational documentation with control plane daemon architecture
Core Architecture & Invariant CI / validate (pull_request) Failing after 1m13s
Core Architecture & Invariant CI / validate (pull_request) Failing after 1m13s
Closes #6
This commit is contained in:
1 parent
528bd0d4bc
commit
25e79898af
6 files changed
+88
-63
No files matched your search
+9
-9
@@ -24,15 +24,15 @@ It describes the implementation trajectory and phased engineering milestones for
|
|||||||
|
|
||||||
## 🔍 Current Implementation Baseline vs. Target Architecture
|
## 🔍 Current Implementation Baseline vs. Target Architecture
|
||||||
|
|
||||||
| Architectural Area | Current Implementation Baseline (Milestone P3) | Target Architecture (Roadmap v6) |
|
| Architectural Area | Current Implementation Baseline (Milestone P4) | Target Architecture (Roadmap v6) |
|
||||||
| :--- | :--- | :--- |
|
| :--- | :--- | :--- |
|
||||||
| **`appctl` Architecture** | Bash CLI wrapper (`scripts/appctl`) driving local subprocesses (`docker compose`, `git`) and Python engine. | Dedicated daemon service (`homelab-appctl.service`, user `homelab-appctl`) exposing `POST /v1/operations` over Unix socket and HTTP. |
|
| **`appctl` Architecture** | Dedicated daemon service (`homelab-appctl.service`, user `homelab-appctl`) exposing `POST /v1/operations` over Unix socket and loopback HTTP, with thin-client CLI (`scripts/appctl_cli.py`). | Expand with Operations UI and external ForwardAuth integration (P5–P7). |
|
||||||
| **Operational Auth** | Host Unix permissions; sourcing runtime secrets from `/run/secrets/`. | Mandatory SHA-256 Bearer token + 3-role RBAC + UDS `SO_PEERCRED` viewer fallback (P4); LLDAP directory RBAC & Authelia ForwardAuth (P5). |
|
| **Operational Auth** | Mandatory SHA-256 Bearer token + 3-role RBAC + UDS `SO_PEERCRED` viewer fallback (`/run/secrets/appctl/tokens.json`). | LLDAP directory RBAC & Authelia ForwardAuth (P5). |
|
||||||
| **Metadata & Schema Engine** | Unified engine (`scripts/appctl_engine.py`) with two-axis provenance and fail-closed Pydantic v2 schema v1.0 parser (`scripts/core_manifest.py`). | Control-plane daemon validates requests via Pydantic v2 (`scripts/appctl_contracts.py`) and invokes `core_manifest.py` / `appctl_engine.py`. |
|
| **Metadata & Schema Engine** | Control-plane daemon validates requests via Pydantic v2 (`scripts/appctl_contracts.py`) and invokes `core_manifest.py` / `appctl_engine.py`. | Unified across `DeploymentModel` materialization (P6). |
|
||||||
| **Deployment Model** | Direct authoring of `app.yaml` and `docker-compose.yml` in `~/Sites/<app>/`. | 5-stage lifecycle (planned in P6): `DeploymentProposal` $\to$ operator-approved `DeploymentModel` in Git $\to$ `appctl` materialization. |
|
| **Deployment Model** | Direct authoring of `app.yaml` and `docker-compose.yml` in `~/Sites/<app>/`. | 5-stage lifecycle (planned in P6): `DeploymentProposal` $\to$ operator-approved `DeploymentModel` in Git $\to$ `appctl` materialization. |
|
||||||
| **GitOps Engine** | Webhook dispatcher (`scripts/gitops_dispatcher.py`) with HMAC-SHA256 auth, Compose AST security validator, and `flock` serialization. | Ingress/queue in `gitops_dispatcher.py`; worker delegates `workload.update` to daemon over `/run/homelab/appctl.sock`. |
|
| **GitOps Engine** | Ingress/queue in `gitops_dispatcher.py`; worker delegates `workload.update` to daemon over `/run/homelab/appctl.sock`. | Integrated with `DeploymentModel` reconciliation (P6). |
|
||||||
| **Secret Distribution** | Age-encrypted `nixos/secrets.yaml` decrypted by `sops-nix` to tmpfs `/run/secrets/`. | Host secrets remain in `sops-nix`; workload secrets referenced by key and projected via `SecretProvider` (planned in P5). |
|
| **Secret Distribution** | Age-encrypted `nixos/secrets.yaml` decrypted by `sops-nix` to tmpfs `/run/secrets/`. | Host secrets remain in `sops-nix`; workload secrets referenced by key and projected via `SecretProvider` (planned in P5). |
|
||||||
| **Dashboard** | `appctl sync` compiles `config/homepage/services.yaml` from `app.yaml` manifests. | Homepage consumes read-only live status from `appctl`; dedicated Operations UI client for management (planned in P7). |
|
| **Dashboard** | `appctl sync` compiles `config/homepage/services.yaml` from `app.yaml` manifests under `_homepage_sync.lock`. | Homepage consumes read-only live status from `appctl`; dedicated Operations UI client for management (planned in P7). |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ It describes the implementation trajectory and phased engineering milestones for
|
|||||||
| **P1** | **Mail Topology Realignment** | Topology & State | ✅ **Completed** | Re-homed Stalwart to the dedicated `smtp.` subdomain; migrated SnappyMail to `~/Sites/snappymail` with zero data loss. |
|
| **P1** | **Mail Topology Realignment** | Topology & State | ✅ **Completed** | Re-homed Stalwart to the dedicated `smtp.` subdomain; migrated SnappyMail to `~/Sites/snappymail` with zero data loss. |
|
||||||
| **P2** | **GitOps Hardening** | Ingress Security | ✅ **Completed** | Authoritative Core repository registry (`deployments.yaml`), Compose AST security validator, systemd sandboxing. |
|
| **P2** | **GitOps Hardening** | Ingress Security | ✅ **Completed** | Authoritative Core repository registry (`deployments.yaml`), Compose AST security validator, systemd sandboxing. |
|
||||||
| **P3** | **Manifest Contract** | Domain Engine | ✅ **Completed** | Schema v1.0 with Pydantic v2 fail-closed models (`core_manifest.py`), two-axis status inspection, unified `appctl_engine.py`. |
|
| **P3** | **Manifest Contract** | Domain Engine | ✅ **Completed** | Schema v1.0 with Pydantic v2 fail-closed models (`core_manifest.py`), two-axis status inspection, unified `appctl_engine.py`. |
|
||||||
| **P4** | **Control Plane Daemon** | API & Dispatch | 🎯 **Current / Up Next** | `homelab-appctl.service` daemon, dual transports (socket + HTTP), mandatory auth admission gate, thin-client CLI, append-only audit log. |
|
| **P4** | **Control Plane Daemon** | API & Dispatch | ✅ **Completed** | `homelab-appctl.service` daemon, dual transports (socket + HTTP), mandatory auth admission gate, thin-client CLI, append-only audit log. |
|
||||||
| **P5** | **Identity & Secrets** | Auth & Providers | ⏳ **Planned** | LLDAP RBAC group mapping, Authelia ForwardAuth header integration, user-scoped token lifecycle, `SecretProvider` reference resolution. |
|
| **P5** | **Identity & Secrets** | Auth & Providers | 🎯 **Current / Up Next** | LLDAP RBAC group mapping, Authelia ForwardAuth header integration, user-scoped token lifecycle, `SecretProvider` reference resolution. |
|
||||||
| **P6** | **Deployment Model & AI**| Intent Authoring | ⏳ **Planned** | Capability catalog, `DeploymentProposal` $\to$ `DeploymentModel` compiler, Git commit pipeline. |
|
| **P6** | **Deployment Model & AI**| Intent Authoring | ⏳ **Planned** | Capability catalog, `DeploymentProposal` $\to$ `DeploymentModel` compiler, Git commit pipeline. |
|
||||||
| **P7** | **Operations UI & Portal** | Client Integration | ⏳ **Planned** | Dedicated Operations UI client, Homepage read-only status integration widgets. |
|
| **P7** | **Operations UI & Portal** | Client Integration | ⏳ **Planned** | Dedicated Operations UI client, Homepage read-only status integration widgets. |
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ It describes the implementation trajectory and phased engineering milestones for
|
|||||||
---
|
---
|
||||||
|
|
||||||
### Milestone P4: Appctl Control Plane Daemon & Command-Oriented API
|
### Milestone P4: Appctl Control Plane Daemon & Command-Oriented API
|
||||||
**Status**: 🎯 **Current / Up Next**
|
**Status**: ✅ **Completed**
|
||||||
* **Objective**: Evolve `appctl` from a collection of local shell scripts into the authoritative platform daemon while enforcing authorization gates from day one.
|
* **Objective**: Evolve `appctl` from a collection of local shell scripts into the authoritative platform daemon while enforcing authorization gates from day one.
|
||||||
* **Key Deliverables**:
|
* **Key Deliverables**:
|
||||||
1. *Daemon Service (`homelab-appctl.service`)*: Systemd daemon running as dedicated user `homelab-appctl` (`Group = "homelab-operators"`), exposing one logical HTTP/1.1 API across dual transports: Unix domain socket (`/run/homelab/appctl.sock`) on host and loopback HTTP listener (`127.0.0.1:9001`).
|
1. *Daemon Service (`homelab-appctl.service`)*: Systemd daemon running as dedicated user `homelab-appctl` (`Group = "homelab-operators"`), exposing one logical HTTP/1.1 API across dual transports: Unix domain socket (`/run/homelab/appctl.sock`) on host and loopback HTTP listener (`127.0.0.1:9001`).
|
||||||
|
|||||||
+42
-41
@@ -3,47 +3,48 @@
|
|||||||
The `appctl` tool is the command-line orchestrator and metadata engine for the **Homelab Core** platform. It coordinates interactions between independent workload repositories in `~/Sites` and platform services in `~/Core`.
|
The `appctl` tool is the command-line orchestrator and metadata engine for the **Homelab Core** platform. It coordinates interactions between independent workload repositories in `~/Sites` and platform services in `~/Core`.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> **Implementation Reference**: This document serves as the **current implementation manual (Milestone P3)** for the `appctl` Bash CLI wrapper (`scripts/appctl`), metadata/provenance engine (`scripts/appctl_engine.py`), and Pydantic v2 manifest parser (`scripts/core_manifest.py`).
|
> **Implementation Reference**: This document serves as the **current implementation manual (Milestone P4)** for the `appctl` Operational Control Plane Daemon (`scripts/appctl_daemon.py`), Operational Router (`scripts/appctl_router.py`), Thin-Client CLI (`scripts/appctl`, `scripts/appctl_cli.py`), metadata/provenance engine (`scripts/appctl_engine.py`), and Pydantic v2 manifest parser (`scripts/core_manifest.py`).
|
||||||
> For the platform's planned Milestone P4 control-plane daemon transition and phased engineering roadmap, see [`ROADMAP.md`](../ROADMAP.md) and the [Architecture Decision Index](decisions/README.md).
|
> For the platform's phased engineering roadmap, see [`ROADMAP.md`](../ROADMAP.md) and the [Architecture Decision Index](decisions/README.md).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 1. How `appctl` Works
|
## 1. How `appctl` Works
|
||||||
|
|
||||||
`appctl` consists of three cooperating modules in `scripts/`:
|
Under Milestone P4, `appctl` operates as a centralized operational control plane daemon (`homelab-appctl.service`, running as isolated user `homelab-appctl:homelab-operators`) backed by cooperating modules in `scripts/`:
|
||||||
1. **[`scripts/appctl`](../scripts/appctl)** (Bash CLI wrapper): Parses CLI arguments, sources runtime secret templates, injects validated workload environment variables, dispatches `docker compose` commands, and provides shell autocompletions.
|
|
||||||
2. **[`scripts/appctl_engine.py`](../scripts/appctl_engine.py)** (Discovery, Provenance & TLS Engine): Scans `~/Sites/*`, evaluates **two-axis status** (local deployment checkout state vs. upstream software provenance), inspects live container health and TLS certificates, and compiles the Homepage dashboard configuration.
|
1. **[`scripts/appctl`](../scripts/appctl) & [`scripts/appctl_cli.py`](../scripts/appctl_cli.py)** (Thin-Client CLI): Dispatches operational commands over the Unix domain socket (`/run/homelab/appctl.sock`) using HTTP/1.1 (`POST /v1/operations`), resolves operator Bearer tokens (`--token`, `APPCTL_TOKEN`, `~/.config/homelab/token`), renders human-readable tables, and fast-paths local shell autocompletions (`complete`, `completion`, `resolve`).
|
||||||
3. **[`scripts/core_manifest.py`](../scripts/core_manifest.py)** (Schema v1.0 Parser & Validator): Enforces fail-closed Pydantic v2 validation (`ConfigDict(extra="forbid")`) on `app.yaml` manifests, validates upstream Git transport schemes (`https://`, `ssh://`, `git@`), classifies reference mutability (branch, tag, commit SHA), and blocks reserved host environment keys (`PATH`, `LD_PRELOAD`, `IFS`, `CORE_DIR`, `SITES_DIR`, etc.).
|
2. **[`scripts/appctl_daemon.py`](../scripts/appctl_daemon.py) & [`scripts/appctl_contracts.py`](../scripts/appctl_contracts.py)** (Dual-Transport Control Plane Server & Contracts): Serves a single logical HTTP/1.1 API (`POST /v1/operations` + `GET /v1/health`) identically across `/run/homelab/appctl.sock` (mode `0660`) and loopback TCP (`127.0.0.1:9001`), enforcing 64 KiB request caps and strict Pydantic v2 contracts (`ConfigDict(extra="forbid", strict=True)`).
|
||||||
|
3. **[`scripts/appctl_auth.py`](../scripts/appctl_auth.py) & [`scripts/appctl_audit.py`](../scripts/appctl_audit.py)** (Zero-Trust Auth, 3-Role RBAC & Fail-Closed Audit Guard): Verifies SHA-256 Bearer tokens against `/run/secrets/appctl/tokens.json` (mode `0400`) using `hmac.compare_digest`, maps tokenless local UDS `SO_PEERCRED` callers strictly to `homelab-viewer` (non-sensitive read-only inspection), enforces `homelab-admin` / `homelab-operator` / `homelab-viewer` RBAC, serializes mutations via per-target `fcntl.flock`, and writes append-only audit records to `/var/log/homelab/appctl/audit.jsonl` (mode `0600`) before any mutation executes.
|
||||||
|
4. **[`scripts/appctl_router.py`](../scripts/appctl_router.py)** (Operational Router & Unified Execution Engine): Enforces pre-flight path containment, `core_manifest.parse_manifest()`, and `validate_compose_security()` AST checks; assembles the 6-layer execution environment in pure Python (zero shell `source` or `eval`); and runs bounded `git` and `docker compose` subprocesses (`shell=False`, 256 KiB output cap, hard timeouts).
|
||||||
|
5. **[`scripts/appctl_engine.py`](../scripts/appctl_engine.py) & [`scripts/core_manifest.py`](../scripts/core_manifest.py)** (Discovery, Provenance & Schema v1.0 Validator): Scans `~/Sites/*`, evaluates **two-axis status** (local deployment checkout state vs. upstream software provenance), inspects live container health and TLS certificates, validates `app.yaml` manifests, and atomically compiles the Homepage dashboard configuration under `_homepage_sync.lock`.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
┌───────────────────────────────┐
|
┌──────────────────────────┐ ┌──────────────────────────┐
|
||||||
│ appctl <command> │
|
│ appctl <cmd> (CLI) │ │ homelab-gitops.service │
|
||||||
└───────────────┬───────────────┘
|
└────────────┬─────────────┘ └────────────┬─────────────┘
|
||||||
│
|
│ UDS (/run/homelab/appctl.sock) │ Bearer Token (homelab-operator)
|
||||||
|
└─────────────────┬─────────────────┘
|
||||||
▼
|
▼
|
||||||
┌───────────────────────────┐
|
┌────────────────────────────────────────────────┐
|
||||||
│ setup_app_env() │
|
│ homelab-appctl.service (appctl_daemon.py) │
|
||||||
└─────────────┬─────────────┘
|
│ • POST /v1/operations & GET /v1/health │
|
||||||
│
|
│ • Auth: SHA-256 tokens.json + SO_PEERCRED │
|
||||||
┌──────────────────────────┴──────────────────────────┐
|
│ • RBAC: admin / operator / viewer │
|
||||||
▼ ▼
|
└────────────────────────┬───────────────────────┘
|
||||||
[ appctl_engine.py resolve ] [ Source Secrets ]
|
|
||||||
• Parses app.yaml via core_manifest.py /run/secrets/traefik-deployments.env
|
|
||||||
• Fails closed on manifest_error /run/secrets/homeserver.env
|
|
||||||
│ │
|
|
||||||
└──────────────────────────┬──────────────────────────┘
|
|
||||||
▼
|
▼
|
||||||
┌─────────────────────────────┐
|
┌────────────────────────────────────────────────┐
|
||||||
│ Injected Compose Context │
|
│ OperationalRouter (appctl_router.py) │
|
||||||
│ • PROXY_NETWORK │
|
│ • Per-target flock + Fail-closed DISPATCHED │
|
||||||
│ • SERVICE_DOMAIN / DOMAIN │
|
│ audit write (/var/log/homelab/appctl/...) │
|
||||||
│ • CONTAINER_NAME │
|
│ • Pre-flight: parse_manifest() + Compose AST │
|
||||||
│ • Validated manifest env │
|
│ • Pure-Python 6-layer .env assembly │
|
||||||
└──────────────┬──────────────┘
|
└────────────────────────┬───────────────────────┘
|
||||||
▼
|
▼
|
||||||
┌─────────────────────────────┐
|
┌────────────────────────────────────────────────┐
|
||||||
│ docker compose <subcommand> │
|
│ Bounded Subprocess Engine (shell=False) │
|
||||||
└─────────────────────────────┘
|
│ • git status / pull --ff-only │
|
||||||
|
│ • docker compose -f <file> <subcommand> │
|
||||||
|
└────────────────────────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -197,21 +198,21 @@ homepage:
|
|||||||
|
|
||||||
## 4. Environment Injection & Resolution Precedence
|
## 4. Environment Injection & Resolution Precedence
|
||||||
|
|
||||||
When `appctl` executes commands against a workload, environment variables are resolved in this sequence:
|
When `OperationalRouter` (`scripts/appctl_router.py`) executes commands against a workload or Core stack, the 6-layer execution environment is assembled in memory using a pure-Python inert `KEY=VALUE` parser (`parse_dotenv`) with zero shell `source` or variable expansion:
|
||||||
|
|
||||||
1. **Global Secrets & Templates**: Sourced from `/run/secrets/rendered/homeserver.env` and `/run/secrets/rendered/traefik-deployments.env` (with `/run/secrets/*` fallbacks).
|
1. **Base System Path & Docker Config**: `PATH` and `DOCKER_CONFIG`.
|
||||||
2. **Canonical Root Domain Lock**: `HOMELAB_DOMAIN` is locked at startup using precedence `HOMELAB_DOMAIN -> DOMAIN_SUFFIX -> DOMAIN` so per-workload `DOMAIN` exports cannot corrupt the platform apex domain.
|
2. **Global Secrets & Templates**: Parsed inertly from `/run/secrets/rendered/homeserver.env` and `/run/secrets/rendered/traefik-deployments.env` (with `/run/secrets/*` fallbacks).
|
||||||
3. **Infrastructure Defaults**:
|
3. **Canonical Root Domain Lock**: `HOMELAB_DOMAIN` is locked using precedence `HOMELAB_DOMAIN -> DOMAIN_SUFFIX -> DOMAIN` (failing closed if unset).
|
||||||
|
4. **Infrastructure Defaults & Application Identity**:
|
||||||
- `PROXY_NETWORK` (defaults to `proxy-net`)
|
- `PROXY_NETWORK` (defaults to `proxy-net`)
|
||||||
- `CERT_RESOLVER` (defaults to `myresolver`)
|
- `CERT_RESOLVER` (defaults to `myresolver`)
|
||||||
- `DOMAIN_SUFFIX` (defaults to `$HOMELAB_DOMAIN`)
|
- `DOMAIN_SUFFIX` (`$HOMELAB_DOMAIN`)
|
||||||
4. **Application Identity**:
|
|
||||||
- `SERVICE_NAME` = `<canonical-name>`
|
- `SERVICE_NAME` = `<canonical-name>`
|
||||||
- `CONTAINER_NAME` = `<canonical-name>`
|
- `CONTAINER_NAME` = `<canonical-name>`
|
||||||
- `SERVICE_DOMAIN` = `<resolved-domain>`
|
- `SERVICE_DOMAIN` = `<canonical-name>.<HOMELAB_DOMAIN>`
|
||||||
- `DOMAIN` = `<resolved-domain>`
|
- `DOMAIN` = `<HOMELAB_DOMAIN>`
|
||||||
5. **Manifest Variables**: Validated key-value pairs from the `env:` block in `app.yaml` (emitted via null-delimited stream without shell `eval`).
|
5. **Manifest Variables**: Validated key-value pairs from the `env:` block in `app.yaml`.
|
||||||
6. **Local Repository Files**: Sourced from `$APP_DIR/.env` and `$APP_DIR/app.env` if present.
|
6. **Local Repository Files**: Parsed inertly from `$APP_DIR/.env` and `$APP_DIR/app.env` if present, rejecting any key violating `ENV_KEY_RE` or matching `RESERVED_ENV_KEYS`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
This document details the architectural structure, component roles, networking models, and security controls of the **Homelab Core** platform.
|
This document details the architectural structure, component roles, networking models, and security controls of the **Homelab Core** platform.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> **Implementation Scope**: This document details the **current runtime architecture (Milestone P3)**, edge routing, container topologies, and network isolation models of Homelab Core.
|
> **Implementation Scope**: This document details the **current runtime architecture (Milestone P4)**, operational control plane daemon (`homelab-appctl.service`), edge routing, container topologies, and network isolation models of Homelab Core.
|
||||||
> For the planned Milestone P4 control-plane daemon transition and phased engineering milestones, see [`ROADMAP.md`](../ROADMAP.md) and the [Architecture Decision Index](decisions/README.md).
|
> For phased engineering milestones (P5–P7), see [`ROADMAP.md`](../ROADMAP.md) and the [Architecture Decision Index](decisions/README.md).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -42,16 +42,17 @@ The runtime environment consists of four functional layers:
|
|||||||
│
|
│
|
||||||
▼
|
▼
|
||||||
┌────────────────────────────────────────────────────────────────────────┐
|
┌────────────────────────────────────────────────────────────────────────┐
|
||||||
│ 4. HOST FOUNDATION │
|
│ 4. HOST FOUNDATION & CONTROL PLANE DAEMONS │
|
||||||
│ NixOS Linux · sops-nix Secrets · Docker Engine · Systemd Units │
|
│ NixOS Linux · sops-nix Secrets · Docker Engine · Systemd Units │
|
||||||
|
│ homelab-appctl.service (Control Plane Daemon) · homelab-gitops │
|
||||||
│ Smart Dynu DDNS Monitor · Host Firewall · /run Secret Projections │
|
│ Smart Dynu DDNS Monitor · Host Firewall · /run Secret Projections │
|
||||||
└────────────────────────────────────────────────────────────────────────┘
|
└────────────────────────────────────────────────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
### C. Cross-Cutting Orchestration
|
### C. Cross-Cutting Orchestration
|
||||||
Orchestration coordinates operations across the runtime layers:
|
Orchestration coordinates operations across the runtime layers:
|
||||||
* **`appctl` CLI, Provenance Engine & Schema Parser (`scripts/appctl`, `scripts/appctl_engine.py`, `scripts/core_manifest.py`)**: Current CLI implementation coordinating workload discovery, fail-closed Pydantic v2 `app.yaml` validation, two-axis provenance inspection, and Homepage compilation across workloads and Core. Under Milestone P4, this transitions into the centralized operational control plane daemon (`homelab-appctl.service`).
|
* **`appctl` Operational Control Plane Daemon (`homelab-appctl.service`, `scripts/appctl_daemon.py`, `scripts/appctl_router.py`)**: Centralized control plane running under isolated service identity `homelab-appctl:homelab-operators`. Exposes `POST /v1/operations` and `GET /v1/health` over `/run/homelab/appctl.sock` (mode `0660`) and `127.0.0.1:9001`, enforcing SHA-256 Bearer token authentication, 3-role RBAC (`homelab-admin`, `homelab-operator`, `homelab-viewer`), per-target `flock` serialization, fail-closed append-only audit logging (`/var/log/homelab/appctl/audit.jsonl`), Pydantic v2 `app.yaml` validation, Compose AST security checks, and pure-Python `.env` assembly.
|
||||||
* **GitOps Webhook Dispatcher (`scripts/gitops_dispatcher.py`)**: Governed by the `homelab-gitops.service` systemd unit, it receives webhooks on port 9000, verifies HMAC-SHA256 signatures, enforces the `config/deployments.yaml` allowlist and Compose AST security checks, and dispatches serialized deployment actions for `~/Sites` workloads.
|
* **GitOps Webhook Dispatcher (`scripts/gitops_dispatcher.py`)**: Governed by the `homelab-gitops.service` systemd unit, it receives webhooks on port 9000, verifies HMAC-SHA256 signatures, enforces the `config/deployments.yaml` allowlist, and delegates serialized `workload.update` execution to `homelab-appctl.service` over `/run/homelab/appctl.sock` using its `homelab-operator` Bearer token.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -91,7 +92,8 @@ Orchestration coordinates operations across the runtime layers:
|
|||||||
|
|
||||||
### F. Host Foundation & Daemons
|
### F. Host Foundation & Daemons
|
||||||
* **`homeserver-core.service`**: Systemd unit managing the Core Docker Compose stack (`~/Core/docker-compose.yml`) using secrets projected to `/run/secrets/homeserver.env`.
|
* **`homeserver-core.service`**: Systemd unit managing the Core Docker Compose stack (`~/Core/docker-compose.yml`) using secrets projected to `/run/secrets/homeserver.env`.
|
||||||
* **`homelab-gitops.service`**: Systemd unit listening on port 9000 executing `scripts/gitops_dispatcher.py` under strict systemd sandboxing (`ProtectSystem=strict`, `ProtectHome=read-only`).
|
* **`homelab-appctl.service`**: Operational control plane daemon running as dedicated user `homelab-appctl:homelab-operators` with dual listeners (`/run/homelab/appctl.sock` and `127.0.0.1:9001`), fail-closed audit logging (`/var/log/homelab/appctl/audit.jsonl`), and strict systemd sandboxing (`ProtectSystem=strict`, `ProtectHome=read-only`).
|
||||||
|
* **`homelab-gitops.service`**: Systemd unit listening on port 9000 executing `scripts/gitops_dispatcher.py` under strict systemd sandboxing (`ProtectSystem=strict`, `ProtectHome=read-only`), delegating worker deployments to `homelab-appctl.service`.
|
||||||
* **`dynu-monitor.service` & `dynu-monitor.timer`**: IP change monitor executing `nixos/scripts/monitor.py` every 30 minutes to detect WAN IP changes and update DNS via `ddclient`.
|
* **`dynu-monitor.service` & `dynu-monitor.timer`**: IP change monitor executing `nixos/scripts/monitor.py` every 30 minutes to detect WAN IP changes and update DNS via `ddclient`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+1
-1
@@ -106,7 +106,7 @@ Before executing `docker compose up -d`, `validate_compose_security()` parses th
|
|||||||
To avoid blocking HTTP connections and handle overlapping pushes:
|
To avoid blocking HTTP connections and handle overlapping pushes:
|
||||||
|
|
||||||
1. **Immediate HTTP 200 Return**: Upon passing admission, the dispatcher writes a pending file (`~/.local/state/homelab/gitops/<target>.pending.json`), spawns a detached worker (`--worker <target>`), and returns HTTP 200.
|
1. **Immediate HTTP 200 Return**: Upon passing admission, the dispatcher writes a pending file (`~/.local/state/homelab/gitops/<target>.pending.json`), spawns a detached worker (`--worker <target>`), and returns HTTP 200.
|
||||||
2. **Per-Target `flock` Serialization**: The worker acquires an exclusive non-blocking `fcntl.flock` on `~/.local/state/homelab/gitops/<target>.lock`. If a worker is already running for this target, the second worker exits safely while the running worker continues to drain the pending file.
|
2. **Per-Target `flock` Serialization & Daemon Delegation**: The worker acquires an exclusive non-blocking `fcntl.flock` on `~/.local/state/homelab/gitops/<target>.lock`. When `/run/homelab/appctl.sock` is available, the worker delegates `workload.update` to `homelab-appctl.service` over UDS authenticating with `/run/secrets/gitops/appctl_token` (`homelab-operator` role), which executes `git pull --ff-only`, re-validates `app.yaml` and Compose security, runs the declared actions, logs to `/var/log/homelab/appctl/audit.jsonl`, and syncs Homepage.
|
||||||
3. **Commit Superseding**:
|
3. **Commit Superseding**:
|
||||||
- Commit A begins deploying.
|
- Commit A begins deploying.
|
||||||
- Commit B arrives and is written to the pending file.
|
- Commit B arrives and is written to the pending file.
|
||||||
|
|||||||
@@ -29,17 +29,23 @@ This document explains the secrets distribution architecture, runtime projection
|
|||||||
│ 3. /run/secrets/gitops/webhook_secret │
|
│ 3. /run/secrets/gitops/webhook_secret │
|
||||||
│ -> Consumed by homelab-gitops.service for HMAC verification │
|
│ -> Consumed by homelab-gitops.service for HMAC verification │
|
||||||
│ │
|
│ │
|
||||||
│ 4. /run/credentials/ddclient.service/ddclient.conf │
|
│ 4. /run/secrets/appctl/tokens.json (mode 0400, homelab-appctl) │
|
||||||
|
│ -> Consumed by homelab-appctl.service for SHA-256 Bearer auth │
|
||||||
|
│ │
|
||||||
|
│ 5. /run/secrets/gitops/appctl_token (mode 0400, operatorUser) │
|
||||||
|
│ -> Consumed by homelab-gitops.service worker for UDS daemon auth │
|
||||||
|
│ │
|
||||||
|
│ 6. /run/credentials/ddclient.service/ddclient.conf │
|
||||||
│ -> Consumed by systemd ddclient service │
|
│ -> Consumed by systemd ddclient service │
|
||||||
│ │
|
│ │
|
||||||
│ 5. /run/secrets/pdf_decrypt_password │
|
│ 7. /run/secrets/pdf_decrypt_password │
|
||||||
│ -> Consumed by shell pdf_dc utility │
|
│ -> Consumed by shell pdf_dc utility │
|
||||||
└────────────────────────────────────────────────────────────────────────┘
|
└────────────────────────────────────────────────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3. Projected Secret Templates
|
## 3. Projected Secret Templates & Token Store
|
||||||
|
|
||||||
### A. Core Platform Environment (`/run/secrets/homeserver.env`)
|
### A. Core Platform Environment (`/run/secrets/homeserver.env`)
|
||||||
Generated by `nixos/modules/homeserver.nix`. Supplies credentials to the Core Compose stack:
|
Generated by `nixos/modules/homeserver.nix`. Supplies credentials to the Core Compose stack:
|
||||||
@@ -54,7 +60,13 @@ Generated by `nixos/modules/homeserver.nix`. Supplies credentials to the Core Co
|
|||||||
* `SMTP_SERVER`, `SMTP_PORT`, `SMTP_LOGIN`, `SMTP_KEY`: Outbound relay credentials (Brevo) for Stalwart mail transport.
|
* `SMTP_SERVER`, `SMTP_PORT`, `SMTP_LOGIN`, `SMTP_KEY`: Outbound relay credentials (Brevo) for Stalwart mail transport.
|
||||||
|
|
||||||
### B. Workload Deployments Environment (`/run/secrets/traefik-deployments.env`)
|
### B. Workload Deployments Environment (`/run/secrets/traefik-deployments.env`)
|
||||||
Generated by `nixos/modules/traefik-deployments.nix`. Projects shared infrastructure secrets and workload credentials that `appctl` sources when orchestrating stacks in `~/Sites` (such as database passwords, API keys, and runner tokens).
|
Generated by `nixos/modules/traefik-deployments.nix`. Projects shared infrastructure secrets and workload credentials that `appctl` parses inertly in pure Python when orchestrating stacks in `~/Sites` (such as database passwords, API keys, and runner tokens).
|
||||||
|
|
||||||
|
### C. Control Plane Token Store (`/run/secrets/appctl/tokens.json` & `/run/secrets/gitops/appctl_token`)
|
||||||
|
Provisioned from `nixos/secrets.yaml` (`appctl/tokens_json` and `gitops/appctl_token`):
|
||||||
|
* `/run/secrets/appctl/tokens.json`: Owned by `homelab-appctl:homelab-operators` with strict mode `0400` (enforced fail-closed by `TokenStore._verify_permissions()`). Stores SHA-256 hex digests of Bearer secrets mapped to `token_id`, `identity`, and `role` (`homelab-admin`, `homelab-operator`, `homelab-viewer`).
|
||||||
|
* `/run/secrets/gitops/appctl_token`: Owned by `config.homelab.operatorUser` (mode `0400`). Supplies the `homelab-operator` Bearer secret to `homelab-gitops.service` when delegating `workload.update` to `homelab-appctl.service`.
|
||||||
|
* `~/.config/homelab/token`: Local operator Bearer token (mode `0600`) read by `appctl_cli.py` for interactive CLI mutations.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -80,6 +92,9 @@ lldap:
|
|||||||
admin_password: "..."
|
admin_password: "..."
|
||||||
gitops:
|
gitops:
|
||||||
webhook_secret: "..."
|
webhook_secret: "..."
|
||||||
|
appctl_token: "..."
|
||||||
|
appctl:
|
||||||
|
tokens_json: "[...]"
|
||||||
brevo:
|
brevo:
|
||||||
smtp_login: "..."
|
smtp_login: "..."
|
||||||
smtp_key: "..."
|
smtp_key: "..."
|
||||||
@@ -97,7 +112,7 @@ sudo nixos-rebuild switch --flake ~/Core#server
|
|||||||
|
|
||||||
Homelab Core separates **user identity** from **static platform secrets**:
|
Homelab Core separates **user identity** from **static platform secrets**:
|
||||||
|
|
||||||
* **Static Secrets**: Stored in `nixos/secrets.yaml` (system API keys, JWT secrets, database passwords).
|
* **Static Secrets**: Stored in `nixos/secrets.yaml` (system API keys, JWT secrets, database passwords, control-plane token hashes).
|
||||||
* **Dynamic User Directory**: User accounts, credentials, and group memberships are managed live in **LLDAP** (`https://users.${HOMELAB_DOMAIN}`). User account updates do not require editing `secrets.yaml` or rebuilding NixOS.
|
* **Dynamic User Directory**: User accounts, credentials, and group memberships are managed live in **LLDAP** (`https://users.${HOMELAB_DOMAIN}`). User account updates do not require editing `secrets.yaml` or rebuilding NixOS.
|
||||||
* **Authelia Integration**: Authelia queries LLDAP over LDAP (`ldap://lldap:3890`) at runtime using credentials projected from `/run/secrets/homeserver.env`.
|
* **Authelia Integration**: Authelia queries LLDAP over LDAP (`ldap://lldap:3890`) at runtime using credentials projected from `/run/secrets/homeserver.env`.
|
||||||
|
|
||||||
@@ -109,7 +124,9 @@ Homelab Core separates **user identity** from **static platform secrets**:
|
|||||||
| :--- | :--- | :--- | :--- |
|
| :--- | :--- | :--- | :--- |
|
||||||
| **Declarative Config** | `~/Core/nixos/*.nix`, `docker-compose.yml` | ✅ Yes | System and container definitions |
|
| **Declarative Config** | `~/Core/nixos/*.nix`, `docker-compose.yml` | ✅ Yes | System and container definitions |
|
||||||
| **Encrypted Secrets** | `~/Core/nixos/secrets.yaml` | ✅ Yes (Encrypted) | SOPS Age-encrypted secret source |
|
| **Encrypted Secrets** | `~/Core/nixos/secrets.yaml` | ✅ Yes (Encrypted) | SOPS Age-encrypted secret source |
|
||||||
| **Runtime Secrets** | `/run/secrets/*` | ❌ No (RAM tmpfs) | Ephemeral decrypted environment files |
|
| **Runtime Secrets** | `/run/secrets/*` | ❌ No (RAM tmpfs) | Ephemeral decrypted environment & token files |
|
||||||
|
| **Control Plane Audit** | `/var/log/homelab/appctl/audit.jsonl` | ❌ No | Append-only JSONL security & mutation log (`0600`) |
|
||||||
|
| **Control Plane Locks** | `/var/lib/homelab/appctl/locks/` | ❌ No | Per-target `flock` files & `_homepage_sync.lock` |
|
||||||
| **SSL Certificates** | `~/Core/config/letsencrypt/acme.json` | ❌ No | Active Let's Encrypt certificates (mode 0600) |
|
| **SSL Certificates** | `~/Core/config/letsencrypt/acme.json` | ❌ No | Active Let's Encrypt certificates (mode 0600) |
|
||||||
| **User Directory** | `~/Core/config/lldap/data/` | ❌ No | LLDAP SQLite database (`users.db`) |
|
| **User Directory** | `~/Core/config/lldap/data/` | ❌ No | LLDAP SQLite database (`users.db`) |
|
||||||
| **Auth Database** | `~/Core/config/authelia/db.sqlite3` | ❌ No | Authelia session database |
|
| **Auth Database** | `~/Core/config/authelia/db.sqlite3` | ❌ No | Authelia session database |
|
||||||
|
|||||||
@@ -30,3 +30,8 @@ x 2026-10-19 (B) Implement dual-transport HTTP/1.1 daemon (UDS + loopback TCP) a
|
|||||||
x 2026-10-19 (B) Add comprehensive unit and security test suite for P4 contracts, RBAC, audit guard, concurrency, and dual-transport parity in tests/unit/test_appctl_daemon.py +test @p4
|
x 2026-10-19 (B) Add comprehensive unit and security test suite for P4 contracts, RBAC, audit guard, concurrency, and dual-transport parity in tests/unit/test_appctl_daemon.py +test @p4
|
||||||
x 2026-10-19 (C) Re-implement scripts/appctl as a thin UDS HTTP client and declare homelab-appctl.service with POSIX ACLs in nixos/modules/homeserver.nix +cli @p4
|
x 2026-10-19 (C) Re-implement scripts/appctl as a thin UDS HTTP client and declare homelab-appctl.service with POSIX ACLs in nixos/modules/homeserver.nix +cli @p4
|
||||||
x 2026-10-19 (C) Scrub remaining hardcoded domain and username literals across NixOS modules, Compose stack, and config/deployments.yaml and add pyright to flake.nix checks +generic @core
|
x 2026-10-19 (C) Scrub remaining hardcoded domain and username literals across NixOS modules, Compose stack, and config/deployments.yaml and add pyright to flake.nix checks +generic @core
|
||||||
|
x 2026-10-19 (A) Enable Core platform stack and core_service container-scoped dispatch in OperationalRouter in scripts/appctl_router.py +router @p4
|
||||||
|
x 2026-10-19 (A) Restore human-readable tabular output, list filter parameters, and bash autocompletion fast-path in scripts/appctl_cli.py and scripts/appctl +cli @p4
|
||||||
|
x 2026-10-19 (A) Add operatorUser to homelab-operators group and configure daemon systemd sandbox HOME and DOCKER_CONFIG in nixos/modules/homeserver.nix +nixos @p4
|
||||||
|
x 2026-10-19 (A) Provision SOPS appctl/tokens_json and gitops/appctl_token secrets and wire GITOPS_APPCTL_TOKEN_FILE in nixos/secrets.yaml and nixos/modules/homeserver.nix +secrets @p4
|
||||||
|
x 2026-10-19 (B) Reconcile operational documentation and ROADMAP.md with Milestone P4 control plane daemon architecture +docs @p4
|
||||||
Reference in new issue
Block a user