From 40a22ff99a2fd46b3a2a6e7f574b9bf75210c974 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Sun, 7 Dec 2014 11:02:50 +0100 Subject: [PATCH 1/2] providers/docker: fix support of agent forwarding --- .../providers/docker/action/prepare_ssh.rb | 7 ++++++- plugins/providers/docker/communicator.rb | 21 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/providers/docker/action/prepare_ssh.rb b/plugins/providers/docker/action/prepare_ssh.rb index 1a7298a66..450b139c6 100644 --- a/plugins/providers/docker/action/prepare_ssh.rb +++ b/plugins/providers/docker/action/prepare_ssh.rb @@ -19,14 +19,19 @@ module VagrantPlugins # Modify the SSH options for when we `vagrant ssh`... ssh_opts = env[:ssh_opts] || {} - # Build the command we'll execute within the host machine + # Build the command we'll execute within the Docker host machine: ssh_command = env[:machine].communicate.container_ssh_command if !Array(ssh_opts[:extra_args]).empty? ssh_command << " #{Array(ssh_opts[:extra_args]).join(" ")}" end + # Modify the SSH options for the original command: # Append "-t" to force a TTY allocation ssh_opts[:extra_args] = ["-t"] + # Enable Agent forwarding when requested for the target VM + if env[:machine].ssh_info[:forward_agent] + ssh_opts[:extra_args] << "-o ForwardAgent=yes" + end ssh_opts[:extra_args] << ssh_command # Set the opts diff --git a/plugins/providers/docker/communicator.rb b/plugins/providers/docker/communicator.rb index 657789575..fb6c9fe9e 100644 --- a/plugins/providers/docker/communicator.rb +++ b/plugins/providers/docker/communicator.rb @@ -137,18 +137,21 @@ module VagrantPlugins info[:port] ||= 22 # Make sure our private keys are synced over to the host VM - key_args = sync_private_keys(info).map do |path| + ssh_args = sync_private_keys(info).map do |path| "-i #{path}" - end.join(" ") + end + + # Use ad-hoc SSH options for the hop on the docker proxy + if info[:forward_agent] + ssh_args << "-o ForwardAgent=yes" + end + ssh_args.concat(["-o Compression=yes", + "-o ConnectTimeout=5", + "-o StrictHostKeyChecking=no", + "-o UserKnownHostsFile=/dev/null"]) # Build the SSH command - "ssh #{key_args} " + - "-o Compression=yes " + - "-o ConnectTimeout=5 " + - "-o StrictHostKeyChecking=no " + - "-o UserKnownHostsFile=/dev/null " + - "-p#{info[:port]} " + - "#{info[:username]}@#{info[:host]}" + "ssh #{info[:username]}@#{info[:host]} -p#{info[:port]} #{ssh_args.join(" ")}" end protected From 0a64b0c4e18ca9ee0db5def530a09e97ad1feaa0 Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Sun, 7 Dec 2014 11:14:21 +0100 Subject: [PATCH 2/2] Update CHANGELOG: fix docker agent forwarding Ref GH-4905 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53565b085..002ad9a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ BUG FIXES: - providers/docker: Fix issue where multiple identical proxy VMs would be created. [GH-3963] - providers/docker: Multiple links with the same name work. [GH-4571] + - providers/docker: Add support of SSH agent forwarding. [GH-4905] - providers/virtualbox: Show a human-friendly error if VirtualBox didn't clean up an existing VM. [GH-4681] - providers/virtualbox: Detect case when VirtualBox reports 0.0.0.0 as