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:
@@ -342,5 +342,40 @@ environments and never where the database is (no identity, host, Outpost or appl
|
||||
|
||||
A relation stops being usable at once when its target is relabelled `production`, when either Outpost on its path is
|
||||
revoked, or (when read) when an Outpost credential has expired. Existing administrator restores (`POST /restore-jobs`)
|
||||
are unchanged. Running the refresh itself comes with the next step; this step only prepares and guards it.
|
||||
are unchanged.
|
||||
|
||||
### Starting a refresh
|
||||
|
||||
`POST /api/v1/refresh-runs` with `relation_id`, an `idempotency_key` and a `confirmation` that says exactly what the person
|
||||
was shown: `REFRESH <source> TO <target> v<version>`. The caller never picks the snapshot or the target. The hub then:
|
||||
|
||||
1. creates the run and queues a **new capture** of the source in one transaction (a failed capture never falls back to an
|
||||
older snapshot, and the run follows its own capture job, not "the latest snapshot");
|
||||
2. when that capture has been published, queues the restore of **that snapshot** onto the relation's target, using the
|
||||
existing restore path (lease, fencing, checksum and identity checks, safety backup of the target before anything is
|
||||
overwritten);
|
||||
3. follows the restore job to its end.
|
||||
|
||||
States: `capturing`, `restoring`, then `completed`, or `capture_failed`, `restore_failed`, `blocked` (with a reason),
|
||||
`expired`, `cancelled`, `recovery_required` (the restore was interrupted after it started overwriting: an administrator
|
||||
must reconcile it), `reconciled`. A target has at most one run in progress; a second request answers `409 run_active`
|
||||
(the run id is only included for people who may see that run) and the same idempotency key from the same person returns
|
||||
the same run. `TESSERA_REFRESH_MAX_ACTIVE` (default 4) bounds how many run at once; `TESSERA_REFRESH_TTL_MINUTES`
|
||||
(default 120) is how long a run may take before it starts overwriting, after which it expires.
|
||||
|
||||
**Authorisation is checked again before anything is overwritten.** The run records what authorised it: an administrator,
|
||||
or the grant on the relation. When the agent asks for permission to apply, the hub checks, in the same transaction that
|
||||
allows it, that the relation is still active and usable (not relabelled production, Outposts still paired), that the
|
||||
person is still an active user, that their grant still exists and has not expired, that the deadline has not passed, and
|
||||
that the target is still not the source database. If any of that no longer holds, the restore is cancelled, the run is
|
||||
`blocked`, and the agent is told `409`, so it overwrites nothing. A group grant can only be verified as of the request: the
|
||||
hub checks that the grant still exists, not that the person is still in the group. Once overwriting has started it is
|
||||
finished (or reconciled), not abandoned, whatever happens to the access.
|
||||
|
||||
A run pins its snapshot from the moment it starts, so retention and manual deletion leave it alone until the run ends.
|
||||
The person who started a run, an administrator and anyone holding a grant on its relation can watch it
|
||||
(`GET /api/v1/refresh-runs`, `/{id}`); only the person who started it or an administrator can cancel it, and only before
|
||||
the restore starts overwriting. Others see names, states and times, never the database identity, the snapshot id or who
|
||||
started it. Audit entries (`refresh.started`, `refresh.restore_queued`, `refresh.completed`, `refresh.blocked`, ...)
|
||||
name the run and, for the start, the person.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user