Open
Description
It would be nice to be able to forward an ssh key agent into a container during a run
or build
.
Frequently we need to build source code which exists in a private repository where access is controlled by ssh key.
Adding the key file into the container is a bad idea as:
- You've just lost control of your ssh key
- Your key might need to be unlocked via passphrase
- Your key might not be in a file at all, and only accessible through the key agent.
You could do something like:
# docker run -t -i -v "$SSH_AUTH_SOCK:/tmp/ssh_auth_sock" -e "SSH_AUTH_SOCK=/tmp/ssh_auth_sock" fedora ssh-add -l
2048 82:58:b6:82:c8:89:da:45:ea:9a:1a:13:9c:c3:f9:52 phemmer@whistler (RSA)
But:
- This only works for
docker run
, notbuild
. - This only works if the docker daemon is running on the same host as the client.
The ideal solution is to have the client forward the key agent socket just like ssh
can.
However the difficulty in this is that it would require the remote API build and attach calls to support proxying an arbitrary number of socket streams. Just doing a single 2-way stream wouldn't be sufficient as the ssh key agent is a unix domain socket, and it can have multiple simultaneous connections.