train-core 3.7.2 → 3.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/train/extras/command_wrapper.rb +3 -0
- data/lib/train/file/remote/windows.rb +1 -1
- data/lib/train/transports/local.rb +21 -8
- data/lib/train/transports/ssh.rb +41 -9
- data/lib/train/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 677b8d64465040ada12f33f5c2fe7689b81922b10482ca7c78e0b57e10b5139a
|
4
|
+
data.tar.gz: 8c3f7518f0453329897de457e4ea4e6f24d6262dd77f5731b42b5cd44ea706c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8998652d978144993b1768c71d25d8b06f6501c661e827576ecbb06d3e2d8748296d26d68578d6c451a2a20617c1750a5cb66c096adb020b5bc3c0e2ad6bfb4e
|
7
|
+
data.tar.gz: 68cad9574d5282fea0d90fc00104506d0d33ecfd5e5d6879f33f88109aec9b881d0c9d49748e178c4b8ca05896827425d4bb283bb7d52aedbcc722d2817b6b27
|
@@ -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
|
@@ -190,8 +190,23 @@ module Train::Transports
|
|
190
190
|
script = "$ProgressPreference='SilentlyContinue';" + cmd
|
191
191
|
encoded_script = Base64.strict_encode64(script)
|
192
192
|
# TODO: no way to safely implement timeouts here.
|
193
|
-
|
194
|
-
|
193
|
+
begin
|
194
|
+
@pipe.puts(encoded_script)
|
195
|
+
@pipe.flush
|
196
|
+
rescue Errno::EPIPE
|
197
|
+
# Retry once if the pipe went away
|
198
|
+
begin
|
199
|
+
# Maybe the pipe went away, but the server didn't? Reset it, to get a clean start.
|
200
|
+
close
|
201
|
+
rescue Errno::EIO
|
202
|
+
# Ignore - server already went away
|
203
|
+
end
|
204
|
+
@pipe = acquire_pipe
|
205
|
+
raise PipeError if @pipe.nil?
|
206
|
+
|
207
|
+
@pipe.puts(encoded_script)
|
208
|
+
@pipe.flush
|
209
|
+
end
|
195
210
|
res = OpenStruct.new(JSON.parse(Base64.decode64(@pipe.readline)))
|
196
211
|
Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
|
197
212
|
end
|
@@ -216,12 +231,10 @@ module Train::Transports
|
|
216
231
|
|
217
232
|
# PowerShell needs time to create pipe.
|
218
233
|
100.times do
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
sleep 0.1
|
224
|
-
end
|
234
|
+
pipe = open("//./pipe/#{pipe_name}", "r+")
|
235
|
+
break
|
236
|
+
rescue
|
237
|
+
sleep 0.1
|
225
238
|
end
|
226
239
|
|
227
240
|
pipe
|
data/lib/train/transports/ssh.rb
CHANGED
@@ -42,12 +42,12 @@ module Train::Transports
|
|
42
42
|
include_options Train::Extras::CommandWrapper
|
43
43
|
|
44
44
|
# common target configuration
|
45
|
-
option :host,
|
46
|
-
option :
|
47
|
-
option :
|
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
|
-
|
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
|
-
|
113
|
-
|
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
|
-
|
119
|
-
options[:auth_methods].
|
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
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.
|
4
|
+
version: 3.8.6
|
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-
|
11
|
+
date: 2021-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|