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
|
|
@ -10,7 +10,12 @@ import { MonitoringService } from './monitoring/monitoring-service.js';
|
|||
import { ProbeRunner } from './monitoring/probes.js';
|
||||
import { AuditService } from './security/audit.js';
|
||||
import { AuthService } from './security/auth.js';
|
||||
import { RateLimiter, attachClientIp } from './security/guards.js';
|
||||
import {
|
||||
RateLimiter,
|
||||
attachClientIp,
|
||||
createStepUpGuard,
|
||||
} from './security/guards.js';
|
||||
import { EmergencyRecoveryService } from './security/recovery-store.js';
|
||||
import { VaultService } from './security/vault.js';
|
||||
import { KeyManager } from './ssh/key-manager.js';
|
||||
import { KnownHostsService } from './ssh/known-hosts.js';
|
||||
|
|
@ -41,6 +46,7 @@ export interface GCoordinatorInstance {
|
|||
authService: AuthService;
|
||||
configManager: ConfigManager;
|
||||
auditService: AuditService;
|
||||
recoveryStore: EmergencyRecoveryService;
|
||||
knownHosts: KnownHostsService;
|
||||
sshPool: SSHPool;
|
||||
keyManager: KeyManager;
|
||||
|
|
@ -65,16 +71,31 @@ export async function createGCoordinatorServer(
|
|||
const db = openDatabase(dbPath);
|
||||
const auditService = new AuditService(db);
|
||||
const vaultService = new VaultService(vaultPath);
|
||||
const authService = new AuthService(db);
|
||||
const recoveryStore = new EmergencyRecoveryService(dataDir);
|
||||
const rateLimiter = new RateLimiter();
|
||||
const configManager = new ConfigManager(configDir, db, vaultService);
|
||||
|
||||
vaultService.tryAutoUnlockFromEnvOrSecret({
|
||||
secretFilePath: options.secretFilePath,
|
||||
envKey: options.envMasterKey,
|
||||
await configManager.init({ watch: options.watchConfig ?? true });
|
||||
|
||||
const authService = new AuthService(db, {
|
||||
getSecuritySettings: () => configManager.getSettings().security,
|
||||
recoveryStore,
|
||||
vaultService,
|
||||
});
|
||||
|
||||
await configManager.init({ watch: options.watchConfig ?? true });
|
||||
const backupKey = configManager.getSettings().security.enableEmergencySecretsBackup
|
||||
? recoveryStore.readSavedMasterKeyHex()
|
||||
: undefined;
|
||||
const unlockResult = vaultService.tryAutoUnlockFromEnvOrSecret({
|
||||
secretFilePath: options.secretFilePath,
|
||||
envKey: options.envMasterKey || backupKey,
|
||||
});
|
||||
if (unlockResult.unlocked) {
|
||||
configManager.recomputeWarnings();
|
||||
if (authService.isBootstrapped()) {
|
||||
authService.syncRecovery();
|
||||
}
|
||||
}
|
||||
|
||||
const app = express();
|
||||
app.disable('x-powered-by');
|
||||
|
|
@ -156,10 +177,18 @@ export async function createGCoordinatorServer(
|
|||
if (event.entityType === 'server' && event.id) {
|
||||
sshPool.closeServer(event.id);
|
||||
}
|
||||
if (event.entityType === 'settings') {
|
||||
authService.syncRecovery();
|
||||
}
|
||||
monitoringService.syncServers();
|
||||
}
|
||||
});
|
||||
|
||||
const stepUpGuard = createStepUpGuard(
|
||||
authService,
|
||||
() => configManager.getSettings().security.stepUpPolicy,
|
||||
);
|
||||
|
||||
app.get('/api/healthz', (_req, res) => {
|
||||
res.json({ ok: true, vaultState: vaultService.state });
|
||||
});
|
||||
|
|
@ -171,6 +200,7 @@ export async function createGCoordinatorServer(
|
|||
vaultService,
|
||||
configManager,
|
||||
auditService,
|
||||
recoveryStore,
|
||||
rateLimiter,
|
||||
trustCloudflare,
|
||||
}),
|
||||
|
|
@ -183,9 +213,13 @@ export async function createGCoordinatorServer(
|
|||
auditService,
|
||||
rateLimiter,
|
||||
wsHub,
|
||||
stepUpGuard,
|
||||
onVaultUnlocked: () => {
|
||||
monitoringService.syncServers();
|
||||
},
|
||||
onVaultChanged: (snapshotReason) => {
|
||||
authService.syncRecovery({ snapshotReason });
|
||||
},
|
||||
});
|
||||
|
||||
app.use('/api/vault', vaultRouter);
|
||||
|
|
@ -201,6 +235,10 @@ export async function createGCoordinatorServer(
|
|||
keyManager,
|
||||
serverInspector,
|
||||
monitoringService,
|
||||
stepUpGuard,
|
||||
onKeysMutated: (snapshotReason) => {
|
||||
authService.syncRecovery({ snapshotReason });
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.use(
|
||||
|
|
@ -242,6 +280,7 @@ export async function createGCoordinatorServer(
|
|||
authService,
|
||||
configManager,
|
||||
auditService,
|
||||
recoveryStore,
|
||||
knownHosts,
|
||||
sshPool,
|
||||
keyManager,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue