Check key permissions on SSH execute (must be 0600)

This commit is contained in:
Mitchell Hashimoto 2010-05-20 01:01:17 -07:00
parent af07bd0d3b
commit e6f628b98b
2 changed files with 12 additions and 0 deletions

View File

@ -42,6 +42,9 @@ module Vagrant
# Opens an SSH connection to this environment's virtual machine and yields # Opens an SSH connection to this environment's virtual machine and yields
# a Net::SSH object which can be used to execute remote commands. # a Net::SSH object which can be used to execute remote commands.
def execute(opts={}) def execute(opts={})
# Check the key permissions to avoid SSH hangs
check_key_permissions(env.config.ssh.private_key_path)
Net::SSH.start(env.config.ssh.host, Net::SSH.start(env.config.ssh.host,
env.config[:ssh][:username], env.config[:ssh][:username],
opts.merge( :port => port, opts.merge( :port => port,

View File

@ -85,6 +85,14 @@ class SshTest < Test::Unit::TestCase
context "executing ssh commands" do context "executing ssh commands" do
setup do setup do
mock_ssh mock_ssh
@ssh.stubs(:check_key_permissions)
end
should "check key permissions then attempt to start connection" do
seq = sequence("seq")
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(seq)
Net::SSH.expects(:start).once.in_sequence(seq)
@ssh.execute
end end
should "call net::ssh.start with the proper names" do should "call net::ssh.start with the proper names" do
@ -123,6 +131,7 @@ class SshTest < Test::Unit::TestCase
context "checking if host is up" do context "checking if host is up" do
setup do setup do
mock_ssh mock_ssh
@ssh.stubs(:check_key_permissions)
end end
should "return true if SSH connection works" do should "return true if SSH connection works" do