devpod icon indicating copy to clipboard operation
devpod copied to clipboard

SSH agent forwarding doesn't work

Open shdwchn10 opened this issue 1 year ago • 11 comments

What happened?
DevPod doesnt forward SSH agent and I'm unable to connect to SSH servers or authenticate against git forges.

What did you expect to happen instead?
Be able to use SSH inside DevPod.

How can we reproduce the bug? (as minimally and precisely as possible)

devpod provider add --name podman -o DOCKER_PATH=podman docker
git clone https://github.com/shdwchn10/teloxide -b dev/improve-dx
cd teloxide
devpod up .

My devcontainer.json:

{
    "build": {
        "dockerfile": "Containerfile"
    },
    "customizations": {
        "vscode": {
            "extensions": [
                "eamodio.gitlens",
                "rust-lang.rust-analyzer",
                "serayuzgur.crates",
                "tamasfe.even-better-toml",
                "nefrob.vscode-just-syntax",
                "Gruntfuggly.todo-tree"
            ]
        }
    },
    "workspaceMount": "",
    "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
    "runArgs": [
        "--volume=${localWorkspaceFolder}:/workspaces/${localWorkspaceFolderBasename}:Z"
    ]
}

Local Environment:

  • DevPod Version: v0.6.10
  • Operating System: Fedora Linux 41.20250203.0 (Silverblue)
  • ARCH of the OS: AMD64
  • IDE: VS Codium

DevPod Provider:

  • Local provider: docker (podman)

Anything else we need to know?
devpod-log.txt

~/.ssh/config:

Host server
    Hostname 192.168.122.107
    Port 22
    User shdwchn10
    IdentityFile ~/.ssh/server

Output from Codium terminal (inside of devpod):

[user@c0ab2f56997f teloxide]$ ssh server
ssh: Could not resolve hostname server: Name or service not known

[user@c0ab2f56997f teloxide]$ ssh-add -L
Error connecting to agent: No such file or directory

[user@c0ab2f56997f teloxide]$ echo $SSH_AUTH_SOCK 
/tmp/auth-agent3411776333/listener.sock

[user@c0ab2f56997f teloxide]$ ls $SSH_AUTH_SOCK 
ls: cannot access '/tmp/auth-agent3411776333/listener.sock': No such file or directory

[user@c0ab2f56997f teloxide]$ ls /tmp
codium-async.pid          vscode-git-1bea5add6a.sock
codium-async.pid.lock     vscode-ipc-171be37f-7173-4d87-8844-6feba872f69d.sock
codium-async.pid.streams  vscode-ipc-47064521-c6c9-407e-bbfb-41d48eba02dd.sock
devpod.activity

shdwchn10 avatar Feb 03 '25 03:02 shdwchn10

I have run into the same issue and from what I can tell this is due to the following:

The devpod ssh server by default creates a new agent forwarding socket (/tmp/auth-agent*/listener.sock) for each individual session, even when within a single connection. Openssh-server, against which I'm assuming open-remote-ssh was primarily written and tested, creates one agent forwarding socket (/tmp/ssh-*/agent.*) per connection, not per session.

So when open-remote-ssh starts a new vscodium-server here that happens within an ssh session that is started and terminated here. That means the agent socket exposed via $SSH_AUTH_SOCK during that session - which is later extracted here and then forwarded to the vscodium terminal here - is no longer valid by the time it ends up being used.

This is effectively a use-after-free issue: Open-remote-ssh extracts and then uses the socket after it has been freed.

Having taken a preliminary look at the ssh key agent protocol document I believe devpod's ssh server behavior is valid with respect to the spec and open-remote-ssh's implicit assumption that the agent socket would be available during the whole connection is invalid.

If that is correct, then this is a bug in open-remote-ssh and would need to be solved there, maybe starting vscodium-server within a long-running exec session so the agent socket doesn't get freed while the server is running.

Note that this is only my observation from having taken a look at both projects and the spec, I'm not deeply familiar with either and if what I wrote is incorrect I apologize in advance.

MoritzMaxeiner avatar Mar 08 '25 15:03 MoritzMaxeiner

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar May 08 '25 02:05 github-actions[bot]

I have the same issue, using devpod-cli + jetbrains. When using devpod-cli + vscode, rebooting the container seems to be a temporary fix (i also have to reopen my vscode terminal(s) after a reboot for the ssh agent forward to work)

gerbernoah avatar Jun 14 '25 15:06 gerbernoah

Possible workaround:

Devpod prints info Run "ssh [workspace_name]" to ssh into the devcontainer

Using ssh -A [workcpace_name] enables to push (and sign? - not tested) commits to githubs

gerbernoah avatar Jun 14 '25 16:06 gerbernoah

@MoritzMaxeiner, great explanation! Maybe it should be sent to open-remote-ssh repo?

WerySkok avatar Aug 12 '25 22:08 WerySkok

Thanks :) Back then I had hoped for someone from the devpod team to weigh in; right now I'm using neither open-remote-ssh nor devpod, but don't let me stop you from reporting it the open-remote-ssh.

MoritzMaxeiner avatar Aug 13 '25 21:08 MoritzMaxeiner

Well, I've decided to not use devcontainers for my usecase, as it became too complicated and I'd gotten into another problem as VSCodium stopped connecting into devcontainer (nothing was happening after opening a tunnel)

WerySkok avatar Aug 13 '25 22:08 WerySkok

Hi there.

I have the same problem, and to make matters worse, my SSH agent is the one from Bitwarden.

Every single devpod instance in my machine with Docker will fail. I have to exit the devcontainer to make every git operation.

Is there any workaround for this?

Thanks.

f8th-io avatar Sep 11 '25 14:09 f8th-io

@n0ct1s-k8sh

I use 1password's ssh agent aswell, i actively use the following workarround:

Possible workaround: Using ssh -A [workcpace_name] enables to push (and sign? - not tested) commits to githubs

The -A here is important to forward your ssh agent.

It's maybe also worth noticing that the connection has to be done after 1password (or bitwardens) ssh agent is already running (at least for me).

gerbernoah avatar Oct 17 '25 12:10 gerbernoah

This issue is stale because it has been open for 60 days with no activity. It will be closed in 30 days on inactivity.

github-actions[bot] avatar Aug 19 '26 01:08 github-actions[bot]

This issue was closed because it has been inactive for 30 days since being marked as stale.

github-actions[bot] avatar Sep 19 '26 01:09 github-actions[bot]