feat: environments and production-to-staging relations (auth M6b)

- environment (production/staging/development) on source orbits and on restore targets;
  an unlabelled target fails closed and a production target is refused
- directed, versioned relations from a managed source orbit to a restore target: one
  active relation per pair, retargeting makes a new id and ends the old one
- refusals name the rule: unknown or unlabelled source/target, not a managed capture
  profile, not restore-ready, application or engine mismatch, inactive Outpost, and a
  target whose identity matches a database captured as production in any snapshot
- relations end in the same transaction when their target is relabelled production or an
  Outpost is revoked; usability is re-read live
- refresh.run is granted per relation id in its own table (user or group, expiry), never
  global, never carried to a new version, and never accepted by the orbit gate
- admin API under /api/v1/relations plus environment endpoints; people holding only a
  relation grant see names and environments, never identity, host, Outpost or application
- Relations console; sign-in form without SSO no longer shows a stray "Details" label

Tests extend the access matrix with relation fixtures and a caller that holds only a
relation grant.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 17:46:08 +07:00
parent e72b72111d
commit 5c4e0bf4a9
17 changed files with 1776 additions and 24 deletions

View File

@@ -319,3 +319,28 @@ The snapshot's recorded size is added to that margin; if a producer did not reco
The audit log records `export.requested`, `export.ready` and then `export.finished` or `export.disconnected` for each
download. "Finished" means the body was handed to the connection, not that a file reached the person's disk.
## Refresh relations (staging from production)
A *relation* says that one source orbit may overwrite one restore target (a staging or development database),
in that direction only. Administrators set it up in the Relations console (or `/api/v1/relations`). Nothing is assumed:
1. Give each **source orbit** and each **restore target** an environment: `production`, `staging` or `development`.
An orbit or target that is not labelled is never used. A target labelled `production` is refused.
2. A source must be a managed Outpost database backup (a capture profile with a restorable PostgreSQL or MySQL format).
Filesystem backups are not databases and cannot be a source.
3. A target is registered for one application, so it can only be connected to that application's orbit, with the same engine.
4. Connect them. The hub refuses a target whose database identity matches a database captured as production (or never
classified) in any snapshot, which catches a production database labelled staging. A staging or development orbit that
backs up the target itself does not count. If the source has no snapshot yet, the relation is created as *not yet
compared* and the refresh checks again before it applies anything. Each refusal names the rule that stopped it.
Relations are versioned. Pointing one at another target creates a new relation (new id, next version) and ends the old one.
Who may start a refresh is granted **per relation id** (`refresh.run`, to a person or an identity-provider group, with an
optional end date), so a new version starts with nobody allowed. These grants are separate from orbit access and never
include `orbit.read`, `snapshot.download` or `capture.run`. A person holding only a relation grant sees its name and
environments and never where the database is (no identity, host, Outpost or application id).
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.