sshkit 1.16.1 → 1.17.0

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: adf8778cdb780fc5190e6e29a913f97c9367073850ec4db02c30ee5fca61b15e
4
- data.tar.gz: b9ad84e2f7cdc7cfd6d5773954b764182a828b3b02886085ce29a96a75f1672f
3
+ metadata.gz: fc70293f2ae9b1fd7a0adf61cac4ff329fa54e4c7461570eec898560777fc006
4
+ data.tar.gz: b707f414b46ca07e1b6b9f0db26f5512d1a1a654922292d959d56f7d2bb9be39
5
5
  SHA512:
6
- metadata.gz: d7a6fc9a49bf60dc427426a988499d081d0666c1a2e3ac06b57952a6352c3ae93c09792d464ad844295cf3a6fb69cfb238213b6bd93fdf5e761b603df205c36c
7
- data.tar.gz: d1e3a4f0eb0cf3e3baca205bffe236581fc260f5c7e70cbd9155d64f827bc3ce6732f2f74f9024171f192aa2e0061dcb9894b651ded2a916479164d98dfcd4fd
6
+ metadata.gz: b127c917a1bd92af92ede9cf7710c75c82504159b4432bd0ec483a8cae1aed2dc269c1e58bfd5fd7f2f384f3ed6115db5e9dacbcab7eedf5bae42597afaec585
7
+ data.tar.gz: cefe7b628ec52664d2753bc09787ef1aae4cbbea93774afce828397bb18d77afbd78622c3ec84f3d90bf6b609af2b6be56c5bb03e6d35c6f48c9a2e9a3d81a9b
@@ -7,6 +7,10 @@ appear at the top.
7
7
 
8
8
  * Your contribution here!
9
9
 
10
+ ## [1.17.0][] (2018-07-07)
11
+
12
+ * [#430](https://github.com/capistrano/sshkit/pull/430): [Feature] Command Argument STDOUT/capistrano.log Hiding - [@NorseGaud](https://github.com/NorseGaud)
13
+
10
14
  ## [1.16.1][] (2018-05-20)
11
15
 
12
16
  * [#425](https://github.com/capistrano/sshkit/pull/425): Command#group incorrectly escapes double quotes, resulting in a a syntax error when specifying the group execution using `as`. This issue manifested when user command quotes changed from double quotes to single quotes. This fix removes the double quote escaping - [@pblesi](https://github.com/pblesi).
@@ -742,7 +746,8 @@ version `0.0.5`.
742
746
 
743
747
  First release.
744
748
 
745
- [Unreleased]: https://github.com/capistrano/sshkit/compare/v1.16.1...HEAD
749
+ [Unreleased]: https://github.com/capistrano/sshkit/compare/v1.17.0...HEAD
750
+ [1.17.0]: https://github.com/capistrano/sshkit/compare/v1.16.1...v1.17.0
746
751
  [1.16.1]: https://github.com/capistrano/sshkit/compare/v1.16.0...v1.16.1
747
752
  [1.16.0]: https://github.com/capistrano/sshkit/compare/v1.15.1...v1.16.0
748
753
  [1.15.1]: https://github.com/capistrano/sshkit/compare/v1.15.0...v1.15.1
data/Gemfile CHANGED
@@ -18,8 +18,3 @@ end
18
18
  if Gem::Requirement.new('< 2.1').satisfied_by?(Gem::Version.new(RUBY_VERSION))
19
19
  gem 'public_suffix', '< 3'
20
20
  end
21
-
22
- # rbnacl-libsodium > 1.0.15.1 requires Ruby 2.2.6+
23
- if Gem::Requirement.new('< 2.2.6').satisfied_by?(Gem::Version.new(RUBY_VERSION))
24
- gem 'rbnacl-libsodium', '<= 1.0.15.1'
25
- end
data/README.md CHANGED
@@ -5,7 +5,6 @@ more servers.
5
5
 
6
6
  [![Gem Version](https://badge.fury.io/rb/sshkit.svg)](https://rubygems.org/gems/sshkit)
7
7
  [![Build Status](https://travis-ci.org/capistrano/sshkit.svg?branch=master)](https://travis-ci.org/capistrano/sshkit)
8
- [![Dependency Status](https://gemnasium.com/capistrano/sshkit.svg)](https://gemnasium.com/capistrano/sshkit)
9
8
 
10
9
  ## How might it work?
11
10
 
@@ -444,6 +443,32 @@ SSHKit.config.output = SSHKit::Formatter::Pretty.new(output)
444
443
  SSHKit.config.output = SSHKit::Formatter::SimpleText.new(File.open('log/deploy.log', 'wb'))
445
444
  ```
446
445
 
446
+ #### Output & Log Redaction
447
+
448
+ If necessary, redact() can be used on a section of your execute arguments to hide it from both STDOUT and the capistrano.log. It supports the majority of data types.
449
+
450
+ ```ruby
451
+ # Example from capistrano-postgresql gem
452
+ execute(:psql, fetch(:pg_system_db), '-c', %Q{"CREATE USER \\"#{fetch(:pg_username)}\\" PASSWORD}, redact("'#{fetch(:pg_password)}'"), %Q{;"})
453
+ ```
454
+ Once wrapped, sshkit logging will replace the actual pg_password with a [REDACTED] value:
455
+
456
+ ```
457
+ # STDOUT
458
+ 00:00 postgresql:create_database_user
459
+ 01 sudo -i -u postgres psql -d postgres -c "CREATE USER \"db_admin_user\" PASSWORD [REDACTED] ;"
460
+ 01 CREATE ROLE
461
+ ✔ 01 user@localhost 0.099s
462
+
463
+ # capistrano.log
464
+ INFO [59dbd2ba] Running /usr/bin/env sudo -i -u postgres psql -d postgres -c "CREATE USER \"db_admin_user\" PASSWORD [REDACTED] ;" as user@localhost
465
+ DEBUG [59dbd2ba] Command: ( export PATH="$HOME/.gem/ruby/2.5.0/bin:$PATH" ; /usr/bin/env sudo -i -u postgres psql -d postgres -c "CREATE USER \"db_admin_user\" PASSWORD [REDACTED] ;" )
466
+ DEBUG [529b623c] CREATE ROLE
467
+
468
+ ```
469
+
470
+ Yet, the created database user will have the value from `fetch(:pg_password)`.
471
+
447
472
  #### Output Colors
448
473
 
449
474
  By default, SSHKit will color the output using ANSI color escape sequences
@@ -21,6 +21,9 @@ module SSHKit
21
21
 
22
22
  end
23
23
 
24
+ # Used for redaction of a certain argument
25
+ module Redaction end
26
+
24
27
  end
25
28
 
26
29
  require_relative 'sshkit/all'
@@ -42,6 +42,10 @@ module SSHKit
42
42
  @group = nil
43
43
  end
44
44
 
45
+ def redact(arg) # Used in execute_command to hide redact() args a user passes in
46
+ arg.to_s.extend(Redaction) # to_s due to our inability to extend Integer, etc
47
+ end
48
+
45
49
  def make(commands=[])
46
50
  execute :make, commands
47
51
  end
@@ -39,10 +39,8 @@ module SSHKit
39
39
  private
40
40
 
41
41
  def execute_command(cmd)
42
- output.log_command_start(cmd)
43
-
42
+ output.log_command_start(cmd.with_redaction)
44
43
  cmd.started = Time.now
45
-
46
44
  Open3.popen3(cmd.to_command) do |stdin, stdout, stderr, wait_thr|
47
45
  stdout_thread = Thread.new do
48
46
  while (line = stdout.gets) do
@@ -50,19 +48,15 @@ module SSHKit
50
48
  output.log_command_data(cmd, :stdout, line)
51
49
  end
52
50
  end
53
-
54
51
  stderr_thread = Thread.new do
55
52
  while (line = stderr.gets) do
56
53
  cmd.on_stderr(stdin, line)
57
54
  output.log_command_data(cmd, :stderr, line)
58
55
  end
59
56
  end
60
-
61
57
  stdout_thread.join
62
58
  stderr_thread.join
63
-
64
59
  cmd.exit_status = wait_thr.value.to_i
65
-
66
60
  output.log_command_exit(cmd)
67
61
  end
68
62
  end
@@ -123,7 +123,7 @@ module SSHKit
123
123
  end
124
124
 
125
125
  def execute_command(cmd)
126
- output.log_command_start(cmd)
126
+ output.log_command_start(cmd.with_redaction)
127
127
  cmd.started = true
128
128
  exit_status = nil
129
129
  with_ssh do |ssh|
@@ -5,7 +5,7 @@ module SSHKit
5
5
  class Printer < Abstract
6
6
 
7
7
  def execute_command(cmd)
8
- output.log_command_start(cmd)
8
+ output.log_command_start(cmd.with_redaction)
9
9
  end
10
10
 
11
11
  alias :upload! :execute
@@ -204,6 +204,13 @@ module SSHKit
204
204
  end
205
205
  end
206
206
 
207
+ def with_redaction
208
+ new_args = args.map{|arg| arg.is_a?(Redaction) ? '[REDACTED]' : arg }
209
+ redacted_cmd = dup
210
+ redacted_cmd.instance_variable_set(:@args, new_args)
211
+ redacted_cmd
212
+ end
213
+
207
214
  def to_s
208
215
  if should_map?
209
216
  [SSHKit.config.command_map[command.to_sym], *Array(args)].join(' ')
@@ -1,3 +1,3 @@
1
1
  module SSHKit
2
- VERSION = "1.16.1".freeze
2
+ VERSION = "1.17.0".freeze
3
3
  end
@@ -29,6 +29,5 @@ Gem::Specification.new do |gem|
29
29
  gem.add_development_dependency('mocha')
30
30
 
31
31
  gem.add_development_dependency('bcrypt_pbkdf')
32
- gem.add_development_dependency('rbnacl', '~> 3.4')
33
- gem.add_development_dependency('rbnacl-libsodium')
32
+ gem.add_development_dependency('ed25519', '>= 1.2', '< 2.0')
34
33
  end
@@ -42,13 +42,43 @@ module SSHKit
42
42
  ], command_lines
43
43
  end
44
44
 
45
+ def test_redaction
46
+ # Be sure redaction in the logs is showing [REDACTED]
47
+ Netssh.new(a_host) do
48
+ execute :echo, 'password:', redact('PASSWORD')
49
+ execute :echo, 'password:', redact(10000)
50
+ execute :echo, 'password:', redact(['test1','test2'])
51
+ execute :echo, 'password:', redact({:test => 'test_value'})
52
+ end.run
53
+ command_lines = @output.lines.select { |line| line.start_with?('Command:') }
54
+ assert_equal [
55
+ "Command: /usr/bin/env echo password: [REDACTED]\n",
56
+ "Command: /usr/bin/env echo password: [REDACTED]\n",
57
+ "Command: /usr/bin/env echo password: [REDACTED]\n",
58
+ "Command: /usr/bin/env echo password: [REDACTED]\n"
59
+ ], command_lines
60
+ # Be sure the actual command executed without *REDACTED*
61
+ Netssh.new(a_host) do
62
+ file_name = 'test.file'
63
+ execute :touch, redact("'#{file_name}'") # Test and be sure single quotes are included in actual command; expected /usr/bin/env touch 'test.file'
64
+ execute :ls, 'test.file'
65
+ end.run
66
+ ls_lines = @output.lines.select { |line| line.start_with?("\ttest.file") }
67
+ assert_equal [
68
+ "\ttest.file\n"
69
+ ], ls_lines
70
+ # Cleanup
71
+ Netssh.new(a_host) do
72
+ execute :rm, ' -f test.file'
73
+ end.run
74
+ end
75
+
45
76
  def test_group_netssh
46
77
  Netssh.new(a_host) do
47
78
  as user: :root, group: :admin do
48
79
  execute :touch, 'restart.txt'
49
80
  end
50
81
  end.run
51
-
52
82
  command_lines = @output.lines.select { |line| line.start_with?('Command:') }
53
83
  assert_equal [
54
84
  "Command: if ! sudo -u root whoami > /dev/null; then echo \"You cannot switch to user 'root' using sudo, please check the sudoers file\" 1>&2; false; fi\n",
@@ -66,16 +96,21 @@ module SSHKit
66
96
  end
67
97
 
68
98
  def test_ssh_option_merge
69
- a_host.ssh_options = { paranoid: true }
99
+ verify_host_opt = if Net::SSH::Version::MAJOR >= 5
100
+ { verify_host_key: :always }
101
+ else
102
+ { paranoid: true }
103
+ end
104
+ a_host.ssh_options = verify_host_opt
70
105
  host_ssh_options = {}
71
106
  SSHKit::Backend::Netssh.config.ssh_options = { forward_agent: false }
72
107
  Netssh.new(a_host) do |host|
73
108
  capture(:uname)
74
109
  host_ssh_options = host.ssh_options
75
110
  end.run
76
- assert_equal [:forward_agent, :paranoid, :known_hosts, :logger, :password_prompt].sort, host_ssh_options.keys.sort
111
+ assert_equal [:forward_agent, *verify_host_opt.keys, :known_hosts, :logger, :password_prompt].sort, host_ssh_options.keys.sort
77
112
  assert_equal false, host_ssh_options[:forward_agent]
78
- assert_equal true, host_ssh_options[:paranoid]
113
+ assert_equal verify_host_opt.values.first, host_ssh_options[verify_host_opt.keys.first]
79
114
  assert_instance_of SSHKit::Backend::Netssh::KnownHosts, host_ssh_options[:known_hosts]
80
115
  end
81
116
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.1
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Hambley
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-21 00:00:00.000000000 Z
12
+ date: 2018-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -152,33 +152,25 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: rbnacl
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - "~>"
159
- - !ruby/object:Gem::Version
160
- version: '3.4'
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - "~>"
166
- - !ruby/object:Gem::Version
167
- version: '3.4'
168
- - !ruby/object:Gem::Dependency
169
- name: rbnacl-libsodium
155
+ name: ed25519
170
156
  requirement: !ruby/object:Gem::Requirement
171
157
  requirements:
172
158
  - - ">="
173
159
  - !ruby/object:Gem::Version
174
- version: '0'
160
+ version: '1.2'
161
+ - - "<"
162
+ - !ruby/object:Gem::Version
163
+ version: '2.0'
175
164
  type: :development
176
165
  prerelease: false
177
166
  version_requirements: !ruby/object:Gem::Requirement
178
167
  requirements:
179
168
  - - ">="
180
169
  - !ruby/object:Gem::Version
181
- version: '0'
170
+ version: '1.2'
171
+ - - "<"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.0'
182
174
  description: A comprehensive toolkit for remotely running commands in a structured
183
175
  manner on groups of servers.
184
176
  email: