Repository navigation
feat: SSH agent relay for DDEV containers and Coder key in an agent, revert PHP2Shell workaround, fixes #220, fixes #210 - #223
Merged
Conversation
DDEV v1.25.5 ships ddev-webserver images with fixed PHP, and the v0.6 image installs it, so the per-start Dockerfile.php2shell upgrade step is no longer needed. This reverts commit cd5e899. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#220, fixes #210 DDEV's containers couldn't use the Coder key or the user's forwarded agent, and a forwarded agent's socket dies on every VS Code reconnect. DDEV v1.25.5 adds ssh_agent_upstream and resolves symlinked sockets. - Image (v0.6, DDEV v1.25.5): add socat, fzf, zstd, and ship ssh-agent-relay/connect and bashrc.sh in /home/coder-files. - shared/ssh-agent-setup.sh (vendored by make sync-ssh-agent-setup, included in all three startup scripts): - loads the Coder key into ssh-agent at ~/.coder-ssh-agent/agent.sock - runs a socat relay at ~/.ssh-agent-relay/agent.sock that, per connection, uses the first live agent of: the most recent shell's forwarded agent (current), the newest /tmp/auth-agent*/listener.sock, the Coder-key agent - sets ddev ssh_agent_upstream to the relay socket - sources bashrc.sh from ~/.bashrc, which retargets current from shells with a live forwarded agent and points SSH_AUTH_SOCK at the relay - Liveness checks use timeout 2 ssh-add -l (exit 0/1 = live). - OpenSpec change add-ssh-agent-relay, user docs, template tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Issue
coder ssh -Aforward the user's agent, for example 1Password, but DDEV's containers can't use it. The forwarded socket also changes on every reconnect, and the old ones stop working.gitcan use the Coder key, throughGIT_SSH_COMMAND. Plainsshand DDEV's containers have no key at all.DDEV v1.25.5 adds
ssh_agent_upstream(ddev/ddev#8861) and resolves symlinked agent sockets (ddev/ddev#8963). v1.25.5 also fixes PHP2Shell, so the #222 workaround can go.How This PR Solves The Issue
v0.6(already pushed): DDEV v1.25.5, plussocat,fzfandzstd. It also ships/home/coder-files/ssh-agent-relay/connectandbashrc.sh.shared/ssh-agent-setup.sh: copied into each template bymake sync-ssh-agent-setup. It runs in every template's startup script after Docker is up:It loads the Coder key into
ssh-agentat~/.coder-ssh-agent/agent.sock. The key is piped from the API intossh-add -and never written to disk.It runs a
socatrelay at~/.ssh-agent-relay/agent.sock. On each connection,connectuses the first live agent of:current, the forwarded agent of the most recent interactive shell;/tmp/auth-agent*/listener.sock;This means it follows a VS Code reconnect without a new terminal, and falls back to the Coder key when nothing is forwarded.
It sets
ddev config global --ssh-agent-upstreamto the relay socket. This is nevercurrent, because DDEV resolves symlinks once, when the project starts.It adds one line to
~/.bashrcthat sourcesbashrc.sh. In an interactive shell with a live forwarded agent, that script retargetscurrent, then points the shell'sSSH_AUTH_SOCKat the relay.timeout 2 ssh-add -lexits 0 or 1. A dead relay never replaces a working socket, and a hung forwarded agent can't stall a shell.ddev-ssh-agent.add-ssh-agent-relay;ssh_agent_relayrun in each template's tests;docs/user/using-workspaces.md.Known limitation, documented: the last session to forward an agent wins for the whole workspace. With workspace sharing, a collaborator's
coder ssh -Aswitches the containers to their keys until the owner opens a new terminal.Manual Testing Instructions
These need the v0.6 image, on staging. Use a fresh workspace from each template:
SSH_AUTH_SOCK=~/.coder-ssh-agent/agent.sock ssh-add -l. It should list the Coder key.ddev auth sshandddev exec ssh -T git@github.com. They should list and use the Coder key, and plainssh -T git@github.comshould work too.coder ssh -A <ws>from a machine with your own agent, then repeat step 2. The containers should get your keys.ddev exec ssh-add -lagain. It should still work.ddev exec ssh-add -lshould fall back to the Coder key.ddev exec php -vshould show a fixed PHP.Automated Testing Overview
terraform fmt,make validateandmake test-templatespass, andopenspec validate add-ssh-agent-relay --strictpasses.connect/bashrc.shfallback order was tested in a plainubuntu:24.04container with fake agents in six scenarios: Coder key only, a forwarded agent, a shell retargetingcurrent, the forwarded agent gone, all forwarded agents gone, and a shell started with a deadSSH_AUTH_SOCK.ddev-ssh-agentin the nested Docker under Sysbox can connect to themode=600relay socket. That's step 2 above.Related Issue Link(s)
🤖 Generated with Claude Code