Skip to content

Commit b7e4b06

Browse files
committed
Fixes #TBFL - Prevent spurious proxy calls when accessing host parameters
1 parent 8fa4503 commit b7e4b06

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

app/models/concerns/foreman_remote_execution/host_extensions.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def remote_execution_proxies(provider, authorized = true)
109109

110110
def remote_execution_ssh_keys
111111
# only include public keys from SSH proxies that don't have SSH cert verification configured
112-
remote_execution_proxies(%w(SSH Script), false).values.flatten.uniq.map { |proxy| proxy.pubkey if proxy.ca_pubkey.blank? }.compact.uniq
112+
remote_execution_proxies(%w(SSH Script), false).values.flatten.uniq.map { |proxy| proxy.pubkey(refresh: false) if proxy.ca_pubkey(refresh: false).blank? }.compact.uniq
113113
end
114114

115115
def remote_execution_ssh_ca_keys
116-
remote_execution_proxies(%w(SSH Script), false).values.flatten.uniq.map { |proxy| proxy.ca_pubkey }.compact.uniq
116+
remote_execution_proxies(%w(SSH Script), false).values.flatten.uniq.map { |proxy| proxy.ca_pubkey(refresh: false) }.compact.uniq
117117
end
118118

119119
def drop_execution_interface_cache

test/unit/concerns/host_extensions_test.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
1111
let(:sshkey) { 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQ foo@example.com' }
1212

1313
before do
14-
SmartProxy.any_instance.stubs(:pubkey).returns(sshkey)
15-
SmartProxy.any_instance.stubs(:ca_pubkey).returns(nil)
14+
host.subnet.remote_execution_proxies.each do |proxy|
15+
proxy.update_column(:pubkey, sshkey)
16+
proxy.update_column(:ca_pubkey, nil)
17+
end
1618
Setting[:remote_execution_ssh_user] = 'root'
1719
Setting[:remote_execution_effective_user_method] = 'sudo'
1820
end
@@ -60,6 +62,17 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
6062
User.current = nil
6163
assert_includes host.remote_execution_ssh_keys, sshkey
6264
end
65+
66+
it 'triggers no calls to the proxy' do
67+
host.subnet.remote_execution_proxies.each do |proxy|
68+
proxy.update_column(:pubkey, nil)
69+
end
70+
71+
SmartProxy.any_instance.expects(:update_pubkey).never
72+
SmartProxy.any_instance.expects(:update_ca_pubkey).never
73+
74+
host.host_param('remote_execution_ssh_keys')
75+
end
6376
end
6477

6578
describe 'has ssh CA key configured' do
@@ -68,8 +81,10 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
6881
let(:ca_sshkey) { 'ssh-rsa AAAAB3NzaC1yc2EAAAABJE bar@example.com' }
6982

7083
before do
71-
SmartProxy.any_instance.stubs(:pubkey).returns(sshkey)
72-
SmartProxy.any_instance.stubs(:ca_pubkey).returns(ca_sshkey)
84+
host.subnet.remote_execution_proxies.each do |proxy|
85+
proxy.update_column(:pubkey, sshkey)
86+
proxy.update_column(:ca_pubkey, ca_sshkey)
87+
end
7388
Setting[:remote_execution_ssh_user] = 'root'
7489
Setting[:remote_execution_effective_user_method] = 'sudo'
7590
end
@@ -102,6 +117,17 @@ class ForemanRemoteExecutionHostExtensionsTest < ActiveSupport::TestCase
102117
assert_includes host.host_param('remote_execution_ssh_ca_keys'), key
103118
assert_includes host.host_param('remote_execution_ssh_ca_keys'), ca_sshkey
104119
end
120+
121+
it 'triggers no calls to the proxy' do
122+
host.subnet.remote_execution_proxies.each do |proxy|
123+
proxy.update_column(:ca_pubkey, nil)
124+
end
125+
126+
SmartProxy.any_instance.expects(:update_pubkey).never
127+
SmartProxy.any_instance.expects(:update_ca_pubkey).never
128+
129+
host.host_param('remote_execution_ssh_ca_keys')
130+
end
105131
end
106132

107133
context 'host has multiple nics' do

0 commit comments

Comments
 (0)