diff --git a/README.md b/README.md index c100d4d..27afed9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It is designed around a strict two-tier boundary: All platform definitions are strictly instance-agnostic; domain names (`HOMELAB_DOMAIN`) and secrets (`/run/secrets/`) are injected declaratively at runtime. > [!NOTE] -> **Current Implementation Baseline vs. Target Architecture**: This README documents the **currently implemented CLI and runtime baseline (Milestone P3)**. Under [Milestone P4 in `ROADMAP.md`](ROADMAP.md), `appctl` is transitioning from a host CLI orchestrator into a dedicated daemon service (`homelab-appctl.service`) exposing a unified logical API across local Unix socket and HTTP transports. See [`ROADMAP.md`](ROADMAP.md) for the full baseline-to-target matrix. +> **Milestone P4 Control Plane Architecture**: Under [Milestone P4 in `ROADMAP.md`](ROADMAP.md), `appctl` operates as an operational control plane daemon service (`homelab-appctl.service`) exposing a unified logical API across a local Unix Domain Socket (`/run/homelab/appctl.sock`) and loopback HTTP (`127.0.0.1:9876`). The thin `appctl` CLI delegates commands to this daemon with automatic `SO_PEERCRED` identity inspection and token-based RBAC. See [`docs/appctl.md`](docs/appctl.md) and [`ROADMAP.md`](ROADMAP.md) for details. --- @@ -49,8 +49,10 @@ All platform definitions are strictly instance-agnostic; domain names (`HOMELAB_ ▲ │ (Host Orchestration & CD) ┌───────────────┴───────────────┐ - │ Host Control Plane Baseline │ - │ • appctl CLI + Engine │ + │ Host Control Plane (P4) │ + │ • thin appctl CLI │ + │ • homelab-appctl.service │ + │ (UDS / HTTP daemon) │ │ • homelab-gitops.service │ └───────────────────────────────┘ ``` @@ -82,10 +84,17 @@ For detailed runtime layers, network segmentation, and the P4 control-plane tran ├── nixos/ # Declarative NixOS modules, systemd units, and SOPS secret wiring ├── config/ # Service configurations (Traefik, Authelia, Homepage, deployments.yaml) ├── scripts/ -│ ├── appctl # Operational CLI entrypoint and Compose environment orchestrator -│ ├── appctl_engine.py # Discovery, two-axis provenance, TLS inspection, and Homepage sync engine -│ ├── core_manifest.py # Authoritative Pydantic v2 schema v1.0 parser for workload app.yaml -│ ├── gitops_dispatcher.py # Authenticated webhook CD engine with Compose AST security validation +│ ├── appctl # Thin operational CLI delegating to control plane daemon +│ ├── appctl_daemon.py # Async HTTP/UDS daemon server (homelab-appctl.service) +│ ├── appctl_router.py # Operational router, locking, RBAC & dispatch +│ ├── appctl_auth.py # SO_PEERCRED & Bearer token RBAC authentication +│ ├── appctl_audit.py # Append-only fail-closed structured audit logger +│ ├── appctl_contracts.py # Pydantic v2 schemas for daemon RPC requests & responses +│ ├── appctl_cli.py # Unified CLI client with dual transport fallbacks +│ ├── appctl_engine.py # Discovery, two-axis provenance, TLS inspection, and Homepage sync +│ ├── bootstrap_token.py # Operator Bearer token provisioning helper +│ ├── core_manifest.py # Authoritative Pydantic v2 schema v1.0 parser for app.yaml +│ ├── gitops_dispatcher.py # Authenticated webhook CD engine with Compose AST validation │ └── test # Automated verification gate (Ruff, Pyright, Pytest, Nix flake checks) ├── tests/ # Unit, structural, and security invariant test suites └── docs/ # Architecture references, operational runbooks, and MADR decisions @@ -93,7 +102,7 @@ For detailed runtime layers, network segmentation, and the P4 control-plane tran --- -## Quickstart & Operations (Current CLI Baseline) +## Quickstart & Operations (Control Plane Daemon & CLI) ### Development & Verification @@ -111,7 +120,12 @@ pyright ### Workload Management (`appctl` CLI) +The thin `appctl` CLI connects directly to `homelab-appctl.service` via Unix Domain Socket (`/run/homelab/appctl.sock`) or loopback HTTP (`127.0.0.1:9876`). Local operators in `homelab-operators` or `wheel` receive read-only viewer access via kernel `SO_PEERCRED` without tokens, while mutating actions consume Bearer tokens from `~/.config/homelab/token`: + ```bash +# Check daemon health status +appctl health + # List all workloads with container health and local Git checkout status appctl list @@ -121,7 +135,7 @@ appctl list --fetch --ssl --core # Inspect detailed manifest, provenance, and container diagnostics for a workload appctl info -# Manage workload or Core service lifecycle (executes docker compose locally in the current baseline) +# Manage workload or Core service lifecycle (dispatched via homelab-appctl daemon) appctl up appctl down appctl restart @@ -136,11 +150,12 @@ appctl sync ### Host System Management ```bash -# Rebuild and activate the NixOS host configuration -sudo nixos-rebuild switch --flake .#server +# Rebuild and activate the NixOS host configuration (or use the 'nix-switch' alias) +sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure # Inspect platform systemd units systemctl status homeserver-core.service +systemctl status homelab-appctl.service systemctl status homelab-gitops.service systemctl status dynu-monitor.service ``` diff --git a/SECURITY.md b/SECURITY.md index e9f555a..159d7ae 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -31,6 +31,15 @@ This document outlines the security controls, container isolation rules, and ope * Secrets are stored encrypted in `nixos/secrets.yaml` using Age keys derived from the host SSH key (`/etc/ssh/ssh_host_ed25519_key`). * Decrypted secrets reside in RAM-backed ephemeral filesystems (`/run/secrets/`, `/run/credentials/`) and are not committed to unencrypted persistent files. +### F. Operational Control Plane Security (`homelab-appctl.service`) +* **Transport Isolation**: Daemon listens on a restricted Unix Domain Socket (`/run/homelab/appctl.sock`, mode `0660`, group `homelab-operators`) and loopback HTTP (`127.0.0.1:9876`). It never binds to public interfaces. +* **Authentication & RBAC**: + - **UDS Peer Credential Identification**: Local connections inspect kernel peer credentials (`SO_PEERCRED`). Callers in `homelab-operators` or `wheel` receive read-only viewer privileges automatically without requiring secrets on disk. + - **Cryptographic Bearer Tokens**: Mutating actions require Bearer tokens defined in SOPS (`/run/secrets/appctl/tokens.json`). Tokens are validated using `hmac.compare_digest` against SHA-256 digests. + - **Three-Tier RBAC**: Granular role enforcement distinguishes read-only inspectors (`viewer`), workload managers (`operator`), and core platform administrators (`admin`). +* **Per-Target Concurrency Control (`flock`)**: Non-blocking file locks (`/run/lock/homelab/.lock`) serialize mutating actions per workload, returning HTTP 409 Conflict if an operation is already in flight. +* **Fail-Closed Structured Audit Logging**: Every operational command is appended synchronously to a tamper-evident audit log (`/var/log/homelab/appctl/audit.jsonl`, mode `0600`). If disk writing fails, the daemon fails closed and rejects the request. + --- ## 2. Threat Model & Operational Considerations @@ -57,3 +66,6 @@ This document outlines the security controls, container isolation rules, and ope - [x] Invariant test runner (`./scripts/test`) passing on changes. - [x] `config/letsencrypt/acme.json` permissions set to `0600`. - [x] Host firewall ports restricted to declared services in `nixos/modules/homeserver.nix`. +- [x] Control plane daemon (`homelab-appctl.service`) isolated to UDS (`0660`) and loopback HTTP. +- [x] Operational audit log (`/var/log/homelab/appctl/audit.jsonl`) append-only with strict `0600` permissions. +- [x] Control plane mutation endpoints enforce per-target `flock` and SHA-256 Bearer tokens. diff --git a/docs/appctl.md b/docs/appctl.md index 8264beb..ef87a94 100644 --- a/docs/appctl.md +++ b/docs/appctl.md @@ -111,7 +111,7 @@ appctl: Save and exit your editor (SOPS will re-encrypt the file), then project the updated secrets: ```bash -sudo nixos-rebuild switch --flake ~/Core#server +sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure ``` This updates `/run/secrets/appctl/tokens.json` (owned by `homelab-appctl:homelab-operators`, mode `0400`), which `homelab-appctl.service` consumes. @@ -135,7 +135,7 @@ Verify permissions using both unauthenticated and authenticated queries: To rotate an operator token: 1. Run `python3 scripts/bootstrap_token.py --force --token-id "operator-admin-$(date +%Y%m%d)"`. 2. Open `sops nixos/secrets.yaml` and add the new descriptor to `appctl.tokens_json`. Keep the old entry temporarily if multiple sessions share it, or replace it immediately. -3. Run `sudo nixos-rebuild switch --flake ~/Core#server` to apply the updated token store. +3. Run `sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure` to apply the updated token store. 4. Verify CLI operations (`appctl config docs`). 5. Remove the deprecated token descriptor from `nixos/secrets.yaml` and re-run `nixos-rebuild switch`. diff --git a/docs/secrets-and-state.md b/docs/secrets-and-state.md index a17eb49..d2a1b79 100644 --- a/docs/secrets-and-state.md +++ b/docs/secrets-and-state.md @@ -103,7 +103,7 @@ brevo: ### 3. Save and Apply Changes Saving the file in your editor automatically re-encrypts it with Age. Apply the updated templates to running services: ```bash -sudo nixos-rebuild switch --flake ~/Core#server +sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure ``` ---