fix(actions): ssh channel pins known_hosts beside key (no HOME dependency)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-04 22:00:52 +10:00
parent 169e3b6d5c
commit cea2442c4f
2 changed files with 6 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import { spawn as nodeSpawn } from 'node:child_process';
import { dirname, join } from 'node:path';
const ID_RE = /^[a-z0-9-]+$/;
@@ -11,8 +12,11 @@ export function restartService({ ip, actionId }, {
spawnImpl = nodeSpawn
} = {}) {
if (!ID_RE.test(actionId || '')) return Promise.reject(new Error(`invalid action id: ${actionId}`));
// Pin known_hosts beside the key (writable, void-owned) so the channel doesn't
// depend on the service's HOME for ~/.ssh.
const knownHosts = join(dirname(keyPath), 'known_hosts');
const args = ['-i', keyPath, '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=accept-new',
`${user}@${ip}`, actionId];
'-o', `UserKnownHostsFile=${knownHosts}`, `${user}@${ip}`, actionId];
return new Promise((resolve, reject) => {
const child = spawnImpl('ssh', args);
let out = '', err = '';