-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DevContainer: SSH und GPG agent forwarding for WSL2 #2925
Comments
Looked into this and part of the challenge is to get at the ssh-agent's socket path stored in the environment variable If you are using the ssh-agent in WSL: How are you starting it and how do you pass |
I am by no mean experienced in using the SSH Agent. But I am using the snipped form the official remote containers documentation in my .bashrc in the WSL (2) distro. (https://code.visualstudio.com/docs/remote/containers#_using-ssh-keys) |
I am having the same problem. Tried using the .bash_profile method as well as putting the same thing in .zprofile (because I use zsh) and neither seems to get me a working ssh agent in the container. SSH_AUTH_SOCK env var is present in WSL.
In the logs there's clear mention of gpg but nothing about ssh agent. |
I've installed keychain in my WSL distro and appended this line to my
|
I have same issue. |
I also encountered the same problem. But after a while I realized that since I am already developing inside a container, I might a well run the container from my windows host, instead of from inside the WSL environment. The ssh agent forwarding works well from there. |
@ATGardner |
Yeah, I just cloned into my windows environment, opened the folder in vscode, and then reopened it inside the container. After seeing up the ssh agent in powershell, it just worked inside the container. |
So that's it. However, if WSL2 Docker is launched from the Windows file system, the CPU usage will increase due to another existing problem, so I would like to put the file on WSL2 and use it if possible. I tried accessing the project on WSL2 mounted as a network drive from VS Code started in Local as a trial and started DevContainer, but the volumes setting described in docker-compose.yml did not work and the container started did not do it. |
I have this issue on Windows 10 with docker on WSL2, inside of DevContainers. Followed both of these guides Repro steps:
Windows:
If I copy the same SSH key into the container at Extension version: 0.128.0 |
I understand the problem, and I am seeing the exact same behavior. But I still don't understand why it matters.
Now my VS Code is running inside a linux container, which is running on my window machine directly. SSH works as expected. The volume mount does not cross WSL<->windows boundaries. Does mounting from Windows into a "standard" Linux container also have some performance cost? update: |
With WSL 2 the docker daemon is runny actually always in WSL (in its own docker-desktop Distribution) and so any Linux container will actually run also inside the WSL (not on windows directly). Beside the performance impact of mounting the Windows Filesystem to the Container inside the WSL I also had a lot of permission problem when not running as root in the container. (The files from Windows belongs always to root). The best practices from docker is also to store your code on the Linux (WSL) filesystem: https://docs.docker.com/docker-for-windows/wsl/#best-practices
That makes not a lot of sense for me. For me the whole point of the dev container is to open an already cloned repo inside a containerized dev environment. If I have to (re-)clone everything again the inside the container first I would lose actually a lot of the advantages of the dev containers. |
Thanks for explaining that any docker Linux mount to Windows will not be as performant. Regarding the 2nd point - that's a valid one. But I just think that slowly clearing my |
That's true, but unfortunately it's actually difficult to have no mounted volumes at all. |
I am using I start it from .zshrc as follows:
Because I often share my $HOME/.config with containers (so I can keep my Zsh and oh-my-zsh stuff consistent), I wrap it all with the check to run it on WSL (which can run an .exe) and in a container (which can't) |
I also use
The Devcontainer Startup Logs (expand to view in full) show some stuff about GPG, but nothing about SSH-agent. Also quite a lot of `exit code 1`s, which I don't know if they are a problem indicator or not.
|
I am also running into this problem (ssh-agent not being forwarded to remote-container when launched from WSL2). I believe the root problem is related to another issue I have seen (#3086). It would seem that the way that remote-containers invokes docker for WSL2 based repos does not provide for a way to load a profile, hence no environment variables are set ( |
Added a fix to extract the environment variables from a login shell (#3456). Looking into forwarding to a socket in WSL now. |
The fix to connect to a WSL socket requires socat to be installed in the WSL distro. I'm adding a notification saying so in case it is not installed. |
@chrmarti By any chance do you know how to properly use I couldnt find anything in the official docs, but this issue has more information : docker/compose#551 The docker for mac docs mention macOS specific things though : https://docs.docker.com/docker-for-mac/osxfs/#ssh-agent-forwarding I've tried to do it, and I'm able to |
@Hebilicious I haven't tried that, best to ask on StackOverflow. Alternatively you could use the forwarding I have implemented, just make sure that your WSL shell's login script set |
Furthermore I tested now also with SSH Auth but that does not work either. Then the my SSH key is not found an
ssh-add -l
(inside the container) saysCould not open a connection to your authentication agent.
But inside the WSL 2 distro it works also using SSH. (ssh-agent is running on the WSL2 distro).Originally posted by @J0F3 in #2858 (comment)
The text was updated successfully, but these errors were encountered: