Skip to content

fix(platform): enforce the GDPR erasure governance gates - #3135

Merged
larryro merged 2 commits into
mainfrom
fix/erasure-governance-gates
Sep 3, 2026
Merged

larryro merged 2 commits into
mainfrom
fix/erasure-governance-gates

Conversation

@larryro

@larryro larryro commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The DSR docs promise a specific governance contract — the whole erasure lifecycle is run by org admins, dual approval means a second admin (distinct from the filer) decides, a rejected or cancelled request leaves the subject re-filable, every documented reason code files, and a receipt that says erased is true down to the bytes in object storage. The code enforced almost none of that: the only role check sat on filing. This PR makes the code match the promise, kind-scoped so the generic approvals door keeps its org-member posture for every non-erasure kind (connector_operation, human_input_request, conversations; review kinds already refuse toward their dedicated doors).

Findings

1. Any org member could approve or reject a dual-approval erasure — fixed.
decideApproval now carries the caller's session-resolved role (orgMember.role, trusted-headers aware) and kind-gates erasure rows via assertRoleMayDecideKind: both deciding directions demand an org admin (403 FORBIDDEN). Filer ≠ approver stays hard-enforced in confirmAndScheduleErasure. Regression: unit tests on the pure gate (backend/domains/approvals/service.test.ts) + integration check "a plain member can decide an erasure approval in neither direction" (member approve AND reject → 403, row stays pending; base run: member approve returned 200 and scheduled the cascade).

2. Cancel/retry/extend/list lacked the admin gate the routes header claimed — fixed.
The erasure router now has a router-level admin gate over every operation (list, file, detail, cancel, retry, extend) on the session-resolved role — reads included, since receipts enumerate subjects and lawful grounds. The header comment now describes what is actually enforced; filing keeps its in-service audited deny as defense in depth. retryErasure also gained the acting admin for honest audit attribution (was hardcoded system). Regression: integration check "every lifecycle door refuses a plain member" (six doors × 403 forbidden; base run: member list returned 200).

3. A rejected dual approval wedged the subject forever — fixed.
Rejection used to update only the approvals row; the receipt sat pending with effective_at_ms NULL — unschedulable, uncancellable (cannotCancelAfterCooldown was a lie in that state), and the live-unique index blocked re-filing. Now decideApproval(status: 'rejected') dispatches rejectErasure in the same transaction: the receipt lands terminal cancelled (the existing status vocabulary; the live index covers only pending/running, so the subject is immediately re-filable), attributed to the rejecting admin, audited as gdpr_erasure_rejected (new i18n label in en/de/fr; de-CH carries no override for this block). Cancelling while parked awaiting approval now also works and settles the linked approvals row. UI needs no new state: the existing cancelled badge + drawer fields render it. Regression: integration checks "DSAR rejection lands the receipt cancelled + re-filable" and "cancelling a parked dual-approval request settles both rows" (base run: receipt stayed pending and the re-file bounced 409 ALREADY_PENDING — the wedge, demonstrated).

4. The documented child reason code could never be filed — fixed.
The service carried a divergent local copy of ERASURE_REASON_CODES with child_consent, while the picker, the i18n labels, and the docs all offer child. The service now validates against the one constants module (core/governance/erasure_constants.ts) via isValidErasureReasonCode; migration 0062 folds any stored child_consent rows into child (idempotent, rolling-safe — reads never validate stored codes). The constants' divergent, unimported ERASURE_WATCHDOG_TIMEOUT_MESSAGE copy is unified the same way: the canonical value is the string persisted on receipts today (the retry guard matches on it), pinned by a unit test. Regression: unit tests + integration check "the documented 'child' reason code files" (base run: 400 unknown reason code). Note: migration is hand-numbered 0062 — 0059-0061 are taken by sibling branches; the boot runner applies by filename order with no contiguity requirement.

5. The uploads pass orphaned the subject's blobs in object storage — fixed.
The pass deleted app.file_metadata rows (document_id IS NULL) without deleting the S3 objects behind storage_ref — after a "done" receipt the subject's bytes lived on. It now deletes blob-then-row per upload with the strict s3DeleteObject (404 = already gone = success; legacy Convex refs have no reachable backend, row-only), deliberately NOT the retention sweeps' best-effort idiom: a failed blob delete throws, the pass fails, the receipt lands partial with failed passes: uploads, the rows stay, and Retry re-attempts. Shared-ref question checked: upload keys are minted per object (buildObjectKey → <org>/<uuid>), no dedup-reuse in any write path; an in-batch ref-dedupe set guards double-listed refs the way purgeDocument guards historyFiles. Regression: integration checks "the uploads pass deletes the blob behind the ledger row" (MinIO-backed: blob HEAD 404 after cascade, counts.uploads on the receipt) and "a failed blob delete lands partial + row kept, retry finishes" (store resolution broken via an org BYO connection.json without its secrets sidecar, then healed; base run: receipt claimed done while the blob survived).

Verification

  • Unit: bunx vitest --run --project server --project pii — 374 files / 72,285 tests green (includes the two new colocated suites and the i18n parity checks over the message catalogs).
  • bunx tsc --noEmit and bunx oxlint --type-aware on services/platform — clean.
  • packages/ui i18n suite (voice/terminology over messages + docs): 124 files / 1,173 tests green. services/docs structural tests: 30 files / 194 tests green.
  • backend:integration on a throwaway tale-db + MinIO: 286/286 green on this branch (observed; the sibling-branch baseline on this box was also 286).
  • Red proof: with the five backend source files stashed (probes kept), the suite fails exactly the new checks — see the per-finding base-run notes above. The two vitest suites are structurally red on main (the gate helpers don't exist there).

Docs

docs/{en,de,fr}/platform/admin/governance/data-subject-requests.md: the Awaiting-approval row documents rejection, the Cancelled row covers both cancel windows + rejection + re-filability, and the audit chain gains gdpr_erasure_rejected.

Refuted / notes

  • None of the five findings refuted — all reproduced in code and in the base run.
  • The approvals door stays org-member for every non-erasure kind on purpose (the 0.4 posture the routes header documents); the gate is kind-scoped to avoid locking down connector/human-input/conversation decisions.

Cross-class discoveries (not fixed here)

  • Docs + i18n cascade categories promise workflow executions and personal prompt templates erased; the 0.5 cascade has no wf_executions / prompt-templates passes (rg wf_execution|prompt over domains/erasure/service.ts and domains/retention/service.ts is empty). Docs-vs-code gap of the same honesty class, but new cascade surface — flagging instead of piggybacking.
  • The retention sweeps' deleteBlobBestEffort swallows blob-delete failures by design; their counts can include undeleted blobs. Pre-existing posture — the erasure pass is now stricter than its siblings.
  • requestErasure (and legal-holds) role checks read the member table directly; under TRUSTED_HEADERS_ENABLED the placeholder row role could deny a proxy-role admin at the service layer. The new router gate uses the session-resolved role, so the erasure lifecycle is correct for trusted-headers admins up to filing's in-service re-check (pre-existing behavior, unchanged).

The DSR docs promise an admin-run lifecycle, admin-only dual control,
a rejection that frees the subject, the documented reason codes, and a
receipt that is true down to the bytes. Enforce all of it:

- kind-gate the generic approvals decide door: erasure rows demand an
  org admin (session-resolved role) in BOTH directions; other kinds
  keep the org-member posture
- admin-gate the whole erasure router (list/file/detail/cancel/retry/
  extend) and make the routes header truthful; retry audits the acting
  admin instead of 'system'
- a rejected dual approval settles the receipt terminally ('cancelled',
  audited as gdpr_erasure_rejected, en/de/fr labels) and the subject is
  re-filable; cancelling a parked request works and settles the
  approvals row
- one reason-code vocabulary: the service validates against
  core/governance/erasure_constants.ts ('child' files; migration 0062
  folds stored 'child_consent' rows in; the watchdog sentinel is
  unified on the persisted value)
- the uploads pass deletes the S3 blob behind each ledger row,
  blob-then-row, strict: a failed delete fails the pass to 'partial'
  and keeps the row for Retry instead of reporting a false erasure

Unit tests pin the pure gates; integration checks cover the member
refusals, the rejection arc, the 'child' filing, and the MinIO-backed
blob deletion + honest-failure retry (286/286; 278/286 unfixed).
The DSR page's status table now says what the code enforces: a second
admin may reject a dual approval (which cancels the request), Cancelled
covers both cancel windows and rejection and leaves the subject
re-filable, and the audit chain includes gdpr_erasure_rejected. Same
three touches in en, de, and fr.
@larryro
larryro marked this pull request as ready for review September 3, 2026 03:53
@larryro
larryro merged commit c067e31 into main Sep 3, 2026
23 checks passed
@larryro
larryro deleted the fix/erasure-governance-gates branch September 3, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant