diff --git a/SECURITY.md b/SECURITY.md index 50d22bb..e9f555a 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -13,8 +13,8 @@ This document outlines the security controls, container isolation rules, and ope * Traefik and Dozzle query Docker metrics and metadata via `tcp://socket-proxy:2375` rather than direct socket mounts. ### B. Identity & Access Management (`lldap` & `authelia`) -* **Directory Service**: User accounts and group memberships are stored in LLDAP (`users.roadtotech.me`). -* **ForwardAuth**: Traefik intercepts incoming HTTP/HTTPS requests and validates sessions with Authelia (`auth.roadtotech.me`) before routing to protected backends. +* **Directory Service**: User accounts and group memberships are stored in LLDAP (`users.${HOMELAB_DOMAIN}`). +* **ForwardAuth**: Traefik intercepts incoming HTTP/HTTPS requests and validates sessions with Authelia (`auth.${HOMELAB_DOMAIN}`) before routing to protected backends. * **MFA Support**: Supports TOTP and FIDO2 authentication. ### C. Network Segmentation @@ -51,7 +51,7 @@ This document outlines the security controls, container isolation rules, and ope ## 3. Verification Checklist - [x] Secrets encrypted in `nixos/secrets.yaml` via Age / SOPS. -- [x] User identities managed in LLDAP (`users.roadtotech.me`). +- [x] User identities managed in LLDAP (`users.${HOMELAB_DOMAIN}`). - [x] `socket-proxy` configured with `POST=0`, `DELETE=0`, `BUILD=0`, `EXEC=0`. - [x] Webhook HMAC signature verification active on port 9000. - [x] Invariant test runner (`./scripts/test`) passing on changes. diff --git a/docs/appctl.md b/docs/appctl.md index 67545e8..576cdef 100644 --- a/docs/appctl.md +++ b/docs/appctl.md @@ -3,18 +3,19 @@ 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] -> **Implementation Reference**: This document serves as the **current implementation manual** for the `appctl` Bash CLI wrapper (`scripts/appctl`), metadata engine (`scripts/appctl_engine.py`), and currently consumed `app.yaml` manifest fields. -> For the platform's overarching control-plane architecture, 5-stage deployment model lifecycle, and phased engineering roadmap, see [`README.md`](../README.md), [`ROADMAP.md`](../ROADMAP.md), and the [Architecture Decision Index](decisions/README.md). +> **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`). +> 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). --- ## 1. How `appctl` Works -`appctl` consists of two cooperating scripts: -1. **`scripts/appctl`** (Bash CLI wrapper): Handles command-line arguments, sources secret environment templates, dispatches `docker compose` commands, and provides shell autocompletions. -2. **`scripts/appctl_engine.py`** (Python metadata engine): Scans directories in `~/Sites`, parses `app.yaml` manifests, computes Git synchronization status against remotes, queries SSL/TLS certificate validity, and compiles the Homepage dashboard configuration. +`appctl` consists of three 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. +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.). -``` +```text ┌───────────────────────────────┐ │ appctl │ └───────────────┬───────────────┘ @@ -27,8 +28,8 @@ The `appctl` tool is the command-line orchestrator and metadata engine for the * ┌──────────────────────────┴──────────────────────────┐ ▼ ▼ [ appctl_engine.py resolve ] [ Source Secrets ] -Resolves aliases, domain, /run/secrets/traefik-deployments.env -and manifest parameters /run/secrets/homeserver.env +• Parses app.yaml via core_manifest.py /run/secrets/traefik-deployments.env +• Fails closed on manifest_error /run/secrets/homeserver.env │ │ └──────────────────────────┬──────────────────────────┘ ▼ @@ -37,7 +38,7 @@ and manifest parameters /run/secrets/homeserver.en │ • PROXY_NETWORK │ │ • SERVICE_DOMAIN / DOMAIN │ │ • CONTAINER_NAME │ - │ • Custom manifest env │ + │ • Validated manifest env │ └──────────────┬──────────────┘ ▼ ┌─────────────────────────────┐ @@ -52,26 +53,27 @@ and manifest parameters /run/secrets/homeserver.en ### Status & Inspection #### `appctl list` / `appctl status` -Lists applications discovered in `~/Sites` with container status, Git synchronization badge, routed domain, and filesystem path. +Lists applications discovered in `~/Sites` using **two-axis inspection**: +- **`DEPLOYMENT` (Axis 1 — Local Checkout)**: Inspects the local `~/Sites/` Git working tree (`✓ Synced`, `* Dirty`, `⬇ Behind`, `⚠️ Non-Git`). +- **`PROVENANCE` (Axis 2 — Upstream Software)**: Evaluates upstream software provenance for Class A (Source-Backed) vs. Class B (`— Image-Only`) workloads. **Options**: -* `--fetch` (`-f`): Runs `git fetch --quiet` across repositories before computing sync badges. -* `--core` (`-c`): Includes Core infrastructure services (`traefik`, `authelia`, `lldap`, `stalwart`, etc.) in the output. -* `--ssl` (`-s`): Queries SSL/TLS certificates for each domain and displays status and expiration days. -* `--all` (`-a`): Equivalent to `--core`. +* `--fetch` (`-f`): Queries upstream Git remotes (`git ls-remote` with a 10s timeout) and fetches local deployment tracking branches before computing provenance badges. +* `--core` (`-c` / `--all` / `-a`): Appends Core infrastructure services (`traefik`, `authelia`, `lldap`, `stalwart`, `homepage`, `dozzle`, `watchtower`) to the output. +* `--ssl` (`-s`): Queries SSL/TLS certificates over port 443 for each public domain and appends a `CERT` column. **Example Output**: ```text -SERVICE STATUS GIT SYNC DOMAIN DIRECTORY -------- ------ -------- ------ --------- -docs 🟢 Running (1) ✓ Synced docs.roadtotech.me ~/Sites/homelab-docs -jellyfin 🟢 Running (1) ✓ Synced jellyfin.roadtotech.me ~/Sites/homelab-jellyfin -gitea 🟢 Running (2) ⬇ 1 Behind gitea.roadtotech.me ~/Sites/homelab-gitea -mongodb 🔴 Stopped ✓ Synced * mongodb.roadtotech.me ~/Sites/homelab-mongodb +SERVICE DEPLOYMENT PROVENANCE STATUS DOMAIN +------- ---------- ---------- ------ ------ +docs ✓ Synced (main) ✓ Synced 🟢 Running (1) docs.example.com +jellyfin ✓ Synced (main) — Image-Only 🟢 Running (1) jellyfin.example.com +gitea ✓ Synced (main) ⬆ Update Available 🟢 Running (2) gitea.example.com +mongodb * Dirty (1) (main) — Image-Only 🔴 Stopped mongodb.example.com ``` #### `appctl ssl [service]` -Inspects SSL/TLS certificates over port 443. If a service is specified, shows detailed issuer, subject, and expiration data; otherwise, inspects all homelab domains. +Inspects SSL/TLS certificates over port 443. If a service is specified, shows detailed issuer, subject, and expiration data; otherwise, inspects all non-internal homelab domains. ```bash # Check all domains @@ -81,14 +83,13 @@ appctl ssl appctl ssl jellyfin ``` -#### `appctl info ` -Displays diagnostic information for a workload or Core service: -* Canonical name, directory, and aliases. -* Docker container running status. -* Primary routed domain and Authelia guard status. -* Git tracking details: branch, upstream remote, uncommitted file count. -* Injected environment variable defaults. -* Homepage card configuration. +#### `appctl info [--ssl]` +Displays comprehensive two-axis diagnostics for a workload or Core service: +* Canonical name, directory path, aliases, and workload class (`Class A (Source-Backed)` vs. `Class B (Image-Only)`). +* Primary routed domain, networks, and Authelia guard status. +* **Axis 1 (Local Deployment Checkout)**: Branch, commit hash, dirty file count, and sync status. +* **Axis 2 (Upstream Software Provenance)**: Upstream Git URL, tracked ref (`branch`, `tag`, or `commit`), resolved remote commit, and running container OCI revision label. +* Injected environment variable defaults and Homepage card metadata. * SSL certificate details (when `--ssl` is passed). ```bash @@ -101,22 +102,22 @@ appctl info docs --ssl #### `appctl up ` Starts the specified service stack in detached mode (`--remove-orphans`). -* For a workload in `~/Sites`: starts containers and calls `appctl sync`. +* For a workload in `~/Sites`: starts containers and triggers `appctl sync`. * For `core`: starts the entire Core Compose stack using `/run/secrets/homeserver.env`. -* For an individual Core service (e.g. `appctl up traefik`): starts that specific container. +* For an individual Core service (e.g., `appctl up traefik`): starts that specific container. #### `appctl down ` -Stops and removes containers defined in the target's Compose file. +Stops and removes containers defined in the target's Compose file (or stops the targeted Core container). #### `appctl restart ` -Restarts the target stack or individual container. -* `appctl restart docs`: Restarts the docs workload. +Restarts the target stack or individual container: +* `appctl restart docs`: Recreates the `docs` workload stack and syncs Homepage. * `appctl restart core`: Restarts all Core Compose services. * `appctl restart traefik`: Restarts only the Traefik container. #### `appctl update ` Performs a sequential update workflow: -1. Checks that the local git working tree is clean (aborts if uncommitted changes exist). +1. Verifies that the local Git working tree is clean (aborts if uncommitted changes exist). 2. Runs `git pull --ff-only` to fast-forward the current branch. 3. Runs `docker compose pull` to fetch updated container images. 4. Runs `docker compose up -d --remove-orphans` to recreate containers. @@ -126,31 +127,32 @@ Performs a sequential update workflow: Pulls latest container images and recreates the target service. #### `appctl logs ` -Streams container logs (`docker compose logs -f`). -* Supports passing container names: `appctl logs core traefik` or `appctl logs stalwart`. +Streams container logs (`docker compose logs -f`). Supports passing specific container names (`appctl logs core traefik` or `appctl logs stalwart`). #### `appctl config ` -Renders the resolved Docker Compose configuration with all injected variables. +Validates the manifest and renders the resolved Docker Compose configuration with all injected variables. Fails closed if `app.yaml` is missing or invalid. #### `appctl sync` -Scans all `~/Sites/*/app.yaml` manifests and re-generates `config/homepage/services.yaml`. +Scans all valid `~/Sites/*/app.yaml` manifests and compiles `config/homepage/services.yaml`. #### `appctl completion [bash]` Outputs the bash autocompletion script. --- -## 3. `app.yaml` Fields Consumed by `appctl` and GitOps +## 3. `app.yaml` Schema v1.0 Contract -`app.yaml` files in `~/Sites` are read by `appctl_engine.py` and `gitops_dispatcher.py` for the following fields: +Workload manifests in `~/Sites//app.yaml` are validated by [`scripts/core_manifest.py`](../scripts/core_manifest.py) using strict Pydantic v2 models (`extra="forbid"`). Any unknown field, invalid transport URL, or prohibited deployment action causes validation to fail closed. ```yaml +schema_version: "1.0" # Schema version (only "1.0" is supported) + # ── Identity & Routing ──────────────────────────────────────────────────────── -name: "jellyfin" # Canonical service name (defaults to folder name minus homelab-) -aliases: # Alternate CLI aliases +name: "jellyfin" # Canonical name: ^[a-zA-Z0-9][a-zA-Z0-9._-]*$ +aliases: # Optional CLI aliases - "media" - "movies" -domain: "jellyfin.roadtotech.me" # Primary routed domain (defaults to .roadtotech.me) +domain: "jellyfin.example.com" # Primary routed domain (defaults to .${HOMELAB_DOMAIN}) description: "Media Streaming Server" # ── Platform Integration ────────────────────────────────────────────────────── @@ -159,30 +161,36 @@ auth: false # Authelia ForwardAuth protection (default: networks: # Docker networks to join (default: [proxy-net]) - proxy-net +# ── Upstream Software Provenance (Optional: Defines Class A vs. Class B) ───── +# Omit 'source' for Class B (Image-Only third-party workloads). +# Include 'source' for Class A (Source-Backed workloads): +source: + url: "https://github.com/example/jellyfin-app.git" # Strictly https://, ssh://, or git@host:path + ref: "main" # Branch, v* tag, or 40-char commit SHA + # ── Injected Environment Defaults ───────────────────────────────────────────── -# Injected into the Compose environment when appctl commands run +# Keys must match ^[a-zA-Z_][a-zA-Z0-9_]*$ and cannot override reserved host keys +# (PATH, LD_PRELOAD, IFS, SHELL, USER, HOME, CORE_DIR, SITES_DIR, etc.) env: MEDIA_PATH: "/media" JELLYFIN_TZ: "UTC" - JELLYFIN_PUID: "1000" - JELLYFIN_PGID: "1000" # ── GitOps Deployment Policy ────────────────────────────────────────────────── -# Evaluated by scripts/gitops_dispatcher.py upon webhook reception +# Evaluated by scripts/gitops_dispatcher.py upon webhook admission deployment: branch: "main" # Target branch that triggers deployment - strategy: "compose" # Deployment strategy (only 'compose' is permitted) - actions: # Strictly allowlisted actions - - git_pull + strategy: "compose" # Only 'compose' strategy is permitted + actions: # Strictly allowlisted: git_pull, compose_pull, + - git_pull # compose_up, compose_build, compose_restart - compose_up # ── Homepage Dashboard Metadata ─────────────────────────────────────────────── homepage: title: "Jellyfin" # Card title - group: "Media & Productivity" # Group name + group: "Media & Productivity" # Dashboard group name icon: "jellyfin.png" # Icon name (matched against config/homepage/icons/) container: "jellyfin" # Container name for live status widget - weight: 10 # Card sort weight + weight: 10 # Card sort weight (lower sorts first) ``` --- @@ -191,26 +199,27 @@ homepage: When `appctl` executes commands against a workload, environment variables are resolved in this sequence: -1. **Global Secrets & Templates**: Sourced from `/run/secrets/homeserver.env` and `/run/secrets/traefik-deployments.env` (or `/run/secrets/rendered/*` fallbacks). -2. **Infrastructure Defaults**: +1. **Global Secrets & Templates**: Sourced from `/run/secrets/rendered/homeserver.env` and `/run/secrets/rendered/traefik-deployments.env` (with `/run/secrets/*` fallbacks). +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. +3. **Infrastructure Defaults**: - `PROXY_NETWORK` (defaults to `proxy-net`) - `CERT_RESOLVER` (defaults to `myresolver`) - - `DOMAIN_SUFFIX` (defaults to `roadtotech.me`) -3. **Application Identity**: + - `DOMAIN_SUFFIX` (defaults to `$HOMELAB_DOMAIN`) +4. **Application Identity**: - `SERVICE_NAME` = `` - `CONTAINER_NAME` = `` - `SERVICE_DOMAIN` = `` - `DOMAIN` = `` -4. **Manifest Variables**: Declared under the `env:` block in `app.yaml`. -5. **Local Repository Files**: Sourced from `$APP_DIR/.env` and `$APP_DIR/app.env` if present. +5. **Manifest Variables**: Validated key-value pairs from the `env:` block in `app.yaml` (emitted via null-delimited stream without shell `eval`). +6. **Local Repository Files**: Sourced from `$APP_DIR/.env` and `$APP_DIR/app.env` if present. --- ## 5. Homepage Dashboard Compilation When `appctl sync` runs: -1. `appctl_engine.py` reads all `~/Sites/*/app.yaml` files. -2. Core services (`traefik`, `authelia`, `lldap`, `stalwart`, `snappymail`, `dozzle`) are assigned to `Core Infrastructure`. -3. Workload applications with `visible: true` are grouped by their `homepage.group` (ordered: `Core Infrastructure`, `Knowledge & Notes`, `Media & Productivity`, `Development & AI`, `Applications`). -4. Custom icons matching files in `config/homepage/icons/` (SVG or PNG) are mapped to `/icons/`. +1. `appctl_engine.py` scans all `~/Sites/*/app.yaml` manifests (skipping any workload with a `manifest_error`). +2. Core services (`traefik`, `authelia`, `lldap`, `stalwart`, `homepage`, `dozzle`, `watchtower`) are assigned to `Core Infrastructure`. +3. Workload applications with `visible: true` are grouped by their `homepage.group` (ordered: `Core Infrastructure`, `Knowledge & Notes`, `Media & Productivity`, `Development & AI`, `Applications`) and sorted by `(weight, title)`. +4. Custom icons matching files in `config/homepage/icons/` (`.svg` or `.png`) are mapped to `/icons/`. 5. The compiled configuration is written to `config/homepage/services.yaml`. diff --git a/docs/architecture.md b/docs/architecture.md index b282a7f..4d70ab9 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,10 +1,10 @@ # 🏛️ Homelab Core — Architecture & System Design -This document details the architectural structure, component roles, networking models, and security controls of the **Homelab Core** platform for `roadtotech.me`. +This document details the architectural structure, component roles, networking models, and security controls of the **Homelab Core** platform. > [!NOTE] -> **Implementation Scope**: This document details the **current runtime architecture**, edge routing, container topologies, and network isolation models of Homelab Core. -> For the overarching control-plane architecture, 5-stage deployment model lifecycle, and phased engineering milestones, see [`README.md`](../README.md), [`ROADMAP.md`](../ROADMAP.md), and the [Architecture Decision Index](decisions/README.md). +> **Implementation Scope**: This document details the **current runtime architecture (Milestone P3)**, 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). --- @@ -14,12 +14,12 @@ To understand how the system is organized, three architectural dimensions are di ### A. Ownership Boundary * **Core (`~/Core`) owns**: NixOS host configuration, shared platform services, edge ingress, identity boundaries, secrets distribution, and deployment orchestration mechanics. -* **Workload Plane (`~/Sites`) owns**: Independent application codebases, application-specific Docker Compose files, application-specific `app.yaml` metadata, and application data/state. +* **Workload Plane (`~/Sites`) owns**: Independent application deployments, workload-specific Docker Compose files, declarative `app.yaml` manifests, and workload-scoped runtime state (`~/var/lib/homelab//`). ### B. Four Runtime Layers The runtime environment consists of four functional layers: -``` +```text ┌────────────────────────────────────────────────────────────────────────┐ │ 1. EDGE GATEWAY & INGRESS │ │ Traefik (v3.6) · Let's Encrypt Wildcard TLS · Dynu DNS-01 Provider │ @@ -27,8 +27,8 @@ The runtime environment consists of four functional layers: │ ▼ ┌────────────────────────────────────────────────────────────────────────┐ -│ 2. CONTROL & PLATFORM SERVICES (Core Compose Stack) │ -│ Authelia SSO · LLDAP Directory · Stalwart Mail · SnappyMail │ +│ 2. CONTROL & PLATFORM SERVICES (Core Compose Stack) │ +│ Authelia SSO · LLDAP Directory · Stalwart Mail Server │ │ Homepage Dashboard · Dozzle · Watchtower · Diun │ │ socket-proxy (Read-Only Docker API Barrier) │ └───────────────────────────────────┬────────────────────────────────────┘ @@ -36,7 +36,7 @@ The runtime environment consists of four functional layers: ▼ ┌────────────────────────────────────────────────────────────────────────┐ │ 3. WORKLOAD PLANE (~/Sites) │ -│ Autonomous Workload Repositories (Jellyfin, Docs, Gitea, DBs, etc.) │ +│ Autonomous Workload Repositories (SnappyMail, Docs, Gitea, etc.) │ │ Declarative app.yaml Manifests & Compose Stacks │ └───────────────────────────────────┬────────────────────────────────────┘ │ @@ -49,9 +49,9 @@ The runtime environment consists of four functional layers: ``` ### C. Cross-Cutting Orchestration -Orchestration coordinates operations across the runtime layers without being a runtime layer itself: -* **`appctl` CLI & Metadata Engine (`scripts/appctl`, `scripts/appctl_engine.py`)**: Current CLI implementation coordinating discovery, Docker status inspection, and Homepage compilation across workloads and Core. In the target architecture, this evolves into the centralized operational control plane daemon (`homelab-appctl.service`). -* **GitOps Webhook Dispatcher (`scripts/gitops_dispatcher.py`)**: Governed by the `homelab-gitops.service` systemd unit, it receives webhooks on port 9000, enforces admission policies, and dispatches serialized deployment actions for workloads or data repositories. +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`). +* **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. --- @@ -59,7 +59,7 @@ Orchestration coordinates operations across the runtime layers without being a r ### A. Edge Gateway (`traefik`) * **Role**: Ingress proxy for incoming HTTP (80) and HTTPS (443) traffic. -* **TLS Management**: Employs Traefik's native ACME resolver using the Dynu DNS-01 challenge provider (`myresolver`) to obtain and renew wildcard certificates for `*.roadtotech.me` and `roadtotech.me`. Certificate data is stored at `config/letsencrypt/acme.json` (mode `0600`). +* **TLS Management**: Employs Traefik's native ACME resolver using the Dynu DNS-01 challenge provider (`myresolver`) to obtain and renew wildcard certificates for `*.${HOMELAB_DOMAIN}` and `${HOMELAB_DOMAIN}` (e.g., `*.example.com`). Certificate data is stored at `config/letsencrypt/acme.json` (mode `0600`). * **Redirection**: Automatically upgrades HTTP traffic to HTTPS via the `https-redirect@docker` middleware. * **Dynamic Routing**: Discovers routers and services dynamically by reading Docker container labels via `socket-proxy` (`tcp://socket-proxy:2375`). @@ -69,40 +69,40 @@ Orchestration coordinates operations across the runtime layers without being a r - Mounted read-only: `/var/run/docker.sock:/var/run/docker.sock:ro`. - State-modifying and execution endpoints disabled: `POST=0`, `DELETE=0`, `BUILD=0`, `EXEC=0`, `COMMIT=0`, `CONFIGS=0`, `DISTRIBUTION=0`, `NODES=0`, `PLUGINS=0`, `SECRETS=0`, `SWARM=0`, `SYSTEM=0`. - Read-only inspection endpoints enabled: `CONTAINERS=1`, `NETWORKS=1`, `SERVICES=1`, `TASKS=1`, `IMAGES=1`, `VOLUMES=1`, `INFO=1`, `EVENTS=1`, `PING=1`, `VERSION=1`. -* **Network**: Attached exclusively to `socket-net`. Application containers in `~/Sites` are not attached to `socket-net`. +* **Network**: Attached exclusively to `socket-net`. Application containers in `~/Sites` are never attached to `socket-net`. ### C. Identity & Directory Services (`lldap` & `authelia`) -* **`lldap`**: Lightweight LDAP directory service storing user accounts, password hashes, and groups. Web UI exposed at `users.roadtotech.me` (protected by Authelia). SQLite database stored in `config/lldap/data/users.db`. -* **`authelia`**: Authentication and SSO gateway (`auth.roadtotech.me`). +* **`lldap`**: Lightweight LDAP directory service storing user accounts, password hashes, and groups. Web UI exposed at `users.${HOMELAB_DOMAIN}` (protected by Authelia). SQLite database stored in `config/lldap/data/users.db`. +* **`authelia`**: Authentication and SSO gateway (`auth.${HOMELAB_DOMAIN}`). - Configured with an LDAP authentication backend querying `ldap://lldap:3890`. - - Exposes the ForwardAuth endpoint (`/api/verify?rd=https://auth.roadtotech.me/`), registered as the `authelia-auth@docker` Traefik middleware. + - Exposes the ForwardAuth endpoint (`/api/verify?rd=https://auth.${HOMELAB_DOMAIN}/`), registered as the `authelia-auth@docker` Traefik middleware. - Passes user identity headers (`Remote-User`, `Remote-Groups`, `Remote-Email`, `Remote-Name`) upon successful session verification. -### D. Mail Subsystem (`stalwart` & `snappymail`) -* **`stalwart`**: All-in-one mail server handling inbound SMTP (25), SMTPS (465), SMTP Submission (587), IMAPS (993), and ManageSieve (4190). - - WebAdmin & JMAP UI accessible at `mail.roadtotech.me` via Traefik. +### D. Mail Subsystem (`stalwart`) +* **`stalwart`**: Core mail transport and storage server handling inbound SMTP (25), SMTPS (465), SMTP Submission (587), IMAPS (993), and ManageSieve (4190). + - WebAdmin & JMAP endpoint accessible at `smtp.${HOMELAB_DOMAIN}` via Traefik. - Authenticates users against the LLDAP directory. - Outbound mail relay configured to route through an external smart host (Brevo SMTP relay via SOPS secrets). -* **`snappymail`**: Webmail client accessible at `webmail.roadtotech.me` routing to Stalwart. + - *(Note: User-facing webmail, such as SnappyMail, runs as an independent Class B workload in `~/Sites/snappymail` with isolated state under `~/var/lib/homelab/snappymail/`.)* ### E. Portal & Observability (`homepage`, `dozzle`) -* **`homepage`**: Service dashboard at `dashboard.roadtotech.me`. Synchronized from `app.yaml` manifests in `~/Sites` by `appctl sync`. -* **`dozzle`**: Log viewing interface at `logs.roadtotech.me`, connecting through `socket-proxy`. +* **`homepage`**: Service dashboard at `dashboard.${HOMELAB_DOMAIN}`. Synchronized from `app.yaml` manifests in `~/Sites` by `appctl sync`. +* **`dozzle`**: Real-time container log viewer at `logs.${HOMELAB_DOMAIN}`, connecting read-only through `socket-proxy`. ### F. Host Foundation & Daemons -* **`homeserver-core.service`**: Systemd unit managing the Core Docker Compose stack (`/home/kiskaadee/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`. +* **`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`). * **`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`. --- ## 3. Network Segmentation -Homelab Core configures two bridge networks: +Homelab Core configures two isolated Docker bridge networks: ```text ┌────────────────────────────────────────────────────────────────────────┐ -│ HOST DOCKER ENGINE │ +│ HOST DOCKER ENGINE │ ├────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────────────────────────────────────────────────────┐ │ @@ -110,8 +110,7 @@ Homelab Core configures two bridge networks: │ │ │ │ │ │ • traefik (router) • authelia (sso) │ │ │ │ • lldap (directory) • stalwart (mail) │ │ -│ │ • snappymail (webmail) • homepage (dashboard) │ │ -│ │ • dozzle (logs) │ │ +│ │ • homepage (dashboard) • dozzle (logs) │ │ │ │ • All User Workloads (~/Sites/*) │ │ │ └──────────────────────────────┬───────────────────────────────┘ │ │ │ │ @@ -129,7 +128,7 @@ Homelab Core configures two bridge networks: ``` 1. **`proxy-net`**: Ingress routing network. Traefik directs traffic to backend service containers on this network. Workload containers in `~/Sites` join `proxy-net`. -2. **`socket-net`**: Isolated Docker socket proxy network. Only Core infrastructure components needing container metadata join this network. +2. **`socket-net`**: Isolated Docker socket proxy network. Only Core infrastructure components needing read-only container metadata join this network. --- @@ -156,9 +155,9 @@ Application containers in `~/Sites` do not bind host ports directly; they receiv ## 5. Workload Integration Model -Workloads in `~/Sites/` integrate with Core through two mechanisms: +Workloads in `~/Sites/` integrate with Core through three mechanisms: -1. **Manifest Metadata (`app.yaml`)**: Declares identity, routed domain, environment variable defaults, homepage card layout, and deployment policy. +1. **Manifest Metadata (`app.yaml`)**: Validated by `scripts/core_manifest.py` (Schema v1.0). Declares canonical identity, routed domain, upstream source provenance (`source.url`, `source.ref`), environment defaults, Homepage card layout, and allowlisted GitOps deployment policy. 2. **Compose Configuration (`docker-compose.yml`)**: - Attaches to the external `proxy-net` network. - Declares Traefik routing labels: @@ -176,4 +175,4 @@ Workloads in `~/Sites/` integrate with Core through two mechanisms: # If auth is required: - "traefik.http.routers.${CONTAINER_NAME}.middlewares=authelia-auth@docker" ``` -3. **Execution**: The `appctl` CLI and GitOps dispatcher supply environment variables (such as `SERVICE_DOMAIN`, `CONTAINER_NAME`, and projected secrets) when invoking Docker Compose. +3. **Execution & State Isolation**: `appctl` and `gitops_dispatcher.py` validate the manifest and Compose AST (blocking privilege escalation and out-of-bounds mounts) before supplying runtime environment variables (`SERVICE_DOMAIN`, `CONTAINER_NAME`, and projected secrets). Persistent mutable workload data resides strictly under `~/var/lib/homelab//`. diff --git a/docs/decisions/README.md b/docs/decisions/README.md index 8117dab..8151774 100644 --- a/docs/decisions/README.md +++ b/docs/decisions/README.md @@ -1,8 +1,8 @@ # 🏛️ Homelab Core & Appctl Architecture Decision Index -This document serves as the repository-facing index for Architectural Decision Records (ADRs) governing **Homelab Core** and the **`appctl` Operational Control Plane**. +This document serves as the authoritative repository index for Architectural Decision Records (ADRs) governing **Homelab Core** and the **`appctl` Operational Control Plane**. -In accordance with platform governance, authoritative ADRs are maintained in the central knowledge vault (`03-records/decisions/`) using the MADR 4.0 specification. This index provides navigation, context, and one-line summaries without duplicating architectural specifications or creating competing sources of truth. +Repository-level architectural decisions are recorded in `docs/decisions/` using the MADR 4.0 specification. Foundational platform ADRs (0001 and 0002) are summarized inline below alongside full MADR records (0003+). --- @@ -10,9 +10,9 @@ In accordance with platform governance, authoritative ADRs are maintained in the | Decision Record | Status | Date | Scope & One-Line Purpose | | :--- | :--- | :--- | :--- | -| [**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. | -| [**Homelab Operational Control Plane & Deployment Model Architecture**](#homelab-operational-control-plane--deployment-model-architecture) | `accepted` | 2026-10-07 | Establishes `appctl` as the central operational control plane daemon, one logical API across dual transports (Unix socket and HTTP), explicit token authentication on host, Git as authoritative deployment state, the 5-stage model lifecycle, AI proposal boundaries, and append-only audit telemetry. | -| [**Homelab 3-Tier Architecture & Deployment Provenance Model**](#homelab-3-tier-architecture--deployment-provenance-model) | `accepted` | 2026-09-28 | Establishes 3-tier separation (Software, OCI Artifact, Sites Deployment, Core Platform), two workload classes (Source-Backed vs. Image-Only), isolated state root (`~/var/lib/homelab//`), and two operational inspection axes. | +| [**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**](#homelab-operational-control-plane--deployment-model-architecture) | `accepted` | 2026-10-07 | Establishes `appctl` as the central operational control plane daemon, one logical API across dual transports (Unix socket and HTTP), explicit token authentication on host, Git as authoritative deployment state, the 5-stage model lifecycle, AI proposal boundaries, and append-only audit telemetry. | +| [**ADR-0001: Homelab 3-Tier Architecture & Deployment Provenance Model**](#homelab-3-tier-architecture--deployment-provenance-model) | `accepted` | 2026-09-28 | Establishes 3-tier separation (Software, OCI Artifact, Sites Deployment, Core Platform), two workload classes (Source-Backed vs. Image-Only), isolated state root (`~/var/lib/homelab//`), and two operational inspection axes. | --- @@ -32,7 +32,7 @@ In accordance with platform governance, authoritative ADRs are maintained in the ### Homelab Operational Control Plane & Deployment Model Architecture -* **Canonical Document**: `03-records/decisions/homelab-appctl-control-plane-architecture.md` +* **Decision ID**: `ADR-0002` * **Status**: `accepted` (Active) * **Governing Implementation Plan**: [ROADMAP.md](../../ROADMAP.md) (Roadmap v5) * **Core Commitments**: @@ -48,7 +48,7 @@ In accordance with platform governance, authoritative ADRs are maintained in the --- ### Homelab 3-Tier Architecture & Deployment Provenance Model -* **Canonical Document**: `03-records/decisions/homelab-3tier-architecture-and-provenance.md` +* **Decision ID**: `ADR-0001` * **Status**: `accepted` (Active) * **Governing Implementation Plan**: [ROADMAP.md](../../ROADMAP.md) (Roadmap v5) * **Core Commitments**: diff --git a/docs/operations.md b/docs/operations.md index 4c8f0bf..6171a87 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -158,7 +158,7 @@ appctl config docs User accounts and group memberships are managed dynamically in **LLDAP** rather than static configuration files. ### Accessing the Directory -1. Open `https://users.roadtotech.me` in your browser. +1. Open `https://users.${HOMELAB_DOMAIN}` (e.g., `https://users.example.com`) in your browser. 2. Authenticate using your admin credentials (`admin` / password configured in `nixos/secrets.yaml`). 3. From the LLDAP UI, you can: - Create and delete user accounts. @@ -167,7 +167,7 @@ User accounts and group memberships are managed dynamically in **LLDAP** rather - Assign users to groups (e.g. `admin`, `users`, `media`). ### Authelia Session & Authentication -* **URL**: `https://auth.roadtotech.me` +* **URL**: `https://auth.${HOMELAB_DOMAIN}` (e.g., `https://auth.example.com`) * **Session Lifetime**: 7 days maximum session, 3 days inactivity timeout. * **ForwardAuth Guard**: Applications requiring authentication attach the `authelia-auth@docker` middleware. @@ -193,12 +193,12 @@ User accounts and group memberships are managed dynamically in **LLDAP** rather ``` ### B. Dynamic DNS (WAN IP) Drift -* **Symptom**: External domain `roadtotech.me` does not resolve to the current ISP WAN address. +* **Symptom**: External domain (`${HOMELAB_DOMAIN}`) does not resolve to the current ISP WAN address. * **Diagnosis**: ```bash # Check current public IP vs resolved DNS IP curl -s https://api.ipify.org - dig +short roadtotech.me @1.1.1.1 + dig +short example.com @1.1.1.1 # Check dynu-monitor logs systemctl status dynu-monitor @@ -263,7 +263,7 @@ To back up the homelab, create secure snapshots of the following state directori | **User Directory** | `~/Core/config/lldap/data/` | LLDAP SQLite database (`users.db`) | | **Auth Database** | `~/Core/config/authelia/db.sqlite3` | Authelia session database | | **Mail Storage** | `~/Core/config/stalwart/` | Stalwart database, mailboxes, and DKIM keys | -| **Webmail State** | `~/Core/config/snappymail/data/` | SnappyMail configuration and sessions | +| **Workload State** | `~/var/lib/homelab//` | Per-workload persistent runtime state (e.g., `snappymail`) | | **Dashboard State** | `~/Core/config/homepage/` | Homepage configuration and custom icons | ### Host Recovery Requirements @@ -272,10 +272,10 @@ To bring up a replacement host from version control: 2. **Restore the host SSH private key** to `/etc/ssh/ssh_host_ed25519_key` (mode `0600`) before running `nixos-install`, as `sops-nix` requires this key during system evaluation and activation. 3. Install NixOS targeting the server flake: ```bash - nixos-install --flake /mnt/home/kiskaadee/Core#server + nixos-install --flake /mnt/home//Core#server reboot ``` -4. Restore persistent data directories (`config/` backups) and start the Core stack: +4. Restore persistent data directories (`config/` and `~/var/lib/homelab/` backups) and start the Core stack: ```bash sudo systemctl start homeserver-core ``` diff --git a/docs/plans/p4-readiness-plan.md b/docs/plans/p4-readiness-plan.md index 404fd35..5a37c33 100644 --- a/docs/plans/p4-readiness-plan.md +++ b/docs/plans/p4-readiness-plan.md @@ -189,7 +189,7 @@ The platform defines three hierarchical authorization tiers: | Role | Permitted Operations | Typical Principals | | :--- | :--- | :--- | -| `homelab-admin` | All operations (including Core platform mutation, daemon reload, secret regeneration). | Break-glass admin token, human interactive operator (`kiskaadee`). | +| `homelab-admin` | All operations (including Core platform mutation, daemon reload, secret regeneration). | Break-glass admin token, human interactive operator (`operator`). | | `homelab-operator` | Workload mutations (`deploy`, `stop`, `restart`, `update`, `pull`, `sync_homepage`). Cannot mutate Core platform infrastructure. | GitOps webhook runner token, automation scripts. | | `homelab-viewer` | Read-only operations (`list`, `get`, `resolve`, `config`, `logs`, `ssl`, `health`). Zero mutations permitted. | Homepage dashboard status monitor, read-only diagnostic CLI. | @@ -244,17 +244,17 @@ Following the pattern established in Milestone P2 for `homelab-gitops.service`, - `ProtectSystem = "strict"`: Host filesystem is read-only. - `ProtectHome = "read-only"`: User home is read-only by default. - `ReadWritePaths`: Explicitly allowlisted writable roots: - - `/home/kiskaadee/Sites` (workload definitions and Git checkouts) - - `/home/kiskaadee/var/lib/homelab` (workload persistent state roots) - - `/home/kiskaadee/Core/config/homepage` (Homepage services.yaml destination) - - `/var/log/homelab/appctl` or `/home/kiskaadee/.local/state/homelab/appctl` (audit log directory) + - `/home//Sites` (workload definitions and Git checkouts) + - `/home//var/lib/homelab` (workload persistent state roots) + - `/home//Core/config/homepage` (Homepage services.yaml destination) + - `/var/log/homelab/appctl` or `/home//.local/state/homelab/appctl` (audit log directory) - `/run/homelab` (socket runtime directory) - `PrivateTmp = true`: Isolated temporary directories. - `NoNewPrivileges = true`: Disallows privilege escalation. ### C. Platform Genericism & Domain Decoupling Per Invariant #8 in `AGENTS.md`, the control plane and all platform components must remain strictly instance-agnostic: -- **No Hardcoded Domains**: Personal domain names (e.g. `roadtotech.me`) must never appear hardcoded in Python modules, NixOS definitions, or default configurations. +- **No Hardcoded Domains**: Personal domain names must never appear hardcoded in Python modules, NixOS definitions, or default configurations. - **Canonical Precedence & Dynamic Resolution**: All domain resolutions follow strict, fail-closed precedence: 1. `HOMELAB_DOMAIN` (Primary platform apex domain) 2. `DOMAIN_SUFFIX` (Secondary routing suffix fallback) @@ -279,7 +279,7 @@ Every operation lifecycle event is emitted as a structured JSON object to `audit "timestamp": "2026-10-13T18:32:05.112Z", "phase": "COMPLETED", "principal": { - "identity": "kiskaadee", + "identity": "operator", "role": "homelab-admin", "token_id": "tok_99fa1b", "auth_method": "bearer_token" diff --git a/docs/secrets-and-state.md b/docs/secrets-and-state.md index 941a2a3..f30b6e4 100644 --- a/docs/secrets-and-state.md +++ b/docs/secrets-and-state.md @@ -43,7 +43,7 @@ This document explains the secrets distribution architecture, runtime projection ### A. Core Platform Environment (`/run/secrets/homeserver.env`) Generated by `nixos/modules/homeserver.nix`. Supplies credentials to the Core Compose stack: -* `DOMAIN`: Apex domain (`roadtotech.me`). +* `DOMAIN`: Apex domain (e.g., `example.com`). * `DYNU_API_KEY`: API key for Dynu DNS-01 ACME Let's Encrypt validation. * `ACME_EMAIL`: Account email for Let's Encrypt certificates. * `AUTHELIA_SESSION_SECRET`: Authelia cookie encryption secret. @@ -98,7 +98,7 @@ sudo nixos-rebuild switch --flake ~/Core#server Homelab Core separates **user identity** from **static platform secrets**: * **Static Secrets**: Stored in `nixos/secrets.yaml` (system API keys, JWT secrets, database passwords). -* **Dynamic User Directory**: User accounts, credentials, and group memberships are managed live in **LLDAP** (`https://users.roadtotech.me`). 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`. --- @@ -114,7 +114,7 @@ Homelab Core separates **user identity** from **static platform secrets**: | **User Directory** | `~/Core/config/lldap/data/` | ❌ No | LLDAP SQLite database (`users.db`) | | **Auth Database** | `~/Core/config/authelia/db.sqlite3` | ❌ No | Authelia session database | | **Mail Data & Keys** | `~/Core/config/stalwart/` | ❌ No | Stalwart mail storage, DKIM keys, mailboxes | -| **Webmail Storage** | `~/Core/config/snappymail/data/` | ❌ No | SnappyMail configuration and sessions | +| **Workload State Root** | `~/var/lib/homelab//` | ❌ No | Per-workload persistent runtime state (e.g., `snappymail`) | | **Container Volumes** | Docker volume `dozzle_data` | ❌ No | Dozzle UI preferences and state | | **DDNS History** | `/var/lib/dynu/ip_history.jsonl` | ❌ No | Historical WAN IP transitions log | | **GitOps State** | `~/.local/state/homelab/gitops/` | ❌ No | Deployment locks, pending JSONs, status logs | diff --git a/docs/setup_guide.md b/docs/setup_guide.md index fca4b96..e684339 100644 --- a/docs/setup_guide.md +++ b/docs/setup_guide.md @@ -12,10 +12,10 @@ When provisioning bare-metal hardware or a virtual machine from a NixOS Minimal 1. Partition and format disks according to `nixos/hardware-configuration.nix` (e.g. boot EFI partition and root filesystem). 2. Mount partitions under `/mnt`. 3. **Restore Host Secrets Key**: Copy the host SSH private key to `/mnt/etc/ssh/ssh_host_ed25519_key` (mode `0600`). This is required because `sops-nix` decrypts `nixos/secrets.yaml` during system activation. -4. Clone the Core repository to `/mnt/home/kiskaadee/Core`. +4. Clone the Core repository to `/mnt/home//Core`. 5. Run the NixOS installer: ```bash - nixos-install --flake /mnt/home/kiskaadee/Core#server + nixos-install --flake /mnt/home//Core#server reboot ``` @@ -69,7 +69,7 @@ docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" ``` ### Step 6: Initialize LLDAP Directory -1. Navigate to `https://users.roadtotech.me`. +1. Navigate to `https://users.${HOMELAB_DOMAIN}` (e.g., `https://users.example.com`). 2. Authenticate using `admin` and the password configured in `nixos/secrets.yaml` (`lldap/admin_password`). 3. Create standard user accounts and assign them to required groups. @@ -89,10 +89,11 @@ git init ### Step 2: Create `app.yaml` Manifest Create `~/Sites/homelab-myapp/app.yaml`: ```yaml +schema_version: "1.0" name: "myapp" aliases: - "app" -domain: "myapp.roadtotech.me" +domain: "myapp.example.com" description: "My New Application Service" visible: true auth: false @@ -104,6 +105,7 @@ env: deployment: branch: "main" + strategy: "compose" actions: - git_pull - compose_up diff --git a/tests/security/test_security_invariants.py b/tests/security/test_security_invariants.py index 08755ec..ba093dc 100644 --- a/tests/security/test_security_invariants.py +++ b/tests/security/test_security_invariants.py @@ -163,23 +163,32 @@ exit 0 def test_platform_genericism_no_hardcoded_personal_domains_in_scripts_and_tests(): - - """Ensure personal domains and operator usernames are absent from scripts and test files.""" + """Ensure personal domains and operator usernames are absent from scripts, tests, and documentation.""" forbidden = ["roadtotech.me", "kiskaadee"] - root_dirs = [CORE_ROOT / "scripts", CORE_ROOT / "tests"] + root_dirs = [CORE_ROOT / "scripts", CORE_ROOT / "tests", CORE_ROOT / "docs"] + root_files = [ + CORE_ROOT / "README.md", + CORE_ROOT / "ROADMAP.md", + CORE_ROOT / "AGENTS.md", + CORE_ROOT / "SECURITY.md", + CORE_ROOT / "flake.nix", + ] violations = [] + candidate_files = list(root_files) for root_dir in root_dirs: - for file_path in root_dir.rglob("*"): - if ( - file_path.is_file() - and file_path.suffix in (".py", ".sh", ".bash", ".yml", ".yaml", "") - and file_path.name != "test_security_invariants.py" - ): - content = file_path.read_text(encoding="utf-8", errors="ignore") - for term in forbidden: - if term in content: - violations.append(f"{file_path.relative_to(CORE_ROOT)}: contains prohibited literal '{term}'") + candidate_files.extend(root_dir.rglob("*")) + + for file_path in candidate_files: + if ( + file_path.is_file() + and file_path.suffix in (".py", ".sh", ".bash", ".yml", ".yaml", ".md", ".nix", "") + and file_path.name != "test_security_invariants.py" + ): + content = file_path.read_text(encoding="utf-8", errors="ignore") + for term in forbidden: + if term in content: + violations.append(f"{file_path.relative_to(CORE_ROOT)}: contains prohibited literal '{term}'") assert not violations, "Platform genericism violations detected:\n" + "\n".join(violations)