Fix/ssh forwarding agent#310
Conversation
|
I'm sorry. I would like to add unit tests before adding new fixes or features. I would like to have it done by the end of the week. So please be patient. Thx |
It sounds more than wise! |
|
Could you add a test with A test: https://github.com/jeanp413/open-remote-ssh/blob/master/test/fixtures/default/linux-bash.yml npm run test:images // to build the docker images
npm run test // execute the tests |
Sure! 😀 |
|
Hi @jeanp413 I pushed the commit with tests, please le me know if they are enough |
|
LGTM |
Problem
With
ForwardAgent yesconfigured, the remote session gets anSSH_AUTH_SOCKpointing at a socket path that does not exist, so agent forwarding silently
fails (
ssh-add -l→ "Could not open a connection to your authentication agent").This is the symptom reported in #11.
Root cause
The
ssh2library binds the forwarded agent socket to the single sessionchannel that first requests agent forwarding (
_agentFwdEnabledis aclient-level flag; the request is sent for that one channel id). sshd tears the
socket down as soon as that channel closes.
The extension read
SSH_AUTH_SOCKfrom the short-lived install/startexecchannel. By the time the value reached VS Code, that channel — and therefore
its forwarding socket — was already gone, leaving every terminal / task /
extension-host process with a dangling path.
Fix
Open a dedicated channel that stays alive for the whole connection to host
the agent forwarding, and read its live
SSH_AUTH_SOCKfrom there:SSHConnection.execChannel()— runs a command and resolves with its channel assoon as it opens (no pty), instead of waiting for completion.
RemoteSSHResolver.openAgentForwardSession()— runsecho "$SSH_AUTH_SOCK"; exec caton that channel: prints the socket path once, then
exec catkeeps the channel(and its socket) open for the connection's lifetime. Closed in
dispose().Notes:
which would otherwise be captured as the command's output (yielding a literal,
unexpanded
$SSH_AUTH_SOCK).blocks connecting to the remote.
remote (e.g.
cmd.exeechoing the command verbatim) falls back to unset —no worse than before, never a bogus value.
Testing
ForwardAgent yes.echo $SSH_AUTH_SOCK,ls -l $SSH_AUTH_SOCK, andssh-add -lall resolvecorrectly inside a remote terminal.
~/.ssh/config(ForwardAgent/IdentityAgent) as well as anSSH_AUTH_SOCKenv var.Closes #11.