feat(vault): keep established secrets active at runtime and require unlock only for modifications

This commit is contained in:
tyuXX 2026-11-26 22:25:55 +00:00
parent c5a5835ae6
commit 10a28bb316
14 changed files with 445 additions and 85 deletions

View file

@ -82,7 +82,9 @@ export async function createGCoordinatorServer(
const db = openDatabase(dbPath);
const auditService = new AuditService(db);
const vaultService = new VaultService(vaultPath);
const vaultService = new VaultService(vaultPath, {
keyFilePath: path.join(dataDir, 'vault.key'),
});
const recoveryStore = new EmergencyRecoveryService(dataDir);
const rateLimiter = new RateLimiter();
const configManager = new ConfigManager(configDir, db, vaultService);
@ -98,11 +100,13 @@ export async function createGCoordinatorServer(
const backupKey = configManager.getSettings().security.enableEmergencySecretsBackup
? recoveryStore.readSavedMasterKeyHex()
: undefined;
const unlockResult = vaultService.tryAutoUnlockFromEnvOrSecret({
const runtimeInit = vaultService.initRuntime({
secretFilePath: options.secretFilePath,
envKey: options.envMasterKey || backupKey,
envKey: options.envMasterKey,
backupKey,
autoCreateIfMissing: true,
});
if (unlockResult.unlocked) {
if (runtimeInit.runtimeReady) {
configManager.recomputeWarnings();
if (authService.isBootstrapped()) {
authService.syncRecovery();
@ -177,6 +181,8 @@ export async function createGCoordinatorServer(
for (const frame of customSystemsEngine.getStreamReplayFrames(jobId)) {
ctx.send(frame);
}
} else if (channel === 'metrics') {
ctx.send({ type: 'servers:state', states: sshPool.getStates() });
}
});
@ -283,7 +289,11 @@ export async function createGCoordinatorServer(
);
app.get('/api/healthz', (_req, res) => {
res.json({ ok: true, vaultState: vaultService.state });
res.json({
ok: true,
vaultState: vaultService.state,
vaultRuntimeReady: vaultService.isRuntimeReady,
});
});
app.use(
@ -338,6 +348,7 @@ export async function createGCoordinatorServer(
authService,
configManager,
auditService,
vaultService,
knownHosts,
sshPool,
keyManager,