Skip to content

Commit 8d44c6a

Browse files
authored
fix: don't let ssh-keyscan abort SSH git clones (Dokploy#4605)
cloneGitRepository runs `ssh-keyscan <host> >> known_hosts` as one step of a `set -e` script. Hosts whose SSH endpoint waits for the client's identification string first — Hugging Face's hf.co among them — never complete the keyscan handshake, so it exits 1 and `set -e` aborts the deploy before `git clone` ever runs. Make ssh-keyscan non-fatal and let the real ssh client record the host key on first connect (StrictHostKeyChecking=accept-new), which reaches hosts ssh-keyscan can't scan. Same TOFU trust model, so no regression; GitHub/GitLab/Gitea still pre-seed and verify known_hosts as before.
1 parent ec9dd28 commit 8d44c6a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • packages/server/src/utils/providers

‎packages/server/src/utils/providers/git.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const cloneGitRepository = async ({
7373
if (customGitSSHKeyId) {
7474
const sshKey = await findSSHKeyById(customGitSSHKeyId);
7575
const { port } = sanitizeRepoPathSSH(customGitUrl);
76-
const gitSshCommand = `ssh -i /tmp/id_rsa${port ? ` -p ${port}` : ""} -o UserKnownHostsFile=${knownHostsPath}`;
76+
const gitSshCommand = `ssh -i /tmp/id_rsa${port ? ` -p ${port}` : ""} -o UserKnownHostsFile=${knownHostsPath} -o StrictHostKeyChecking=accept-new`;
7777
command += `echo "${sshKey.privateKey}" > /tmp/id_rsa;`;
7878
command += "chmod 600 /tmp/id_rsa;";
7979
command += `export GIT_SSH_COMMAND="${gitSshCommand}";`;
@@ -111,7 +111,10 @@ const addHostToKnownHostsCommand = (repositoryURL: string) => {
111111
const { domain, port } = sanitizeRepoPathSSH(repositoryURL);
112112
const knownHostsPath = path.join(SSH_PATH, "known_hosts");
113113

114-
return `ssh-keyscan -p ${port} ${domain} >> ${knownHostsPath};`;
114+
// ssh-keyscan is best-effort: some Git hosts (e.g. Hugging Face) never answer
115+
// it, and its exit code must not abort the clone under `set -e`. The clone's
116+
// own host-key check (StrictHostKeyChecking=accept-new) is the real boundary.
117+
return `ssh-keyscan -p ${port} ${domain} >> ${knownHostsPath} || true;`;
115118
};
116119
const sanitizeRepoPathSSH = (input: string) => {
117120
const SSH_PATH_RE = new RegExp(

0 commit comments

Comments
 (0)