Skip to content

Commit ca0debd

Browse files
committed
Refs #38478 - Introduce SSH CA certificate support
1 parent ced5e82 commit ca0debd

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

lib/smart_proxy_remote_execution_ssh.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ def validate!
1313
validate_socket_path!
1414
end
1515

16+
def ca_public_key_file
17+
File.expand_path(Plugin.settings.ssh_ca_public_key_file)
18+
end
19+
20+
def ca_cert_file
21+
File.expand_path(Plugin.settings.ssh_ca_cert_file)
22+
end
23+
24+
def ca_known_hosts_file
25+
File.expand_path(Plugin.settings.ssh_ca_known_hosts_file)
26+
end
27+
1628
def private_key_file
1729
File.expand_path(Plugin.settings.ssh_identity_key_file)
1830
end
@@ -72,6 +84,16 @@ def validate_ssh_settings!
7284
raise "SSH public key file #{public_key_file} doesn't exist"
7385
end
7486

87+
if Plugin.settings.ssh_ca_public_key_file
88+
unless File.exist?(ca_public_key_file)
89+
raise "SSH CA public key file #{ca_public_key_file} doesn't exist"
90+
end
91+
92+
unless File.exist?(ca_cert_file)
93+
raise "SSH CA certificate file #{ca_cert_file} doesn't exist"
94+
end
95+
end
96+
7597
validate_ssh_log_level!
7698
end
7799

lib/smart_proxy_remote_execution_ssh/api.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class Api < ::Sinatra::Base
99
include Sinatra::Authorization::Helpers
1010
include Proxy::Dynflow::Helpers
1111

12+
get "/ca_pubkey" do
13+
if Ssh.ca_public_key_file
14+
File.read(Ssh.ca_public_key_file)
15+
end
16+
end
17+
1218
get "/pubkey" do
1319
File.read(Ssh.public_key_file)
1420
end

lib/smart_proxy_remote_execution_ssh/multiplexed_ssh_connection.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def initialize(options, logger:)
6060
@host_public_key = options.fetch(:host_public_key, nil)
6161
@verify_host = options.fetch(:verify_host, nil)
6262
@client_private_key_file = settings.ssh_identity_key_file
63+
@client_ca_known_hosts_file = settings.ssh_ca_known_hosts_file
64+
@client_ca_public_key_file = settings.ssh_ca_public_key_file
65+
@client_ca_cert_file = settings.ssh_ca_cert_file
6366

6467
@local_working_dir = options.fetch(:local_working_dir, settings.local_working_dir)
6568
@socket_working_dir = options.fetch(:socket_working_dir, settings.socket_working_dir)
@@ -154,9 +157,14 @@ def establish_ssh_options
154157
ssh_options << "-o User=#{@ssh_user}"
155158
ssh_options << "-o Port=#{@ssh_port}" if @ssh_port
156159
ssh_options << "-o IdentityFile=#{@client_private_key_file}" if @client_private_key_file
160+
ssh_options << "-o CertificateFile=#{@client_ca_cert_file}" if @client_ca_cert_file
157161
ssh_options << "-o IdentitiesOnly=yes"
158162
ssh_options << "-o StrictHostKeyChecking=accept-new"
159-
ssh_options << "-o UserKnownHostsFile=#{prepare_known_hosts}" if @host_public_key
163+
if @host_public_key
164+
ssh_options << "-o UserKnownHostsFile=#{prepare_known_hosts}"
165+
elsif @client_ca_known_hosts_file
166+
ssh_options << "-o UserKnownHostsFile=#{@client_ca_known_hosts_file}"
167+
end
160168
ssh_options << "-o LogLevel=#{ssh_log_level(true)}"
161169
ssh_options << "-o ControlMaster=auto"
162170
ssh_options << "-o ControlPath=#{socket_file}"

lib/smart_proxy_remote_execution_ssh/plugin.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class Plugin < Proxy::Plugin
1212

1313
settings_file "remote_execution_ssh.yml"
1414
default_settings :ssh_identity_key_file => '~/.ssh/id_rsa_foreman_proxy',
15+
:ssh_ca_known_hosts_file => '~/.ssh/ca_known_hosts',
16+
# :ssh_ca_public_key_file => nil,
17+
# :ssh_ca_cert_file => nil,
1518
:ssh_user => 'root',
1619
:remote_working_dir => '/var/tmp',
1720
:local_working_dir => '/var/tmp',

0 commit comments

Comments
 (0)