feat: durable refresh runs from a source to a staging target (auth M6c)
A refresh captures a new dump of the relation's source, then restores exactly that snapshot onto the relation's target through the existing restore path. - refresh_runs in SQLite, one active run per target, per-requester idempotency keys, a cap on concurrent runs and a TTL that only applies until the restore starts overwriting - the run and its capture job are created in one transaction; the run follows its own capture job, never the latest snapshot, and pins that snapshot until it ends - the restore is queued and linked in one guarded transaction; every step is safe to repeat after a crash; a background driver only reads the database - authorize_apply re-checks, in the transaction that allows the overwrite, that the relation is still usable, the requester is still active, the authorising grant still exists, the deadline has not passed and the target is not the source; otherwise the restore is cancelled, the run is blocked and the agent gets 409. Administrator restores are untouched - POST/GET/DELETE /api/v1/refresh-runs: confirmation names source, target and version; non-administrators never see the snapshot id, the requester or the database identity - audit refresh.* per run Tests drive the agent through the real Outpost endpoints and cover revocation at every stage; the access matrix gains a RunRow kind. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,8 @@ admin/browser. Semua status/data job hanya di scope owner/admin yang berizin.
|
||||
| /api/v1/relations/:id/access | GET,POST | human | relation.manage | admin | grant refresh.run per relasi (user atau grup, expiry); diaudit |
|
||||
| /api/v1/relations/:id/access/:grant | DELETE | human | relation.manage | admin | berlaku pada request berikutnya; diaudit |
|
||||
| /api/v1/refresh-relations | GET | human | refresh.run | relasi yang di-grant | nama dan environment saja; tanpa identity, host, Outpost, application id; 403 bila tanpa grant |
|
||||
| /api/v1/refresh-runs | GET,POST | human | refresh.run | relasi yang di-grant | POST: relation_id + konfirmasi `REFRESH <sumber> TO <target> v<versi>` + kunci idempotensi; tidak memilih snapshot atau target; 404 bila bukan pemegang grant; GET: run milik sendiri atau relasi yang di-grant (admin: semua), tanpa snapshot id dan pemohon untuk non-admin |
|
||||
| /api/v1/refresh-runs/:id | GET,DELETE | human | refresh.run | admin, pemohon, atau pemegang grant relasinya | GET 404 bagi yang lain; DELETE hanya pemohon atau admin (pemegang grant lain 403) dan hanya sebelum apply, sesudahnya 409 |
|
||||
| /api/v1/operator/login | POST | public | — | emergency account | cookie opaque dan CSRF; limiter, no-store |
|
||||
| /api/v1/snapshots | GET | human | snapshot.read | orbit | metadata aman terfilter |
|
||||
| /api/v1/snapshots/:id | DELETE | human | snapshot.delete | snapshot→orbit | tidak ada; cek pin |
|
||||
|
||||
@@ -101,12 +101,15 @@ Bukti: `cargo test --workspace` hijau (hub 106 tes; 12 tes baru: 9 store, 5 HTTP
|
||||
Catatan untuk M6d: pengguna yang hanya punya grant relasi belum dianggap `authorized` oleh status sesi dan vault UI memanggil `/orbits` dan `/snapshots` saat load (403); UI QA harus menangani itu (hitung grant relasi atau wajibkan viewer pada orbit sumber).
|
||||
Belum ada / batas: relasi belum menjalankan apa pun (M6c); sumber yang di-capture tidak di-cek terhadap target yang sama bila snapshot-nya belum ada (ditandai belum dibandingkan); pendaftaran restore target masih lewat Orbits console dan memerlukan Outpost aktif; ekstra: form login tanpa SSO tidak lagi menampilkan label "Details" dan memakai gaya field yang sama.
|
||||
|
||||
### M6c — Refresh run durable (backend)
|
||||
### M6c — Refresh run durable (backend) (selesai di working tree, belum di-commit, 14 November 2026)
|
||||
Hasil: satu permintaan "refresh staging" menjalankan capture baru lalu restore snapshot hasil capture itu, tanpa persetujuan DevOps per eksekusi.
|
||||
- `refresh_runs` dengan state `queued → capturing → snapshot_ready → restoring → completed`, plus `capture_failed`, `blocked/revoked`, `restore_failed`, `cancelled`, `recovery_required`; kunci idempotensi; satu run aktif per target (constraint unik); snapshot dikaitkan tepat dari job capture run itu (bukan "latest"), dipin sampai aman dilepas; relasi dan versi terikat sejak awal, browser tidak dapat mengganti tujuan.
|
||||
- Revalidasi user aktif, grant, versi relasi, dan TTL sebelum enqueue restore dan sebelum apply; cancel sebelum apply; recovery setelah restart dari SQLite; memakai lease/fencing dan safety backup yang sudah ada.
|
||||
- `POST /refresh-runs`, `GET /refresh-runs/:id`, cancel.
|
||||
Selesai bila: tes crash/retry pada tiap transisi, double submit konkuren, revoke di tiap tahap (capturing, queued, sebelum apply), target atau versi salah, capture gagal tidak memakai snapshot lama.
|
||||
- `refresh_runs` (di SQLite, bertahan setelah restart): `capturing`, `restoring`, lalu `completed`, `capture_failed`, `restore_failed`, `blocked` (dengan alasan), `expired`, `cancelled`, `recovery_required`, `reconciled`. Satu run aktif per target (indeks unik parsial), kunci idempotensi per pemohon, plafon run serentak (`TESSERA_REFRESH_MAX_ACTIVE`), TTL sampai mulai menimpa (`TESSERA_REFRESH_TTL_MINUTES`, default 120 menit; setelah apply dimulai tidak pernah dipotong).
|
||||
- Run dan capture job dibuat dalam satu transaksi; run mengikuti `capture_job_id`-nya sendiri (id snapshot sama dengan id job), bukan "snapshot terbaru", sehingga capture gagal tidak pernah memakai snapshot lama. Restore di-enqueue dan dikaitkan dalam satu transaksi dengan penjaga `restore_job_id IS NULL`; setiap langkah aman diulang setelah crash. Snapshot dipin sejak run dimulai lewat `snapshot_in_restore` (dipakai prune retensi dan hapus manual).
|
||||
- Pemeriksaan ulang sebelum menimpa: `authorize_apply` memeriksa dalam transaksi yang sama dengan perpindahan ke `applying` bahwa relasi masih aktif dan usable, pemohon masih user aktif, grant yang mengotorisasi masih ada dan belum kedaluwarsa, TTL belum lewat, dan target bukan database sumber. Bila tidak, restore dibatalkan, run `blocked`, agen mendapat 409 (agen tidak menimpa apa pun tanpa 2xx; dicek di `tessera-agent`). Restore yang diantrekan admin langsung (`POST /restore-jobs`) tidak punya run dan berperilaku persis seperti sebelumnya (ada tesnya). Sesudah apply dimulai, run diselesaikan, bukan dibatalkan.
|
||||
- Driver (`refresh.rs`) hanya melihat DB setiap 3 detik; pembacaan manifest snapshot dilakukan di luar kunci DB, lalu transaksi memvalidasi ulang sebelum meng-enqueue restore. Alasan penolakan sebelum restore: relasi berakhir atau tidak usable, user dinonaktifkan, akses dicabut, kedaluwarsa, target cocok dengan database production yang di-capture, target ditolak oleh pemeriksaan restore.
|
||||
- API: `POST /refresh-runs` (relation_id + konfirmasi `REFRESH <sumber> TO <target> v<versi>` + kunci idempotensi; 404 bagi yang bukan pemegang grant; 409 `stale_confirmation`, `run_active` dengan id hanya bagi yang boleh melihatnya, `source_unavailable`, `relation_unusable`), `GET /refresh-runs`, `GET /refresh-runs/:id`, `DELETE /refresh-runs/:id` (pemohon atau admin, sebelum apply). Non-admin tidak melihat id snapshot, pemohon, atau identity database. Audit `refresh.*` per run.
|
||||
Bukti: `cargo test --workspace` hijau. 13 tes refresh yang menjalankan agen lewat endpoint Outpost sungguhan (claim, report, payload dengan manifest dan hint asli, claim restore, safety, apply): alur penuh dengan snapshot milik run (bukan yang lama), double submit satu run, dua kunci pada satu target satu run dan satu 409, capture gagal tidak memakai snapshot lama, pencabutan (grant dihapus, user dinonaktifkan, relasi di-retarget, target di-relabel production, Outpost dicabut) pada tiap tahap (saat capture, setelah capture sebelum restore diantrekan, restore diantrekan, setelah safety backup sebelum apply) selalu berakhir `blocked` dengan restore dibatalkan dan apply ditolak 409, setelah apply dimulai tidak ada yang membatalkan, restore admin tidak tersentuh, pin dari awal (hapus ditolak, prune melewatkannya) dan dilepas saat selesai, TTL, konfirmasi basi dan plafon, visibilitas dan pembatalan, kepemilikan langkah yang diulang, target = sumber atau cocok dengan production. Matriks akses diperluas dengan jenis `RunRow` dan run fixture. Mutasi sengaja tertangkap: guard apply dihapus, pin dihapus, sinkronisasi mengabaikan hilangnya otorisasi, tanpa kedaluwarsa, semua orang bisa membaca run, pemegang grant bisa membatalkan run orang lain. Proses nyata (hub sungguhan, data sintetis, agen disimulasikan dengan curl ke endpoint Outpost): loop driver menggerakkan run ke `restoring` sendiri dengan restore memakai snapshot milik run, run bertahan setelah hub dimatikan dan dinyalakan lagi, relabel target menjadi production membuat run `blocked` dan restore `cancelled`.
|
||||
Belum ada / batas: UI QA (M6d); sumber yang dibuat lewat API memakai jalur commit Restic (payload langsung ditolak 409), jadi rehearsal dengan agen, Restic, dan PostgreSQL asli ada di M6d; untuk grant grup, hub hanya memeriksa bahwa grant masih ada, bukan bahwa orang itu masih anggota grup (dicatat di dokumentasi); admin yang diturunkan lewat konfigurasi tidak menghentikan run yang sudah dimulai; pemanggilan gate relasi saat memulai run bersifat berlapis (pencarian grant memberi 404 yang sama), jadi mutasi yang menghapusnya hanya menghilangkan satu baris audit.
|
||||
|
||||
### M6d — UI refresh QA dan rehearsal nyata
|
||||
Hasil: QA menekan "Refresh staging" dan melihat progres; developer mengunduh `.gz`.
|
||||
|
||||
Reference in New Issue
Block a user