feat: per-orbit access grants and an Access console (auth M5)
Authorization - one gate for every human endpoint: authenticate, resolve the resource, then admin_only / scoped / visible; require_admin* removed so each handler must choose - grants (user or IdP group; global or one orbit; optional end date) read live on every request; only orbit.read, snapshot.read, capture.run and snapshot.download can be granted, everything else stays with configured administrators - an orbit without orbit.read is 404, a visible one without the permission is 403, a caller with nothing to see gets 403 on lists; job history is filtered before LIMIT - jobs and audit record the stable principal id, not the IdP display name - restore targets and restore history are admin-only until self-service (M6) - sessions keep the groups verified at sign-in Administration - /api/v1/access grants and users (enable, disable, sign out everywhere), validated and audited by id; admins cannot disable themselves or the emergency operator - Access console with the shared Select and a themed DatePicker; non-administrators only see Vault and Activity and never call administrator endpoints - the Window/Radar view is stored per account (/api/v1/me/preferences) - UI tolerates older hubs and mocks (missing admin/grants) and a console that fails to render no longer blanks the app Tests: a matrix generated from the endpoint contract exercises every human route against real resources in two orbits for each kind of caller. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,11 +54,77 @@ export type OperatorSession = {
|
||||
login_enabled: boolean;
|
||||
oidc_enabled: boolean;
|
||||
authorized: boolean;
|
||||
admin: boolean;
|
||||
actor: string | null;
|
||||
csrf: string | null;
|
||||
expires_at: number | null;
|
||||
};
|
||||
|
||||
export type MyGrant = { permission: string; orbit_id: string | null };
|
||||
export type Me = {
|
||||
id: string;
|
||||
kind: string;
|
||||
auth_method: string;
|
||||
display_name: string;
|
||||
admin: boolean;
|
||||
capabilities: string[];
|
||||
grants: MyGrant[];
|
||||
};
|
||||
|
||||
export async function fetchMe(signal?: AbortSignal): Promise<Me> {
|
||||
return api<Me>("/api/v1/me", { signal });
|
||||
}
|
||||
|
||||
export type Look = "window" | "radar";
|
||||
|
||||
/** The account's saved display choices. A hub without this endpoint, or an account without one, yields `{}`. */
|
||||
export async function fetchPreferences(signal?: AbortSignal): Promise<{ look?: Look }> {
|
||||
const data = await api<unknown>("/api/v1/me/preferences", { signal }).catch(() => undefined);
|
||||
const look = (data as { look?: unknown } | undefined)?.look;
|
||||
return look === "window" || look === "radar" ? { look } : {};
|
||||
}
|
||||
|
||||
export const savePreferences = (preferences: { look?: Look }) =>
|
||||
api<void>("/api/v1/me/preferences", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(preferences) });
|
||||
|
||||
export type Grant = {
|
||||
id: string;
|
||||
principal_type: "user" | "group";
|
||||
principal: string;
|
||||
permission: string;
|
||||
scope_type: "global" | "orbit";
|
||||
scope_id: string | null;
|
||||
expires_at: number | null;
|
||||
created_by: string;
|
||||
created_at: number;
|
||||
};
|
||||
export type GrantList = { grants: Grant[]; roles: { name: string; permissions: string[] }[]; grantable: string[] };
|
||||
export type AccessUser = {
|
||||
id: string;
|
||||
issuer: string;
|
||||
display_name: string;
|
||||
active: boolean;
|
||||
created_at: number;
|
||||
last_login_at: number | null;
|
||||
is_emergency: boolean;
|
||||
};
|
||||
export type NewGrant = {
|
||||
principal_type: "user" | "group";
|
||||
principal: string;
|
||||
role?: string;
|
||||
orbit_id?: string;
|
||||
expires_at?: string;
|
||||
};
|
||||
|
||||
export const fetchGrants = () => api<GrantList>("/api/v1/access/grants");
|
||||
export const fetchAccessUsers = () => api<AccessUser[]>("/api/v1/access/users");
|
||||
export const createGrant = (grant: NewGrant) =>
|
||||
api<Grant[]>("/api/v1/access/grants", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(grant) });
|
||||
export const deleteGrant = (id: string) => api<void>(`/api/v1/access/grants/${id}`, { method: "DELETE" });
|
||||
export const setUserActive = (id: string, active: boolean) =>
|
||||
api<void>(`/api/v1/access/users/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ active }) });
|
||||
export const revokeUserSessions = (id: string) => api<void>(`/api/v1/access/users/${id}/revoke-sessions`, { method: "POST" });
|
||||
|
||||
let csrf: string | null = null;
|
||||
|
||||
export async function fetchOperatorSession(signal?: AbortSignal): Promise<OperatorSession> {
|
||||
|
||||
Reference in New Issue
Block a user