Add local production infra lab

This commit is contained in:
thanhnv
2026-07-06 12:00:27 +09:00
parent ec261bcbc5
commit fc736aabf1
16 changed files with 623 additions and 23 deletions
+12 -11
View File
@@ -5,7 +5,7 @@
> cũng làm tiếp được ngay**. Cập nhật mỗi khi hoàn thành một mục.
>
> Cập nhật lần cuối: 2026-07-06 · Nhánh làm tiếp từ handoff Claude.
> Test hiện tại: **218 PASS / 0 FAIL** trên 13 core harness suite; `phase3-model-router` riêng **10 PASS / 0 FAIL**; frontend Vitest **16 PASS / 0 FAIL**. Backend `npm test` còn bị chặn bởi test-infra cũ (`schema.prisma` MySQL nhưng `setup-sqlite.mjs` chạy SQLite).
> Test hiện tại: **218 PASS / 0 FAIL** trên 13 core harness suite; local-prod Docker infra lab **2 PASS / 0 FAIL** (`infra-lab verify`: 7/0 internal checks); `phase3-model-router` riêng **10 PASS / 0 FAIL**; frontend Vitest **16 PASS / 0 FAIL**. Backend `npm test` còn bị chặn bởi test-infra cũ (`schema.prisma` MySQL nhưng `setup-sqlite.mjs` chạy SQLite).
> Điểm công tâm vẫn quanh **~81/100**, harness thấp nhất 80; TIER 2 infra thật vẫn là trần Strong.
> Nguồn liên quan: `CASAN_HARDENING_STATUS.md` (chi tiết control) · `evidence/scoring-run-report.md` (điểm).
@@ -24,15 +24,15 @@
| T1.2 | **IdP/OIDC cho approval** (thay registry pubkey tĩnh) | 07 C4 / V20 | ✅ MVP done+test | `approval-verify.sh` chấp nhận `CASAN_APPROVAL_JWT` RS256 ký bởi mock IdP, verify chữ ký bằng pubkey, check `sub`/`role`/`exp` + bind `action`/`actor`/`input_sha256`. Test: JWT hợp lệ→APPROVED, hết hạn/sai role/chữ ký giả→DENY. Prod còn cần IdP/JWKS thật. |
| T1.3 | **Traceability REQ→code→test** (khác biệt nhất) | 10 | ✅ MVP done+test | `traceability-matrix.py` parse FR-xx từ requirement, dùng `.specify/traceability-map.json`, gate mọi FR có ≥1 code + ≥1 test; Evidence Pack thêm `traceability-matrix.json`. Test: FR đủ→PASS, FR thiếu test→FAIL. |
## TIER 2 — Plan-07 gaps cần hạ tầng (MVP đã có, cần bản prod) 🔌
## TIER 2 — Plan-07 gaps cần hạ tầng (Docker local-prod lab đã có; prod managed thật vẫn cần) 🔌
| # | Hạng mục | Trạng thái | Bước tiếp theo (bản production) |
|---|---|:--:|---|
| T2.1 | KMS mặc định + HSM | 🟡 (Vault Transit live, chưa default) | Đặt `sign-audit-head.sh`/`telemetry-integrity.sh` route qua KMS khi có `VAULT_ADDR` (đã vậy); thêm cấu hình prod: Vault/AWS-KMS/CloudHSM + token ngắn hạn qua IdP; bỏ fallback khoá local ở môi trường prod (giữ cho dev). |
| T2.2 | WORM store thật (S3 Object Lock) | 🟡 (ledger local hash-link) | `audit-ship.sh` thêm backend S3: `aws s3api put-object --object-lock-mode COMPLIANCE --retain-until-date …`; hoặc QLDB. Giữ ledger local làm cache. Cần: AWS creds + bucket Object-Lock. |
| T2.3 | Dashboard deploy + auth | 🟡 (HTTP local + /healthz) | Đóng gói `dashboard-server.py` vào container + nginx reverse-proxy + auth (OIDC/basic); expose `/healthz` cho uptime monitor. Cần: host + TLS cert. |
| T2.4 | Kênh alert managed + on-call | 🟡 (webhook + dead-letter) | `alert-dispatch.sh` trỏ `CASAN_ALERT_WEBHOOK` tới Slack/PagerDuty incoming-webhook; map severity→on-call rota (tie C7 incident). Cần: webhook URL + rota. |
| T2.5 | Billing-API telemetry thật | 🟡 (fetch vs endpoint local) | `provider-usage-fetch.sh` trỏ tới usage API thật của OpenAI/Anthropic (đã có schema-gate + reconcile). Cần: API key thật (chưa test). |
| T2.1 | KMS mặc định + HSM | 🟡 Docker lab ✅ (Vault Transit) | `infra/local-prod` dựng Vault dev @ `:18200`; `infra-lab verify` chứng minh sign+verify. Prod: Vault/AWS-KMS/CloudHSM + token ngắn hạn qua IdP; bỏ fallback khoá local ở môi trường prod. |
| T2.2 | WORM store thật (S3 Object Lock) | 🟡 Docker lab ✅ (MinIO Object Lock) | MinIO bucket `casan-worm` bật Object Lock COMPLIANCE 1d. Prod: S3 Object Lock/QLDB + trusted timestamp; cần AWS creds + bucket Object-Lock. |
| T2.3 | Dashboard deploy + auth | 🟡 Docker lab ✅ (nginx basic auth + /healthz) | Dashboard container + nginx reverse-proxy @ `:18080`, user/pass lab `casan/casan`; `/healthz` exposed. Prod: host/TLS/OIDC or enterprise auth. |
| T2.4 | Kênh alert managed + on-call | 🟡 Docker lab ✅ (webhook emulator) | `alert-webhook` @ `:19092` nhận live POST. Prod: trỏ `CASAN_ALERT_WEBHOOK` tới Slack/PagerDuty + rota/on-call thật. |
| T2.5 | Billing-API telemetry thật | 🟡 Docker lab ✅ (billing API mock) | `billing-api` @ `:19093/usage`; `provider-usage-fetch.sh` import được provider telemetry. Prod: OpenAI/Anthropic usage API thật + key. |
| T2.6 | Sandbox: rootless/nsjail + base image CI | 🟡 (container isolation live via Docker) | Thêm profile nsjail/bubblewrap cho Linux CI (không cần Docker daemon); hardened base image tối thiểu. `sandbox-container.sh` đã có bản Docker. |
## TIER 3 — Platform plans (INDEX 01–12, việc lớn nhiều phiên) 📋
@@ -53,10 +53,10 @@
---
## Trần điểm & điều kiện lên "Strong (81+)"
Harness thấp nhất = 80 (H5, H6). Để CẢ pipeline vào Strong cần đóng **các mục 🔌 TIER 2**
(IdP live, WORM-S3, KMS default, dashboard deploy, managed alert, billing-API) — đều là
**hạ tầng/khoá thật**, không code thuần được nữa. Các mục 🟦 TIER 1 nâng H4/H2 nhưng không
đổi trần (H5/H6 vẫn 80) cho tới khi TIER 2 xong.
Harness thấp nhất = 80 (H5, H6). Docker local-prod lab đã chứng minh luồng infra
production-like chạy được trên Mac, nhưng để CẢ pipeline vào Strong vẫn cần bản **managed thật**
(enterprise IdP/JWKS, WORM-S3/QLDB, KMS default/HSM, dashboard deploy TLS/OIDC, managed alert/on-call, billing-API thật).
Các mục này cần key/dịch vụ ngoài nên chưa nên claim production Strong.
## Cách kiểm chứng nhanh (bất kỳ AI kế nào)
```bash
@@ -67,4 +67,5 @@ for s in run-casan4-harness adversarial-harness phase1-track-a phase2-track-c \
phase10-traceability; do
bash .specify/tests/$s-tests.sh >/dev/null 2>&1 && echo "$s OK" || echo "$s FAIL"; done
# KMS live cần Vault dev; C6 live cần Docker (không có thì SKIP, không fail).
bash .specify/tests/phase-prod-infra-lab-tests.sh # starts/verifies local-prod Docker lab
```
+11 -4
View File
@@ -64,6 +64,12 @@
| B4 | **Model-digest pinning (V16)**: approved Ollama model digest pinned; router verifies live digest before generation/classify/judge; mismatch blocks by default with warn mode for rollout | [implemented+tested] | `model-digest-check.sh`, `model-call.py`, `.specify/security/model-digest.pin` | phase3-model-router (digest cases) |
| Plan-10 | **Traceability REQ→code→test MVP**: parse `FR-*`, require code+test mapping per FR, generate matrix, and include it in Evidence Pack | [implemented+tested] | `traceability-matrix.py`, `.specify/traceability-map.json`, `docs/output/casan/traceability-matrix.json` | phase10-traceability (3) |
### Phase 7 — Local production-like infra lab (Tier-2 emulation) — [implemented+tested]
| Control | Status | Where | Test |
|---|---|---|---|
| Docker Compose lab for Vault KMS, OIDC/JWKS IdP, MinIO Object Lock WORM, dashboard behind nginx basic auth, alert webhook, and provider billing API mock | [implemented+tested] (local-prod emulation; managed prod services still required for Strong claim) | `infra/local-prod/docker-compose.yml`, `infra-lab.sh` | phase-prod-infra-lab (2); `infra-lab verify` internal 7/0 |
## 2. Test inventory (all suites)
| Suite | Checks | Purpose |
@@ -81,7 +87,8 @@
| `phase-c6-sandbox-tests.sh` | 6 | **New** — TRUE container isolation (C6, live via Docker / skip-aware) |
| `phase-h4-split-inject-tests.sh` | 8 | **New** — split-injection assembly scan + classifier-inject (B2) |
| `phase10-traceability-tests.sh` | 3 | **New** — Plan-10 FR→code→test matrix + fail-able missing-test gate |
| **Total** | **218** | Baseline 79 preserved; +139 new hardening/traceability checks. Last full harness run 2026-07-06, 0 fail. Direct `phase3-model-router-tests.sh` adds 10/0 for model-router/digest/cloud/fallback checks. |
| `phase-prod-infra-lab-tests.sh` | 2 | **New optional/local-prod** — Docker Compose infra lab starts + verifies Vault/IdP/MinIO/dashboard/alert/billing |
| **Total** | **218 core + 2 local-prod infra lab** | Baseline 79 preserved; +139 new hardening/traceability checks. Last full harness run 2026-07-06, 0 fail. Direct `phase3-model-router-tests.sh` adds 10/0; `infra-lab verify` adds 7 internal infra checks. |
Run order note: `run-casan4-harness-tests.sh` does `rm -rf .specify/logs`, so run it
**first** and never concurrently with the other suites.
@@ -96,7 +103,7 @@ Run order note: `run-casan4-harness-tests.sh` does `rm -rf .specify/logs`, so ru
| Provider billing-API telemetry | [partial] — API fetch + schema gate + local-vs-provider reconciliation done against a live local endpoint; real OpenAI/Anthropic usage-API calls (needs keys) planned | Phase 5 D2 |
| True runtime isolation | [partial] — real container isolation done + validated live via Docker (C6 phase-6); nsjail/rootless + a hardened base image for CI still planned | Plan-07 C6 (V22) |
| KMS key management (rotation, non-exportable) | [partial] — Vault Transit path implemented + validated live; not yet the default (local-key fallback), no HSM/short-lived IdP tokens | Plan-07 B3 |
| Reviewer approval workflow | [partial] — cryptographic **approval-identity** done (signed reviewer + role) + mock **IdP/OIDC JWT** done; live IdP/JWKS + policy versioning/diff still planned | Plan-07 C4 (V20) |
| Reviewer approval workflow | [partial] — cryptographic **approval-identity** done + Docker mock **IdP/OIDC JWKS** done; enterprise IdP/JWKS + policy versioning/diff still planned | Plan-07 C4 (V20) |
| External append-only (WORM) audit | [partial] — hash-linked local ledger + rollback/tamper detection done; true WORM store (S3 Object Lock/QLDB) + trusted timestamp planned | Plan-07 C5 (V21) |
| Live CVE/OSV scanning wired in | [partial] — availability detected; local denylist authoritative offline | Plan-07 C2 follow-up |
@@ -113,7 +120,7 @@ isolation validated live/skip-aware via Vault dev + Docker). Fair maturity score
dimension closed; **H5 and H6 remain at 80** (their remaining gaps are infra), so the
**lowest harness stays 80** — CASAN **Level 4**, proven by attack. This is **not** full
production readiness: crossing the whole pipeline into "Strong (81+)" still needs the
H5/H6 infra items — live IdP/JWKS, a true WORM store (S3 Object Lock),
KMS-by-default + HSM, a deployed dashboard host + managed alert channel/on-call, and
H5/H6 infra items — enterprise IdP/JWKS, a true WORM store (S3 Object Lock/QLDB),
KMS-by-default + HSM, a deployed dashboard host with TLS/OIDC + managed alert channel/on-call, and
real billing-API telemetry — the [partial]/[planned] rows above and in
`CASAN_PLAN_07_PRODUCTION_HARDENING.md`.
@@ -19,7 +19,7 @@
## 2. Thang điểm sẵn sàng production (0–5, cao = tốt)
> ✅ **CẬP NHẬT 2026-07-06 — Track A + C-MVP + Evidence Pack + H5/H6/deep-gap hardening + Plan-10 traceability ĐÃ LÀM + TEST (218 core checks, 0 fail; model-router riêng 10/0).**
> ✅ **CẬP NHẬT 2026-07-06 — Track A + C-MVP + Evidence Pack + H5/H6/deep-gap hardening + Plan-10 traceability ĐÃ LÀM + TEST (218 core checks, 0 fail; model-router riêng 10/0). Local production-like Docker infra lab cũng đã có (2/0, verify nội bộ 7/0).**
> Bảng dưới có cột **Baseline → Nay**. Điểm chấm CÔNG TÂM (0–100, theo `casan_harness_assessment.md`):
> **H4 = 80 · H5 = 76→80 ⬆ · H6 = 79→80 ⬆ · trung bình 7 harness ~80.9/100 · không còn harness nào dưới 80 → CASAN Level 4 (vững ngưỡng)**.
> Nguồn: `00_SUBMISSION_PACKAGE/evidence/scoring-run-report.md`. Chi tiết implemented-vs-planned: `CASAN_HARDENING_STATUS.md`.
@@ -30,7 +30,7 @@
| Fail-safe | 4 | **4.5** | `CASAN_SECURITY_STRICT` fail-closed — hết "semantic SKIP âm thầm" | — |
| Toàn vẹn/chống giả mạo (H5) | 3 | **4** | telemetry vào manifest **ký RSA** (sửa 1 token → MISMATCH) | — |
| Kiểm soát chi phí (H6) | 3 | **4** | trần tuyệt đối/call + ngân sách tích luỹ + cold-start (ngoài median×mult) | hard-cap per-provider live |
| Quan sát (observability) | 3 | **4** | telemetry toàn vẹn (ký) · **alerting LIVE** (webhook + dedup + dead-letter, end-to-end từ step fail) · **dashboard hosted** (`/healthz` stale-aware) · **provider-API reconcile** (bắt under-reporting) · window breaker (V15) | dashboard deploy thật + auth · kênh alert managed (Slack/PagerDuty + on-call) · billing-API thật |
| Quan sát (observability) | 3 | **4** | telemetry toàn vẹn (ký) · **alerting LIVE** (webhook + dedup + dead-letter, end-to-end từ step fail) · **dashboard hosted** (`/healthz` stale-aware) · **Docker lab** có nginx auth + alert/billing mock · provider-API reconcile · window breaker (V15) | dashboard deploy managed + TLS/OIDC · Slack/PagerDuty/on-call thật · billing-API thật |
| Đa domain/i18n | 2 | **2.5** | benign corpus VI/JA/EN đo được (FP 0%) | detection vẫn chủ yếu EN (Track B) |
| Quản lý khóa | 2 | **4** | **KMS live** (Vault Transit) — ký qua KMS, **rotate**, khoá **non-exportable** (đã chạy thật) | KMS chưa mặc định (fallback local) · HSM · IdP token ngắn hạn |
| Phủ kiểm thử | 4 | **4.5** | **218 core tests** (35+44+25+29+7+12+7+20+15+7+6+8+3) đối kháng, 0 fail | line/symbol-level traceability + CI release gate |
@@ -45,12 +45,12 @@
| Supply-chain (dependency sinh ra) | 1 | **3.5** | `supply-chain-gate.sh` (V18) — typosquat/postinstall/denylist + dep-diff | CVE/OSV scanner live chưa nối |
| Data-governance / anti-exfil | 2 | **4** | `data-exfil-guard.sh` (V19) — secret→cloud BLOCK, PII→audit mask | — |
| Evidence Pack (Plan-09) | — | **4** | `casan pack/verify-pack` — manifest ký, tamper-evident, certified-gate | KMS sign · hosted store |
| Policy governance / approval | 2 | **4** | **approval-identity + mock IdP/OIDC** (C4) — reviewer KÝ request hoặc JWT RS256 + role authz, hết env-var; SoD giữ (đã test 12/12) | live IdP/JWKS · policy versioning/diff [planned] |
| Policy governance / approval | 2 | **4** | **approval-identity + Docker mock IdP/OIDC JWKS** (C4) — reviewer KÝ request hoặc JWT RS256 + role authz, hết env-var; SoD giữ (đã test 12/12 + infra lab) | enterprise IdP/JWKS · policy versioning/diff [planned] |
| Runtime sandbox | 1 | **2.5** | `sandbox-run.sh` scaffold (V22) — chặn ssh/egress/forkbomb/write-outside + ulimit | **cô lập kernel thật** (container/nsjail) [planned] |
| External append-only audit | 1 | **3.5** | **WORM ledger** (C5) — ship head hash-link ngoài, bắt rollback (`AUDIT_GAP_DETECTED`) + tamper | WORM store thật (S3 Object Lock) · trusted timestamp [planned] |
| Incident response | 1 | **1** | — | severity/owner/kill-switch (C7) [planned] |
**→ C-MVP (C1+C2+C3 + Evidence Pack) ~3.8/5 + H5-hardening (C4 approval-identity + mock OIDC, KMS live, C5 WORM) + H6-hardening (D1 alerting live, D2 provider-API reconcile, D3 dashboard hosted, D4 window breaker V15) + deep-gap closers + Plan-10 traceability [đã làm + test thật]. Còn: live IdP/JWKS, WORM-store thật, KMS default/HSM, dashboard deploy + kênh alert managed, billing-API thật [planned].** Trio H4/H5/H6 nay **~4.0/5 (H4=80·H5=80·H6=80)**; harness thấp nhất nhích **76 (H5) → 79 (H6) → 80 (đồng đều)**. Production toàn diện vẫn cần các mục [planned] ở trên.
**→ C-MVP (C1+C2+C3 + Evidence Pack) ~3.8/5 + H5-hardening (C4 approval-identity + Docker mock OIDC/JWKS, KMS live, C5 WORM/MinIO Object Lock lab) + H6-hardening (D1 alerting live, D2 provider-API reconcile, D3 dashboard hosted/nginx auth lab, D4 window breaker V15) + deep-gap closers + Plan-10 traceability [đã làm + test thật]. Còn: enterprise IdP/JWKS, S3 Object Lock/QLDB thật, KMS default/HSM, dashboard deploy managed + kênh alert managed, billing-API thật [planned].** Trio H4/H5/H6 nay **~4.0/5 (H4=80·H5=80·H6=80)**; harness thấp nhất nhích **76 (H5) → 79 (H6) → 80 (đồng đều)**. Production toàn diện vẫn cần các mục [planned] ở trên.
## 3. Bảng đường lọt (tóm tắt từ threat-model)