I ran into a situation today where I needed to support agent forwarding with sudo. Specifically, I wanted to check out a git repository using agent forwarding, sudo’ing to a (non-root) user.
My plan for the sudo support is to use the “env” program to inject the SSH_AUTH_SOCK environment variable into the sudo’d process, so that editing /etc/sudoers isn’t necessary.
For sudo’ing to non-root users, I’m going to use access control lists to grant the sudo_user access to the auth socket, like this:
Just thinking out loud here, not all filesystems we log in to may support ACLs, it will need to plan accordingly if so configured, or at least raise errors.
Good point. I will probably make the ACL-based approach opt-in by an additional configuration option. Without ACLs, it probably will only support agent-forwarding when sudo’ing to root.
the patch works but the solution need some hacks that cannot be accepted by everyone ; so Michael preferred to not accept it knowing that paramiko support is doomed on the long term. I agree with his decision even though I had to change my deploy approach.
you have in fact 3 patches in the link above :
1 - support agent forwarding for paramiko (so the ansible_ssh_user can use the keys)
2- export the SSH_AUTH_SOCK when sudo’ing without requiring a modification of sudoers (sudo_user = root can use the keys)
3- change the ACLs on SSH_AUTH_SOCK (sudo_user != root can use the keys)
(1) is not necessary if your control machine does not need paramiko
(2) is not necessary if you accept to modify sudoers
(3) is the only way I found to give access to the keys to sudo_user != root
other ways around that people have mentioned for (3) :
a) do (1) and authorize the control machine to ssh directly login = user
b) create temporary read-only keys on the git repo that you dispatch to the users
c) do (1), git with ansible_ssh_user and then move the files to another user
d) pre-package all apps on the control machine and do not invoke github on the remotes
I would be interested in hearing how github dependent people are handling their deployments.
I would be interested in hearing how github dependent people are handling
their deployments.
I'd like to see the git module enhanced to take an optional
username/password, or a deploy key, and also be smart enough to add
github.com to known hosts if a special flag is added, I think that would
reduce most confusion with git, especially SSH.
We've got a feature idea ticket open, but are probably chasing a few other
things first.
If someone wants to upgrade it, I will build a statue of you in our formal
gardens in your choice of rock or affordable metals (sorry Platinum is
probably not a good option) (once we have a formal gardens, of course).