Skip to content

Commit eb749be

Browse files
committed
Windows: write SSH keys with LF endings — CRLF keys are rejected (#347)
Remote SSH repos failed from Windows agents with 'Connection closed by remote host. Is borg working on the server?' while local repos worked and Linux agents used the same remote host fine. The per-job remote SSH key is normalized to LF and then written with text-mode open(), which on Windows converts every newline back to CRLF — and OpenSSH rejects CRLF private keys ('invalid format'), so pubkey auth never happens and the remote host closes the connection. Local backups were unaffected only because the installer downloads the agent's own key byte-for-byte. All five key writes (agent key download fallback, backup task, and the three database-restore handlers) now open with newline="\n", which disables newline translation on every platform.
1 parent e50d300 commit eb749be

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

agent/bbs-agent.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def download_ssh_key(config):
598598
try:
599599
key_dir = os.path.dirname(SSH_KEY_PATH)
600600
os.makedirs(key_dir, exist_ok=True)
601-
with open(SSH_KEY_PATH, "w") as f:
601+
with open(SSH_KEY_PATH, "w", newline="\n") as f: # LF endings — CRLF keys are rejected by ssh (#347)
602602
f.write(private_key)
603603
if IS_WINDOWS:
604604
_lockdown_key_windows(SSH_KEY_PATH)
@@ -2573,7 +2573,7 @@ def execute_restore_pg(config, task):
25732573
normalized_key = remote_ssh_key.replace("\r\n", "\n").replace("\r", "\n").rstrip() + "\n"
25742574
if IS_WINDOWS:
25752575
_clear_stale_key_windows(remote_key_path)
2576-
with open(remote_key_path, "w") as kf:
2576+
with open(remote_key_path, "w", newline="\n") as kf: # LF endings — CRLF keys are rejected by ssh (#347)
25772577
kf.write(normalized_key)
25782578
if IS_WINDOWS:
25792579
_lockdown_key_windows(remote_key_path)
@@ -2790,7 +2790,7 @@ def execute_restore_mysql(config, task):
27902790
normalized_key = remote_ssh_key.replace("\r\n", "\n").replace("\r", "\n").rstrip() + "\n"
27912791
if IS_WINDOWS:
27922792
_clear_stale_key_windows(remote_key_path)
2793-
with open(remote_key_path, "w") as kf:
2793+
with open(remote_key_path, "w", newline="\n") as kf: # LF endings — CRLF keys are rejected by ssh (#347)
27942794
kf.write(normalized_key)
27952795
if IS_WINDOWS:
27962796
_lockdown_key_windows(remote_key_path)
@@ -3020,7 +3020,7 @@ def execute_restore_mongo(config, task):
30203020
normalized_key = remote_ssh_key.replace("\r\n", "\n").replace("\r", "\n").rstrip() + "\n"
30213021
if IS_WINDOWS:
30223022
_clear_stale_key_windows(remote_key_path)
3023-
with open(remote_key_path, "w") as kf:
3023+
with open(remote_key_path, "w", newline="\n") as kf: # LF endings — CRLF keys are rejected by ssh (#347)
30243024
kf.write(normalized_key)
30253025
if IS_WINDOWS:
30263026
_lockdown_key_windows(remote_key_path)
@@ -3593,7 +3593,7 @@ def _execute_task_inner(config, task, job_id, task_type, command, env_vars,
35933593
normalized_key = remote_ssh_key.replace("\r\n", "\n").replace("\r", "\n").rstrip() + "\n"
35943594
if IS_WINDOWS:
35953595
_clear_stale_key_windows(remote_key_path)
3596-
with open(remote_key_path, "w") as kf:
3596+
with open(remote_key_path, "w", newline="\n") as kf: # LF endings — CRLF keys are rejected by ssh (#347)
35973597
kf.write(normalized_key)
35983598
if IS_WINDOWS:
35993599
_lockdown_key_windows(remote_key_path)

0 commit comments

Comments
 (0)