diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0d307be..3b92d0fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ BUG FIXES: - core: On a graceful halt, force halt if capability "insert public key" is missing. [GH-4684] - core: Don't share `/vagrant` if any "." folder is shared. [GH-4675] + - core: Fix SSH private key permissions more aggressively. [GH-4670] - commands/box: `--cert` flag works properly. [GH-4691] - command/docker-logs: Won't crash if container is removed. [GH-3990] - command/docker-run: Synced folders will be attached properly. [GH-3873] diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index d23f759a2..62646fc90 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -72,7 +72,7 @@ module Vagrant # @return [Vagrantfile] attr_reader :vagrantfile - # The SSH information for accessing this machine. + # The SSH information for accessing this machine. # This attribute is set only when the machine is ready for SSH communication. # # @return [Hash] @@ -391,9 +391,6 @@ module Vagrant # # @return [Hash] SSH information. def ssh_info - - return @ssh_info unless @ssh_info.nil? - # First, ask the provider for their information. If the provider # returns nil, then the machine is simply not ready for SSH, and # we return nil as well. @@ -461,8 +458,7 @@ module Vagrant end end - # Memoize the final compiled SSH info data and return it - @ssh_info = info + info end # Returns the state of this machine. The state is queried from the diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index bc912a6d7..38321e306 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -581,22 +581,11 @@ describe Vagrant::Machine do it "should not check the permissions of a private key file that does not exist" do provider_ssh_info[:private_key_path] = "/foo" - + expect(ssh_klass).to_not receive(:check_key_permissions) instance.ssh_info end - # It is not possible to test the memoization of a Ruby Hash with object equality, - # but we can verify that some code of ssh_info method is not executed again. - it "should check and try to fix the permissions of the private key file only once" do - provider_ssh_info[:private_key_path] = nil - instance.config.ssh.private_key_path = nil - - expect(ssh_klass).to receive(:check_key_permissions).once.with(Pathname.new(instance.env.default_private_key_path.to_s)) - instance.ssh_info - instance.ssh_info - end - context "expanding path relative to the root path" do it "should with the provider key path" do provider_ssh_info[:private_key_path] = "~/foo"