feat(api): wire multi-factor endpoints, policy-aware step-up guard, and recovery backup auto-unlock
This commit is contained in:
parent
99ee259cec
commit
4915bce1e4
5 changed files with 463 additions and 63 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Router } from 'express';
|
||||
import { Router, type RequestHandler } from 'express';
|
||||
import { ZodError, z } from 'zod';
|
||||
import { EntityIdSchema } from '../../../shared/schemas/common.js';
|
||||
import { ServerConfigSchema } from '../../../shared/schemas/server.schema.js';
|
||||
|
|
@ -29,6 +29,8 @@ export interface ServersRouterDeps {
|
|||
keyManager: KeyManager;
|
||||
serverInspector: ServerInspector;
|
||||
monitoringService: MonitoringService;
|
||||
stepUpGuard?: RequestHandler;
|
||||
onKeysMutated?: (snapshotReason?: string) => void;
|
||||
}
|
||||
|
||||
const VALID_RANGES = new Set<MetricRange>(['1h', '6h', '24h', '7d', '30d']);
|
||||
|
|
@ -44,6 +46,8 @@ export function createServersRouter(deps: ServersRouterDeps): Router {
|
|||
keyManager,
|
||||
serverInspector,
|
||||
monitoringService,
|
||||
stepUpGuard = requireStepUp,
|
||||
onKeysMutated,
|
||||
} = deps;
|
||||
|
||||
router.get('/', requireAuth(authService), (_req, res) => {
|
||||
|
|
@ -68,7 +72,7 @@ export function createServersRouter(deps: ServersRouterDeps): Router {
|
|||
requireAuth(authService),
|
||||
requireCsrf,
|
||||
enforceSafeMode,
|
||||
requireStepUp,
|
||||
stepUpGuard,
|
||||
(req, res) => {
|
||||
const hostPort = typeof req.query.hostPort === 'string' ? req.query.hostPort : '';
|
||||
if (!hostPort) {
|
||||
|
|
@ -92,7 +96,7 @@ export function createServersRouter(deps: ServersRouterDeps): Router {
|
|||
requireAuth(authService),
|
||||
requireCsrf,
|
||||
enforceSafeMode,
|
||||
requireStepUp,
|
||||
stepUpGuard,
|
||||
async (req, res) => {
|
||||
const parsed = z
|
||||
.object({
|
||||
|
|
@ -129,6 +133,7 @@ export function createServersRouter(deps: ServersRouterDeps): Router {
|
|||
sessionIdHash: req.authSession!.idHash,
|
||||
});
|
||||
monitoringService.syncServers();
|
||||
onKeysMutated?.('ssh-key-rotation');
|
||||
res.json({ results });
|
||||
},
|
||||
);
|
||||
|
|
@ -305,7 +310,7 @@ export function createServersRouter(deps: ServersRouterDeps): Router {
|
|||
requireAuth(authService),
|
||||
requireCsrf,
|
||||
enforceSafeMode,
|
||||
requireStepUp,
|
||||
stepUpGuard,
|
||||
async (req, res) => {
|
||||
const id = String(req.params.id ?? '');
|
||||
const parsed = z.object({ fingerprint: z.string().min(1) }).safeParse(req.body);
|
||||
|
|
@ -417,7 +422,7 @@ export function createServersRouter(deps: ServersRouterDeps): Router {
|
|||
requireAuth(authService),
|
||||
requireCsrf,
|
||||
enforceSafeMode,
|
||||
requireStepUp,
|
||||
stepUpGuard,
|
||||
async (req, res) => {
|
||||
const id = String(req.params.id ?? '');
|
||||
const parsed = z
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue