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

@@ -75,6 +75,56 @@ export async function fetchMe(signal?: AbortSignal): Promise<Me> {
return api<Me>("/api/v1/me", { signal });
}
export type Environment = "production" | "staging" | "development";
export type RelationView = {
id: string;
version: number;
source_orbit_id: string;
target_id: string;
engine: string;
verified: boolean;
active: boolean;
deactivated_reason: string | null;
source_name: string;
source_environment: Environment | null;
target_name: string;
target_environment: Environment | null;
usable: boolean;
unusable_reason: string | null;
};
export type OrbitSetup = {
id: string; name: string; environment: Environment | null; application_id: string | null;
engine: string | null; ready: boolean; reason: string | null;
};
export type TargetSetup = {
id: string; name: string; engine: string; identity: { instance: string; database: string };
application_id: string; environment: Environment | null; outpost_active: boolean;
};
export type RelationOverview = { relations: RelationView[]; orbits: OrbitSetup[]; targets: TargetSetup[] };
export type RelationGrant = { id: string; principal_type: "user" | "group"; principal: string; expires_at: number | null; created_at: number };
/** The rule a refused relation request names (`{"reason": "..."}`), if the error carries one. */
export function refusalReason(error: unknown): string | undefined {
try {
return JSON.parse((error as Error).message).reason;
} catch {
return undefined;
}
}
const json = (method: string, body: unknown) => ({ method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
export const fetchRelations = () => api<RelationOverview>("/api/v1/relations");
export const setOrbitEnvironment = (id: string, environment: Environment) => api<void>(`/api/v1/orbits/${id}/environment`, json("PUT", { environment }));
export const setTargetEnvironment = (id: string, environment: Environment) =>
api<{ ended_relations: string[] }>(`/api/v1/restore-targets/${id}/environment`, json("PUT", { environment }));
export const createRelation = (source_orbit_id: string, target_id: string) => api<RelationView>("/api/v1/relations", json("POST", { source_orbit_id, target_id }));
export const retargetRelation = (id: string, target_id: string) => api<RelationView>(`/api/v1/relations/${id}`, json("PUT", { target_id }));
export const endRelation = (id: string) => api<void>(`/api/v1/relations/${id}`, { method: "DELETE" });
export const fetchRelationAccess = (id: string) => api<RelationGrant[]>(`/api/v1/relations/${id}/access`);
export const grantRelationAccess = (id: string, grant: { principal_type: "user" | "group"; principal: string; expires_at?: string }) =>
api<RelationGrant>(`/api/v1/relations/${id}/access`, json("POST", grant));
export const revokeRelationAccess = (id: string, grant: string) => api<void>(`/api/v1/relations/${id}/access/${grant}`, { method: "DELETE" });
export type Look = "window" | "radar";
/** The account's saved display choices. A hub without this endpoint, or an account without one, yields `{}`. */