Skip to content

Commit 9af464b

Browse files
Ramesh7Neil Anderson
and
Neil Anderson
authored
(ITHELP-98367) - Fix AiTM attacks vulnerability (#502)
* (ITHELP-98367) - Fix AiTM attacks vulnerability * Changing localhost out for certnames --------- Co-authored-by: Neil Anderson <[email protected]>
1 parent 7798c27 commit 9af464b

9 files changed

+37
-54
lines changed

REFERENCE.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,14 +1075,6 @@ Run on a PE primary node to check if Code Manager is enabled.
10751075

10761076
**Supports noop?** false
10771077

1078-
#### Parameters
1079-
1080-
##### `host`
1081-
1082-
Data type: `String[1]`
1083-
1084-
Hostname of the PE primary node
1085-
10861078
### <a name="code_sync_status"></a>`code_sync_status`
10871079

10881080
A task to confirm code is in sync accross the cluster for clusters with code manager configured

plans/add_replica.pp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
$replica_target = peadm::get_targets($replica_host, 1)
2323
$replica_postgresql_target = peadm::get_targets($replica_postgresql_host, 1)
2424

25-
$code_manager_enabled = run_task(
26-
'peadm::code_manager_enabled', $primary_target, host => $primary_target.peadm::certname()
27-
).first.value['code_manager_enabled']
25+
$code_manager_enabled = run_task('peadm::code_manager_enabled', $primary_target).first.value['code_manager_enabled']
2826

2927
if $code_manager_enabled == false {
3028
fail('Code Manager must be enabled to add a replica. Please refer to the docs for more information on enabling Code Manager.')

tasks/backup_classification.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ def execute!
2020
private
2121

2222
def https_client
23-
client = Net::HTTP.new('localhost', '4433')
23+
client = Net::HTTP.new(Puppet.settings[:certname], 4433)
2424
client.use_ssl = true
2525
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
2626
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
27-
client.verify_mode = OpenSSL::SSL::VERIFY_NONE
27+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
28+
client.ca_file = Puppet.settings[:localcacert]
2829
client
2930
end
3031

tasks/code_manager_enabled.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
22
"description": "Run on a PE primary node to check if Code Manager is enabled.",
3-
"parameters": {
4-
"host": {
5-
"type": "String[1]",
6-
"description": "Hostname of the PE primary node"
7-
}
8-
},
3+
"parameters": {},
94
"input_method": "stdin"
105
}

tasks/code_manager_enabled.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
require 'net/http'
77
require 'puppet'
88

9-
# GetPEAdmConfig task class
10-
class GetPEAdmConfig
11-
def initialize(params)
12-
@host = params['host']
13-
end
14-
9+
# CodeManagerEnabled task class
10+
class CodeManagerEnabled
1511
def execute!
1612
code_manager_enabled = groups.dig('PE Master', 'classes', 'puppet_enterprise::profile::master', 'code_manager_auto_configure')
1713

@@ -20,18 +16,16 @@ def execute!
2016
puts({ 'code_manager_enabled' => code_manager_enabled_value }.to_json)
2117
end
2218

23-
# Returns a GetPEAdmConfig::NodeGroups object created from the /groups object
24-
# returned by the classifier
2519
def groups
2620
@groups ||= begin
27-
net = https(@host, 4433)
21+
net = https
2822
res = net.get('/classifier-api/v1/groups')
2923
NodeGroup.new(JSON.parse(res.body))
3024
end
3125
end
3226

33-
def https(host, port)
34-
https = Net::HTTP.new(host, port)
27+
def https
28+
https = Net::HTTP.new(Puppet.settings[:certname], 4433)
3529
https.use_ssl = true
3630
https.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
3731
https.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
@@ -68,6 +62,6 @@ def dig(name, *args)
6862
# testing of this task.
6963
unless ENV['RSPEC_UNIT_TEST_MODE']
7064
Puppet.initialize_settings
71-
task = GetPEAdmConfig.new(JSON.parse(STDIN.read))
65+
task = CodeManagerEnabled.new
7266
task.execute!
7367
end

tasks/code_sync_status.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ def execute!
1919
private
2020

2121
def https_client
22-
client = Net::HTTP.new('localhost', '8140')
22+
client = Net::HTTP.new(Puppet.settings[:certname], 8140)
2323
client.use_ssl = true
2424
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
2525
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
26-
client.verify_mode = OpenSSL::SSL::VERIFY_NONE
26+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
27+
client.ca_file = Puppet.settings[:localcacert]
2728
client
2829
end
2930

tasks/pe_ldap_config.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ def main
3232
end
3333

3434
uri = URI("https://#{pe_main}:4433/rbac-api/v1/ds")
35-
http = Net::HTTP.new(uri.host, uri.port)
36-
http.use_ssl = true
37-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
38-
http.ca_file = cafout.strip
39-
http.cert = OpenSSL::X509::Certificate.new(File.read(certout.strip))
40-
http.key = OpenSSL::PKey::RSA.new(File.read(keyout.strip))
35+
https = Net::HTTP.new(uri.host, uri.port)
36+
https.use_ssl = true
37+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
38+
https.ca_file = cafout.strip
39+
https.cert = OpenSSL::X509::Certificate.new(File.read(certout.strip))
40+
https.key = OpenSSL::PKey::RSA.new(File.read(keyout.strip))
4141

4242
req = Net::HTTP::Put.new(uri, 'Content-type' => 'application/json')
4343
req.body = data.to_json
4444

45-
resp = http.request(req)
45+
resp = https.request(req)
4646

4747
puts resp.body
4848
raise "API response code #{resp.code}" unless resp.code == '200'

tasks/puppet_infra_upgrade.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require 'open3'
88
require 'timeout'
99
require 'etc'
10+
require 'puppet'
1011

1112
# Class to run and execute the `puppet infra upgrade` command as a task.
1213
class PuppetInfraUpgrade
@@ -39,39 +40,38 @@ def execute!
3940
end
4041
end
4142

42-
def inventory_uri
43-
@inventory_uri ||= URI.parse('https://localhost:8143/orchestrator/v1/inventory')
44-
end
45-
4643
def request_object(nodes:, token_file:)
4744
token = File.read(token_file)
4845
body = {
4946
'nodes' => nodes,
5047
}.to_json
5148

52-
request = Net::HTTP::Post.new(inventory_uri.request_uri)
49+
request = Net::HTTP::Post.new('/orchestrator/v1/inventory')
5350
request['Content-Type'] = 'application/json'
5451
request['X-Authentication'] = token.chomp
5552
request.body = body
5653

5754
request
5855
end
5956

60-
def http_object
61-
http = Net::HTTP.new(inventory_uri.host, inventory_uri.port)
62-
http.use_ssl = true
63-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
57+
def https_object
58+
https = Net::HTTP.new(Puppet.settings[:certname], 8143)
59+
https.use_ssl = true
60+
https.cert = OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
61+
https.key = OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
62+
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
63+
https.ca_file = Puppet.settings[:localcacert]
6464

65-
http
65+
https
6666
end
6767

6868
def wait_until_connected(nodes:, token_file:, timeout: 120)
69-
http = http_object
69+
https = https_object
7070
request = request_object(nodes: nodes, token_file: token_file)
7171
inventory = {}
7272
Timeout.timeout(timeout) do
7373
loop do
74-
response = http.request(request)
74+
response = https.request(request)
7575
unless response.is_a? Net::HTTPSuccess
7676
raise "Unexpected result from orchestrator: #{response.class}\n#{response}"
7777
end
@@ -92,6 +92,7 @@ def wait_until_connected(nodes:, token_file:, timeout: 120)
9292
# environment flag is used to disable auto-execution and enable Ruby unit
9393
# testing of this task.
9494
unless ENV['RSPEC_UNIT_TEST_MODE']
95+
Puppet.initialize_settings
9596
upgrade = PuppetInfraUpgrade.new(JSON.parse(STDIN.read))
9697
upgrade.execute!
9798
end

tasks/restore_classification.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ def execute!
2020
private
2121

2222
def https_client
23-
client = Net::HTTP.new('localhost', '4433')
23+
client = Net::HTTP.new(Puppet.settings[:certname], 4433)
2424
client.use_ssl = true
2525
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
2626
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
27-
client.verify_mode = OpenSSL::SSL::VERIFY_NONE
27+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
28+
client.ca_file = Puppet.settings[:localcacert]
2829
client
2930
end
3031

0 commit comments

Comments
 (0)