machinery-tool 1.22.0 → 1.22.1

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
  SHA1:
3
- metadata.gz: 33037a49f9cd5990355d5c07ad549d035542379b
4
- data.tar.gz: ea404796918a26ef4e0571a568bf60045d4dbd0b
3
+ metadata.gz: dacdd7ed294b3fa071ce5c205cff0c9bc4888c33
4
+ data.tar.gz: e5679c290377bd246cbde4d82c3bab5ad64c2ef7
5
5
  SHA512:
6
- metadata.gz: 2c93f3958a8423294a50709550983a336fc65ab4f9588f1a5957a4d6c3ed10eda6d899986941194694525f8de96a28b3e5b7095e7984d3565bcfee6c24df7e6d
7
- data.tar.gz: e7a29850ca4d1891e2bf1719870fe24a9f37312d0dcd3814e69274f2a012c9ed1e3fcbdf1c9356fb220842da15f1a3e5274644e66d1f7e49b9ccbc026bf6bceb
6
+ metadata.gz: b66684bde79b39bb03551a8249a600b1c9c1811df5582ae4d48559c240a4dfc46a975e6bbb8425747216a576599297cb43b2419385cb15be5d36c5dd94569572
7
+ data.tar.gz: aba642cb4e81b629a4cf1aa6a0090c97507b2995ba36097387eaed96a0a7f7f107ce976f3af602655b042f4c557ba4d2425655557ce884614d29df4133d3e86b
@@ -1 +1 @@
1
- 964505b0908b5f767f7fb74053b19884ae2e0954
1
+ c9cc765d7146920c59d05dd9e483a82eb5f836df
data/NEWS CHANGED
@@ -1,6 +1,12 @@
1
1
  # Machinery Release Notes
2
2
 
3
3
 
4
+ ## Version 1.22.1 - Fri Oct 14 16:13:50 CEST 2016 - thardeck@suse.de
5
+
6
+ * Only use sudo for reading files when necessary (gh#SUSE/machinery#2077)
7
+ * Gracefully handle RequireTTY enabled sudo configs (gh#SUSE/machinery#2135)
8
+ * Add rsync requirement check for remote system (gh#SUSE/machinery#2165)
9
+
4
10
  ## Version 1.22.0 - Thu Oct 06 17:03:33 CEST 2016 - thardeck@suse.de
5
11
 
6
12
  * Add remaining systemd service states in Kiwi export (gh#SUSE/machinery#2122)
@@ -54,7 +54,7 @@ class DockerSystem < System
54
54
  end
55
55
 
56
56
  # Reads a file from the System. Returns nil if it does not exist.
57
- def read_file(file)
57
+ def read_file(file, _options = {})
58
58
  run_command("cat", file, stdout: :capture)
59
59
  rescue Cheetah::ExecutionFailed => e
60
60
  if e.status.exitstatus == 1
@@ -118,12 +118,23 @@ module Machinery
118
118
  end
119
119
 
120
120
  def to_s
121
- "sudo isn't configured on the inspected host '#{@host}' for user '#{@remote_user}' to " \
121
+ "'sudo' isn't configured on the inspected host '#{@host}' for user '#{@remote_user}' to " \
122
122
  "give all required commands enough privileges. See 'PREREQUISITES' section in the " \
123
123
  "machinery documentation for a description on how to configure sudo on the inspected host."
124
124
  end
125
125
  end
126
126
 
127
+ class SudoMissingTTY < MachineryError
128
+ def initialize(host)
129
+ @host = host
130
+ end
131
+
132
+ def to_s
133
+ "'sudo' isn't configured on the inspected host '#{@host}'." \
134
+ " Remove the RequireTTY settings from sudoers.conf."
135
+ end
136
+ end
137
+
127
138
  class MigrationError < MachineryError; end
128
139
 
129
140
  class InvalidFilter < MachineryError; end
@@ -138,7 +138,7 @@ You can install it by running `zypper install #{package}`.
138
138
  end
139
139
 
140
140
  # Reads a file from the System. Returns nil if it does not exist.
141
- def read_file(file)
141
+ def read_file(file, _options = {})
142
142
  File.read(file)
143
143
  rescue Errno::ENOENT
144
144
  # File not found, return nil
@@ -41,6 +41,11 @@ class RemoteSystem < System
41
41
  false
42
42
  end
43
43
 
44
+ def connect
45
+ check_connection
46
+ check_sudo if sudo_required?
47
+ end
48
+
44
49
  def run_command(*args)
45
50
  options = args.last.is_a?(Hash) ? args.pop : {}
46
51
 
@@ -83,45 +88,24 @@ class RemoteSystem < System
83
88
  cheetah_class = LoggedCheetah
84
89
  end
85
90
 
86
- sudo = ["sudo", "-n"] if options[:privileged] && remote_user != "root"
91
+ sudo = ["sudo", "-n"] if options[:privileged] && sudo_required?
87
92
  cmds = [
88
93
  *build_command(:ssh), "#{remote_user}@#{host}", "-o", \
89
94
  "LogLevel=ERROR", sudo, "LANGUAGE=", "LC_ALL=#{locale}", *piped_args, options
90
95
  ].compact.flatten
91
96
 
92
97
  cheetah_class.run(*cmds)
93
- rescue Cheetah::ExecutionFailed => e
94
- if e.stderr && e.stderr.include?("password is required")
95
- raise Machinery::Errors::InsufficientPrivileges.new(remote_user, host)
96
- else
97
- raise e
98
- end
99
- end
100
-
101
- # Tries to run the noop-command(:) on the remote system as root (without a password or passphrase)
102
- # and raises an Machinery::Errors::SshConnectionFailed exception when it's not successful.
103
- def connect
104
- LoggedCheetah.run(*build_command(:ssh), "-q", "-o", "BatchMode=yes",
105
- "#{remote_user}@#{host}", ":")
106
- rescue Cheetah::ExecutionFailed
107
- raise Machinery::Errors::SshConnectionFailed.new(
108
- "Could not establish SSH connection to host '#{host}'. Please make sure that " \
109
- "you can connect non-interactively as #{remote_user}, e.g. using ssh-agent.\n\n" \
110
- "To copy your default ssh key to the machine run:\n" \
111
- "ssh-copy-id #{remote_user}@#{host}"
112
- )
113
98
  end
114
99
 
115
-
116
100
  # Retrieves files specified in filelist from the remote system and raises an
117
101
  # Machinery::Errors::RsyncFailed exception when it's not successful. Destination is
118
102
  # the directory where to put the files.
119
103
  def retrieve_files(filelist, destination)
120
104
  source = "#{remote_user}@#{host}:/"
121
- if remote_user != "root"
122
- rsync_path = "sudo -n rsync"
105
+ rsync_path = if sudo_required?
106
+ "sudo -n rsync"
123
107
  else
124
- rsync_path = "rsync"
108
+ "rsync"
125
109
  end
126
110
 
127
111
  cmd = [
@@ -146,12 +130,17 @@ class RemoteSystem < System
146
130
  end
147
131
 
148
132
  def check_retrieve_files_dependencies
149
- LocalSystem.new.check_requirement("rsync", "--version")
133
+ LocalSystem.validate_existence_of_command("rsync", "rsync")
134
+ check_requirement("rsync", "--version")
150
135
  end
151
136
 
152
137
  # Reads a file from the System. Returns nil if it does not exist.
153
- def read_file(file)
154
- run_command("cat", file, stdout: :capture, privileged: true)
138
+ def read_file(file, options = {})
139
+ command_options = {
140
+ stdout: :capture,
141
+ privileged: options.fetch(:privileged, false)
142
+ }
143
+ run_command("cat", file, command_options)
155
144
  rescue Cheetah::ExecutionFailed => e
156
145
  if e.status.exitstatus == 1
157
146
  # File not found, return nil
@@ -191,6 +180,38 @@ class RemoteSystem < System
191
180
 
192
181
  private
193
182
 
183
+ def sudo_required?
184
+ remote_user != "root"
185
+ end
186
+
187
+ # Tries to run the noop-command(:) on the remote system as root (without a password or passphrase)
188
+ # and raises an Machinery::Errors::SshConnectionFailed exception when it's not successful.
189
+ def check_connection
190
+ LoggedCheetah.run(*build_command(:ssh), "-q", "-o", "BatchMode=yes",
191
+ "#{remote_user}@#{host}", ":")
192
+ rescue Cheetah::ExecutionFailed
193
+ raise Machinery::Errors::SshConnectionFailed.new(
194
+ "Could not establish SSH connection to host '#{host}'. Please make sure that " \
195
+ "you can connect non-interactively as #{remote_user}, e.g. using ssh-agent.\n\n" \
196
+ "To copy your default ssh key to the machine run:\n" \
197
+ "ssh-copy-id #{remote_user}@#{host}"
198
+ )
199
+ end
200
+
201
+ def check_sudo
202
+ check_requirement("sudo", "-h")
203
+ LoggedCheetah.run(*build_command(:ssh), "-q", "-o", "BatchMode=yes",
204
+ "#{remote_user}@#{host}", "sudo", "id")
205
+ rescue Cheetah::ExecutionFailed => e
206
+ if e.stderr && e.stderr.include?("password is required")
207
+ raise Machinery::Errors::InsufficientPrivileges.new(remote_user, host)
208
+ elsif e.stderr && e.stderr.include?("you must have a tty to run sudo")
209
+ raise Machinery::Errors::SudoMissingTTY.new(host)
210
+ else
211
+ raise e
212
+ end
213
+ end
214
+
194
215
  def build_command(name)
195
216
  raise Machinery::Errors::MachineryError.new("You must set one of these flags in " \
196
217
  "build_command: :ssh or :scp") unless [:ssh, :scp].include?(name)
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Machinery
19
19
 
20
- VERSION = "1.22.0"
20
+ VERSION = "1.22.1"
21
21
 
22
22
  end
@@ -2,4 +2,4 @@
2
2
 
3
3
  package main
4
4
 
5
- const VERSION = "964505b0908b5f767f7fb74053b19884ae2e0954"
5
+ const VERSION = "c9cc765d7146920c59d05dd9e483a82eb5f836df"
Binary file
@@ -4,7 +4,7 @@
4
4
 
5
5
  <url>
6
6
  <loc>None/docs/</loc>
7
- <lastmod>2016-10-06</lastmod>
7
+ <lastmod>2016-10-14</lastmod>
8
8
  <changefreq>daily</changefreq>
9
9
  </url>
10
10
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  <url>
14
14
  <loc>None/machinery_main_general.1/</loc>
15
- <lastmod>2016-10-06</lastmod>
15
+ <lastmod>2016-10-14</lastmod>
16
16
  <changefreq>daily</changefreq>
17
17
  </url>
18
18
 
@@ -20,7 +20,7 @@
20
20
 
21
21
  <url>
22
22
  <loc>None/machinery_main_scopes.1/</loc>
23
- <lastmod>2016-10-06</lastmod>
23
+ <lastmod>2016-10-14</lastmod>
24
24
  <changefreq>daily</changefreq>
25
25
  </url>
26
26
 
@@ -28,7 +28,7 @@
28
28
 
29
29
  <url>
30
30
  <loc>None/machinery_main_usecases.1/</loc>
31
- <lastmod>2016-10-06</lastmod>
31
+ <lastmod>2016-10-14</lastmod>
32
32
  <changefreq>daily</changefreq>
33
33
  </url>
34
34
 
@@ -36,7 +36,7 @@
36
36
 
37
37
  <url>
38
38
  <loc>None/machinery_main_security_implications.1/</loc>
39
- <lastmod>2016-10-06</lastmod>
39
+ <lastmod>2016-10-14</lastmod>
40
40
  <changefreq>daily</changefreq>
41
41
  </url>
42
42
 
@@ -45,115 +45,115 @@
45
45
 
46
46
  <url>
47
47
  <loc>None/machinery-analyze.1/</loc>
48
- <lastmod>2016-10-06</lastmod>
48
+ <lastmod>2016-10-14</lastmod>
49
49
  <changefreq>daily</changefreq>
50
50
  </url>
51
51
 
52
52
  <url>
53
53
  <loc>None/machinery-build.1/</loc>
54
- <lastmod>2016-10-06</lastmod>
54
+ <lastmod>2016-10-14</lastmod>
55
55
  <changefreq>daily</changefreq>
56
56
  </url>
57
57
 
58
58
  <url>
59
59
  <loc>None/machinery-compare.1/</loc>
60
- <lastmod>2016-10-06</lastmod>
60
+ <lastmod>2016-10-14</lastmod>
61
61
  <changefreq>daily</changefreq>
62
62
  </url>
63
63
 
64
64
  <url>
65
65
  <loc>None/machinery-config.1/</loc>
66
- <lastmod>2016-10-06</lastmod>
66
+ <lastmod>2016-10-14</lastmod>
67
67
  <changefreq>daily</changefreq>
68
68
  </url>
69
69
 
70
70
  <url>
71
71
  <loc>None/machinery-copy.1/</loc>
72
- <lastmod>2016-10-06</lastmod>
72
+ <lastmod>2016-10-14</lastmod>
73
73
  <changefreq>daily</changefreq>
74
74
  </url>
75
75
 
76
76
  <url>
77
77
  <loc>None/machinery-deploy.1/</loc>
78
- <lastmod>2016-10-06</lastmod>
78
+ <lastmod>2016-10-14</lastmod>
79
79
  <changefreq>daily</changefreq>
80
80
  </url>
81
81
 
82
82
  <url>
83
83
  <loc>None/machinery-export-autoyast.1/</loc>
84
- <lastmod>2016-10-06</lastmod>
84
+ <lastmod>2016-10-14</lastmod>
85
85
  <changefreq>daily</changefreq>
86
86
  </url>
87
87
 
88
88
  <url>
89
89
  <loc>None/machinery-export-kiwi.1/</loc>
90
- <lastmod>2016-10-06</lastmod>
90
+ <lastmod>2016-10-14</lastmod>
91
91
  <changefreq>daily</changefreq>
92
92
  </url>
93
93
 
94
94
  <url>
95
95
  <loc>None/machinery-export-html.1/</loc>
96
- <lastmod>2016-10-06</lastmod>
96
+ <lastmod>2016-10-14</lastmod>
97
97
  <changefreq>daily</changefreq>
98
98
  </url>
99
99
 
100
100
  <url>
101
101
  <loc>None/machinery-inspect.1/</loc>
102
- <lastmod>2016-10-06</lastmod>
102
+ <lastmod>2016-10-14</lastmod>
103
103
  <changefreq>daily</changefreq>
104
104
  </url>
105
105
 
106
106
  <url>
107
107
  <loc>None/machinery-inspect-container.1/</loc>
108
- <lastmod>2016-10-06</lastmod>
108
+ <lastmod>2016-10-14</lastmod>
109
109
  <changefreq>daily</changefreq>
110
110
  </url>
111
111
 
112
112
  <url>
113
113
  <loc>None/machinery-list.1/</loc>
114
- <lastmod>2016-10-06</lastmod>
114
+ <lastmod>2016-10-14</lastmod>
115
115
  <changefreq>daily</changefreq>
116
116
  </url>
117
117
 
118
118
  <url>
119
119
  <loc>None/machinery-man.1/</loc>
120
- <lastmod>2016-10-06</lastmod>
120
+ <lastmod>2016-10-14</lastmod>
121
121
  <changefreq>daily</changefreq>
122
122
  </url>
123
123
 
124
124
  <url>
125
125
  <loc>None/machinery-move.1/</loc>
126
- <lastmod>2016-10-06</lastmod>
126
+ <lastmod>2016-10-14</lastmod>
127
127
  <changefreq>daily</changefreq>
128
128
  </url>
129
129
 
130
130
  <url>
131
131
  <loc>None/machinery-remove.1/</loc>
132
- <lastmod>2016-10-06</lastmod>
132
+ <lastmod>2016-10-14</lastmod>
133
133
  <changefreq>daily</changefreq>
134
134
  </url>
135
135
 
136
136
  <url>
137
137
  <loc>None/machinery-serve.1/</loc>
138
- <lastmod>2016-10-06</lastmod>
138
+ <lastmod>2016-10-14</lastmod>
139
139
  <changefreq>daily</changefreq>
140
140
  </url>
141
141
 
142
142
  <url>
143
143
  <loc>None/machinery-show.1/</loc>
144
- <lastmod>2016-10-06</lastmod>
144
+ <lastmod>2016-10-14</lastmod>
145
145
  <changefreq>daily</changefreq>
146
146
  </url>
147
147
 
148
148
  <url>
149
149
  <loc>None/machinery-upgrade-format.1/</loc>
150
- <lastmod>2016-10-06</lastmod>
150
+ <lastmod>2016-10-14</lastmod>
151
151
  <changefreq>daily</changefreq>
152
152
  </url>
153
153
 
154
154
  <url>
155
155
  <loc>None/machinery-validate.1/</loc>
156
- <lastmod>2016-10-06</lastmod>
156
+ <lastmod>2016-10-14</lastmod>
157
157
  <changefreq>daily</changefreq>
158
158
  </url>
159
159
 
@@ -25,7 +25,7 @@ class UsersInspector < Inspector
25
25
 
26
26
  def inspect(_filter, _options = {})
27
27
  passwd = @system.read_file("/etc/passwd")
28
- shadow = @system.read_file("/etc/shadow")
28
+ shadow = @system.read_file("/etc/shadow", privileged: true)
29
29
 
30
30
  users = passwd ? parse_users(passwd, shadow) : []
31
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machinery-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.0
4
+ version: 1.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUSE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-06 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cheetah