mirror of
https://github.com/beenuar/AiSOC.git
synced 2026-11-24 08:35:46 +08:00
## What WS2 of the gap-closure program: the long-term security data lake. The lake's 400-day TTL is a hard ceiling nothing exempts — everything older exists only if it was exported first. This PR makes that export real, verified, rehydratable and portable, and narrows legal holds to their own rows. ## WS2.1 — Archive tier (migration 170) Closed `(tenant, month)` partitions export to the tenant's **own S3-compatible bucket** as Parquet with a **signed manifest** (row count, event-time bounds, schema + OCSF version, per-file SHA-256; the evidence-bundle signer). Design decisions that carry the honesty: - **The database that owns the rows writes the files**: export, count re-read and SHA-256 all run *inside ClickHouse* (`INSERT INTO FUNCTION s3(...) Parquet`, `s3(...,'Parquet')`, `s3(...,'RawBLOB')`) — no second data path whose row semantics could drift. - **"Exported" is a claim; "verified" means the bucket was read back and matched.** A corrupted object fails naming what differed — including the sharp case a count check cannot see: a *valid* Parquet with the same rows and different bytes, caught by the checksum leg alone (proven live, and pinned by the negative control). - An **open month is refused** (it is still receiving rows — the connector-window lesson applied to archival). UUID/IP columns export as strings (ClickHouse cannot write UUID to Parquet; found live, Code 50). - Per-tenant policy, **default off**; bucket credentials vault-encrypted, decrypted at export time; ClickHouse masks `s3()` credential positions in its query log (documented reliance). **WORM** is recorded as *declared by operator, not verified by this service* — never implied verified. - Hourly sweep worker (`lake_archive_sweep`) exports closed months for opted-in tenants, verifies, and expires rehydrations; bounded per tick. ## WS2.2 — Rehydration (migration 171) **Estimate first** (bytes/files/months from the manifests; retrieval cost **null unless `AISOC_ARCHIVE_RETRIEVAL_PRICE_PER_GB` is configured** — never an invented figure), then an audited load (**requester + reason required**) into an expiring scratch table `aisoc.rehydrated_<8hex>`. The lake explorer queries it through its own rewriter: the allowlist gained a **regex-pinned arm** that cannot widen (non-hex/overlong/foreign-schema names refused) and injects the same tenant predicate `raw_events` gets — live-proven: owner reads 3 rows, another tenant reads 0. The loader **evicts foreign-tenant rows after landing** because a bucket is not a tenancy boundary. (ClickHouse 23.8's Parquet pushdown cannot compare file-schema strings with UUID hints in either direction — Code 169, found live — so tenancy is enforced post-landing by mutation, not by pushdown.) ## WS2.3 — Portability (migration 171) Range export to a bucket **the tenant names** (per-request credentials, never persisted): one Parquet object per month + signed manifest + schema document. The gate proves "no AiSOC code": **DuckDB** opens the object over s3 and its count matches the signed manifest. ## WS2.4 — Scoped legal holds (migration 172) Holds gain `covers_from`/`covers_until`. A `user`/`host`/`ip` hold now **exempts exactly its own rows** from the retention purge — the Postgres alert DELETE through the affected-* arrays, the ClickHouse mutation through user/hostname/IP columns (addresses compared as addresses: `toIPv6OrDefault`, because IPv6 columns render v4 mapped), each within the hold's window, **every value a bind**. The rest of the tenant purges on schedule. This deliberately supersedes the recorded whole-tenant freeze — the superseded test now pins the narrowing — while a tenant-wide hold still freezes everything, because that is what it means. The lake TTL stays untouchable: a hold older than 400 days is only satisfiable through the archive tier, and the new **retention attestation** (`GET /lake/retention-attestation`) says so — each tier from its own store, "not measured" where a store cannot answer. ## Testing - **`tests/isolation/test_lake_archive_live.py` — 9 cases on real ClickHouse 23.8 + MinIO + Postgres** (new `integration.yml` step provisions all three; no-skip guard): export→manifest→verify green path; open-month refusal; garbage corruption fails; **same-count content swap caught by checksum alone**; rehydration lands tenant-scoped and explorer-queryable; estimate honesty; DuckDB portability; **held rows survive the live purge (5→3) while unheld rows delete**; attestation from real stores. - `services/api/tests/test_lake_archive.py` — 20 unit cases (paths/windows, destination refusals, cost honesty both ways, scratch-table namespace pinning, explorer-arm cannot widen, hold-exemption composers never interpolate a value, IPv6-as-address, `covers()` window semantics). - Full API suite **5,577 passed**; lake_sql + retention suites green with the superseded freeze test rewritten to pin the narrowing. **Negative controls (applied, observed failing, restored):** 1. Disabling the SHA-256 comparison → `test_a_same_count_content_swap_is_caught_by_the_checksum_alone` fails (the count leg cannot see it). 2. Removing the exemption composition from the alerts purge → the live hold test fails at 5 ≠ 3 (held rows purged). ## Gates route_auth OK · route_tenant_scope OK · tenant_query_predicates OK (ratchet 80 → **85**, five sweep statements recorded with the approval_expiry/sessions enumeration shapes) · module_reachability OK · migration_numbering OK (170–172, allocated block) · ORM parity OK · mypy baseline OK (which caught real API mismatches: `emit_audit` signature, `CredentialVault` construction — fixed, not ignored) · ruff clean · claim matrix **+3 GATED rows, 410 — 401/9/0** recomputed by the script · readme_gates OK · OpenAPI regenerated (additive) · README's "not a SIEM replacement" sentence updated to the proven scope · new ops doc `operations/lake-archive` in the sidebar. ## Could not verify - GCS/Azure arms: the client interface is S3-compatible-first; GCS interop/Azure need their own arms (stated in docs, not claimed). - WORM/Object-Lock: bucket properties this service does not manage; recorded as a declaration and reported as such, never as verified. - The sweep worker's scheduling is wired through the same guarded-lease path as the other workers but was exercised via `run_once` in the live suite, not through a multi-hour soak.
1.2 MiB
1.2 MiB