fix: harden the vault before release

Require a private passphrase and loopback-or-token admin auth. New vaults use Argon2id; existing PBKDF2 vaults still open, and new snapshot metadata is encrypted. Wormhole tokens survive restart, offset uploads seal into the vault, and client-certificate uploads are real. Reject the command provider and keep Postgres passwords off the process arguments. Keep the interruptible canvas motion.
This commit is contained in:
2026-11-10 09:53:06 +07:00
parent 60ba8fed88
commit 95778d54e4
46 changed files with 2311 additions and 415 deletions

View File

@@ -1,6 +1,9 @@
import { AnimatePresence, motion } from "motion/react";
import type { KeyboardEvent, ReactNode } from "react";
import type { Orbit, Snapshot } from "../../api";
import { useReducedMotion } from "../../hooks/useReducedMotion";
import { formatBytes, formatWhen, orbitStatus, schedulePhrase } from "../../lib/format";
import { SpringPane } from "../ui/SpringPane";
export function TelemetryStrip({
orbitCount, failedCount, snapCount, totalBytes,
@@ -29,6 +32,7 @@ export function OrbitRegister({
onSelect: (id: string) => void;
onManage: () => void;
}) {
const reducedMotion = useReducedMotion();
const active = orbits.some(({ id }) => id === selected) ? selected : orbits[0]?.id;
function moveFocus(event: KeyboardEvent<HTMLButtonElement>, index: number) {
@@ -47,11 +51,11 @@ export function OrbitRegister({
<h2 id="register-title">Orbits</h2>
</header>
{message && <p className="console-empty" role="status">{message}</p>}
<ul className="register-list">
<motion.ul className="register-list" layoutScroll>
{orbits.map((orbit, index) => {
const status = orbitStatus(orbit.last_status);
return (
<li key={orbit.id}>
<motion.li key={orbit.id} layout={reducedMotion ? false : "position"}>
<button
type="button"
id={`register-${orbit.id}`}
@@ -68,10 +72,10 @@ export function OrbitRegister({
</span>
<span className={`register-state tone-${status.tone}`}>{status.label}</span>
</button>
</li>
</motion.li>
);
})}
</ul>
</motion.ul>
<div className="console-bottom">
<button type="button" className="console-control" onClick={onManage}>
{orbits.length ? "Manage orbits" : "Set up an orbit"} <span aria-hidden="true">↗</span>
@@ -98,35 +102,41 @@ export function OrbitInspector({
<h2 id="inspector-title">{orbit?.name ?? "Select an orbit"}</h2>
{orbit && <p className={`inspector-state tone-${status.tone}`}><span className={`register-signal signal-${status.tone}`} />{status.label}</p>}
</header>
{orbit ? (
<>
<p className="inspector-schedule">{schedulePhrase(orbit.schedule, orbit.dry_run)}</p>
<div className="inspector-capture">{capture}</div>
<section className="inspector-history" aria-labelledby="history-title">
<header>
<h3 id="history-title">Snapshot history</h3>
<span>{snapshots.length.toString().padStart(2, "0")}</span>
</header>
{snapshotMessage && <p className="console-empty" role="status">{snapshotMessage}</p>}
<ul>
{snapshots.map((snapshot, index) => (
<li key={snapshot.id}>
<button id={`snapshot-${snapshot.id}`} type="button" className="snapshot-row" onClick={() => onSelectSnapshot(snapshot.id)}>
<span className="snapshot-glyph" aria-hidden="true">◇</span>
<span>
<strong>{formatWhen(snapshot.taken_at)}</strong>
<small>{formatBytes(snapshot.size_bytes)}{index === 0 ? " · Latest" : ""}</small>
</span>
<span className="snapshot-arrow" aria-hidden="true">›</span>
</button>
</li>
))}
</ul>
</section>
</>
) : (
<p className="console-empty">Choose a star on the map or an orbit in the register to inspect its status and recovery points.</p>
)}
<div className="spring-stack inspector-stack">
<AnimatePresence initial={false}>
{orbit ? (
<SpringPane key={orbit.id}>
<p className="inspector-schedule">{schedulePhrase(orbit.schedule, orbit.dry_run)}</p>
<div className="inspector-capture">{capture}</div>
<section className="inspector-history" aria-label="Snapshot history">
<header>
<h3>Snapshot history</h3>
<span>{snapshots.length.toString().padStart(2, "0")}</span>
</header>
{snapshotMessage && <p className="console-empty" role="status">{snapshotMessage}</p>}
<ul>
{snapshots.map((snapshot, index) => (
<li key={snapshot.id}>
<button id={`snapshot-${snapshot.id}`} type="button" className="snapshot-row" onClick={() => onSelectSnapshot(snapshot.id)}>
<span className="snapshot-glyph" aria-hidden="true">◇</span>
<span>
<strong>{formatWhen(snapshot.taken_at)}</strong>
<small>{formatBytes(snapshot.size_bytes)}{index === 0 ? " · Latest" : ""}</small>
</span>
<span className="snapshot-arrow" aria-hidden="true">›</span>
</button>
</li>
))}
</ul>
</section>
</SpringPane>
) : (
<SpringPane key="empty">
<p className="console-empty">Choose a star on the map or an orbit in the register to inspect its status and recovery points.</p>
</SpringPane>
)}
</AnimatePresence>
</div>
</section>
);
}

View File

@@ -1,4 +1,5 @@
import { useId, useLayoutEffect, useRef, type ReactNode } from "react";
import { motion } from "motion/react";
import { useEffect, useId, useLayoutEffect, useRef, type ReactNode } from "react";
export function HUDPanel({
open, title, subtitle, onClose, children,
@@ -9,46 +10,73 @@ export function HUDPanel({
onClose: () => void;
children: ReactNode;
}) {
const dialog = useRef<HTMLDialogElement>(null);
const panel = useRef<HTMLElement>(null);
const heading = useRef<HTMLHeadingElement>(null);
const returnFocus = useRef<HTMLElement>(null);
const lastHeading = useRef({ title, subtitle });
const labelId = useId();
const descriptionId = useId();
useLayoutEffect(() => {
const panel = dialog.current;
if (!open || !panel) return;
panel.showModal();
return () => panel.close();
const focused = document.activeElement;
if (open) {
returnFocus.current = focused instanceof HTMLElement ? focused : null;
if (!focused?.closest(".vault-nav")) heading.current?.focus({ preventScroll: true });
} else if (returnFocus.current && (panel.current?.contains(focused) || focused === document.body)) {
const previous = returnFocus.current;
const target = previous.isConnected && previous !== document.body
? previous
: document.querySelector<HTMLElement>(".vault-nav button[aria-current]");
target?.focus({ preventScroll: true });
}
}, [open]);
useLayoutEffect(() => {
if (open) heading.current?.focus();
}, [open, title]);
if (open) {
lastHeading.current = { title, subtitle };
panel.current?.scrollTo(0, 0);
}
}, [open, title, subtitle]);
useEffect(() => {
if (!open) return;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key !== "Escape" || event.defaultPrevented || event.repeat) return;
event.preventDefault();
onClose();
};
window.addEventListener("keydown", closeOnEscape);
return () => window.removeEventListener("keydown", closeOnEscape);
}, [open, onClose]);
const display = open ? { title, subtitle } : lastHeading.current;
return (
<dialog
ref={dialog}
className="vault-dialog"
aria-labelledby={labelId}
aria-describedby={subtitle ? descriptionId : undefined}
onCancel={(event) => {
event.preventDefault();
onClose();
}}
>
{open && (
<div className="vault-overlay">
<motion.div className="vault-scrim" aria-hidden="true" initial={false} animate={{ opacity: open ? 1 : 0 }} />
<motion.aside
ref={panel}
className="vault-dialog"
role="dialog"
aria-labelledby={labelId}
aria-describedby={display.subtitle ? descriptionId : undefined}
aria-hidden={!open}
inert={!open}
initial={false}
animate={{ x: open ? "0%" : "100%" }}
>
<header className="dialog-heading">
<div>
<p className="instrument-label">Vault console</p>
<h2 id={labelId} ref={heading} tabIndex={-1}>{title}</h2>
{subtitle && <p id={descriptionId}>{subtitle}</p>}
<h2 id={labelId} ref={heading} tabIndex={-1}>{display.title}</h2>
{display.subtitle && <p id={descriptionId}>{display.subtitle}</p>}
</div>
<button type="button" className="console-control" onClick={onClose}>
Close <span aria-hidden="true">×</span>
</button>
</header>
)}
<div className="dialog-content">{children}</div>
</dialog>
<div className="dialog-content"><div className="spring-stack">{children}</div></div>
</motion.aside>
</div>
);
}

View File

@@ -1,31 +1,189 @@
import { animate, motion, useMotionValue, useTransform, useVelocity } from "motion/react";
import { useCallback, useId, useLayoutEffect, useRef, type PointerEvent } from "react";
import { uiSpring } from "../../lib/motion";
export type HUDMode = "scene" | "orbits" | "wormhole" | "decay" | "reconstitute" | "snapshot";
const items = [
{ id: "scene", label: "Vault" },
{ id: "orbits", label: "Orbits" },
{ id: "wormhole", label: "Outposts" },
{ id: "decay", label: "Retention" },
{ id: "reconstitute", label: "Restore" },
{ id: "scene", label: "Vault", icon: "M4 9l8-4 8 4v6l-8 4-8-4z M4 9l8 4 8-4 M12 13v6" },
{ id: "orbits", label: "Orbits", icon: "M21 12a9 5 0 1 1-18 0 9 5 0 1 1 18 0z M12 10.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 1 1 0-3z M18 5h.01" },
{ id: "wormhole", label: "Outposts", icon: "M12 3v3 M4.2 7.5l2.6 1.5 M4.2 16.5 6.8 15 M12 18v3 M17.2 15l2.6 1.5 M17.2 9l2.6-1.5 M15.5 12a3.5 3.5 0 1 1-7 0 3.5 3.5 0 1 1 7 0z" },
{ id: "decay", label: "Retention", icon: "M6 4h12 M6 20h12 M8 4v3l4 5-4 5v3 M16 4v3l-4 5 4 5v3" },
{ id: "reconstitute", label: "Restore", icon: "M4 12a8 8 0 1 1 2.3 5.7 M4 6v6h6 M12 8v4l3 2" },
] as const;
type Slot = { center: number; width: number };
type Gesture = { pointer: number; x: number; y: number; origin?: number };
export function HUDRail({
active, onSelect,
active, floating, panelOpen, reducedMotion, onSelect,
}: {
active: HUDMode;
floating: boolean;
panelOpen: boolean;
reducedMotion: boolean;
onSelect: (mode: HUDMode) => void;
}) {
const nav = useRef<HTMLElement>(null);
const slots = useRef<Slot[]>([]);
const gesture = useRef<Gesture>(undefined);
const suppressClick = useRef(false);
const center = useMotionValue(0);
const width = useMotionValue(0);
const velocity = useVelocity(center);
const tail = useTransform(() => center.get() - Math.max(-22, Math.min(22, velocity.get() * 0.032)));
const id = useId();
const activeIndex = Math.max(0, items.findIndex(item => item.id === active));
const snap = useCallback((index: number, immediate = false) => {
const slot = slots.current[index];
if (!slot) return;
if (immediate || reducedMotion) {
center.jump(slot.center);
width.jump(slot.width);
} else {
animate(center, slot.center, uiSpring);
animate(width, slot.width, uiSpring);
}
}, [center, reducedMotion, width]);
useLayoutEffect(() => () => {
center.stop();
width.stop();
}, [center, width]);
useLayoutEffect(() => {
const element = nav.current!;
const buttons = Array.from(element.querySelectorAll("button"));
const measure = () => {
const left = element.getBoundingClientRect().left + element.clientLeft;
const next = buttons.map(button => {
const rect = button.getBoundingClientRect();
return { center: rect.left + rect.width / 2 - left, width: rect.width - 10 };
});
const changed = next.some((slot, index) =>
slot.center !== slots.current[index]?.center || slot.width !== slots.current[index]?.width,
);
slots.current = next;
if (changed) gesture.current = undefined;
return changed;
};
snap(activeIndex, measure());
const observer = new ResizeObserver(() => {
if (measure()) snap(activeIndex, true);
});
observer.observe(element);
buttons.forEach(button => observer.observe(button));
return () => observer.disconnect();
}, [activeIndex, floating, snap]);
function start(event: PointerEvent<HTMLElement>) {
if (!event.isPrimary || event.button !== 0) return;
suppressClick.current = false;
const button = (event.target as Element).closest("button");
if (button?.hasAttribute("aria-current")) {
gesture.current = { pointer: event.pointerId, x: event.clientX, y: event.clientY };
}
}
function move(event: PointerEvent<HTMLElement>) {
const drag = gesture.current;
if (drag?.pointer !== event.pointerId) return;
const dx = event.clientX - drag.x;
if (drag.origin === undefined) {
if (Math.abs(dx) < 5 || Math.abs(dx) < Math.abs(event.clientY - drag.y)) return;
center.stop();
drag.origin = center.get();
suppressClick.current = true;
event.currentTarget.setPointerCapture(event.pointerId);
}
center.set(Math.max(slots.current[0].center, Math.min(slots.current.at(-1)!.center, drag.origin + dx)));
}
function finish(event: PointerEvent<HTMLElement>) {
const drag = gesture.current;
if (drag?.pointer !== event.pointerId) return;
gesture.current = undefined;
if (drag.origin === undefined) return;
if (event.type !== "pointerup") {
snap(activeIndex);
return;
}
const projected = center.get() + Math.max(-18, Math.min(18, center.getVelocity() * 0.1));
const next = slots.current.reduce((nearest, slot, index) =>
Math.abs(slot.center - projected) < Math.abs(slots.current[nearest].center - projected) ? index : nearest,
0);
if (next === activeIndex) snap(activeIndex);
else onSelect(items[next].id);
}
return (
<nav className="vault-nav" aria-label="Vault systems">
{items.map(({ id, label }) => (
<motion.nav
ref={nav}
className="vault-nav"
aria-label="Vault systems"
initial={false}
animate={{ "--dock-morph": panelOpen && !floating ? 1 : 0 }}
onPointerDown={start}
onPointerMove={move}
onPointerUp={finish}
onPointerCancel={finish}
onLostPointerCapture={event => {
if (event.target === event.currentTarget) finish(event);
}}
onPointerLeave={event => {
if (gesture.current?.pointer === event.pointerId && gesture.current.origin === undefined) {
gesture.current = undefined;
}
}}
onClickCapture={event => {
if (event.detail > 0 && suppressClick.current) {
event.preventDefault();
event.stopPropagation();
}
}}
>
{floating ? (
<svg className="nav-liquid" aria-hidden="true">
<defs>
<filter id={`${id}-goo`} x="-25%" y="-50%" width="150%" height="200%">
<feGaussianBlur in="SourceGraphic" stdDeviation="3.5" result="blur" />
<feColorMatrix in="blur" type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -8" result="goo" />
<feComposite in="SourceGraphic" in2="goo" operator="atop" />
</filter>
<linearGradient id={`${id}-fill`} x2="0%" y2="100%">
<stop stopColor="#724a34" />
<stop offset="100%" stopColor="#38251e" />
</linearGradient>
</defs>
<g filter={`url(#${id}-goo)`} fill={`url(#${id}-fill)`}>
<motion.ellipse cx={reducedMotion ? center : tail} cy="50%" rx="17" ry="13" />
<motion.ellipse cx={center} cy="50%" rx="21" ry="17" />
</g>
</svg>
) : (
<>
<span aria-hidden="true" className="nav-text-dock" />
<motion.span aria-hidden="true" className="nav-underline" style={{ x: center, width }} />
</>
)}
{items.map(({ id, label, icon }) => (
<button
key={id}
type="button"
aria-label={floating ? label : undefined}
title={floating ? label : undefined}
onClick={() => onSelect(id)}
aria-current={active === id ? "page" : undefined}
>
{label}
{floating ? (
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d={icon} />
</svg>
) : label}
</button>
))}
</nav>
</motion.nav>
);
}