From 58a043e2aa375caa9550c11f1ccd18b684b1aa07 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 Apr 2014 16:31:19 -0700 Subject: [PATCH] providers/docker: upload the keys we need for SSH --- plugins/providers/docker/communicator.rb | 36 +++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/providers/docker/communicator.rb b/plugins/providers/docker/communicator.rb index 0e5cd936d..1e61748c6 100644 --- a/plugins/providers/docker/communicator.rb +++ b/plugins/providers/docker/communicator.rb @@ -1,3 +1,4 @@ +require "digest/md5" require "tempfile" module VagrantPlugins @@ -132,8 +133,13 @@ module VagrantPlugins info = @machine.ssh_info info[:port] ||= 22 + # Make sure our private keys are synced over to the host VM + key_args = sync_private_keys(info).map do |path| + "-i #{path}" + end.join(" ") + # Build the SSH command - "ssh -i /home/vagrant/insecure " + + "ssh #{key_args} " + "-o Compression=yes " + "-o ConnectTimeout=5 " + "-o StrictHostKeyChecking=no " + @@ -141,6 +147,34 @@ module VagrantPlugins "-p#{info[:port]} " + "#{info[:username]}@#{info[:host]}" end + + protected + + def sync_private_keys(info) + @keys ||= {} + + id = Digest::MD5.hexdigest( + @machine.env.root_path.to_s + @machine.name.to_s) + + result = [] + info[:private_key_path].each do |path| + if !@keys[path.to_s] + # We haven't seen this before, upload it! + guest_path = "/tmp/key_#{id}_#{Digest::MD5.hexdigest(path.to_s)}" + @host_vm.communicate.upload(path.to_s, guest_path) + + # Make sure it has the proper chmod + @host_vm.communicate.execute("chmod 0600 #{guest_path}") + + # Set it + @keys[path.to_s] = guest_path + end + + result << @keys[path.to_s] + end + + result + end end end end