smart_proxy_remote_execution_ssh 0.10.6 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 524c8e78e1750ce728c124861bfb6b011b93b270dc9937866c54031fe8403a16
4
- data.tar.gz: 3a67985ff45e4d81b993bdba3b0f849ab4dd25588452ad97799f3b152c36ee26
3
+ metadata.gz: db736b4bf0a21a18f335774778041f20480f18b886669d87c9d0f902e749eb14
4
+ data.tar.gz: 49741c279188b7371c212949d77cb8ebe488eccde6198018c41853bdad673f33
5
5
  SHA512:
6
- metadata.gz: fee698f670f8d5c7e350a05407e38be6ce7c48c492d03c1cdaccbe896fb49ea54227f672e2ae46ebc34cd142507b72b9f49ee6285b3e0a1b669398e9d37c2b1c
7
- data.tar.gz: 8da52396e057f78ddaee30d67d9d8aff50306ec49d7c20b7ba5d506f806494ecc8868ff2233db9285d4e799d21202a5491108fd7a974c97de00fdf8a15821462
6
+ metadata.gz: 92b94f0e609c6f5485f1519a6f853f74b75de8e1efec6f93bcf52519af8f585eb6a1189c547ce606434bdccf16764704d06c4d7bf0aa42b83a990a599585cce7
7
+ data.tar.gz: 4b0bc9999579dda06bcbdee9d0e6e422e67441e8fc82af6ea9064d8aec843a505a8a6505ba267bfdea514f8ba6ceb772ac06db5d4b0b2db27a1268a37033231f
@@ -22,7 +22,6 @@ module Proxy::RemoteExecution::Ssh::Actions
22
22
 
23
23
  def plan(action_input)
24
24
  super(action_input)
25
- input[:with_mqtt] = Proxy::RemoteExecution::Ssh::Plugin.settings.mode == :'pull-mqtt'
26
25
  end
27
26
 
28
27
  def run(event = nil)
@@ -48,10 +47,6 @@ module Proxy::RemoteExecution::Ssh::Actions
48
47
  end
49
48
 
50
49
  def init_run
51
- otp_password = if input[:with_mqtt]
52
- ::Proxy::Dynflow::OtpManager.generate_otp(execution_plan_id)
53
- end
54
-
55
50
  plan_event(PickupTimeout, input[:time_to_pickup], optional: true) if input[:time_to_pickup]
56
51
 
57
52
  input[:job_uuid] =
@@ -60,14 +55,13 @@ module Proxy::RemoteExecution::Ssh::Actions
60
55
  output[:state] = READY_FOR_PICKUP
61
56
  output[:result] = []
62
57
 
63
- mqtt_start(otp_password) if input[:with_mqtt]
58
+ mqtt_start if with_mqtt?
64
59
  suspend
65
60
  end
66
61
 
67
62
  def cleanup(_plan = nil)
68
63
  job_storage.drop_job(execution_plan_id, run_step_id)
69
- Proxy::Dynflow::OtpManager.passwords.delete(execution_plan_id)
70
- Proxy::RemoteExecution::Ssh::MQTT::Dispatcher.instance.done(input[:job_uuid])
64
+ Proxy::RemoteExecution::Ssh::MQTT::Dispatcher.instance.done(input[:job_uuid]) if with_mqtt?
71
65
  end
72
66
 
73
67
  def process_external_event(event)
@@ -131,7 +125,7 @@ module Proxy::RemoteExecution::Ssh::Actions
131
125
  # Client was notified or is already running, dealing with this situation
132
126
  # is only supported if mqtt is available
133
127
  # Otherwise we have to wait it out
134
- if input[:with_mqtt]
128
+ if with_mqtt?
135
129
  mqtt_cancel
136
130
  fail_msg += ', notifying the host over MQTT'
137
131
  else
@@ -144,14 +138,12 @@ module Proxy::RemoteExecution::Ssh::Actions
144
138
  suspend unless exit_code
145
139
  end
146
140
 
147
- def mqtt_start(otp_password)
141
+ def mqtt_start
148
142
  payload = mqtt_payload_base.merge(
149
143
  content: "#{input[:proxy_url]}/ssh/jobs/#{input[:job_uuid]}",
150
144
  metadata: {
151
145
  'event': 'start',
152
146
  'job_uuid': input[:job_uuid],
153
- 'username': execution_plan_id,
154
- 'password': otp_password,
155
147
  'return_url': "#{input[:proxy_url]}/ssh/jobs/#{input[:job_uuid]}/update",
156
148
  'version': 'v1',
157
149
  'effective_user': input[:effective_user]
@@ -207,5 +199,9 @@ module Proxy::RemoteExecution::Ssh::Actions
207
199
 
208
200
  kill_run 'The job was not picked up in time'
209
201
  end
202
+
203
+ def with_mqtt?
204
+ ::Proxy::RemoteExecution::Ssh.with_mqtt?
205
+ end
210
206
  end
211
207
  end
@@ -25,26 +25,9 @@ module Proxy::RemoteExecution
25
25
  end
26
26
  end
27
27
 
28
- delete '/known_hosts/:name' do |name|
29
- do_authorize_any
30
- keys = Net::SSH::KnownHosts.search_for(name)
31
- return [204] if keys.empty?
32
- ssh_keys = keys.map { |key| Base64.strict_encode64 key.to_blob }
33
- Net::SSH::KnownHosts.hostfiles({}, :user)
34
- .map { |file| File.expand_path file }
35
- .select { |file| File.readable?(file) && File.writable?(file) }
36
- .each do |host_file|
37
- lines = File.foreach(host_file).reject do |line|
38
- ssh_keys.any? { |key| line.end_with? "#{key}\n" }
39
- end
40
- File.open(host_file, 'w') { |f| f.write lines.join }
41
- end
42
- 204
43
- end
44
-
45
28
  # Payload is a hash where
46
29
  # exit_code: Integer | NilClass
47
- # output: String
30
+ # output: any, depends on the action consuming the data
48
31
  post '/jobs/:job_uuid/update' do |job_uuid|
49
32
  do_authorize_with_ssl_client
50
33
 
@@ -64,9 +47,11 @@ module Proxy::RemoteExecution
64
47
  do_authorize_with_ssl_client
65
48
 
66
49
  with_authorized_job(job_uuid) do |job_record|
67
- Proxy::RemoteExecution::Ssh::MQTT::Dispatcher.instance.running(job_record[:uuid])
50
+ if Proxy::RemoteExecution::Ssh.with_mqtt?
51
+ Proxy::RemoteExecution::Ssh::MQTT::Dispatcher.instance.running(job_record[:uuid])
52
+ end
68
53
  notify_job(job_record, Actions::PullScript::JobDelivered)
69
- response.headers['X-Foreman-Effective-User'] = job_record[:effective_user]
54
+ response.headers['X-Foreman-Effective-User'] = job_record[:effective_user] if job_record[:effective_user]
70
55
  job_record[:job]
71
56
  end
72
57
  end
@@ -94,9 +79,7 @@ module Proxy::RemoteExecution
94
79
  end
95
80
 
96
81
  def authorized_job(uuid)
97
- job_record = Proxy::RemoteExecution::Ssh.job_storage.find_job(uuid) || {}
98
- return job_record if authorize_with_token(clear: false, task_id: job_record[:execution_plan_uuid]) ||
99
- job_record[:hostname] == https_cert_cn
82
+ Proxy::RemoteExecution::Ssh.job_storage.find_job(uuid, https_cert_cn)
100
83
  end
101
84
  end
102
85
  end
@@ -16,8 +16,8 @@ module Proxy::RemoteExecution::Ssh
16
16
  end
17
17
  end
18
18
 
19
- def find_job(uuid)
20
- jobs.where(uuid: uuid).first
19
+ def find_job(uuid, hostname)
20
+ jobs.where(uuid: uuid, hostname: hostname).first
21
21
  end
22
22
 
23
23
  def job_uuids_for_host(hostname)
@@ -40,7 +40,6 @@ module Proxy::RemoteExecution::Ssh
40
40
  require 'smart_proxy_remote_execution_ssh/api'
41
41
  require 'smart_proxy_remote_execution_ssh/actions'
42
42
  require 'smart_proxy_remote_execution_ssh/dispatcher'
43
- require 'smart_proxy_remote_execution_ssh/log_filter'
44
43
  require 'smart_proxy_remote_execution_ssh/runners'
45
44
  require 'smart_proxy_remote_execution_ssh/utils'
46
45
  require 'smart_proxy_remote_execution_ssh/job_storage'
@@ -48,7 +47,7 @@ module Proxy::RemoteExecution::Ssh
48
47
  Proxy::RemoteExecution::Ssh.validate!
49
48
 
50
49
  Proxy::Dynflow::TaskLauncherRegistry.register('ssh', Proxy::Dynflow::TaskLauncher::Batch)
51
- if settings.mode == :'pull-mqtt'
50
+ if Proxy::RemoteExecution::Ssh.with_mqtt?
52
51
  require 'smart_proxy_remote_execution_ssh/mqtt'
53
52
  # Force initialization
54
53
  Proxy::RemoteExecution::Ssh::MQTT::Dispatcher.instance
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module RemoteExecution
3
3
  module Ssh
4
- VERSION = '0.10.6'
4
+ VERSION = '0.11.0'
5
5
  end
6
6
  end
7
7
  end
@@ -44,7 +44,7 @@ module Proxy::RemoteExecution
44
44
  end
45
45
 
46
46
  def validate_mqtt_settings!
47
- return unless Plugin.settings.mode == :'pull-mqtt'
47
+ return unless with_mqtt?
48
48
 
49
49
  raise 'mqtt_broker has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_broker.nil?
50
50
  raise 'mqtt_port has to be set when pull-mqtt mode is used' if Plugin.settings.mqtt_port.nil?
@@ -110,6 +110,10 @@ module Proxy::RemoteExecution
110
110
  def job_storage
111
111
  @job_storage ||= Proxy::RemoteExecution::Ssh::JobStorage.new
112
112
  end
113
+
114
+ def with_mqtt?
115
+ Proxy::RemoteExecution::Ssh::Plugin.settings.mode == :'pull-mqtt'
116
+ end
113
117
  end
114
118
  end
115
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_remote_execution_ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-18 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -174,7 +174,6 @@ files:
174
174
  - lib/smart_proxy_remote_execution_ssh/dispatcher.rb
175
175
  - lib/smart_proxy_remote_execution_ssh/http_config.ru
176
176
  - lib/smart_proxy_remote_execution_ssh/job_storage.rb
177
- - lib/smart_proxy_remote_execution_ssh/log_filter.rb
178
177
  - lib/smart_proxy_remote_execution_ssh/mqtt.rb
179
178
  - lib/smart_proxy_remote_execution_ssh/mqtt/dispatcher.rb
180
179
  - lib/smart_proxy_remote_execution_ssh/multiplexed_ssh_connection.rb
@@ -1,14 +0,0 @@
1
- module Proxy::RemoteExecution::Ssh
2
- class LogFilter < ::Logger
3
- def initialize(base_logger)
4
- @base_logger = base_logger
5
- end
6
-
7
- def add(severity, *args, &block)
8
- severity ||= ::Logger::UNKNOWN
9
- return true if @base_logger.nil? || severity < @level
10
-
11
- @base_logger.add(severity, *args, &block)
12
- end
13
- end
14
- end