Skip to content

Erasure audit rows name the request token's principal, not the body's requester - #203

Merged
zlareb1 merged 22 commits into
mainfrom
fix/erasure-audit-actor-from-token
Nov 3, 2026
Merged

zlareb1 merged 22 commits into
mainfrom
fix/erasure-audit-actor-from-token

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The erasure.started, erasure.failed, erasure.completed and erasure.exported audit rows name the principal of the request's token as actor; the body's requester is recorded in the row's subject.

Why

Failing case: an admin calls erasure.request {org:"o", scope_type:"user_id", scope_value:"u-42", requester:"someone-else@o"}. Every erasure.* audit row of that saga was written with actor = "someone-else@o", and erasure.export wrote its erasure.exported row the same way. audit.emit stores the actor it is given, so the caller chose who the audit log blamed.

Pattern: the server sets actor from the token (server.memory.app.provenance.writer_actor); these four rows took it from a free-text body field instead.

Fix: the actor comes from writer_actor(input.requester), which reads the token first and the body only with auth off (a CLI command's pipeline actor wins over the body too). requester moves into each audit row's subject. A saga can be resumed without a token, by the recovery worker or by loom erasure-re-verify --resume, so the actor is kept on the saga's ledger row in a new loom.erasure_requests.actor column (081_erasure_request_actor.sql) and every checkpoint carries it forward. A resumed saga's rows name the principal that asked. A ledger row from before the column, or checkpointed since by an older build during a rolling upgrade, reads '', and its resumed saga's rows name the process that resumes it: erasure-recovery-worker (the actor the worker already uses for erasure.recovered and erasure.abandoned), or the CLI command's process:cli:... actor.

I considered an alternative that needs no migration: a resumed saga's rows would name the recovery worker. That loses the requesting principal from a resumed saga's erasure.completed row. The extraction queue's enqueued_by column is the same pattern as the one used here.

Scope and risk

Touches the erasure saga (server/erasure/app/saga.py), the export handler, the recovery worker, loom erasure-re-verify --resume, and the ledger reads that feed a resume. request_row_template now takes actor. The ledger's requester column and the requester fields of erasure.status / erasure.list / erasure.export keep the body's value as before. Audit rows a saga step writes itself (a user's grant revocations, writer_actor("-")) are unchanged.

Rolling upgrade: N-1 never reads the column, and its inserts leave it at the default ''. If an N-1 replica checkpoints a saga that N started, the actor resets to '' and a later resume names the resuming process (the recovery worker or the CLI command). docs/architecture/rolling-upgrades.md rule 27 records this.

Compatibility, rollout and rollback

  • Wire: no op or field changes. The actor of the four audit events changes from the body's requester to the token's kind:subject.
  • Operator steps: run migration 081 (make migrate). Nothing else.
  • Rollback: the column stays and the previous build ignores it.

Tests

  • tests/unit/test_erasure_audit_actor.py (new): a completed saga and a failed saga run under an admin token with a different requester. The erasure.started / erasure.completed / erasure.failed rows and every ledger row name human:admin@o, and the subject keeps the requester. A recovery-worker resume with no token carries the ledger row's actor forward unchanged, and its erasure.completed row names that actor, or erasure-recovery-worker when the row has none. Run against main (with the worker's actor written out as a string), test_a_completed_saga_names_the_token_on_every_row and test_a_failed_saga_names_the_token fail on the actor ({'ops'} == {'human:admin@o'}), and the resume cases fail with a KeyError on actor.
  • tests/unit/test_erasure_export_restricted.py::test_the_exported_audit_row_names_the_token_not_the_body: fails on main ('dpo@y' == 'human:ops@x').
  • test_audit_actor_falls_back_to_the_pipeline_actor_when_the_row_has_none checks audit_actor under the CLI's pipeline actor. test_the_cli_resume_reopens_from_the_fresh_census_and_reports_what_ran and test_the_recovery_worker_hands_the_ledgers_residue_to_the_saga (tests/unit/test_erasure_resume_reopens_steps.py) assert that the CLI and worker resumes pass the ledger's actor to the resumed run. tests/integration/test_erasure.py and test_erasure_export.py now expect the token's actor and find the requester in the subject.
  • Updated the saga tests that pass a hand-built ledger row so that the row carries actor, and added 081 to test_schema_baseline.py. list_completed_requests now selects actor and purge, the columns its LedgerRow type names.
  • make format lint typecheck pass locally, and so do the erasure, webhook, schema-baseline, analyzer-corpus, public-copy and doc-link tests. CI runs the rest of make test-unit and the integration suite.
  • schemas/schema.sql: no ClickHouse was available here for make schema-dump; the change is the fresh dump CI's schema check printed for this branch (one column), applied as printed. tests/analyzer/shapes.txt is regenerated with python -m tests.analyzer.corpus --write (the ledger reads now select actor). tests/integration/test_erasure_ledger_actor_ch.py writes ledger rows through checkpoint and reads them back through all three resume reads.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked the failing tests on main, every caller of request_row_template and run_saga, and the tokenless resume paths.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint and make typecheck pass locally; make test-unit (beyond the targeted tests) and the integration suite run in CI (see Tests).
  • Generated files are regenerated in this PR: schemas/schema.sql from CI's dump, tests/analyzer/shapes.txt; the reference docs are current.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the fix/erasure-audit-actor-from-token branch from 900e1ec to 7e0c353 Compare November 3, 2026 18:06
zlareb1 and others added 22 commits November 3, 2026 20:15
… requester

erasure.started, erasure.failed, erasure.completed and erasure.exported
recorded `actor = input.requester`, a free-text field the caller fills in.
The actor now comes from the token (`writer_actor`), and `requester` moves
into each row's subject. The saga's ledger row keeps the actor in a new
`erasure_requests.actor` column (migration 079), so a saga the recovery
worker or `loom erasure-re-verify --resume` continues without a token names
the original principal; a row from before the column names the worker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…h resume path

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…he actor column

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ry ledger read selects it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…older-build checkpoint case

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…allback only for its audit rows

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tly; the worker's actor is named for what it is

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…res every column it reads

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…eps its kind:subject form

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ommand on every row

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e.* rows only

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/erasure-audit-actor-from-token branch from badb9c9 to 0949b08 Compare November 3, 2026 20:17
@zlareb1
zlareb1 merged commit bc4d4ff into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/erasure-audit-actor-from-token branch November 3, 2026 21:19
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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