feat(vault): keep established secrets active at runtime and require unlock only for modifications
This commit is contained in:
parent
c5a5835ae6
commit
10a28bb316
14 changed files with 445 additions and 85 deletions
|
|
@ -161,8 +161,9 @@ export class KeyManager {
|
|||
);
|
||||
}
|
||||
|
||||
const vaultCreds =
|
||||
this.vaultService.state === 'unlocked' ? this.vaultService.listMetadata() : [];
|
||||
const vaultCreds = this.vaultService.isRuntimeReady
|
||||
? this.vaultService.listMetadata()
|
||||
: [];
|
||||
const entries = parseAuthorizedKeys(res.stdout, vaultCreds, server.credentialId);
|
||||
return { raw: res.stdout, entries };
|
||||
}
|
||||
|
|
@ -172,7 +173,7 @@ export class KeyManager {
|
|||
credentialId: string,
|
||||
actor = { ip: 'hub', sessionIdHash: null as string | null },
|
||||
): Promise<{ deployed: boolean; alreadyPresent: boolean; fingerprint: string }> {
|
||||
const cred = this.vaultService.getSecret(credentialId);
|
||||
const cred = this.vaultService.getRuntimeSecret(credentialId);
|
||||
if (!cred || cred.type !== 'ssh-key' || !cred.publicKey) {
|
||||
throw new Error(`Vault credential "${credentialId}" is not an SSH key with a publicKey`);
|
||||
}
|
||||
|
|
@ -210,7 +211,7 @@ export class KeyManager {
|
|||
throw new Error(`Unknown server "${serverId}"`);
|
||||
}
|
||||
|
||||
const activeCred = this.vaultService.getSecret(server.credentialId);
|
||||
const activeCred = this.vaultService.getRuntimeSecret(server.credentialId);
|
||||
const activeFp =
|
||||
activeCred?.type === 'ssh-key'
|
||||
? activeCred.fingerprint ??
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ export class TunnelManager {
|
|||
}
|
||||
|
||||
async syncAutoStart(): Promise<void> {
|
||||
if (this.vaultService.state !== 'unlocked') return;
|
||||
if (!this.vaultService.isRuntimeReady) return;
|
||||
for (const server of this.configManager.listServers()) {
|
||||
if (!server.enabled) continue;
|
||||
for (const tunnel of server.tunnels) {
|
||||
|
|
@ -121,7 +121,7 @@ export class TunnelManager {
|
|||
if (!tunnel) {
|
||||
throw new Error(`Tunnel "${tunnelId}" not found on server "${serverId}"`);
|
||||
}
|
||||
if (this.vaultService.state !== 'unlocked') {
|
||||
if (!this.vaultService.isRuntimeReady) {
|
||||
throw new Error('Vault must be unlocked before starting SSH tunnels');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue