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.61k stars 276 forks source link

Gpg agent not forwarded when using devcontainer through remote-ssh #7814

Open max06 opened 1 year ago

max06 commented 1 year ago

Connection to dev Container through remote-ssh extension. GPG-Agent is missing inside the devcontainer.

Comparison: DevContainer used via docker context:

[2693 ms] Start: Run in container: touch '/vscode/vscode-server/bin/linux-x64/e8a3071ea4344d9d48ef8a4df2c097372b0c5161'
[2693 ms] Start: Launching Dev Containers helper.
[2693 ms] ssh-agent: SSH_AUTH_SOCK in container (/tmp/vscode-ssh-auth-7e3a446ef6b9db23fe750a7e37db5bc8f2686e1a.sock) forwarded to local host (\\.\pipe\openssh-ssh-agent).
[2694 ms] X11 forwarding: DISPLAY not set on host.
[2694 ms] Start: Run: gpgconf --list-dir agent-extra-socket
[2696 ms] 
[2696 ms] 
[2738 ms] C:\Users\max06\AppData\Local\gnupg\S.gpg-agent.extra
[2738 ms] 
[2738 ms] Start: Run in container: gpgconf --list-dir agent-socket
[2744 ms] /root/.gnupg/S.gpg-agent

Steps to Reproduce:

  1. Open remote-ssh-connection to Docker-Host.
  2. Open DevContainer on remote Host
  3. Run gpg2 --list-secret-keys --keyid-format long --verbose - it should list at least something

Does this issue occur when you try this locally?: No Does this issue occur when you try this locally and all extensions are disabled?: No

Happy to provide information as requested.

chrmarti commented 1 year ago

It would lookup the GPG socket locally if it couldn't find it remotely. We could add a setting to change the order.

max06 commented 1 year ago

@chrmarti Based on your info I uninstalled gpg from the linux remote host. The rebuild causes some red error messages now, related to not finding gpg-conf anymore, but in the end I have access to my hosts gpg-agent. I can sign commits again. 👍🏼

A setting for reversing the lookup order sounds great, although I would reverse the order by default. I'd think the device running the vscode frontend is most likely the device holding all secrets. And you'll probably find a gpg agent on many linux machines, installed by default.

hpe-ykoehler commented 1 year ago

I have the same issue with ssh-agent, but in my case I need "remote" to be the one being used because my ssh keys are on my linux remote workstation, but when I use devcontainer the connection seems to be using my local windows ssh-agent. Seems very similar to this. Is there a way to control which one will be used for different credentials agent (gpg/ssh/others)?

chrmarti commented 1 year ago

@hpe-ykoehler Currently it will always prefer the remote one. For the ssh-agent it will check if SSH_AUTH_SOCK is set. Make sure that is being set in your ~/.profile / ~/.bash_profile by launching or reusing the ssh-agent there. See, e.g., https://stackoverflow.com/a/18915067/7857763. If that doesn't get it working, please open a new issue for us to investigate. Thanks.

hpe-ykoehler commented 1 year ago

I had validated that I have a remote ssh-agent working and yet it didn't take that one. Using ssh it works but using devcontainer over ssh it didn't (on that same remote). It really just wanted my windows ssh-agent nothing more.

I do have heard from others that it works for them properly, so somehow it seems like a setup issue, but I can't find why I am having this problem.

chrmarti commented 1 year ago

@hpe-ykoehler You can check in the containers log (F1 > Dev Containers: Show Container Log) which SSH_AUTH_SOCK it picks up. If you want to use the ssh-agent from your local machine, it's best to not set SSH_AUTH_SOCK remotely. (Maybe I misunderstood your goal earlier.) Please open a new issue if this doesn't work as described.

max06 commented 1 year ago

I remember having similar difficulties with remote ssh and devcontainers.

I solved mine by adding ForwardAgent yes to the ssh configuration of my remote hosts.

wittwitt commented 1 year ago

.ssh/config ForwardAgent yes

this not work somtime


vscdoe version

版本: 1.75.0 提交: e2816fe719a4026ffa1ee0189dc89bdfdbafb164 日期: 2023-02-01T15:29:17.766Z Electron: 19.1.9 Chromium: 102.0.5005.194 Node.js: 16.14.2 V8: 10.2.154.23-electron.0 OS: Linux x64 5.15.0-58-generic 沙盒化: No

wittwitt commented 1 year ago

get_agent_identities: ssh_get_authentication_socket: No such file or directory

avanderbergh commented 7 months ago

In case any NixOS users encounter this issue, you need to set { programs.gnupg.agent.enableExtraSocket = true }

ZauberNerd commented 1 week ago

It would lookup the GPG socket locally if it couldn't find it remotely. We could add a setting to change the order.

Most systems have gpg installed by default and need it too (e.g. to validate package signatures, etc), so uninstalling it on the remote isn't always a viable solution and I would like to see an option to change it in the settings.