Skip to content

fix(ssh): resolve the SSH config with ssh -G and forward the session type with SendEnv - #1197

Merged
EhabY merged 2 commits into
mainfrom
fix/vsc-8-ssh-g-remote-command
Nov 23, 2026
Merged

EhabY merged 2 commits into
mainfrom
fix/vsc-8-ssh-g-remote-command

Conversation

@EhabY

@EhabY EhabY commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

After writing the generated SSH config, the extension resolved the Coder host's options with a manual parser that ignores Include, Match and negated Host lines, so a RemoteCommand from any of them went undetected. The host is now resolved with ssh -G, using the ssh executable the active Remote-SSH extension is configured with. If ssh fails, the extension falls back to the parser.

Also in this PR:

  • PermitLocalCommand no: the generated block sets it, so a LocalCommand elsewhere in the user's config never runs for workspaces.
  • SendEnv instead of SetEnv: the session type is set in the environment ssh inherits and forwarded with SendEnv. This works on every OpenSSH version, so the ssh -V check is gone.
  • Deployment options that expose the client are ignored: SendEnv forwards local environment variables, SetEnv (OpenSSH 10+), User and RemoteForward expand ${VAR} into values sent to the workspace, and RemoteForward can also forward local sockets such as the Docker socket. They are dropped from the deployment's options, logged, and listed in a warning. "Don't Show Again" hides it per deployment until a new option appears. The user's own options from coder.sshConfig or coder config-ssh -o are written as given.
  • Devin config file: Devin 3.12.32+ passes remote.devinSSH.configFile to ssh, so Coder hosts go into that file there.

Refs VSC-8. Closes VSC-52. The post-write check VSC-8 describes was already removed in #1061.

Decision log
  • No blocking check: the Include sits at the top of the user's config and ssh keeps the first value it reads, so the pinned options can't be overridden. I confirmed this with ssh -G.
  • -F only when Remote-SSH passes it: -F makes ssh skip /etc/ssh/ssh_config, so ssh -G reads the same files the connection does.
  • ssh executable: each extension's key comes from its shipped code: remote.SSH.path (Microsoft, Cursor, open-remote-ssh in native mode), remote.devinSSH.path and remote.antigravitySSH.path.
    • If the configured ssh is missing, ssh -G fails and is logged, then the parser takes over. It never silently runs a different ssh from PATH.
    • Windows batch wrappers fall back to the parser, so we never use a shell.
    • Microsoft's Windows search for ssh is not copied. With Git for Windows installed, a different ssh may evaluate the same config, and the worst case is today's behavior.
  • SendEnv: I checked against a real sshd that it delivers the same value as SetEnv. Every extension spawns ssh with process.env. open-remote-ssh's default ssh2 backend ignored SetEnv and exports SendEnv values in its setup script instead of sending them, so the agent still sees a plain SSH session there, as on main: SendEnv is exported in the setup script instead of sent as SSH env requests (ssh2 backend) jeanp413/open-remote-ssh#415.
  • Deployment env options dropped, not denied: coderd's ValidateSSHConfigOption accepts them, so rejecting them like DENIED_DEPLOYMENT_KEYS would block connections to deployments that set them today. They are dropped even when the user sets the same key, because SetEnv and SendEnv accumulate and the deployment's values would otherwise be written next to the user's. I checked the expansion with ssh -G on OpenSSH 9.5 and 10.3; HostName, HostKeyAlias and Tag do not expand environment variables. LocalForward expands ${VAR} in its target, but that only reaches the workspace when a local client connects to the forwarded port, so it is kept. ForwardAgent, DynamicForward and ForwardX11Trusted also expose the client but have legitimate deployment-wide uses, so they are left for a follow-up.
  • Breakage: ignored options never fail a connection. The agent runs sessions as the workspace's OS user and ignores the SSH login name, so dropping User changes nothing. An admin who set SendEnv for locale or a deployment-wide RemoteForward (for example, for GPG) loses it, sees the warning, and can move it to coder.sshConfig.
  • User env options untouched: the OpenSSH client session setup sends SendEnv values before SetEnv values, so a user's SetEnv CODER_SSH_SESSION_TYPE=… replaces ours. That is the user's choice about their own machine, so it is not filtered. The # :ssh-option= lines read from the coder config-ssh block hold only the user's -o flags; the CLI merges deployment options separately.

Generated by Coder Agents on behalf of @EhabY.

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

VSC-8

VSC-52

@EhabY EhabY changed the title fix(ssh): resolve the SSH config with ssh -G and disable LocalCommand fix(ssh): resolve the SSH config with ssh -G and forward the session type with SendEnv Nov 17, 2026
@EhabY
EhabY force-pushed the fix/vsc-8-ssh-g-remote-command branch 3 times, most recently from bbb0962 to 07b4e92 Compare November 17, 2026 14:37
@EhabY
EhabY marked this pull request as ready for review November 18, 2026 14:52
@EhabY
EhabY force-pushed the fix/vsc-8-ssh-g-remote-command branch from 07b4e92 to 0e40ec3 Compare November 18, 2026 14:53
@EhabY
EhabY requested a review from code-asher November 18, 2026 19:49
@EhabY
EhabY force-pushed the fix/vsc-8-ssh-g-remote-command branch from 113b5a2 to 880f53f Compare November 19, 2026 10:58
@EhabY
EhabY added this pull request to stack #1204 November 19, 2026 12:42
@EhabY
EhabY force-pushed the fix/vsc-8-ssh-g-remote-command branch from 9bb15bf to 2e22f05 Compare November 20, 2026 11:24

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice changes!

Comment thread src/remote/sshConfig.ts Resolved
…type with SendEnv

After writing the generated SSH config, the extension resolved the Coder host's options with a manual parser that ignores `Include`, `Match` and negated `Host` lines, so a `RemoteCommand` from any of them went undetected. The host is now resolved with `ssh -G`, using the ssh executable the active Remote-SSH extension is configured with. If ssh fails, the extension falls back to the parser.
@EhabY
EhabY force-pushed the fix/vsc-8-ssh-g-remote-command branch from 2e22f05 to 65cfabe Compare November 23, 2026 09:56
A deployment's SendEnv forwards local environment variables to the workspace, and SetEnv (OpenSSH 10+), User and RemoteForward expand ${VAR} into values sent to it; RemoteForward can also forward local sockets. These are dropped from the deployment's options, logged, and listed in a warning that Don't Show Again hides per deployment until a new option appears. The user's own options are written as given, so the session type SetEnv filter is gone.

ssh -G now falls back to the parser when it resolves no ProxyCommand, meaning it never read the Coder config. The CHANGELOG entries move out of the released v1.18.2 section.

Closes VSC-52.
@EhabY
EhabY force-pushed the fix/vsc-8-ssh-g-remote-command branch from 997c2a2 to cb0bf7b Compare November 23, 2026 10:54
@EhabY
EhabY merged commit ae685e9 into main Nov 23, 2026
16 checks passed
@EhabY
EhabY deleted the fix/vsc-8-ssh-g-remote-command branch November 23, 2026 11:16
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.

2 participants