docs(p4): clarify pydantic target architecture and domain precedence in readiness plan
- Clarify Pydantic v2 as the target architecture for Milestone P4 implementation rather than existing code - Detail strict type validation vs extra="forbid" rules, forbidding type coercion on operations, targets, flags, and tokens - Specify error response transformation and information disclosure prevention (omitting raw secret values) - Formalize domain configuration precedence (HOMELAB_DOMAIN -> DOMAIN_SUFFIX -> DOMAIN -> fail closed) and RFC 2606 placeholders - Synchronize todo.txt with completed pre-P4 tasks and schedule follow-up repository-wide domain scrub
This commit is contained in:
1 parent
4786bbe1ca
commit
fae36700b7
2 files changed
+25
-10
No files matched your search
@@ -117,11 +117,17 @@ Every client (local CLI, remote CLI, GitOps dispatcher, and future Operations UI
|
||||
• platform.health
|
||||
```
|
||||
|
||||
### B. Typed Request and Response Models (Pydantic v2 Validation Pipeline)
|
||||
### B. Typed Request and Response Models (Target Architecture: Pydantic v2 Pipeline)
|
||||
|
||||
All control plane API requests, responses, error payloads, and workload manifest schemas are defined and validated through **Pydantic v2** (`pydantic.BaseModel`, `pydantic.Field`, `ConfigDict(extra="forbid")`):
|
||||
- **Runtime Validation**: Incoming payloads over both Unix Domain Socket and HTTP endpoints are validated at the transport boundary before reaching the operational router.
|
||||
- **Fail-Closed Type Safety**: Unrecognized fields, malformed types, or invalid operations immediately fail validation with structured `ERR_VALIDATION_FAILED` (400) payloads.
|
||||
All control plane API requests, responses, error payloads, and workload manifest schemas will be defined and validated through **Pydantic v2** (`pydantic.BaseModel`, `pydantic.Field`, `ConfigDict(extra="forbid", strict=True)`). While the dependency has been integrated into runtime environments, the schema migration and model definitions are the first implementation deliverables of Milestone P4:
|
||||
|
||||
- **Runtime Validation Boundary**: Incoming payloads over both Unix Domain Socket and HTTP endpoints are validated at the transport boundary before reaching the operational router.
|
||||
- **Fail-Closed Extra Fields (`extra="forbid"`)**: Rejects any undeclared or unknown fields immediately.
|
||||
- **Strict Typing vs. Coercion Rules**:
|
||||
- *Strict Validation*: Operations (`operation`), target identifiers (`target`), boolean flags (`recreate`, `remove_orphans`, `visible`, `auth`), and authentication tokens require strict types (`strict=True` or `StrictStr`, `StrictBool`). Coercion (e.g. converting `"true"` or `1` to `True`, or floats to ints) is strictly forbidden for control plane commands to prevent ambiguous execution.
|
||||
- *Permitted Coercion / Sanitization*: Only explicitly defined string stripping/normalization (e.g. whitespace trimming) is permitted via field validators.
|
||||
- **Structured Error Transformation**: Transport handlers intercept `pydantic.ValidationError` and map it to canonical `ERR_VALIDATION_FAILED` (`400 Bad Request`) responses.
|
||||
- **Information Disclosure Prevention**: Error details must include field names and validation issue descriptions, but must strictly redact and omit raw input values to prevent leaking secrets, credentials, or host filesystem paths.
|
||||
- **Contract Enforcement**: Manifest definitions in `core_manifest.py` migrate to Pydantic v2 models, guaranteeing uniform schema enforcement across the CLI, daemon, and GitOps engines.
|
||||
|
||||
All requests and responses use strict JSON payloads with explicit schema versioning (`version: "1.0"`):
|
||||
@@ -248,8 +254,13 @@ Following the pattern established in Milestone P2 for `homelab-gitops.service`,
|
||||
### 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.
|
||||
- **Dynamic Resolution**: Domains must resolve exclusively through `HOMELAB_DOMAIN`, `DOMAIN_SUFFIX`, or `DOMAIN` environment variables.
|
||||
- **Generic Fallbacks & Tests**: Test fixtures, documentation examples, and schema defaults must use RFC-reserved generic domains (`example.com`, `example.org`, `testdomain.local`).
|
||||
- **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)
|
||||
3. `DOMAIN` (Legacy environment fallback)
|
||||
If none are set, the platform fails closed rather than defaulting to hardcoded values.
|
||||
- **Generic Placeholders & Test Fixtures**: Test fixtures, documentation examples, and schema defaults must use RFC 2606 reserved domains (`example.com`, `example.org`, `example.test`).
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -325,4 +336,5 @@ Before marking Milestone P4 complete, the following automated regression suite m
|
||||
| **Truthful Error Reporting** | `test_execution_failure_audit`: Mock failing Docker compose run (exit 1). Assert daemon returns `ERR_EXECUTION_FAILED` (500) and records `phase: FAILED` in audit log. | Reject PR |
|
||||
| **Audit Persistence Gate** | `test_audit_failure_blocks_mutation`: Mock read-only audit log. Assert mutating command fails closed with zero Docker invocations. | Block Release |
|
||||
| **Daemon Crash Recovery** | `test_daemon_restart_preserves_state`: Kill and restart `homelab-appctl.service`. Assert running container stacks are undisturbed and desired Git state remains intact. | Reject PR |
|
||||
| **Existing Invariant Regression** | Run `./scripts/test`: All 86 existing unit, security, and nix flake tests pass with 0 regressions. | Block Merge |
|
||||
| **Existing Invariant Regression** | Run `./scripts/test`: All 121 existing unit, security, structural, and Nix flake sandbox tests pass with 0 regressions. | Block Merge |
|
||||
|
||||
@@ -13,17 +13,20 @@ x 2026-10-13 (B) Define append-only audit telemetry schema, lifecycle, and failu
|
||||
x 2026-10-13 (C) Establish P4 acceptance test matrix and definition of done before daemon implementation in docs/plans/p4-readiness-plan.md +test @p4-gate
|
||||
x 2026-10-14 (A) Eliminate eval in scripts/appctl and enforce strict env key validation in scripts/core_manifest.py +security @appctl
|
||||
x 2026-10-15 (A) Enforce deployments.yaml as sole registry and remove dynamic discovery fallback in scripts/gitops_dispatcher.py +registry @gitops
|
||||
|
||||
x 2026-10-15 (A) Harden validate_compose_security in scripts/gitops_dispatcher.py blocking relative traversal, cross-tenant mounts, and privilege escalation +compose @gitops
|
||||
|
||||
x 2026-10-15 (A) Unify manifest parsing on core_manifest.py and eliminate duplicate parsers in scripts/appctl_engine.py +manifest @engine
|
||||
x 2026-10-15 (A) Codify Platform Genericism invariant in AGENTS.md and add Pydantic to flake.nix, pyproject.toml, and scripts/test +invariant @core
|
||||
x 2026-10-15 (A) Add pydantic to host NixOS runtime and constrain dependency range in flake.nix and nixos/configuration.nix +nixos @core
|
||||
x 2026-10-15 (A) Wire app_name and harden compose validator for env_file and undeclared volumes in scripts/gitops_dispatcher.py +compose @gitops
|
||||
x 2026-10-15 (B) Scrub hardcoded domain defaults across scripts and tests enforcing instance-agnostic parameterization +generic @core
|
||||
x 2026-10-15 (A) De-tautologize appctl env injection test to execute scripts/appctl directly with mock docker in tests/security/test_security_invariants.py +test @security
|
||||
x 2026-10-15 (A) Clarify Pydantic v2 target architecture, strict typing rules, and domain precedence in docs/plans/p4-readiness-plan.md +docs @p4-gate
|
||||
(A) Migrate core_manifest.py to Pydantic v2 models for strict type validation and serialization +manifest @schema
|
||||
(A) Scaffold asyncio daemon server with Pydantic request/response models supporting dual transports in scripts/appctl_daemon.py +daemon @p4
|
||||
(A) Implement unit and integration tests for dual-transport requests and error handling in tests/unit/test_appctl_daemon.py +test @p4
|
||||
(B) Implement command-oriented operational router wiring domain actions to in-process appctl_engine.py methods and fixed subprocess executions +router @p4
|
||||
(B) Scrub hardcoded domain defaults across scripts and tests enforcing instance-agnostic parameterization +generic @core
|
||||
(B) Implement token authentication middleware validating user-scoped Bearer tokens for mutating requests +auth @p4
|
||||
(B) Implement append-only audit logger writing structured RFC JSONL records with fail-closed disk guard +audit @p4
|
||||
(B) Scrub remaining hardcoded domain references across NixOS modules, Compose stack, and repository documentation +generic @core
|
||||
(C) Re-implement scripts/appctl as a thin client dispatching JSON requests to the daemon Unix domain socket +cli @p4
|
||||
(C) Create NixOS systemd unit module for homelab-appctl.service with strict sandboxing and socket management +nixos @p4
|
||||
Reference in new issue
Block a user