summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Parra <6844225+erikparra@users.noreply.github.com>2018-02-27 03:17:59 -0600
committerThom May <thom@may.lt>2018-02-27 09:17:59 +0000
commitbd4937ce55896113452034deebcf61a8ac353e28 (patch)
tree587bbaf4a7344b4f9cc65fc69b391cb4ba7660c9
parentbd43de8cb5b58dc7731d2945434aa2edf3d585e4 (diff)
downloadchef-bd4937ce55896113452034deebcf61a8ac353e28.tar.gz
Added Flag to distinguish between gateway and host key to fix issue #6210 (#6514)
* Added Flag to distinguish between gateway and host key to fix issue #6210 Signed-off-by: Erik <Erik.Parra4@gmail.com>
-rw-r--r--lib/chef/knife/ssh.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index e02ea4ae1d..e01977a976 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -148,7 +148,7 @@ class Chef
if config[:ssh_gateway]
gw_host, gw_user = config[:ssh_gateway].split("@").reverse
gw_host, gw_port = gw_host.split(":")
- gw_opts = session_options(gw_host, gw_port, gw_user)
+ gw_opts = session_options(gw_host, gw_port, gw_user, gateway: true)
user = gw_opts.delete(:user)
begin
@@ -251,18 +251,19 @@ class Chef
# @param host [String] Hostname for this session.
# @param port [String] SSH port for this session.
# @param user [String] Optional username for this session.
+ # @param gateway [Boolean] Flag: host or gateway key
# @return [Hash<Symbol, Object>]
- def session_options(host, port, user = nil)
+ def session_options(host, port, user = nil, gateway: false)
ssh_config = Net::SSH.configuration_for(host, true)
{}.tap do |opts|
# Chef::Config[:knife][:ssh_user] is parsed in #configure_user and written to config[:ssh_user]
opts[:user] = user || config[:ssh_user] || ssh_config[:user]
- if config[:ssh_gateway_identity]
- opts[:keys] = File.expand_path(config[:ssh_gateway_identity])
- opts[:keys_only] = true
- elsif config[:ssh_identity_file]
+ if !gateway && config[:ssh_identity_file]
opts[:keys] = File.expand_path(config[:ssh_identity_file])
opts[:keys_only] = true
+ elsif gateway && config[:ssh_gateway_identity]
+ opts[:keys] = File.expand_path(config[:ssh_gateway_identity])
+ opts[:keys_only] = true
elsif config[:ssh_password]
opts[:password] = config[:ssh_password]
end
@@ -288,7 +289,7 @@ class Chef
host, ssh_port, prefix = item
prefix = host unless prefix
Chef::Log.debug("Adding #{host}")
- session_opts = session_options(host, ssh_port)
+ session_opts = session_options(host, ssh_port, gateway: false)
# Handle port overrides for the main connection.
session_opts[:port] = Chef::Config[:knife][:ssh_port] if Chef::Config[:knife][:ssh_port]
session_opts[:port] = config[:ssh_port] if config[:ssh_port]