Skip to content

fix(ssh): prevent tar from overwriting remote home dir permissions (#17767) - #17898

Merged
teknium1 merged 2 commits into
mainfrom
fix/17767-ssh-tar-preserve-dir-mode
Apr 30, 2026
Merged

fix(ssh): prevent tar from overwriting remote home dir permissions (#17767)#17898
teknium1 merged 2 commits into
mainfrom
fix/17767-ssh-tar-preserve-dir-mode

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvages #17867 by @vominh1919 onto current main. Closes #17767.

Problem

The SSH terminal backend's _ssh_bulk_upload() runs tar xf - -C / on the remote, extracting a staging directory tree to the remote root. GNU tar's default is to overwrite metadata (including mode) of existing directories. When the local umask is 002 (Ubuntu default), staging dirs are 0775, and tar chmods /home/<user> to 0775 on the remote.

That violates sshd StrictModes yes (which requires non-group-writable home dirs), so subsequent SSH connections fail with Permission denied (publickey). Recovery requires out-of-band console access to chmod the home dir back. Reporter (@luismartinezs) hit this on a Hetzner VPS and couldn't reconnect.

Confirmed on current main — tools/environments/ssh.py:185 still has the bare tar xf - -C /.

Fix (author: @vominh1919, 1 file, +5/-1)

Add --no-overwrite-dir to the remote tar command. Tar skips updating attributes of already-existing directories, so new entries (~/.hermes/, ~/.hermes/skills/) are still created with reasonable modes via remote umask, but /home/<user> keeps its original 0755.

Follow-up test update

tests/tools/test_ssh_bulk_upload.py::test_tar_pipe_commands asserted the literal substring "tar xf - -C /" in the ssh command — which is no longer present with --no-overwrite-dir between tar xf - and -C /. Split into three separate assertions; added an explicit check for the new flag as a regression guard.

Validation

scripts/run_tests.sh tests/tools/test_ssh_bulk_upload.py tests/tools/test_ssh_environment.py
34 passed, 11 skipped

Authorship preserved for @vominh1919 via plain cherry-pick.

vominh1919 and others added 2 commits April 30, 2026 03:23
tar xf - -C / extracts the staging directory tree to the remote root.
GNU tar default behavior overwrites metadata (including mode) of existing
directories. When the local umask is 002 (Ubuntu default), the staging
dirs are 0775, and tar chmod's /home/<user> to 0775 — breaking sshd
StrictModes which requires 0755 or stricter for home dirs.

Add --no-overwrite-dir to the remote tar command so existing directory
metadata is preserved.

Fixes #17767
Existing test_tar_pipe_commands asserted the literal substring
'tar xf - -C /' in ssh_str, which is no longer present after the
#17767 fix adds --no-overwrite-dir between 'tar xf -' and '-C /'.

Split the one substring check into three independent assertions for
the tar stdin mode, the new --no-overwrite-dir flag (regression guard
for #17767), and the extract target.
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround backend/ssh SSH remote execution labels Apr 30, 2026
@teknium1
teknium1 merged commit 87f5e1a into main Apr 30, 2026
12 checks passed
@teknium1
teknium1 deleted the fix/17767-ssh-tar-preserve-dir-mode branch April 30, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/ssh SSH remote execution P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSH backend: tar xf - -C / corrupts remote home directory mode, breaks sshd StrictModes

3 participants