# Enterprise Readiness Design and Implementation Plan ## Goal Description Archie is moving into a single static binary (`cmd/archie`) backed by PostgreSQL. Several core governance controls already exist. These include pre-action Cedar judgement, earned autonomy, and fresh WebAuthn passkey checks for irreversible actions. They also include Ed25519-signed extension catalogues, Linux namespace egress confinement, a DDL/DML database role split, and an external deletion ledger that survives database restores. This plan sets out the locked architecture and phased work to deploy `cmd/archie` in regulated enterprise environments. It targets finance, healthcare, government, and critical infrastructure aligned with SOC 2 Type II, ISO 27001, SOX ITGC, PCI-DSS, and APRA CPS 234. It covers multi-stage containerised environments across `dev`, `staging`, and `prod`. All work targets the single-binary architecture (`cmd/archie`, `internal/app/archie`, `modules/*`, and `internal/platform/*`), not the legacy six-service stack. --- ## Locked Decisions These architectural choices are locked in for Enterprise v1 and Enterprise v2: 1. **Hard isolation per Archie stage (`dev`, `staging`, and `prod`):** Each stage runs its own Archie instance. It keeps its own Postgres database, sealing key, OIDC client, egress allow-list, and approval log. Earned autonomy in Staging never carries over to Production. One Production instance can still manage non-prod and prod servers using CMDB facts and Cedar rules. 2. **Orchestrator priority:** Kubernetes and Helm first, with hardened Docker Compose secondary. 3. **Extension confinement in strict Kubernetes:** Ship static remote gRPC+mTLS extension endpoints in v1 (never SSH), passing Kubernetes `restricted` Pod Security Standards and `NetworkPolicy`, alongside existing `CLONE_NEWUSER` confinement for Compose and VMs. 4. **Cryptography and secret offloading:** Keep `age`, add `archie rekey`, and ship a Vault/OpenBao secret engine extension in v1 so target credentials stay in the enterprise secret manager. Do not bundle cloud KMS SDKs. Defer FIPS 140-3 stdlib AES-256-GCM sealing (`GOFIPS140`) to v2. 5. **Control-plane mutability and promotion:** Keep the dashboard as the complete control plane, and add versioned promotion bundles (`archie bundle export`, `diff`, and `apply`) for peer-reviewed promotion across stages. 6. **Identity and approvals:** Ship OIDC confidential client, group-to-role claim mapping, SSO-only mode, session timeouts, four-eyes Segregation of Duties (`initiator != approver`), and ITSM `ChangeRequests` wiring in v1. Defer SCIM 2.0 and N-of-M quorum to v2. 7. **Audit and telemetry:** Ship an append-only `audit` table (`INSERT` and `SELECT` only for `archie_app`), structured JSON audit logs to stdout, and a unified audit export API. Customer log collectors handle SIEM shipping, WORM retention, and Legal Hold. Also ship OTel tracing with trace-ID logs, internal `/metrics`, and graceful `SIGTERM` drain in v1. Defer cryptographic hash-chaining to v2. 8. **High availability:** Ship Active-Passive (one active replica plus HA PostgreSQL) in v1. Document Active-Active HA (`LISTEN/NOTIFY` hub, Postgres lease leader election for pollers, and shared WORM deletion ledger) in v2 so requirements are preserved. --- ## Target Architecture ### Multi-Stage Regulated Deployment Topology ```mermaid flowchart LR subgraph CI["Release and Supply Chain (Signed OCI + SBOM)"] IMG["archie OCI image\n(digest-pinned, cosign)"] CAT["Internal Extension Catalogue\n(Ed25519-signed, OCI mirror)"] BND["Promotion Bundle\n(workflows, Cedar, guards, pins)"] end subgraph DEV["Dev Stage (Isolated)"] D_ARC["archie (dev)"] D_DB[("PostgreSQL (dev)")] D_SEC["Vault / OpenBao (dev)"] D_ARC --> D_DB D_ARC --> D_SEC end subgraph STG["Staging Stage (Isolated)"] S_ARC["archie (staging)"] S_DB[("PostgreSQL (staging)")] S_SEC["Vault / OpenBao (staging)"] S_ARC --> S_DB S_ARC --> S_SEC end subgraph PRD["Production Stage (Regulated)"] P_MIG["Pre-upgrade Job:\narchie migrate (owner_url)"] P_ARC["archie (prod)\n(runtime url only)"] P_DB[("HA PostgreSQL\nTLS verify-full")] P_SEC["Vault / OpenBao (prod)"] P_LOG["Customer Log Collector\n(Stdout JSON -> SIEM / WORM)"] P_ITSM["ITSM Change Control\n(ServiceNow / Jira)"] P_MIG --> P_DB P_ARC --> P_DB P_ARC --> P_SEC P_ARC --> P_LOG P_ARC --> P_ITSM end IMG -->|GitOps PR| DEV IMG -->|Verified digest| STG IMG -->|Approved CR| PRD CAT --> DEV & STG & PRD BND -->|Export + Diff| STG BND -->|Peer Review + Approval Gate| PRD ``` ### Production Pod and Network Boundary ```mermaid flowchart TD EXT_SRC["External Alert/Webhook Sources"] -->|TLS + HMAC| EDGE_ING["Perimeter Webhook Ingress\n(/webhooks/* only)"] OPS["Operators / Approvers"] -->|Corporate VPN / SSO| INT_ING["Internal Ingress\n(Dashboard + /api/* + OIDC)"] subgraph NS["Kubernetes Namespace: archie-prod"] EDGE_ING --> POD["archie Pod (nonroot UID 65532, RO root filesystem)"] INT_ING --> POD POD -->|Unix socket or remote mTLS gRPC| EXT["Isolated Extensions\n(Allow-list Egress / NetworkPolicy)"] EXT -->|Chained via corporate proxy| PROXY["Corporate Egress Proxy / DLP"] POD -->|TLS verify-full, DML role only| PG[("Managed HA Postgres")] POD -->|RWO PVC| STATE[("state_dir / Deletion Ledger")] end ``` --- ## Enterprise v1 (Build Now) Enterprise v1 delivers a lean, auditable, Active-Passive containerised deployment across six tracks. --- ### Track 1: Container Packaging, Bootstrap, and Least-Privilege Runtime #### [NEW] `Dockerfile.archie` - Build `ui/dist` with Node 24 (`pnpm run build`) and static `cmd/archie` with Go 1.27 (`CGO_ENABLED=0 -trimpath`). - Ship on `gcr.io/distroless/static-debian12:nonroot` (UID `65532`) with OCI labels and read-only root filesystem compatibility. - Support enterprise CA bundles via `SSL_CERT_FILE`. #### [MODIFY] `cmd/archie/main.go` and `internal/app/archie/run.go` - Add `archie migrate [-config ...]` to acquire the migration lock, run Goose migrations and runtime DML grants via `owner_url`, and exit `0` for a Kubernetes `Job` or Helm pre-upgrade hook. - Add `archie bootstrap [-config ...] [-spec path]` for idempotent headless first-boot setup (org, workspace, public URL, OIDC provider, and initial owner or break-glass identity). #### [MODIFY] `internal/app/archie/config.go` and `internal/platform/pg/pg.go` - Support env and `*_FILE` overrides for bootstrap secrets (`ARCHIE_DATABASE_URL`, `ARCHIE_DATABASE_OWNER_URL`, `ARCHIE_AGE_IDENTITY`, `ARCHIE_ADMIN_TOKEN_SHA256`, and `*_FILE` variants) so `config.toml` stays non-secret and read-only. - Allow serving without `database.owner_url`. In DML-only mode, `pg.VerifySchema` checks that all embedded migrations are applied and fails closed on lag. - Grant `SELECT` on `public.goose_db_version` to the runtime role in `pg.grantRuntime`. - Remove runtime writes to `config.toml` (`WriteAdminHash` in running servers) and add configurable `shutdown_grace` (default `30s`) plus `[catalogue]` overrides for air-gapped stages. #### [MODIFY] `internal/platform/health/health.go` and `internal/app/archie/gate.go` - Separate `/healthz` (liveness), `/startupz` (DB reachable, schema verified, and deletion ledger ready), and `/readyz` (readiness, returning `503` on `SIGTERM` drain). #### [MODIFY] `modules/connectors/internal/egress/tunnel.go` and `modules/connectors/internal/host/host.go` - Chain allowed egress hosts through `HTTPS_PROXY` (respecting `NO_PROXY`) after enforcing Archie's allow-list and loopback/SSRF checks. - Propagate `SSL_CERT_FILE` and `SSL_CERT_DIR` into confined extensions so internal PKI works with full TLS checks. --- ### Track 2: Kubernetes Extension Isolation and Supply Chain #### [NEW] `modules/connectors/internal/host/remote.go` - Add a `Runtime` abstraction supporting `LocalNamespaceRuntime` (existing `CLONE_NEWUSER | CLONE_NEWNET` for Compose/VMs) and `RemoteGRPCRuntime` (static gRPC+mTLS endpoints for sidecar or dedicated extension Pods running under Kubernetes `restricted` PSS and `NetworkPolicy`). Fail closed if neither is available. #### [NEW] Air-Gapped Catalogue and Supply Chain (`modules/connectors/internal/catalogue/`) - Support OCI registry authentication for internal extension mirrors. - Emit SPDX/CycloneDX SBOMs, SLSA provenance, and cosign signatures in CI for `archie` images and extensions, plus `archie catalogue mirror` for air-gapped transfer. --- ### Track 3: Key Rotation and Enterprise Secret Offloading #### [NEW] `internal/app/archie/rekey.go` (`archie rekey`) - Rotate `age` identities across `connectors` credentials and `events` webhook secrets in transactional batches under an advisory lock, checking decryption before commit and logging an audit event. #### [NEW] Vault and OpenBao Secret Engine Extension - Offload target infrastructure credentials to the customer's secret manager using Archie's existing `secretengine/v1` contract. --- ### Track 4: Enterprise Identity, Approvals, and Segregation of Duties #### [MODIFY] `modules/governance/oidc.go` and `modules/governance/accounts_api.go` - Add confidential OIDC client auth (`client_secret` and `private_key_jwt`), group-to-role claim mapping synced on sign-in, SSO-only mode with audited break-glass alerting, idle/max session lifetimes, and OIDC back-channel logout (`POST /oauth2/backchannel-logout`). #### [MODIFY] `modules/approvals/approvals.go` and `internal/app/archie/run.go` - **Segregation of Duties (SoD):** Persist `InitiatorID` on approval requests and reject self-approval (`answerer.ID == req.InitiatorID`) when SoD applies. - **ITSM Change Requests:** Wire `allow.UseChangeRequests(...)` in `internal/app/archie/run.go` to a ServiceNow or Jira Service Management extension driven by `judgement.KindChangeRequest` rules. --- ### Track 5: Audit Stream, OpenTelemetry, and Prometheus Metrics #### [NEW] `modules/audit/` (Append-Only Audit Table and Unified Export) - Create an append-only `audit.events` table where `archie_app` holds only `SELECT` and `INSERT` privileges. - Emit every audit record as structured JSON to stdout so the customer's log collector (Fluent Bit, Vector, OTel Collector, or Splunk Forwarder) routes it to SIEM and WORM retention. - Serve a unified Cedar-gated export API (`GET /api/audit/events` and `POST /api/audit/exports`). #### [MODIFY] `internal/app/archie/run.go` and `internal/app/archie/api.go` - Wire `otelhttp` and OTLP trace export (`OTEL_EXPORTER_OTLP_ENDPOINT`), spans around runs, steps, LLM calls, judgements, and extensions, plus a `slog.Handler` injecting `trace_id` and `span_id`. - Serve Prometheus `/metrics` on an internal-only port and drain active HTTP requests and run checkpoints on `SIGTERM` up to `shutdown_grace`. --- ### Track 6: Multi-Stage Promotion and Helm Deployment Kit #### [NEW] `internal/app/archie/bundle.go` (`archie bundle`) - Separate portable definitions (`bundle.yaml`: workflows, Cedar policies, judgement rules, action types, event schemas, and extension digest pins) from stage-local bindings (`bindings..yaml`: credentials, OIDC client, public URL, target hosts, schedules, channels, and per-stage autonomy ceilings). - Provide `archie bundle export`, `diff`, and `apply` (transactional, runs `RecheckConnector`, preserves earned autonomy counts, and supports a Prod approval gate). #### [NEW] `deployments/helm/archie/` and Hardened Compose - Ship a Helm chart with `values-{dev,staging,prod}.yaml` overlays: `StatefulSet` (Active-Passive, 1 replica + RWO PVC), `Job` pre-upgrade hook (`archie migrate`), split Ingress (perimeter `/webhooks/*` vs internal Dashboard/API), default-deny `NetworkPolicy`, `ExternalSecret` examples, `ServiceMonitor`, and hardened Compose overlay. - Document Postgres pool settings (requiring PgBouncer session pooling for `ClaimServe`) and independent backup/restore of Postgres, recovery keys, and the deletion ledger. --- ## Enterprise v2 (Documented for Demand) These items are deferred from v1 so engineering effort stays focused, while interfaces avoid locking them out: 1. **Active-Active HA:** Back `hub.Hub` (`internal/platform/hub/hub.go`) with PostgreSQL `LISTEN/NOTIFY`, add PostgreSQL lease-based leader election for polling sources and channel listeners, and add an S3/GCS Object Lock store for `deletions.Store` (`internal/platform/deletions/deletions.go`). 2. **FIPS 140-3 Sealing Profile:** Add a stdlib AES-256-GCM `seal.Sealer` compiled with `GOFIPS140=v1.0.0`, reading the master key from an External Secrets / CSI KMS mount. 3. **SCIM 2.0 Lifecycle:** Add `/scim/v2/Users` and `/scim/v2/Groups` for automated IdP provisioning and instant offboarding. 4. **N-of-M Approval Quorum:** Add `approvals.votes` requiring multiple distinct approvers for high-risk production actions. 5. **Cryptographic Audit Hash Chain and Multi-Org Tenancy:** Add per-org `prev_hash`/`entry_hash` chaining on `audit.events` and replace single-org routing (`const orgID = "default"`) when multi-BU tenancy in one instance is needed. --- ## Verification Plan ### Automated Tests (`task check`) All changes must pass `task check` (`go test -short`, `golangci-lint`, `gosec`, generated OpenAPI/SQL checks). Add boundary tests per track: - **Track 1:** `go test -short ./internal/app/archie/... ./internal/platform/pg/... ./internal/platform/health/... ./modules/connectors/internal/...` tests schema checks, `*_FILE` secret loading, `/startupz` vs `/readyz`, `HTTPS_PROXY` allow-lists, and CA env forwarding. - **Track 2:** `go test -short ./modules/connectors/internal/host/...` tests `RemoteGRPCRuntime` mTLS checks and fail-closed startup. - **Track 3:** `go test -short ./internal/app/archie/...` tests atomic `archie rekey` rollback on failure. - **Track 4:** `go test -short ./modules/governance/... ./modules/approvals/...` tests confidential OIDC, group claim mapping, SSO-only refusal, and SoD self-approval refusal. - **Track 5:** `go test -short ./modules/audit/... ./internal/app/archie/...` tests runtime `UPDATE`/`DELETE` refusal on `audit.events`, trace-ID log injection, and `SIGTERM` drain. - **Track 6:** `go test -short ./internal/app/archie/... ./modules/runs/...` tests that `archie bundle apply` keeps earned autonomy and stage credentials. ### Manual and Container Verification 1. **Container and Kubernetes hardening:** Build `Dockerfile.archie`, scan with Trivy or Grype (0 critical or high CVEs), and verify UID `65532` with `--read-only` root filesystem. Deploy the Helm chart to `kind` or `k3s` under `restricted` PSS, checking `archie migrate` Job vs DML-only Pod. 2. **Proxy and air-gapped drill:** Run on a zero-internet network behind an HTTP proxy and private CA, verifying OIDC login, private OCI extension install, and egress allow-lists. 3. **Promotion and SoD drill:** Export bundle from `staging`, run `diff` and `apply` to `prod`, and confirm credentials and autonomy ceilings stay intact. Check self-approval rejection, ITSM CR creation, and stdout audit JSON output. 4. **DR restore drill:** Delete a memory note, restore Postgres from a pre-deletion snapshot, boot `archie`, and confirm the note remains deleted via the deletion ledger.