Skip to content

SSH agent host: add agent forwarding setting & fix encrypted key failures#312013

Merged
joshspicer merged 2 commits intomainfrom
agents/add-agent-forward-ssh-feature
Apr 23, 2026
Merged

SSH agent host: add agent forwarding setting & fix encrypted key failures#312013
joshspicer merged 2 commits intomainfrom
agents/add-agent-forward-ssh-feature

Conversation

@joshspicer
Copy link
Copy Markdown
Member

@joshspicer joshspicer commented Apr 22, 2026

Two changes to the SSH remote agent host:

1. Skip fallback privateKey when SSH agent socket is present

ssh2 eagerly parses privateKey at connect time — before attempting any auth. If the key is passphrase-encrypted this immediately throws "Cannot parse privateKey: Encrypted private OpenSSH key detected, but no passphrase given", even when the key is already loaded in the SSH agent.

2. Add chat.agentHost.forwardSSHAgent setting

Adds an opt-in setting that enables OpenSSH agent forwarding on SSH connections, allowing tools running under the remote agent host to authenticate using the local user's SSH keys.

Copilot AI review requested due to automatic review settings April 22, 2026 21:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SSH remote agent host implementation to avoid ssh2 failures when passphrase-encrypted keyfiles are present but an SSH agent is available, and adds an opt-in setting to enable OpenSSH agent forwarding for remote agent host connections.

Changes:

  • Avoid reading/parsing fallback key files when an SSH agent socket is present to prevent ssh2 encrypted-key parsing failures.
  • Add chat.agentHost.forwardSSHAgent (default false, experimental) and propagate agentForward through connect/reconnect flows.
  • Update logging and add test coverage for the new auth/forwarding behaviors.
Show a summary per file
File Description
src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHostActions.ts Adjusts SSH connect UI defaults to avoid auto-selecting KeyFile; records IdentityFile for optional user selection.
src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHost.contribution.ts Registers the new chat.agentHost.forwardSSHAgent setting.
src/vs/platform/agentHost/test/node/sshRemoteAgentHostService.test.ts Adds/updates tests for agent auth fallback behavior and agentForward flag propagation.
src/vs/platform/agentHost/node/sshRemoteAgentHostService.ts Implements the new reconnect signature, skips fallback privateKey when agent is present, and applies agentForward to ssh2 connect config.
src/vs/platform/agentHost/electron-browser/sshRemoteAgentHostServiceImpl.ts Reads the new setting, disconnectes on setting change, and forwards agentForward on connect/reconnect.
src/vs/platform/agentHost/common/sshRemoteAgentHost.ts Extends ISSHAgentHostConfig with agentForward and updates the main-service reconnect API.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 3

Comment thread src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHost.contribution.ts Outdated
Comment thread src/vs/platform/agentHost/electron-browser/sshRemoteAgentHostServiceImpl.ts Outdated
@joshspicer joshspicer force-pushed the agents/add-agent-forward-ssh-feature branch from 880a59d to 79a7485 Compare April 22, 2026 21:51
@joshspicer joshspicer marked this pull request as draft April 22, 2026 21:54
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

Screenshot Changes

Base: 67f69ba4 Current: 361d4798

Changed (1)

editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after

@joshspicer joshspicer force-pushed the agents/add-agent-forward-ssh-feature branch from 57ca399 to ead30e7 Compare April 22, 2026 22:08
@joshspicer joshspicer force-pushed the agents/add-agent-forward-ssh-feature branch 6 times, most recently from 26308fb to bf2ba11 Compare April 22, 2026 23:14
@joshspicer joshspicer marked this pull request as ready for review April 22, 2026 23:22
@joshspicer joshspicer requested a review from roblourens April 22, 2026 23:22
Comment thread src/vs/platform/agentHost/node/sshRemoteAgentHostService.ts Outdated
Comment thread src/vs/platform/agentHost/electron-browser/sshRemoteAgentHostServiceImpl.ts Outdated
When using Agent auth, _connectSSH was loading the first default key file
(~/.ssh/id_ed25519, etc.) as a fallback privateKey alongside the agent
socket. ssh2 parses privateKey eagerly before attempting agent auth, so
if the key is passphrase-encrypted the connection fails immediately with
"Cannot parse privateKey: Encrypted private OpenSSH key detected, but
no passphrase  even though the key is already loaded in thegiven"
agent and would work fine.

Keep the fallback key logic for cases where no SSH agent is available
(SSH_AUTH_SOCK unset), so publickey auth can still be attempted via the
raw key file. But skip it when an agent socket is  in that casepresent
the agent should have the keys loaded, and passing an encrypted key file
alongside the agent can only cause problems.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshspicer joshspicer force-pushed the agents/add-agent-forward-ssh-feature branch 3 times, most recently from 9040b3c to 481dddd Compare April 23, 2026 02:28
Add a new boolean setting that enables OpenSSH agent forwarding
(auth-agent@openssh.com) on SSH agent host connections. When enabled
and the connection uses Agent auth, sets agentForward=true in the
ssh2 connect config so the remote machine can use the local SSH agent.

- Add agentForward field to ISSHAgentHostConfig
- Register chat.agentHost.forwardSSHAgent setting (default: false)
- Read the setting in the renderer-side _augmentConfig
- Apply agentForward in _connectSSH when agent socket is present

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Address code review comments

- Add security warning to chat.agentHost.forwardSSHAgent setting description
- Pass error object to warn() instead of stringifying it
- Prompt for auth method when non-default IdentityFile is configured (so
  users without an SSH agent can still choose KeyFile)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Refactor _augmentConfig to use if statements instead of spread tricks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Revert unnecessary changes to remoteAgentHostActions.ts

The encrypted key fix is handled server-side in _connectSSH and reconnect.
No need to change the UI connect flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshspicer joshspicer force-pushed the agents/add-agent-forward-ssh-feature branch from 481dddd to 7f30f56 Compare April 23, 2026 02:28
@joshspicer joshspicer merged commit 515c4fb into main Apr 23, 2026
26 checks passed
@joshspicer joshspicer deleted the agents/add-agent-forward-ssh-feature branch April 23, 2026 03:47
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 23, 2026
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.

3 participants