feat: confine a compromised worker and drill its compromise end to end

- narrow the worker S3 user to staging reads and attachments writes
- add database rules the worker role cannot bypass: no return to pending,
  variant keys of its own attachment, known error codes only
- let the cleaner remove a ready source only after its own SHA-256 check
- add make jobs_audit [REPAIR=1] to name and requeue damaged jobs
- add make worker_compromise: isolated before/after stands, one operation
  table, response windows, job safety, controls and committed hypotheses

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 03:01:20 +03:00
co-authored by Claude Opus 5.5
parent ea3f791364
commit 4f2f940a07
53 changed files with 10062 additions and 101 deletions
+7 -1
View File
@@ -182,7 +182,13 @@ paths:
KEY UPDATE SKIP LOCKED` с теми же условиями → DELETE в S3 → `staging_key = NULL`.
`NO KEY`, не `FOR UPDATE`: отправка сообщения берёт `FOR KEY SHARE` и не должна
ждать DELETE в S3. У `failed` ещё объекты вариантов всех имён и конечный
оригинал; ключ вне своего префикса staging — `warning`, строка не меняется;
оригинал; ключ вне своего префикса staging — `warning`, строка не меняется.
У `ready` до DELETE — своя сверка оригинала (`_result_mismatch`, change
`track1-worker-compromise`, решение 7): потоком, под той же блокировкой,
тело другого размера не читается; `missing` / `size` / `checksum` — `error`
«Attachment result does not match its source», исходник остаётся, проход
идёт дальше, отказ S3 — прерван. Слову worker «готово» удаление
единственного исходника не доверять;
- чтение: `pending`, нет строки, не участник — одно
`AttachmentNotFound`; варианты подставляются только у `ready`;
скачивание любого `variant` не `ready` вложения — `AttachmentNotReady`