Repository navigation
fix(platform): enforce the GDPR erasure governance gates - #3135
Merged
Merged
Conversation
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.
This was referenced Sep 2, 2026
larryro
marked this pull request as ready for review
September 3, 2026 03:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
decideApprovalnow carries the caller's session-resolved role (orgMember.role, trusted-headers aware) and kind-gates erasure rows viaassertRoleMayDecideKind: both deciding directions demand an org admin (403FORBIDDEN). Filer ≠ approver stays hard-enforced inconfirmAndScheduleErasure. 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.
retryErasurealso gained the acting admin for honest audit attribution (was hardcodedsystem). Regression: integration check "every lifecycle door refuses a plain member" (six doors × 403forbidden; 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
pendingwitheffective_at_msNULL — unschedulable, uncancellable (cannotCancelAfterCooldownwas a lie in that state), and the live-unique index blocked re-filing. NowdecideApproval(status: 'rejected')dispatchesrejectErasurein the same transaction: the receipt lands terminalcancelled(the existing status vocabulary; the live index covers only pending/running, so the subject is immediately re-filable), attributed to the rejecting admin, audited asgdpr_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 existingcancelledbadge + 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 409ALREADY_PENDING— the wedge, demonstrated).4. The documented
childreason code could never be filed — fixed.The service carried a divergent local copy of
ERASURE_REASON_CODESwithchild_consent, while the picker, the i18n labels, and the docs all offerchild. The service now validates against the one constants module (core/governance/erasure_constants.ts) viaisValidErasureReasonCode; migration0062folds any storedchild_consentrows intochild(idempotent, rolling-safe — reads never validate stored codes). The constants' divergent, unimportedERASURE_WATCHDOG_TIMEOUT_MESSAGEcopy 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: 400unknown 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_metadatarows (document_id IS NULL) without deleting the S3 objects behindstorage_ref— after a "done" receipt the subject's bytes lived on. It now deletes blob-then-row per upload with the stricts3DeleteObject(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 landspartialwithfailed 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 waypurgeDocumentguardshistoryFiles. Regression: integration checks "the uploads pass deletes the blob behind the ledger row" (MinIO-backed: blob HEAD 404 after cascade,counts.uploadson the receipt) and "a failed blob delete lands partial + row kept, retry finishes" (store resolution broken via an org BYOconnection.jsonwithout its secrets sidecar, then healed; base run: receipt claimed done while the blob survived).Verification
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 --noEmitandbunx oxlint --type-awareonservices/platform— clean.packages/uii18n suite (voice/terminology over messages + docs): 124 files / 1,173 tests green.services/docsstructural tests: 30 files / 194 tests green.backend:integrationon a throwaway tale-db + MinIO: 286/286 green on this branch (observed; the sibling-branch baseline on this box was also 286).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 gainsgdpr_erasure_rejected.Refuted / notes
Cross-class discoveries (not fixed here)
wf_executions/ prompt-templates passes (rg wf_execution|promptoverdomains/erasure/service.tsanddomains/retention/service.tsis empty). Docs-vs-code gap of the same honesty class, but new cascade surface — flagging instead of piggybacking.deleteBlobBestEffortswallows 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 themembertable directly; underTRUSTED_HEADERS_ENABLEDthe 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).