From e10e8aae86ea106e1346e5416de33dab229a1149 Mon Sep 17 00:00:00 2001 From: Sean Wolfe Date: Tue, 1 May 2012 13:26:12 -0700 Subject: [PATCH 1/2] After changing the file permissions, we need to reload the stat before comparing again. Otherwise we will always throw an exception even if we set the permissions successfully. --- lib/vagrant/ssh.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 03dfefe4f..e806433cc 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -113,6 +113,7 @@ module Vagrant @logger.info("Attempting to correct key permissions to 0600") File.chmod(0600, key_path) + stat = File.stat(key_path) if Util::FileMode.from_octal(stat.mode) != "600" raise Errors::SSHKeyBadPermissions, :key_path => key_path end From 024f492cb3aa8362c75b5be2c909cdfcd7ca79fc Mon Sep 17 00:00:00 2001 From: Sean Wolfe Date: Tue, 1 May 2012 14:05:22 -0700 Subject: [PATCH 2/2] Added spec to test the ssh key file permission changing. --- test/unit/vagrant/ssh_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/unit/vagrant/ssh_test.rb diff --git a/test/unit/vagrant/ssh_test.rb b/test/unit/vagrant/ssh_test.rb new file mode 100644 index 000000000..c98af011d --- /dev/null +++ b/test/unit/vagrant/ssh_test.rb @@ -0,0 +1,25 @@ +require File.expand_path("../../base", __FILE__) + +describe Vagrant::SSH do + context "check_key_permissions" do + let(:key_path) { File.expand_path("../id_rsa", __FILE__) } + let(:ssh_instance) { Vagrant::SSH.new(double) } + + before(:each) do + File.open(key_path, 'w') do |file| + file.write("hello!") + end + File.chmod(644, key_path) + end + + after(:each) do + FileUtils.rm(key_path) + end + + it "should not raise an exception if we set a keyfile permission correctly" do + ssh_instance.check_key_permissions(key_path) + end + + end +end +