-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow forwarding SSH agent in fig #551
Comments
This example is using a volume to share the socket, and setting the environment variable to tell ssh to use that socket. That seems like a good solution, and you can do that from fig.yml using |
Having some difficulties with this approach. Given: web:
build: .
command: sh -c "bundle install --local && bundle exec rackup -p 3000"
volumes:
- .:/app
- $(dirname $SSH_AUTH_SOCK):/ssh-agent
environment:
- SSH_AUTH_SOCK=/ssh-agent/Listeners
ports:
- "3000:3000" I get as output:
So, host env variables are parsed when using |
Related: moby/moby#6396 and moby/moby#6697. Would be open to hearing other thoughts or if it would be OK to allow shell code in the yaml. |
@clifton I too am having the same issue and I guessing like me you are using a vm in OSX? The problem as I see it is that currently boot2docker will automatically mount the /Users directory but the /tmp directory where the SSH socket is on a mac will not be. This means that instead of mounting the path on the host machine the path on the vm is mounted which is wrong. Could the /tmp directory be automated too or is that not a good idea? |
Yep, I'm using boot2docker from OSX. I'm still lost as to how I can could get non-trival environments up and running without resorting to hacks. |
I imagine one day docker will have a way of building using secrets. Until then, I wrote a docker build replacement called docket which lets you build with private files from your host machine. If you can hack fig to run docket instead of the regular docker build, it should let you build with your private ssh keys. |
@pwaller Actually, with |
Thanks for the tip @aanand ! I don't see that documented anywhere over here, is it a secret/new feature? :) |
No, just a hole in the documentation I'm afraid. |
So someone clarify for this dummy the undocumented feature? What should I put in my volumes to make this work? |
@cddr: try volumes:
- $SSH_AUTH_SOCK:$SSH_AUTH_SOCK
environment:
- SSH_AUTH_SOCK Good luck! |
I had no luck with this. Did you manage to get this working ?
Env variables are not replaced |
@djhi, in our Vagrantfile we have config.trigger.after [:up, :reload] do
command = %Q(vagrant ssh -- -t 'ln -sf `ls -d /tmp/ssh*/* | head -n 1` /tmp/authsock; sh')
pid = Process.spawn(command, out: '/dev/null', err: '/dev/null')
Process.detach(pid)
end web:
volumes:
- /tmp:/tmp
environment:
SSH_AUTH_SOCK: /tmp/authsock |
@clifton nice one! This is what I needed but apparently ssh cannot follow authsock:
do you have any idea to fix that ? EDIT: Never mind, I just remplaced ln -s by mv and it works. Thanks again! |
Yep, no problem! @hadronzoo came up with the solution, so credit to him |
Thx clifton, we don't use vagrant and ended up mouting the user
The container user is |
Passing env variables on both sides of the volume option doesn't work yet, but (thanks to @dnephin for pointing this out in #1626) this should work:
You mount the randomly named SSH_AUTH_SOCK file as a fixed name file in the container, and then instead of passing the env variable, you set it explicitly. |
@jeffk This always worked for me on Linux, without any VM since I run docker on an available linux kernel. |
Where can I find the trick from @hadronzoo ? Some of my colleagues are on Mac |
@djhi Get rid of boot2docker and use Vagrant. Then in your Vagrantfile write that:
You need to install the triggers vagrant plugin. Then in your docker-compose you can share the socket by creating a volume on /tmp:/tmp and set SSH_AUTH_SOCK to /tmp/authsock EDIT: don't forget to set ssh-forwarding option to true in your Vagrantfile |
Ok, thx @catuss-a ! |
There's an issue here when someone doesn't want to run their container as root. If I forward either an SSH directory or the agent and I'm running the container as a UID to match my filesystem, I can't use SSH due to the fact that it insists on the user being in You end up getting this: I'm basically stuck again having to run an entrypoint script to hand off a username that I then have to ensure exists inside the container to satisfy ssh. Not optimal. |
I think you might want to use EDIT: On the host run |
What's the best practice on cloning private repos (e.g. gems or npm modules)? Currently, I'd need to add my private ssh keys into the repo via
volumes
in fig.yml. Is there a better way?I'd think the optimal way of handling this would be to forward the ssh agent. Perhaps have an option in the fig.yml for doing that?
Example: https://gist.github.com/d11wtq/8699521
The text was updated successfully, but these errors were encountered: