- Implement scripts/bootstrap_token.py generating 256-bit token with 0600 mode - Enforce parent directory 0700 mode and refuse overwrite without --force - Output SHA-256 JSON descriptor matching TokenDescriptor for SOPS tokens_json - Ensure zero plaintext secret leakage to stdout/stderr - Document token bootstrapping, SOPS configuration, and rotation in docs/appctl.md - Update control plane token store section in docs/secrets-and-state.md - Add 10 unit tests covering API, permissions, and CLI paths - Mark item completed in todo.txt and p4-refactor-and-decoupling-plan.md Closes #12 Refs #12
6.9 KiB
6.9 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
- Core modules in
nixos/modules/remain strictly generic, defaulting to RFC 2606 placeholders (example.test). nixos/configuration.nixserves as the appliance instance profile wherehomelab.domainandhomelab.operatorUserare explicitly set (e.g., using the host's configured production domain).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.
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.