microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.67k stars 292 forks source link

openssh agent not working inside devcontainer with Win10 2004 and WSL2 #3597

Closed casparjespersen closed 4 years ago

casparjespersen commented 4 years ago

Steps to Reproduce:

I am unable to use Git/SSH inside by devcontainer. This worked perfectly before upgrading to Version 2004 of Windows and running Docker with WSL2. Now I am receiving the following error when the container opens:

Remote-Containers server: Remote to local stream terminated with error: {
  message: 'connect ENOENT \\\\.\\pipe\\openssh-ssh-agent',
  name: 'Error',
  stack: 'Error: connect ENOENT \\\\.\\pipe\\openssh-ssh-agent\n\tat ' +
    'PipeConnectWrap.afterConnect [as oncomplete] ' +
    '(net.js:1056:14)'
}

However, the container can start. This error prompts periodically while container is running. When I open up a bash shell inside the container and execute ssh-add-l, I receive the following:

root@35e2cb36cac0:/workspaces/wsa-lbn# ssh-add -l
error fetching identities: communication with agent failed

The result of this is that I am not able to use Git inside the devcontainer environment.

PavelSosin-320 commented 4 years ago

O.K. the base image can be stable. But the user uses it's own, "tagged variant" image which should be instantly available. Docker images have no versions, only tags. To tag the image registry must be available because of local image can't be tagged. Docker build can be broken easily by Docker upgrade, switch between docker end-points, Network configuration, used custom tools versions, etc. This is not a 100% reproducible process. But the user doesn't always need the last development environment version to correct a bug in the project. The user needs a development environment that is usable to correct a bug. Also, new project features don't always require a new development environment upgrade. A user who deploys his project to separate "testing" landscape positively doesn't want to deal with development environment rebuild in the testing landscape. Runtime dependencies vs. Development dependencies. The test result depends on dev tools in rare cases because dev dependencies issues appear during the build. Docker exec git fetch & build in the testing landscape usually reproduces the development landscape results even without VSCode.

casparjespersen commented 4 years ago

@PavelSosin-320 Did you intend to post your reply in this thread?

chrmarti commented 4 years ago

@casparjespersen To be sure: You expect the container to get the SSH keys from the SSH agent on Windows, correct?

Does ssh-add -l work on Windows? Maybe your SSH agent service on Windows is not running?

casparjespersen commented 4 years ago

@chrmarti Correct. This was also the behaviour before I upgraded to Win10 2004 and enabled WSL2.

Observation: Disabling WSL2 engine in Docker did not have any effect, hence I suppose it must be related to the Windows upgrade.


ssh-add -l on my Windows actually provides a different error message:

Error connecting to agent: No such file or directory

This is different than what I receive when doing it inside the container ("communication with agent failed"). I am not an expert in how SSH works, so I'm not 100% on what to derive from this difference. However, what I can say:

Before upgrading Windows 10 to version 2004 (version 1909):

After upgrading Windows 10 to version 2004:

casparjespersen commented 4 years ago

After writing the previous reply and digging a bit further, I figured out that the Windows upgrade had for some reason disabled the ssh-agent service.

Following the guidelines on this StackOverflow post fixed the issue.

PS C:\Developer> ssh-agent
unable to start ssh-agent service, error :1058

PS C:\Developer> Get-Service ssh-agent

Status   Name               DisplayName
------   ----               -----------
Stopped  ssh-agent          OpenSSH Authentication Agent

PS C:\Developer> Get-Service ssh-agent | Select StartType

StartType
---------
 Disabled

PS C:\Developer> Get-Service -Name ssh-agent | Set-Service -StartupType Manual
PS C:\Developer> ssh-agent
PS C:\Developer> Get-Service ssh-agent

Status   Name               DisplayName
------   ----               -----------
Running  ssh-agent          OpenSSH Authentication Agent

So in the end, this had nothing to do with devcontainers/vscode remote. Closing the issue.