Discover and set SSH_AUTH_SOCK on sudo with forward agent [GH-1307]
This commit is contained in:
parent
92a61f96a0
commit
aeb0132dcb
|
@ -52,6 +52,9 @@ BUG FIXES:
|
|||
- Retry SSH on ENETUNREACH error. [GH-1732]
|
||||
- NFS is silently ignored on Windows. [GH-1748]
|
||||
- Validation so that private network static IP does not end in ".1" [GH-1750]
|
||||
- With forward agent enabled and sudo being used, Vagrant will automatically
|
||||
discover and set `SSH_AUTH_SOCK` remotely so that forward agent
|
||||
works properly despite misconfigured sudoers. [GH-1307]
|
||||
|
||||
## 1.2.4 (July 16, 2013)
|
||||
|
||||
|
|
|
@ -306,6 +306,31 @@ module VagrantPlugins
|
|||
# Set the terminal
|
||||
ch2.send_data "export TERM=vt100\n"
|
||||
|
||||
# Set SSH_AUTH_SOCK if we are in sudo and forwarding agent.
|
||||
# This is to work around often misconfigured boxes where
|
||||
# the SSH_AUTH_SOCK env var is not preserved.
|
||||
if @machine.ssh_info[:forward_agent] && sudo
|
||||
auth_socket = ""
|
||||
execute("echo; printf $SSH_AUTH_SOCK") do |type, data|
|
||||
if type == :stdout
|
||||
auth_socket += data
|
||||
end
|
||||
end
|
||||
|
||||
if auth_socket != ""
|
||||
# Make sure we only read the last line which should be
|
||||
# the $SSH_AUTH_SOCK env var we printed.
|
||||
auth_socket = auth_socket.split("\n").last.chomp
|
||||
end
|
||||
|
||||
if auth_socket == ""
|
||||
@logger.warn("No SSH_AUTH_SOCK found despite forward_agent being set.")
|
||||
else
|
||||
@logger.info("Setting SSH_AUTH_SOCK remotely: #{auth_socket}")
|
||||
ch2.send_data "export SSH_AUTH_SOCK=#{auth_socket}\n"
|
||||
end
|
||||
end
|
||||
|
||||
# Output the command
|
||||
ch2.send_data "#{command}\n"
|
||||
|
||||
|
|
Loading…
Reference in New Issue