diff --git a/projects/homelab/README.md b/projects/homelab/README.md index 229fff4..c7a2f5a 100644 --- a/projects/homelab/README.md +++ b/projects/homelab/README.md @@ -58,6 +58,7 @@ Implementation roadmaps currently in progress (`status: active`) that are active 1. 🟑 [**Architecture Consolidation & Hardening Roadmap v2**](plans/architecture-consolidation-roadmap-v2.md) `[Active]` - Formalizing the three-layer architectural model, closing the GitOps trust boundary, codifying `app.yaml` v1 schema contracts, and establishing machine-enforced invariants. + - πŸ“‹ *Execution Guide*: [**Architecture Consolidation Implementation Guide**](plans/architecture-consolidation-implementation-guide.md) 2. 🟑 [**Rust Daemon Migration Plan: Standalone `dynu-monitor`**](plans/dynu-monitor-rust-daemon.md) `[Active]` - Implementing a standalone Rust daemon with 30-second polling and round-robin public DNS resolution across 5 independent providers (Cloudflare, Quad9, Google, OpenDNS, Dynu). 3. 🟑 [**Custom API Security Hardening & Threat Analysis**](plans/api-security-hardening.md) `[Active]` @@ -96,13 +97,13 @@ Archived and foundational documentation for completed milestones: * [**Dynu DDNS Polling Frequency and Rust Migration**](discussions/dynu-monitor-polling-and-language-tradeoffs.md) β€” Investigated polling intervals and language trade-offs; resolved via `dynu-monitor-rust-daemon.md` plan. ### Completed Plans -* 🟒 [**Architecture Consolidation & Hardening Roadmap v1**](plans/architecture-consolidation-roadmap.md) (Superseded by v2) -* 🟒 [**Turn `homelab-core` into a Declarative NixOS Appliance**](plans/nixos-appliance-migration.md) -* 🟒 [**Core & Sites Cutover and Testing Plan**](plans/appctl/core-sites-cutover-testing-plan.md) -* 🟒 [**appctl Refactor & Decentralized `app.yaml` Metadata Architecture**](plans/appctl/refactor-and-metadata-sync.md) -* 🟒 [**appctl Git Synchronization & Full-Stack Lifecycle Strategy**](plans/appctl/git-sync-and-lifecycle.md) +* 🟒 [**Architecture Consolidation & Hardening Roadmap v1**](archive/architecture-consolidation-roadmap.md) (Superseded by v2) +* 🟒 [**Turn `homelab-core` into a Declarative NixOS Appliance**](archive/nixos-appliance-migration.md) +* 🟒 [**Core & Sites Cutover and Testing Plan**](archive/core-sites-cutover-testing-plan.md) +* 🟒 [**appctl Refactor & Decentralized `app.yaml` Metadata Architecture**](archive/refactor-and-metadata-sync.md) +* 🟒 [**appctl Git Synchronization & Full-Stack Lifecycle Strategy**](archive/git-sync-and-lifecycle.md) * 🟒 [**CI/CD & Deployment Strategy**](plans/gitea/deployment-and-cicd-strategy.md) -* 🟒 [**Real-Time Brain Synchronization & Gitea Push Mirroring**](plans/gitea/brain-sync-and-gitea-mirroring.md) -* 🟒 [**NixOS Server & Laptop Migration**](plans/server-24-7/nixos-server-laptop-migration.md) -* 🟒 [**Domain Migration (`roadtotech.me`)**](plans/server-24-7/domain-migration-roadtotech.md) +* 🟒 [**Real-Time Brain Synchronization & Gitea Push Mirroring**](archive/brain-sync-and-gitea-mirroring.md) +* 🟒 [**NixOS Server & Laptop Migration**](archive/nixos-server-laptop-migration.md) +* 🟒 [**Domain Migration (`roadtotech.me`)**](archive/domain-migration-roadtotech.md) * 🟒 [**Production Folder Structure Reorganization**](plans/server-24-7/folder-structure-reorganization.md) diff --git a/projects/homelab/plans/architecture-consolidation-roadmap.md b/projects/homelab/archive/architecture-consolidation-roadmap.md similarity index 99% rename from projects/homelab/plans/architecture-consolidation-roadmap.md rename to projects/homelab/archive/architecture-consolidation-roadmap.md index de1517d..cac5373 100644 --- a/projects/homelab/plans/architecture-consolidation-roadmap.md +++ b/projects/homelab/archive/architecture-consolidation-roadmap.md @@ -13,7 +13,7 @@ tags: # Architectural Discussion & Phased Implementation Plan: Homelab Core Appliance > [!NOTE] -> Superseded by [Architecture Consolidation & Hardening Roadmap v2](architecture-consolidation-roadmap-v2.md). +> Superseded by [Architecture Consolidation & Hardening Roadmap v2](../plans/architecture-consolidation-roadmap-v2.md). ## Executive Summary diff --git a/projects/homelab/plans/gitea/brain-sync-and-gitea-mirroring.md b/projects/homelab/archive/brain-sync-and-gitea-mirroring.md similarity index 94% rename from projects/homelab/plans/gitea/brain-sync-and-gitea-mirroring.md rename to projects/homelab/archive/brain-sync-and-gitea-mirroring.md index e85a90f..1c2ea5b 100644 --- a/projects/homelab/plans/gitea/brain-sync-and-gitea-mirroring.md +++ b/projects/homelab/archive/brain-sync-and-gitea-mirroring.md @@ -18,7 +18,7 @@ The **Brain** repository (`~/Brain`) is an actively edited, durable personal kno ### Core Pipeline Invariants: 1. **The Curation Boundary**: Raw thoughts and scratch captures stay in `inbox/` (uncommitted, unvalidated, zero-friction). Once moved to their semantic home (`knowledge/`, `projects/`, `records/`, `practice/`), they join the committed graph. -2. **Local Schema Integrity Gate**: Every commit is verified locally by [`scripts/validate-brain.py`](../../../../scripts/validate-brain.py) via a `pre-commit` hook to ensure valid metadata and prevent broken relative links. +2. **Local Schema Integrity Gate**: Every commit is verified locally by [`scripts/validate-brain.py`](../../../scripts/validate-brain.py) via a `pre-commit` hook to ensure valid metadata and prevent broken relative links. 3. **Instant Zero-Delay Auto-Push**: A resilient `post-commit` hook automatically pushes commits to the primary self-hosted Gitea forge (`gitea.roadtotech.me`), falling back gracefully if offline. 4. **Automated Cloud Replication**: Gitea natively push-mirrors every commit to GitHub (`github.com/kiskaadee/second-brain`) immediately on receive. 5. **Server-Side CI & Observability**: Gitea Actions validates graph health on every push asynchronously without blocking editing or live rendering. @@ -150,5 +150,5 @@ Configured under repository **Settings** $\rightarrow$ **Repository** $\rightarr --- ## πŸ”— Related Production Guides -* [Brain GitOps & Auto-Sync Deployment Pipeline](../../guides/brain-gitops-deployment-pipeline.md) -* [Dynamic Decentralized GitOps Dispatcher Architecture](../../discussions/gitops-dispatcher-architecture.md) +* [Brain GitOps & Auto-Sync Deployment Pipeline](../guides/brain-gitops-deployment-pipeline.md) +* [Dynamic Decentralized GitOps Dispatcher Architecture](../discussions/gitops-dispatcher-architecture.md) diff --git a/projects/homelab/plans/appctl/core-sites-cutover-testing-plan.md b/projects/homelab/archive/core-sites-cutover-testing-plan.md similarity index 100% rename from projects/homelab/plans/appctl/core-sites-cutover-testing-plan.md rename to projects/homelab/archive/core-sites-cutover-testing-plan.md diff --git a/projects/homelab/plans/server-24-7/domain-migration-roadtotech.md b/projects/homelab/archive/domain-migration-roadtotech.md similarity index 100% rename from projects/homelab/plans/server-24-7/domain-migration-roadtotech.md rename to projects/homelab/archive/domain-migration-roadtotech.md diff --git a/projects/homelab/plans/appctl/git-sync-and-lifecycle.md b/projects/homelab/archive/git-sync-and-lifecycle.md similarity index 98% rename from projects/homelab/plans/appctl/git-sync-and-lifecycle.md rename to projects/homelab/archive/git-sync-and-lifecycle.md index c2f86cf..a4e93e5 100644 --- a/projects/homelab/plans/appctl/git-sync-and-lifecycle.md +++ b/projects/homelab/archive/git-sync-and-lifecycle.md @@ -93,4 +93,4 @@ appctl update --all --- ## πŸ”— Production Guide -* [Homelab Architecture: Appctl & Decentralized Repositories](../../guides/appctl-operations-and-manifest-guide.md) +* [Homelab Architecture: Appctl & Decentralized Repositories](../guides/appctl-operations-and-manifest-guide.md) diff --git a/projects/homelab/plans/nixos-appliance-migration.md b/projects/homelab/archive/nixos-appliance-migration.md similarity index 100% rename from projects/homelab/plans/nixos-appliance-migration.md rename to projects/homelab/archive/nixos-appliance-migration.md diff --git a/projects/homelab/plans/server-24-7/nixos-server-laptop-migration.md b/projects/homelab/archive/nixos-server-laptop-migration.md similarity index 100% rename from projects/homelab/plans/server-24-7/nixos-server-laptop-migration.md rename to projects/homelab/archive/nixos-server-laptop-migration.md diff --git a/projects/homelab/plans/appctl/refactor-and-metadata-sync.md b/projects/homelab/archive/refactor-and-metadata-sync.md similarity index 98% rename from projects/homelab/plans/appctl/refactor-and-metadata-sync.md rename to projects/homelab/archive/refactor-and-metadata-sync.md index deb6a0a..4b445db 100644 --- a/projects/homelab/plans/appctl/refactor-and-metadata-sync.md +++ b/projects/homelab/archive/refactor-and-metadata-sync.md @@ -88,4 +88,4 @@ All 11 homelab applications will include an `app.yaml` defining their identity, --- ## πŸ”— Production Guide -* [Homelab Architecture: Appctl & Decentralized Repositories](../../guides/appctl-operations-and-manifest-guide.md) +* [Homelab Architecture: Appctl & Decentralized Repositories](../guides/appctl-operations-and-manifest-guide.md) diff --git a/projects/homelab/guides/appctl-operations-and-manifest-guide.md b/projects/homelab/guides/appctl-operations-and-manifest-guide.md index 116bc6f..17d940c 100644 --- a/projects/homelab/guides/appctl-operations-and-manifest-guide.md +++ b/projects/homelab/guides/appctl-operations-and-manifest-guide.md @@ -135,6 +135,6 @@ jellyfin 🟒 Running (1) βœ“ Synced jellyfin.roadtotech.me --- ## πŸ”— Related Plans & Implementation Runbooks -- [Core & Sites Cutover and Testing Plan](../plans/appctl/core-sites-cutover-testing-plan.md) β€” Completed zero-downtime cutover runbook from `~/Deployments` to `~/Core` and `~/Sites`. -- [appctl Refactor & Metadata Sync Plan](../plans/appctl/refactor-and-metadata-sync.md) β€” Architectural design for `app.yaml` manifests and Homepage auto-compilation. -- [appctl Git Synchronization & Lifecycle Plan](../plans/appctl/git-sync-and-lifecycle.md) β€” Design specification for Git tracking badges, `--fetch`, and `appctl update`. +- [Core & Sites Cutover and Testing Plan](../archive/core-sites-cutover-testing-plan.md) β€” Completed zero-downtime cutover runbook from `~/Deployments` to `~/Core` and `~/Sites`. +- [appctl Refactor & Metadata Sync Plan](../archive/refactor-and-metadata-sync.md) β€” Architectural design for `app.yaml` manifests and Homepage auto-compilation. +- [appctl Git Synchronization & Lifecycle Plan](../archive/git-sync-and-lifecycle.md) β€” Design specification for Git tracking badges, `--fetch`, and `appctl update`. diff --git a/projects/homelab/plans/architecture-consolidation-implementation-guide.md b/projects/homelab/plans/architecture-consolidation-implementation-guide.md new file mode 100644 index 0000000..04709aa --- /dev/null +++ b/projects/homelab/plans/architecture-consolidation-implementation-guide.md @@ -0,0 +1,1277 @@ +--- +type: plan +status: active +project: homelab +tags: + - homelab + - architecture + - gitops + - security + - implementation +--- + +# Homelab Core β€” Architecture Consolidation & Hardening Implementation Guide + +This guide turns the [Architecture Consolidation & Hardening Roadmap v2](architecture-consolidation-roadmap-v2.md) into an executable sequence of work. + +The objective is not to introduce new infrastructure. It is to make the existing system's trust boundaries, contracts, deployment behavior, and recovery semantics explicit and machine-enforced. + +--- + +# 0. Working Rules + +Before starting the implementation, establish four rules for the entire refactor. + +## Rule 1 β€” One architectural change at a time + +Each deliverable should have a small, independently reviewable commit or commit series. + +Avoid combining: + +- GitOps security changes +- manifest redesign +- NixOS privilege changes +- documentation migration + +into one large commit. + +--- + +## Rule 2 β€” Preserve behavior unless the deliverable explicitly changes it + +The refactor should distinguish: + +- **security changes** +- **contract changes** +- **behavioral changes** +- **documentation changes** + +For example, replacing: + +```yaml +actions: + - git_pull + - compose_up +``` + +with: + +```yaml +deployment: + strategy: compose +``` + +is intentionally a contract change. + +Moving a secret declaration between NixOS modules should not change runtime behavior. + +--- + +## Rule 3 β€” The repository is the source of truth + +Before implementing a deliverable, inspect the actual consumers. + +Do not assume a field is unused because it is not documented. + +For every migration: + +```text +producer β†’ parser β†’ consumer β†’ runtime behavior +``` + +must be identified. + +--- + +## Rule 4 β€” Every deliverable finishes with a proof + +Each implementation should end with at least one reproducible verification command. + +Examples: + +```bash +python -m pytest +``` + +```bash +nix flake check +``` + +```bash +docker compose config -q +``` + +or: + +```bash +git grep ... +``` + +A completed change should be demonstrably correct, not merely plausible. + +--- + +# 1. P0 β€” GitOps Trust Boundary + +The first objective is to turn GitOps from a remotely triggerable command executor into a constrained deployment admission pipeline. + +The current threat chain is: + +```text +repository modification + ↓ +app.yaml + ↓ +webhook + ↓ +dispatcher + ↓ +shell execution + ↓ +kiskaadee + ↓ +Docker / sudo + ↓ +host +``` + +The roadmap explicitly identifies this as the highest-risk vulnerability. + +## Deliverable 1.1 β€” Remove arbitrary `custom` execution + +### Step 1 β€” Inventory current custom consumers + +Search every application manifest: + +```bash +find ~/Sites -name app.yaml -print0 | + xargs -0 grep -n "custom:" +``` + +Also search the Core repository: + +```bash +git grep -n "custom" +git grep -n "shell=True" +git grep -n "subprocess.run" +``` + +Record every existing consumer before changing the dispatcher. + +The roadmap already identifies `homelab-magnetflix` as a known consumer. + +### Step 2 β€” Decide the replacement for each consumer + +For every `custom` command, classify it: + +```text +normal deployment operation + β†’ built-in deployment behavior + +database migration + β†’ explicit lifecycle mechanism + +one-off administrative command + β†’ manual operator action + +unsupported behavior + β†’ remove +``` + +Do not create a generic replacement such as: + +```yaml +post_deploy: + command: "..." +``` + +That simply recreates the vulnerability with a different name. + +### Step 3 β€” Remove `custom` from the dispatcher + +Delete the code path that eventually reaches: + +```python +subprocess.run(cmd, shell=True, ...) +``` + +Then make unsupported action values fail closed: + +```text +unknown action β†’ deployment rejected +``` + +### Step 4 β€” Migrate MagnetFlix + +Replace its current custom migration mechanism with the explicitly approved mechanism chosen above. + +Deploy MagnetFlix manually once to prove the replacement works. + +### Step 5 β€” Add a regression test + +Create a test proving that a manifest containing: + +```yaml +custom: "..." +``` + +cannot result in command execution. + +### Exit condition + +The following must be true: + +```bash +git grep -n "shell=True" scripts/gitops_dispatcher.py +``` + +returns nothing relevant, and no manifest can provide arbitrary shell input. + +--- + +# 2. Deliverable 1.2 β€” Trusted Repository Resolution + +The webhook payload must identify a repository by **logical identity**, not by filesystem path. Core resolves that identity locally. + +## Step 1 β€” Define the trusted mapping + +Decide what constitutes the canonical repository identity. + +For example: + +```text +homelab-docs +homelab-gitea +homelab-magnetflix +``` + +Map those identities to known directories under: + +```text +/home/kiskaadee/Sites/ +``` + +The important property is: + +```text +payload β†’ name β†’ trusted mapping β†’ local path +``` + +never: + +```text +payload β†’ path +``` + +## Step 2 β€” Implement one resolver + +Create one function responsible for: + +```python +resolve_repository(name) -> trusted repository +``` + +Every deployment must use it. + +Do not allow callers to construct paths independently. + +## Step 3 β€” Canonicalize the resolved path + +After resolution: + +```python +realpath(target) +``` + +must still be checked against the allowed root. + +This remains defense in depth rather than the primary trust mechanism. + +## Step 4 β€” Test traversal and ambiguity + +Reject: + +```text +../../foo +/home/foo +/etc +symlink escapes +unknown repositories +``` + +Test both malicious and valid names. + +### Exit condition + +A webhook can select only repositories explicitly recognized by Core. + +--- + +# 3. Deliverable 1.3 β€” Webhook Authentication + +The roadmap specifies HMAC-SHA256 using `X-Gitea-Signature`, with the secret stored via SOPS and projected through `/run/secrets/`. + +## Step 1 β€” Obtain the exact incoming request representation + +Before implementing verification, establish exactly what bytes the signature covers: + +```text +HTTP body +``` + +Do not verify a reconstructed or parsed JSON object. + +Signature verification must operate on the original request body. + +## Step 2 β€” Store the webhook secret + +Add a dedicated secret to SOPS. + +Do not place it in: + +```text +app.yaml +docker-compose.yml +gitops_dispatcher.py +``` + +Project it to the service at runtime. + +## Step 3 β€” Implement verification + +Verification should: + +1. read the raw body +2. read the signature header +3. calculate HMAC-SHA256 +4. compare using a constant-time comparison +5. reject invalid requests before deployment + +Conceptually: + +```text +request + ↓ +read raw body + ↓ +calculate HMAC + ↓ +constant-time compare + ↓ +valid β†’ continue +invalid β†’ reject +``` + +## Step 4 β€” Reject missing signatures + +These are failures: + +```text +no signature +malformed signature +wrong signature +empty secret +``` + +There should be no anonymous fallback. + +## Step 5 β€” Test + +Create tests for: + +```text +valid signature +invalid signature +missing signature +modified body +modified signature +``` + +### Exit condition + +No unauthenticated request can reach deployment admission. + +--- + +# 4. Deliverable 1.4 β€” Repository, Event, and Branch Admission + +Authentication answers: + +> Who sent this? + +It does not answer: + +> Should this request be deployed? + +The admission layer must validate the repository, event/ref, and branch policy before execution. + +## Step 1 β€” Define accepted event semantics + +Document which webhook events are deployable. + +For example: + +```text +push β†’ eligible +pull_request β†’ rejected +tag β†’ rejected unless explicitly supported +``` + +Use the actual webhook payload structure rather than assuming every event is equivalent. + +## Step 2 β€” Validate repository identity + +Verify: + +```text +payload repository + ↓ +trusted repository mapping +``` + +Reject unknown repositories. + +## Step 3 β€” Validate the branch + +Determine the branch from the manifest: + +```yaml +deployment: + branch: main +``` + +with: + +```text +default = main +``` + +Then require the incoming ref to match the declared policy. + +## Step 4 β€” Validate manifest before execution + +The manifest must be parsed and validated before Git or Docker actions occur. + +The roadmap explicitly places manifest validation inside the admission pipeline. + +### Exit condition + +An authenticated request still gets rejected if: + +```text +wrong repository +wrong event +wrong branch +invalid manifest +unsupported strategy +``` + +--- + +# 5. Deliverable 1.5 β€” Serialized Deployment + +The desired behavior is: + +```text +A arrives β†’ deploy A +B arrives β†’ queue B +C arrives β†’ replace B +A finishes β†’ deploy C +``` + +rather than attempting every intermediate revision. + +## Step 1 β€” Identify deployment targets + +Serialization should be per application/repository. + +Two unrelated applications should be able to deploy independently. + +## Step 2 β€” Choose filesystem-level synchronization + +Use a simple mechanism such as: + +```text +flock +``` + +or a systemd-managed worker. + +Do not add Redis, RabbitMQ, or another message broker. + +## Step 3 β€” Separate admission from execution + +The HTTP request should not perform: + +```text +git pull +docker compose pull +docker compose up +``` + +Instead: + +```text +HTTP request + ↓ +validate + ↓ +enqueue latest desired revision + ↓ +return +``` + +Then: + +```text +worker + ↓ +take target + ↓ +deploy +``` + +This directly addresses the roadmap's asynchronous-dispatch requirement. + +## Step 4 β€” Implement superseding + +Maintain at most: + +```text +one active deployment +one pending deployment +``` + +When a newer valid request arrives: + +```text +pending old revision β†’ replaced +pending new revision β†’ retained +``` + +## Step 5 β€” Test race behavior + +Simulate: + +```text +A starts +B arrives +C arrives +A finishes +``` + +and verify that: + +```text +B is skipped +C is deployed +``` + +### P0 exit condition + +The complete flow is now: + +```text +webhook + ↓ +cryptographic verification + ↓ +repository admission + ↓ +event/ref admission + ↓ +manifest validation + ↓ +deployment scheduling + ↓ +serialized executor + ↓ +closed deployment strategy +``` + +This is the first major milestone. + +--- + +# 6. P1 β€” Manifest Contract v1 + +The manifest currently functions as an informal configuration format. The goal is to turn it into a strict API contract. + +Do this only after the P0 trust boundary is established. + +--- + +## Deliverable 2.1 β€” Write the Manifest Specification First + +Do not begin by writing JSON Schema. + +Begin with a human specification. + +Create: + +```text +docs/architecture/manifest-specification.md +``` + +Define: + +### Required fields + +For example: + +```yaml +schemaVersion +name +domain +``` + +### Optional fields + +For example: + +```yaml +title +description +aliases +visible +auth +networks +env +deployment +homepage +``` + +### Types + +Explicitly define: + +```text +name β†’ string +aliases β†’ array[string] +visible β†’ boolean +networks β†’ array[string] +env β†’ mapping[string,string] +``` + +### Defaults + +Document defaults explicitly. + +### Allowed values + +For example: + +```yaml +deployment.strategy: + compose +``` + +### Cross-field constraints + +Examples: + +```text +auth=true may require the proxy network +deployment.strategy must be supported +domain must be unique +name must be unique +``` + +### Security constraints + +Explicitly prohibit: + +```text +arbitrary commands +filesystem paths +Docker socket access +privileged deployment directives +``` + +The manifest must describe application intent, not host capabilities. + +--- + +# 7. Deliverable 2.2 β€” Create JSON Schema v1 + +Create: + +```text +schemas/app-v1.schema.json +``` + +Start from the written specification. + +Include: + +```text +$schema +$id +title +type +required +properties +additionalProperties +``` + +Prefer rejecting unknown fields rather than silently accepting them. + +The roadmap deliberately makes JSON Schema the normative external contract and Pydantic the runtime enforcement mechanism. + +## Step-by-step + +1. encode primitive types +2. encode required fields +3. encode defaults +4. encode enumerations +5. encode nested objects +6. add security restrictions +7. add cross-field constraints where supported +8. write valid examples +9. write invalid examples + +Create fixtures such as: + +```text +tests/fixtures/manifests/valid/ +tests/fixtures/manifests/invalid/ +``` + +--- + +# 8. Deliverable 2.3 β€” Introduce `schemaVersion` + +Every application manifest becomes: + +```yaml +schemaVersion: 1 +``` + +Core must reject: + +```yaml +schemaVersion: 2 +``` + +and missing `schemaVersion` unless a future compatibility policy explicitly says otherwise. + +This prevents silent interpretation changes. + +--- + +# 9. Deliverable 2.4 β€” Replace Imperative Deployment Actions + +Current: + +```yaml +deployment: + branch: main + actions: + - git_pull + - compose_up +``` + +Target: + +```yaml +deployment: + strategy: compose + branch: main + verify: healthcheck +``` + +The important principle is: + +```text +application declares intent + ↓ +Core owns execution +``` + +not: + +```text +application tells Core which commands to run +``` + +The roadmap explicitly adopts this intent-over-imperative model. + +## Migration procedure + +For each application: + +1. inspect current actions +2. determine the intended strategy +3. convert to `deployment.strategy` +4. remove `actions` +5. validate +6. deploy manually +7. confirm equivalent behavior +8. commit migration + +--- + +# 10. Deliverable 2.5 β€” Replace the Custom YAML Parser + +The existing parser should stop being the source of truth. + +Choose a real YAML parser compatible with the project constraints. + +Then construct a typed model representing the v1 manifest. + +The runtime flow becomes: + +```text +app.yaml + ↓ +YAML parser + ↓ +Pydantic model + ↓ +validated manifest object + ↓ +appctl / GitOps +``` + +Do not let every consumer parse YAML independently. + +--- + +# 11. Deliverable 2.6 β€” Desired State vs Observed State + +Make the distinction explicit. + +```text +app.yaml + ↓ +desired state +``` + +while: + +```text +Git / Docker / TLS / container health + ↓ +observed state +``` + +`appctl` reconciles and presents the two rather than storing observed runtime facts in `app.yaml`. + +## Practical test + +Ask of every field: + +> Could this value be determined from runtime inspection instead? + +If yes, it probably does not belong in the manifest. + +--- + +# 12. Deliverable 2.7 β€” Preflight Validation + +Both consumers must use the same validation layer: + +```text +appctl +GitOps dispatcher +``` + +Create one reusable validation interface. + +For example: + +```text +load_manifest(path) +validate_manifest(manifest) +``` + +The CLI and dispatcher should not implement different validation rules. + +### Exit condition + +Every application manifest in `~/Sites` is: + +```text +schemaVersion: 1 +valid +intent-based +strictly parsed +``` + +--- + +# 13. P1 β€” Architecture Invariant Tests + +The objective here is to convert `AGENTS.md` architectural rules into executable constraints. The roadmap defines five categories. + +Create: + +```text +tests/ +β”œβ”€β”€ structural/ +β”œβ”€β”€ security/ +β”œβ”€β”€ manifests/ +β”œβ”€β”€ operational/ +└── documentation/ +``` + +--- + +# 14. Deliverable 3.1 β€” Structural Tests + +Verify `nixos/`, `scripts/`, `docs/`, `docker-compose.yml`, `flake.nix`, `AGENTS.md`, `UNLICENSE` exist. + +Also reject deprecated structures such as `infra/core/`, `./up.sh`, `./down.sh`. + +The test should inspect the filesystem rather than relying on documentation claims. + +--- + +# 15. Deliverable 3.2 β€” Security Tests + +Create assertions for: + +```text +no direct docker.sock mounts +socket-proxy POST=0 +socket-proxy DELETE=0 +no privileged containers +no forbidden host paths +no shell=True in GitOps +``` + +Where possible, parse Compose/YAML rather than using fragile grep-only checks. + +--- + +# 16. Deliverable 3.3 β€” Manifest Tests + +Scan every `~/Sites/*/app.yaml` and validate: + +```text +schemaVersion +schema validity +unique names +unique domains +allowed networks +allowed deployment strategies +``` + +This creates a repository-wide contract test rather than validating only the application currently being deployed. + +--- + +# 17. Deliverable 3.4 β€” Operational Tests + +Run: + +```bash +docker compose config -q # for Core +nix flake check # for NixOS configuration +``` + +Then run equivalent Compose validation for each application stack. + +--- + +# 18. Deliverable 3.5 β€” Documentation Tests + +Build simple checks that identify commands, paths, and deprecated paths referenced in docs. + +Focus on known failure modes rather than building a natural-language parser. + +The immediate reason for this is existing documentation drift. + +--- + +# 19. Deliverable 3.6 β€” CI Integration + +Add a Gitea Actions workflow. + +On every Core change, run at minimum: + +```text +structural +security +manifest +``` + +The desired property is: + +```text +architectural regression β†’ CI failure +``` + +--- + +# 20. P1 β€” Privilege Boundary + +After arbitrary command execution is removed, reduce the remaining GitOps authority. + +The roadmap proposes a dedicated Unix user and systemd hardening. + +--- + +# 21. Deliverable 4.1 β€” Create the `gitops` User + +Add a dedicated NixOS user `gitops` with only the permissions necessary for deployment. No `wheel`. Docker access only. + +--- + +# 22. Deliverable 4.2 β€” Move GitOps Runtime to `gitops` + +Change `User=kiskaadee` to the dedicated identity. + +Then inspect every dependency: Sites permissions, Docker permissions, secret access, configuration files, working directory, logs, temporary files. + +Do not assume the service will continue working simply because the user belongs to `docker`. + +--- + +# 23. Deliverable 4.3 β€” Apply systemd Hardening + +Apply the planned directives: + +```text +ProtectSystem=strict +ProtectHome=read-only +ReadWritePaths=... +PrivateTmp=yes +NoNewPrivileges=yes +CapabilityBoundingSet= +``` + +After each restriction: + +```bash +sudo systemctl daemon-reload +sudo systemctl restart homelab-gitops +journalctl -u homelab-gitops +``` + +This incremental process is important because systemd hardening often exposes previously implicit filesystem assumptions. + +--- + +# 24. Deliverable 4.4 β€” Prove the New Boundary + +Perform an explicit capability review: + +```text +Can GitOps write outside Sites? +Can GitOps access unrelated secrets? +Can GitOps invoke sudo? +Can GitOps modify NixOS? +Can GitOps execute arbitrary shell? +Can GitOps access the Docker daemon? +``` + +The goal is not merely "It runs." The goal is "Its authority is intentionally bounded." + +--- + +# 25. P2 β€” Architecture Documentation + +Do this after P0/P1 behavior has stabilized. + +The documentation tree proposed by the roadmap is: + +```text +docs/ +β”œβ”€β”€ architecture/ +β”‚ β”œβ”€β”€ system-topology.md +β”‚ β”œβ”€β”€ ownership-matrix.md +β”‚ β”œβ”€β”€ gitops-protocol-v1.md +β”‚ └── manifest-specification.md +β”œβ”€β”€ security/ +β”‚ β”œβ”€β”€ trust-model.md +β”‚ β”œβ”€β”€ secret-management.md +β”‚ └── socket-proxy-policy.md +β”œβ”€β”€ operations/ +β”‚ β”œβ”€β”€ nixos-management.md +β”‚ └── disaster-recovery.md +β”œβ”€β”€ adr/ +└── archive/ +``` + +Principle: `docs/` = current truth; `docs/archive/` = historical truth. + +--- + +# 26–34. Documentation Deliverables (5.1–5.9) + +Create each document after the implementation it describes is stable: + +- **5.1** `docs/architecture/system-topology.md` β€” three-layer diagram (use the approved Mermaid flowchart from the roadmap), orchestration as cross-cutting +- **5.2** `docs/architecture/ownership-matrix.md` β€” owns / must not own per layer +- **5.3** `docs/architecture/gitops-protocol-v1.md` β€” webhook format, auth, resolution, branch policy, serialization, failure semantics +- **5.4** `docs/architecture/manifest-specification.md` β€” human-readable companion to JSON Schema +- **5.5** `docs/security/trust-model.md` β€” full trust chain and component authority +- **5.6** `docs/security/secret-management.md` β€” SOPS lifecycle, projection, ownership vs. consumption +- **5.7** `docs/operations/disaster-recovery.md` β€” split declarative recovery vs. state recovery +- **5.8** Historical migration β€” ADRs to `docs/adr/`, obsolete docs to `docs/archive/` +- **5.9** Audit active docs β€” correct ports, paths, commands, TLS/Watchtower/DDNS claims + +--- + +# 35. P3 β€” Deployment Verification + +## Deliverable 6.1 β€” Preflight Validation + +Before changing runtime state, run schema validation, branch validation, and `docker compose config -q`. + +## Deliverable 6.2 β€” Implement Deployment Lifecycle + +Standardize the sequence: + +```text +capture current revision β†’ fetch target β†’ validate manifest + β†’ validate Compose β†’ pull images β†’ compose up β†’ verify β†’ record result +``` + +Keep execution deterministic. Do not allow manifests to change the sequence arbitrarily. + +## Deliverable 6.3 β€” Health Verification + +Implement container state + health status checks. Optionally HTTP probe when a domain is declared. + +A health verification failure should not automatically imply rollback in v1. + +## Deliverable 6.4 β€” Explicit Failure Semantics + +```text +Preflight failure β†’ reject + log reason +Git failure β†’ FAILED, stop +Compose failure β†’ FAILED, stop +Health failure β†’ DEGRADED, log warning +``` + +No automatic rollback in v1. + +## Deliverable 6.5 β€” Structured Deployment Logging + +Produce JSON logs with: `repository`, `revision`, `stage`, `timestamp`, `result`, `error`. + +--- + +# 36. P4 β€” Deployment State & Observability + +## Deliverable 7.1 β€” Define Deployment Record Schema + +```json +{ + "id": "deploy-docs-20260912-001422", + "repository": "homelab-docs", + "commit": "9ac3f7b2", + "previous_commit": "87b2e1a4", + "branch": "main", + "timestamp": "2026-09-12T00:14:22-05:00", + "duration_seconds": 22, + "result": "SUCCESS", + "failure_reason": null, + "triggered_by": "webhook" +} +``` + +## Deliverable 7.2 β€” Implement Append-Only Storage + +Use JSON Lines. One record per line. Decide per-repo file vs. global log based on querying needs. + +## Deliverable 7.3 β€” Track Previous Revision + +Capture previous commit at deployment time for rollback context. + +## Deliverable 7.4 β€” Add `appctl deployment` + +```bash +appctl deployment +``` + +Shows last and previous deployment: commit, time, duration, result. + +--- + +# 46. Final Integration Pass + +After all deliverables are implemented, confirm the five acceptance questions from the roadmap can be answered from the repository alone: + +1. What does **NixOS** own? +2. What does **Core** own? +3. What does an **application repository** own? +4. What can **GitOps** execute? +5. What happens **when deployment fails**? + +--- + +# Suggested Commit Sequence + +```text +1. refactor(gitops): remove arbitrary custom execution +2. feat(gitops): add trusted repository resolution +3. feat(gitops): add webhook authentication +4. feat(gitops): enforce repository/event/branch admission +5. feat(gitops): add serialized asynchronous deployment +6. migrate(apps): convert custom deployment consumers + +7. docs(manifest): define app.yaml v1 specification +8. feat(manifest): add JSON Schema v1 +9. feat(manifest): add typed runtime validation +10. migrate(apps): add schemaVersion and intent-based deployment + +11. test(architecture): add structural invariants +12. test(architecture): add security invariants +13. test(manifests): add manifest invariants +14. test(architecture): add operational invariants +15. test(docs): add documentation invariants +16. ci: run architecture validation in Gitea Actions + +17. feat(security): create dedicated gitops user +18. harden(systemd): restrict GitOps service + +19. docs(architecture): add system topology +20. docs(architecture): add ownership matrix +21. docs(gitops): document protocol v1 +22. docs(manifest): add specification reference +23. docs(security): document trust and secrets +24. docs(operations): document recovery +25. docs: archive historical material + +26. feat(gitops): add deployment preflight +27. feat(gitops): add deployment verification +28. feat(gitops): define failure semantics + +29. feat(gitops): add deployment records +30. feat(appctl): add deployment history +``` + +--- + +# Definition of Done + +The consolidation is complete when: + +```text +[ ] GitOps cannot execute arbitrary repository-supplied shell +[ ] webhook requests are authenticated +[ ] repositories are resolved through trusted identity +[ ] branch/event policy is enforced +[ ] deployment execution is asynchronous and serialized +[ ] app.yaml v1 is formally specified +[ ] JSON Schema is normative +[ ] runtime validation is typed +[ ] all manifests use schemaVersion +[ ] deployment configuration expresses intent +[ ] architectural invariants are tested automatically +[ ] CI enforces those invariants +[ ] GitOps runs under a restricted identity +[ ] systemd limits GitOps filesystem authority +[ ] current architecture is documented +[ ] historical documentation is separated +[ ] deployment preflight exists +[ ] deployment health is verified +[ ] failure semantics are explicit +[ ] deployment history is persisted +[ ] appctl can report deployment history +``` + +The resulting system should be **more constrained than the current one, not merely more documented**. Its architecture should be understandable from the repository, while its most important boundaries are enforced even when a future contributor does not remember them. diff --git a/projects/homelab/plans/architecture-consolidation-roadmap-v2.md b/projects/homelab/plans/architecture-consolidation-roadmap-v2.md index 98f90bc..8b45630 100644 --- a/projects/homelab/plans/architecture-consolidation-roadmap-v2.md +++ b/projects/homelab/plans/architecture-consolidation-roadmap-v2.md @@ -13,10 +13,12 @@ tags: # Architecture Consolidation & Hardening Roadmap v2 -> Supersedes the [original phased implementation plan](architecture-consolidation-roadmap.md). +> Supersedes the [original phased implementation plan](../archive/architecture-consolidation-roadmap.md). > Integrates reviewer feedback across fourteen areas: trust model, manifest > contracts, privilege separation, protocol versioning, invariant testing, and > deployment observability. +> +> πŸ“‹ **Companion Execution Guide**: [Architecture Consolidation & Hardening Implementation Guide](architecture-consolidation-implementation-guide.md) --- @@ -44,7 +46,7 @@ repository: 2. What does **Core** own? 3. What does an **application repository** own? 4. What can **GitOps** execute? -5. What happens **when deployment fails**? +5. What happens when deployment fails? Right now those answers exist, but they're scattered across code, conventions, comments, and historical documentation. This plan turns them into explicit diff --git a/projects/homelab/plans/server-24-7/folder-structure-reorganization.md b/projects/homelab/plans/server-24-7/folder-structure-reorganization.md index b96d62e..043832e 100644 --- a/projects/homelab/plans/server-24-7/folder-structure-reorganization.md +++ b/projects/homelab/plans/server-24-7/folder-structure-reorganization.md @@ -19,7 +19,7 @@ Establish clear, unambiguous directory boundaries across both the Server and Lap ## πŸ—ΊοΈ Realized Production Layout > [!NOTE] -> The initial proposal for a monolithic `~/Deployments` directory was superseded by the decoupled `~/Core` and `~/Sites` architecture documented in [Homelab Architecture: Appctl & Decentralized Repositories](../../guides/appctl-operations-and-manifest-guide.md) and executed in [Core & Sites Cutover and Testing Plan](../appctl/core-sites-cutover-testing-plan.md). +> The initial proposal for a monolithic `~/Deployments` directory was superseded by the decoupled `~/Core` and `~/Sites` architecture documented in [Homelab Architecture: Appctl & Decentralized Repositories](../../guides/appctl-operations-and-manifest-guide.md) and executed in [Core & Sites Cutover and Testing Plan](../../archive/core-sites-cutover-testing-plan.md). ### πŸ–₯️ Production Server Layout (`/home/kiskaadee/`) ```text @@ -53,4 +53,4 @@ Establish clear, unambiguous directory boundaries across both the Server and Lap ## πŸ”— Related Documents * [Homelab Architecture: Appctl & Decentralized Repositories](../../guides/appctl-operations-and-manifest-guide.md) -* [Core & Sites Cutover and Testing Plan](../appctl/core-sites-cutover-testing-plan.md) +* [Core & Sites Cutover and Testing Plan](../../archive/core-sites-cutover-testing-plan.md)