train-core 3.7.4 → 3.8.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ccf18cbe443b73ae4ddf1d26acd7bd86730482130481d2d1ab4110311829cba
4
- data.tar.gz: 4e377e9a24cfe32eefa8b4a09a5c54a65f1acf8d1d120eb76e4170e45238dc3f
3
+ metadata.gz: 0e3153fa7d5928d42936093a793c001b1c0988a10c320edba2b887f63a1ec4ab
4
+ data.tar.gz: 3da18aa2c5e772b2881a670c23074c1775d1d560a87576fdd15d885e4e954c79
5
5
  SHA512:
6
- metadata.gz: 23bec0bbce7a152996c8c881211fc46908637720f768c3e1254b44409b7da2091984806165d6545e08354b2291d7652f9c1db0b9f930e6a6998a0e5506553d48
7
- data.tar.gz: 0eb390214488b1b6ae193235b4c9addc1c3750349b8e5ec59c8314dc5a746ab9533d47b8774bb872baabd339768dd1f0e8b6c7c84edb1fbb7a95b2cadf2a71ba
6
+ metadata.gz: c64082d00fb778a8326543df95888d03c98a4223a54dfc2073087c7dcef695ca9ca9d8e2c40f5980a9d726431b431283e5a205ba2cdbe1ec2c9a38ce8966be0b
7
+ data.tar.gz: b10c8793c74e7ae271eaae49e94a7222c1b347ad808d3a16b68f23564c03a6fec5baea0bf8209a99330f3dfcfc76a61a5ef1b1b5df8ff403d995c1fda37f7536
@@ -81,6 +81,9 @@ module Train::Extras
81
81
  when /sudo: sorry, you must have a tty to run sudo/
82
82
  ["Sudo requires a TTY. Please see the README on how to configure "\
83
83
  "sudo to allow for non-interactive usage.", :sudo_no_tty]
84
+ when /sudo: a terminal is required to read the password; either use/
85
+ ["Sudo cannot prompt for password because there is no terminal. "\
86
+ "Please provide the sudo password directly", :sudo_missing_terminal]
84
87
  else
85
88
  [rawerr, nil]
86
89
  end
@@ -42,12 +42,12 @@ module Train::Transports
42
42
  include_options Train::Extras::CommandWrapper
43
43
 
44
44
  # common target configuration
45
- option :host, required: true
46
- option :port, default: 22, coerce: proc { |u| read_options_from_ssh_config(u, :port) }, required: true
47
- option :user, default: "root", coerce: proc { |u| read_options_from_ssh_config(u, :user) }, required: true
45
+ option :host, required: true
46
+ option :ssh_config_file, default: true
47
+ option :port, default: 22, coerce: proc { |v| read_options_from_ssh_config(v, :port) }, required: true
48
+ option :user, default: "root", coerce: proc { |v| read_options_from_ssh_config(v, :user) }, required: true
48
49
  option :key_files, default: nil
49
50
  option :password, default: nil
50
-
51
51
  # additional ssh options
52
52
  option :keepalive, default: true
53
53
  option :keepalive_interval, default: 60
@@ -75,6 +75,7 @@ module Train::Transports
75
75
 
76
76
  # (see Base#connection)
77
77
  def connection(state = {}, &block)
78
+ apply_ssh_config_file(options[:host])
78
79
  opts = merge_options(options, state || {})
79
80
  validate_options(opts)
80
81
  conn_opts = connection_options(opts)
@@ -90,12 +91,36 @@ module Train::Transports
90
91
  # Params options [Hash], option_type [String]
91
92
  # Return String
92
93
  def self.read_options_from_ssh_config(options, option_type)
93
- config_options = Net::SSH.configuration_for(options[:host], true)
94
+ files = options[:ssh_config_file].nil? || options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
95
+ config_options = Net::SSH::Config.for(options[:host], files)
94
96
  config_options[option_type]
95
97
  end
96
98
 
99
+ def apply_ssh_config_file(host)
100
+ files = options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
101
+ host_cfg = ssh_config_file_for_host(host, files)
102
+ host_cfg.each do |key, value|
103
+ # setting the key_files option to the private keys set in ssh config file
104
+ if key == :keys && options[:key_files].nil? && !host_cfg[:keys].nil? && options[:password].nil?
105
+ options[:key_files] = host_cfg[key]
106
+ elsif options[key].nil?
107
+ # Precedence is given to the option set by the user manually.
108
+ # And only assigning value to the option from the ssh config file when it is not set by the user
109
+ # in the option. When the option has a default value for e.g. option "keepalive_interval" has the "60" as the default
110
+ # value, then the default value will be used even though the value for "user" is present in the ssh
111
+ # config file. That is because the precedence is to the options set manually, and currently we don't have
112
+ # any way to differentiate between the value set by the user or is it the default. This has a future of improvement.
113
+ options[key] = host_cfg[key]
114
+ end
115
+ end
116
+ end
117
+
97
118
  private
98
119
 
120
+ def ssh_config_file_for_host(host, files)
121
+ Net::SSH::Config.for(host, files)
122
+ end
123
+
99
124
  def reusable_connection?(conn_opts)
100
125
  return false unless @connection_options
101
126
 
@@ -109,14 +134,18 @@ module Train::Transports
109
134
  key_files = Array(options[:key_files])
110
135
  options[:auth_methods] ||= ["none"]
111
136
 
112
- unless key_files.empty?
113
- options[:auth_methods].push("publickey")
137
+ # by default auth_methods has a default values [none publickey password keyboard-interactive]
138
+ # REF: https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/authentication/session.rb#L48
139
+ if key_files.empty?
140
+ options[:auth_methods].delete("publickey")
141
+ else
114
142
  options[:keys_only] = true if options[:password].nil?
115
143
  options[:key_files] = key_files
116
144
  end
117
145
 
118
- unless options[:password].nil?
119
- options[:auth_methods].push("password", "keyboard-interactive")
146
+ if options[:password].nil?
147
+ options[:auth_methods].delete("password")
148
+ options[:auth_methods].delete("keyboard-interactive")
120
149
  end
121
150
 
122
151
  if options[:auth_methods] == ["none"]
@@ -131,6 +160,8 @@ module Train::Transports
131
160
  end
132
161
  end
133
162
 
163
+ options[:auth_methods] = options[:auth_methods].uniq
164
+
134
165
  if options[:pty]
135
166
  logger.warn("[SSH] PTY requested: stderr will be merged into stdout")
136
167
  end
@@ -186,6 +217,7 @@ module Train::Transports
186
217
  bastion_port: opts[:bastion_port],
187
218
  non_interactive: opts[:non_interactive],
188
219
  append_all_supported_algorithms: opts[:append_all_supported_algorithms],
220
+ config: options[:ssh_config_file],
189
221
  transport_options: opts,
190
222
  }
191
223
  # disable host key verification. The hash key and value to use
data/lib/train/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
3
3
 
4
4
  module Train
5
- VERSION = "3.7.4".freeze
5
+ VERSION = "3.8.7".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.4
4
+ version: 3.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable