8.3 KiB
8.3 KiB
📋 Implementation Plan: Control Plane Hardening, Instance Decoupling & MCP Alignment
Document Version: 1.0
Status: 🚀 Approved for Implementation
Date: 2026-10-23
Target Milestone: P4 Hardening & P6 Deprecation
Branch: refactor/appctl-rework
1. Executive Summary & Context
During the pre-merge readiness investigation of the refactor/appctl-rework branch, four deployment blockers and several architectural divergences were identified:
- Unconfigured Root Domain:
options.homelab.domaindefaulted to"example.test", which would overwrite live routing templates (homeserver.env,traefik-deployments.env) uponnixos-rebuild switch. - Authelia/LLDAP Base DN Desynchronization: Compose defaulted
LLDAP_LDAP_BASE_DNtodc=example,dc=test, conflicting with the existing on-host LLDAP database (dc=<domain-prefix>,dc=<tld>). - Operator Identity Coupling: Core configurations referenced legacy operator username literals rather than a generic system operator (
operator). - POSIX ACL & Git Dubious Ownership:
tmpfiles.rulesused lowercasea+(non-recursive), leaving existing checkouts in~/Sitesunwriteable tohomelab-appctl. Furthermore, Git 2.35.2+ lackedsafe.directorydeclarations forhomelab-appctl. - AI Authoring Boundary Evolution: Earlier architectural planning explored an on-server 5-stage deployment authoring pipeline (
ApplicationProfile\toDeploymentProposal\toDeploymentModelcompiler). This requirement is formally deprecated in favor of a decoupled Model Context Protocol (MCP) tool gateway.
This plan establishes the concrete implementation work packages to resolve these findings and ensure 100% deployment safety.
2. Architectural Decisions & Scope
A. Operator Identity Decoupling (Legacy Operator \to operator)
- Standardize the primary platform operator as
operatorwith home directory/home/operator. config.homelab.operatorUserdefaults to"operator".- NixOS declares user
operator(uid = 1000or standard user,extraGroups = [ "wheel" "docker" "homelab-operators" "networkmanager" ]). - Eliminates hardcoded personal usernames from the Core platform foundation.
B. Platform Genericism & Instance Profile (Decision D1)
- Core modules in
nixos/modules/remain strictly generic, defaulting to RFC 2606 placeholders (example.testandoperator). - Decision D1: Dual-Path Instance Domain Injection: Rather than committing host-specific production domains to tracked Git files,
nixos/configuration.niximplements an optional dual-path import mechanism:imports = [ ./hardware-configuration.nix ./modules/homeserver.nix ./modules/traefik-deployments.nix ./modules/dynu.nix ./modules/shell.nix ] ++ lib.optional (builtins.pathExists ./instance.nix) ./instance.nix ++ lib.optional (builtins.pathExists /etc/nixos/homelab-instance.nix) /etc/nixos/homelab-instance.nix; nixos/instance.nixis git-ignored, allowing host-specific overrides (likehomelab.domain = "example.com";) without dirtying version control. Alternatively,/etc/nixos/homelab-instance.nixprovides a persistent host-level configuration path outside the repository checkout.LLDAP_LDAP_BASE_DNis computed dynamically in Nix fromconfig.homelab.domain(domain: example.test\impliesdc=example,dc=test), eliminating hardcoded domain strings across templates and Compose files.
C. Control Plane Security & POSIX Permissions
- Recursive ACLs: Change
a+to uppercaseA+for${config.homelab.sitesDir}and${config.homelab.coreDir}/config/homepageinsystemd.tmpfiles.rules. - Git Safe Directory: Configure
programs.git.config.safe.directory = [ "/home/operator/Sites/*" ]for the host. - Fail-Closed CLI: If
/run/homelab/appctl.sockis unavailable,scripts/appctlfails closed with an informative error rather than silently falling back to unauthenticated Bash execution. - CLI Status Restoration: Restore live container inspection (
get_docker_status()) inworkload.listand format theSTATUScolumn inscripts/appctl_cli.py.
D. Deprecation of On-Server AI Authoring Pipeline (MCP Gateway Adoption)
- As documented in
~/Brain/02-discussions/homelab/mcp-gateway-and-platform-evolution.md, on-server AI deployment agents (DeploymentProposalcompilers) are deprecated. - Milestone P6 is redefined as the Homelab MCP Gateway:
- Exposes deterministic
appctloperations over JSON-RPC Model Context Protocol tools (appctl_status,appctl_deploy,appctl_logs,appctl_audit). - Gated by native client-side human confirmation (Antigravity, Claude Code, Cursor).
- Keeps Core 100% deterministic with zero autonomous agent loops executing on the appliance host.
- Exposes deterministic
3. Work Breakdown Structure (WBS)
Phase 1: Host Configuration & Identity Migration
- Task 1.1: Update
nixos/configuration.nixto declare useroperatorand configurehomelab.operatorUser = "operator"andhomelab.domainwith the configured production domain. - Task 1.2: Declare
programs.git.config.safe.directory = [ "/home/operator/Sites/*" ]innixos/configuration.nix. - Task 1.3: Derive
LLDAP_LDAP_BASE_DNdynamically fromconfig.homelab.domaininnixos/modules/homeserver.nixand pass it tosops.templates."homeserver.env". - Task 1.4: Update
docker-compose.ymlto consumeLLDAP_LDAP_BASE_DNfromhomeserver.env. - Task 1.5: Update
systemd.tmpfiles.rulesinnixos/modules/homeserver.nixfroma+to recursiveA+onsitesDir.
Phase 2: CLI Hardening & Status Parity
- Task 2.1: Update
scripts/appctlto fail closed when[ ! -S "$SOCKET_PATH" ], removing the silent fallback to legacy Bash. - Task 2.2: Update
_op_workload_listinscripts/appctl_router.pyto query live container health (get_docker_status()). - Task 2.3: Update
_format_workload_tableinscripts/appctl_cli.pyto render theSTATUScolumn (🟢 Running (1)/🔴 Stopped). - Task 2.4: Bootstrap operator admin token documentation and setup instructions in
docs/appctl.mdanddocs/secrets-and-state.md. - Task 2.5: Wire
--buildand--no-cacheinscripts/appctl_cli.py, pass--pullduringcompose_buildinscripts/appctl_router.py, and document source-built action policy indocs/appctl.md.
Phase 3: Architectural Records & Roadmap Synchronization
- Task 3.1: Update
ROADMAP.md(P6 redefined as Homelab MCP Gateway; on-server AI compiler deprecated). - Task 3.2: Add architectural amendment note to
docs/decisions/0002-appctl-control-plane-architecture.md. - Task 3.3: Update
docs/decisions/README.md. - Task 3.4: Update
docs/appctl.md(clarifying bounded log snapshots and Core update workflow). - Task 3.5: Synchronize
todo.txtwith active implementation tasks.
Phase 4: Work Package 6 (WP6: Instance Decoupling & Operator Cutover Runbook)
- Task 4.1: Update
nixos/configuration.nixwith optional dual-path imports for./instance.nixand/etc/nixos/homelab-instance.nix(Decision D1). - Task 4.2: Add
nixos/instance.nixto.gitignoreto preserve 100% repository genericism. - Task 4.3: Implement automated invariant tests in
tests/security/test_security_invariants.py(default domain evaluation, dynamic LDAP base DN, instance override, platform genericism). - Task 4.4: Document instance domain injection procedure in
docs/setup_guide.md. - Task 4.5: Codify the 4-stage Staged Coexistence Cutover Runbook (Decision D2) in
docs/operations.mdwith explicit notice blocking live host execution pending maintenance window.
4. Verification & Quality Gates
The implementation must pass:
- Static Analysis & Linting:
ruff check .andpyright(0 errors, 0 warnings). - Full Regression Suite: All 283 existing unit, security, and invariant tests passing.
- New Test Coverage:
- Assert dynamic LDAP base DN computation from domain.
- Assert
scripts/appctlfails closed when socket is absent. - Assert
appctl listoutput formatting includes container status. - Assert platform genericism invariants across updated Nix modules.
- Hermetic Flake Check:
nix flake checkbuilds cleanly. - NixOS Evaluation:
nix eval .#nixosConfigurations.server.config.system.build.toplevel.drvPathevaluates without warnings.