feat(api): M8 7.15 slice 1 — container/file classification + upload gating (CLS-04) #203

Merged
amiryahaya merged 1 commit from feat/m8-715-classification-core-1 into main 2026-11-14 05:18:19 +01:00
Owner

First enforcement slice of the CLS lattice (#158, SRS §3.18 as amended by #199's §12).

What

  • folders.LevelId + files.LevelId — nullable FKs to the ladder; NULL while the tenant flag is off = byte-identical zero-delta
  • Folder creation: optional level (flag on → defaults Internal; capped at creator's clearance per F-CLS1; flag off + explicit level → 409)
  • Upload gating on BOTH upload paths (multipart + chunked CreateUploadUrl): caller clearance ≥ folder level, else 403 classification_insufficient (CLS-04)
  • Per-file override at upload: raise-only, capped at the uploader's own clearance; omitted = inherit
  • Re-classification: PATCH /api/folders/{id}/classification + /api/files/{id}/classification — owner/uploader-or-tenant-admin, audited classification_set/raised/lowered; container-constraint semantics (§12 CLS-E4): folder changes never cascade to stored files (test-pinned)
  • Backfill extension: enabling classification migrates existing folders/files to Internal too (CLS-01)
  • DTOs carry level (name+rank) — feeds 7.16 UX
  • Fix ride-along: invitation-accepted members of a classified tenant now get the Internal clearance row (CLS-02 gap)
  • AuthzMatrix rows for both routes

Verification

12 new tests; full suite 1062 total, 0 failed, 40 skipped (known set). Flag-off zero-delta pinned by three assertions (create-with-level 409, plain flow unchanged + level null, reclassify 409).

Notes

  • Tenant-admin re-classify arm: covered by CanReclassifyAsync's role check + the member-403 integration path; the happy-path-through-a-tenant-admin hit a test-infra seam (test-scope writes intermittently invisible to request scopes on the shared SQLite connection) — documented + filed as #202; production unaffected.
  • No new migration ordering risk: AddContainerClassification is additive (nullable columns + FKs + indexes); the #196 migrations CI leg exercises it on fresh PG17.
First enforcement slice of the CLS lattice (#158, SRS §3.18 as amended by #199's §12). ## What - **`folders.LevelId` + `files.LevelId`** — nullable FKs to the ladder; NULL while the tenant flag is off = byte-identical zero-delta - **Folder creation**: optional level (flag on → defaults Internal; capped at creator's clearance per F-CLS1; flag off + explicit level → 409) - **Upload gating on BOTH upload paths** (multipart + chunked CreateUploadUrl): `caller clearance ≥ folder level`, else **403 `classification_insufficient`** (CLS-04) - **Per-file override at upload**: raise-only, capped at the uploader's own clearance; omitted = inherit - **Re-classification**: `PATCH /api/folders/{id}/classification` + `/api/files/{id}/classification` — owner/uploader-or-tenant-admin, audited `classification_set/raised/lowered`; **container-constraint semantics** (§12 CLS-E4): folder changes never cascade to stored files (test-pinned) - **Backfill extension**: enabling classification migrates existing folders/files to Internal too (CLS-01) - **DTOs** carry level (name+rank) — feeds 7.16 UX - **Fix ride-along**: invitation-accepted members of a classified tenant now get the Internal clearance row (CLS-02 gap) - AuthzMatrix rows for both routes ## Verification 12 new tests; full suite **1062 total, 0 failed, 40 skipped** (known set). Flag-off zero-delta pinned by three assertions (create-with-level 409, plain flow unchanged + level null, reclassify 409). ## Notes - Tenant-admin re-classify arm: covered by `CanReclassifyAsync`'s role check + the member-403 integration path; the happy-path-through-a-tenant-admin hit a **test-infra seam** (test-scope writes intermittently invisible to request scopes on the shared SQLite connection) — documented + filed as #202; production unaffected. - No new migration ordering risk: `AddContainerClassification` is additive (nullable columns + FKs + indexes); the #196 migrations CI leg exercises it on fresh PG17.
feat(api): M8 7.15 slice 1 — container/file classification + upload gating (CLS-04)
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m41s
API CI / migrations (pull_request) Successful in 2m53s
API CI / build-and-test (pull_request) Successful in 5m45s
982faf68c4
Schema: folders.LevelId + files.LevelId (nullable FK to
classification_levels, Restrict; indexed). Migration
AddContainerClassification. NULL while the tenant flag is off —
byte-identical zero-delta behavior.

CLS-04 surface:
- Folder creation accepts level_id (flag on: defaults Internal; capped
  at the creator's clearance per F-CLS1; flag off + level → 409)
- BOTH upload paths gated (simple multipart + chunked CreateUploadUrl):
  caller clearance >= folder level, else 403 classification_insufficient
- Per-file override at upload: raise-only (>= folder level) and capped
  at the uploader's own clearance; omitted = inherit folder level
- EnableClassification backfill extended to containers/files (CLS-01
  'existing data migrates to Internal')
- PATCH /api/folders/{id}/classification + PATCH /api/files/{id}/
  classification — owner/uploader-or-tenant-admin (CLS-07), audited
  classification_set/raised/lowered; CONTAINER-CONSTRAINT semantics per
  §12 CLS-E4: folder level changes never cascade to stored files (pinned
  by test); folder lowering with violating-grant auto-revoke lands with
  slice 3's lattice filter
- Folder/file DTOs carry the level (name+rank) for the 7.16 UX

ClassificationGates (Files module): ladder/clearance resolvers, upload
gate, override resolution, reclassify permission. Null clearance reads
as Internal (CLS-02 default).

Fix ride-along: members joining a classified tenant via invitation now
get the Internal clearance row (CLS-02 gap — UserTenant was created
without clearance).

Tests: ClassificationUploadGatingTests (12) — backfill, defaults,
explicit-level audit, above-own-clearance 403, inherit, below-folder
403, override up/down/capped, flag-off zero-delta trio, no-cascade,
member-403 + owner raise/lower audits. Suite 1062/0/40. Tenant-admin
re-classify arm covered by CanReclassifyAsync role check + member-403
integration (test-infra seam documented in #202).

AuthzMatrix rows added for both classification routes (Coverage test).
Sign in to join this conversation.
No description provided.