From 64921db66ff00aefc64ef940bfceec520f15c040 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 28 Mar 2013 16:54:39 -0700 Subject: [PATCH] Error message if private key not owned by right user [GH-1503] --- CHANGELOG.md | 2 ++ lib/vagrant/errors.rb | 4 ++++ lib/vagrant/util/ssh.rb | 7 ++++++- templates/locales/en.yml | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4cb4cd1c..910006c7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ BUG FIXES: - Proper error message if invalid provisioner is used. [GH-1515] - Don't error on graceful halt if machine just shut down very quickly. [GH-1505] + - Error message if private key for SSH isn't owned by the proper + user. [GH-1503] ## 1.1.4 (March 25, 2013) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 361a6d80d..58cf99887 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -371,6 +371,10 @@ module Vagrant error_key(:ssh_host_down) end + class SSHKeyBadOwner < VagrantError + error_key(:ssh_key_bad_owner) + end + class SSHKeyBadPermissions < VagrantError error_key(:ssh_key_bad_permissions) end diff --git a/lib/vagrant/util/ssh.rb b/lib/vagrant/util/ssh.rb index 912ef4645..a5bcaafe2 100644 --- a/lib/vagrant/util/ssh.rb +++ b/lib/vagrant/util/ssh.rb @@ -27,7 +27,12 @@ module Vagrant LOGGER.debug("Checking key permissions: #{key_path}") stat = key_path.stat - if stat.owned? && FileMode.from_octal(stat.mode) != "600" + if !stat.owned? + # The SSH key must be owned by ourselves + raise Errors::SSHKeyBadOwner, :key_path => key_path + end + + if FileMode.from_octal(stat.mode) != "600" LOGGER.info("Attempting to correct key permissions to 0600") key_path.chmod(0600) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 6d233a9e6..79598496b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -299,6 +299,13 @@ en: While attempting to connect with SSH, a "host is down" (EHOSTDOWN) error was received. Please verify your SSH settings are correct and try again. + ssh_key_bad_owner: |- + The private key to connect to the machine via SSH must be owned + by the user running Vagrant. This is a strict requirement from + SSH itself. Please fix the following key to be owned by the user + running Vagrant: + + %{key_path} ssh_key_bad_permissions: |- The private key to connect to this box via SSH has invalid permissions set on it. The permissions of the private key should be set to 0600, otherwise SSH will