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

@ -121,7 +121,7 @@ export class SSHPool {
this.updateState(serverId, { status: 'disabled' });
throw new Error(`Server "${serverId}" is disabled`);
}
if (this.vaultService.state !== 'unlocked') {
if (!this.vaultService.isRuntimeReady) {
this.updateState(serverId, {
status: 'vault_locked',
lastError: 'Vault is locked',
@ -170,7 +170,7 @@ export class SSHPool {
if (opts.sudo) {
let sudoPassword: string | undefined;
if (server.sudoCredentialId) {
const sudoCred = this.vaultService.getSecret(server.sudoCredentialId);
const sudoCred = this.vaultService.getRuntimeSecret(server.sudoCredentialId);
if (sudoCred && (sudoCred.type === 'sudo-password' || sudoCred.type === 'ssh-password')) {
sudoPassword = sudoCred.password;
}
@ -404,7 +404,7 @@ export class SSHPool {
privateKey: string,
passphrase?: string,
): Promise<void> {
if (this.vaultService.state !== 'unlocked') {
if (!this.vaultService.isRuntimeReady) {
throw new Error('Vault is locked');
}
@ -509,14 +509,21 @@ export class SSHPool {
syncWithConfig(): void {
const activeIds = new Set<string>();
const runtimeReady = this.vaultService.isRuntimeReady;
for (const server of this.configManager.listServers()) {
activeIds.add(server.id);
const prev = this.states.get(server.id);
if (!server.enabled) {
this.closeServer(server.id);
this.updateState(server.id, { status: 'disabled' });
} else if (!this.states.has(server.id)) {
} else if (
!prev ||
(runtimeReady && prev.status === 'vault_locked') ||
(!runtimeReady && prev.status !== 'vault_locked')
) {
this.updateState(server.id, {
status: this.vaultService.state === 'unlocked' ? 'disconnected' : 'vault_locked',
status: runtimeReady ? 'disconnected' : 'vault_locked',
lastError: runtimeReady ? undefined : prev?.lastError,
});
}
}
@ -597,7 +604,7 @@ export class SSHPool {
server: ServerConfig,
visited: Set<string>,
): Promise<Client> {
const cred = this.vaultService.getSecret(server.credentialId);
const cred = this.vaultService.getRuntimeSecret(server.credentialId);
if (!cred || (cred.type !== 'ssh-key' && cred.type !== 'ssh-password')) {
const msg = `Missing or incompatible SSH credential "${server.credentialId}" in Vault`;
this.updateState(server.id, { status: 'auth_error', lastError: msg });
@ -747,7 +754,7 @@ export class SSHPool {
? 'host_key_mismatch'
: tofu
? 'tofu_pending'
: this.vaultService.state !== 'unlocked'
: !this.vaultService.isRuntimeReady
? 'vault_locked'
: 'disconnected';
@ -833,7 +840,7 @@ export class SSHPool {
tofuPending: tofu,
};
}
if (this.vaultService.state !== 'unlocked') {
if (!this.vaultService.isRuntimeReady) {
return {
...(existing ?? { serverId: server.id }),
status: 'vault_locked',