Skip to content

fix(ssh): use POSIX shell quoting for MSYS/Cygwin ProxyCommand on Windows - #318

Open
leddele wants to merge 1 commit into
googlecolab:mainfrom
leddele:fix/msys-ssh-proxycommand-quoting
Open

leddele wants to merge 1 commit into
googlecolab:mainfrom
leddele:fix/msys-ssh-proxycommand-quoting

Conversation

@leddele

@leddele leddele commented Dec 3, 2026

Copy link
Copy Markdown

Summary

Follow-up to #295 for colab ssh under Git for Windows' MSYS/Cygwin ssh.

MSYS/Cygwin OpenSSH executes ProxyCommand through a POSIX shell (bash -c "exec <cmd>"), whereas native Windows OpenSSH invokes it directly via CreateProcessW. Currently _proxy_command always uses subprocess.list2cmdline(argv) on Windows, which leaves arguments without spaces unquoted and wraps arguments with spaces in double quotes. Under Git Bash's ssh, arguments containing shell metacharacters (e.g. $(...), ;, &, ', \) are expanded, split, or rejected by bash rather than passed literally.

Changes

  • src/colab_cli/commands/ssh.py:
    • Extracted _is_msys_ssh() from _ssh_null_device() (checking for msys-2.0.dll or cygwin1.dll alongside ssh.exe on Windows).
    • Updated _proxy_command() to use shlex.join(argv) when _is_msys_ssh() is true, keeping subprocess.list2cmdline(argv) for native Windows OpenSSH.
  • tests/test_windows_ssh.py:
    • Expanded test_proxy_command_survives_msys_ssh_shell to cover the same literal-argument parameter set as test_proxy_command_launches_with_literal_arguments (simple, with space, a'b, a"b, $(echo test), a;b, a&b, a\b\, Unicode) under an MSYS ssh.exe layout.
    • Isolated test_proxy_command_launches_with_literal_arguments from ambient MSYS ssh on PATH so it reliably tests the native CreateProcessW path even when pytest is invoked from Git Bash.
    • Added portable cross-platform unit tests for _proxy_command() quoting under MSYS/Cygwin vs. native Windows ssh.exe.
  • docs/06_ssh_access.md:
    • Updated the changelog frontmatter and Windows regression test summary.

Verification

  • uv run pytest tests/test_windows_ssh.py tests/test_ssh.py tests/test_ssh_cmd.py tests/test_ssh_autocreate.py tests/test_ssh_lifecycle.py tests/test_ssh_wire_contract.py tests/test_ssh_workdir.py on Windows 11 (Python 3.12.13, Git for Windows installed): 231 passed.
  • uv run ruff check src/colab_cli/commands/ssh.py tests/test_windows_ssh.py: passed.
  • uv run ruff format --check src/colab_cli/commands/ssh.py tests/test_windows_ssh.py: passed.
  • Live Colab VM SSH testing was not run (offline unit & local shell/stub tests only).

@google-cla

google-cla Bot commented Dec 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant