Error message if private key not owned by right user [GH-1503]

This commit is contained in:
Mitchell Hashimoto 2013-03-28 16:54:39 -07:00
parent 665450614a
commit 64921db66f
4 changed files with 19 additions and 1 deletions

View File

@ -9,6 +9,8 @@ BUG FIXES:
- Proper error message if invalid provisioner is used. [GH-1515] - Proper error message if invalid provisioner is used. [GH-1515]
- Don't error on graceful halt if machine just shut down very - Don't error on graceful halt if machine just shut down very
quickly. [GH-1505] 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) ## 1.1.4 (March 25, 2013)

View File

@ -371,6 +371,10 @@ module Vagrant
error_key(:ssh_host_down) error_key(:ssh_host_down)
end end
class SSHKeyBadOwner < VagrantError
error_key(:ssh_key_bad_owner)
end
class SSHKeyBadPermissions < VagrantError class SSHKeyBadPermissions < VagrantError
error_key(:ssh_key_bad_permissions) error_key(:ssh_key_bad_permissions)
end end

View File

@ -27,7 +27,12 @@ module Vagrant
LOGGER.debug("Checking key permissions: #{key_path}") LOGGER.debug("Checking key permissions: #{key_path}")
stat = key_path.stat 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") LOGGER.info("Attempting to correct key permissions to 0600")
key_path.chmod(0600) key_path.chmod(0600)

View File

@ -299,6 +299,13 @@ en:
While attempting to connect with SSH, a "host is down" (EHOSTDOWN) While attempting to connect with SSH, a "host is down" (EHOSTDOWN)
error was received. Please verify your SSH settings are correct error was received. Please verify your SSH settings are correct
and try again. 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: |- ssh_key_bad_permissions: |-
The private key to connect to this box via SSH has invalid 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 set on it. The permissions of the private key should be set to 0600, otherwise SSH will