Skip to content

Commit 10634e0

Browse files
author
petergmurphy
committed
Better checking for legacy compiler OID
1 parent 531c2ad commit 10634e0

File tree

4 files changed

+57
-34
lines changed

4 files changed

+57
-34
lines changed

Diff for: plans/upgrade.pp

+2-14
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,11 @@
135135

136136
peadm::assert_supported_pe_version($_version, $permit_unsafe_versions)
137137

138-
# Gather certificate extension information from all systems
139-
$cert_extensions_temp = run_task('peadm::cert_data', $all_targets).reduce({}) |$memo,$result| {
140-
$memo + { $result.target.peadm::certname => $result['extensions'] }
141-
}
142-
143-
# Add legacy compiler role to compilers that are missing it
144-
$compilers_with_legacy_compiler_flag = $cert_extensions_temp.filter |$name,$exts| {
145-
($name in $compiler_targets.map |$t| { $t.name }) and
146-
($exts[peadm::oid('peadm_legacy_compiler')] != undef)
147-
}
148-
149-
if $compilers_with_legacy_compiler_flag.size > 0 {
138+
$rules_check = run_task('peadm::check_pe_master_rules', $primary_target).first.value
139+
unless $rules_check['updated'] {
150140
fail_plan('Please run the Convert plan to convert your Puppet infrastructure to be managed by this version of PEADM.')
151141
}
152142

153-
run_task('peadm::update_pe_master_rules', $primary_target)
154-
155143
# Gather certificate extension information from all systems
156144
$cert_extensions = run_task('peadm::cert_data', $all_targets).reduce({}) |$memo,$result| {
157145
$memo + { $result.target.peadm::certname => $result['extensions'] }

Diff for: tasks/check_pe_master_rules.json

+1-15
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,5 @@
66
{"name": "check_pe_master_rules.rb"}
77
],
88
"parameters": {},
9-
"supports_noop": false,
10-
"output": {
11-
"updated": {
12-
"description": "Whether the PE Master rules have already been updated",
13-
"type": "Boolean"
14-
},
15-
"message": {
16-
"description": "A message describing the current state of the PE Master rules",
17-
"type": "String"
18-
},
19-
"error": {
20-
"description": "Error message if the task failed",
21-
"type": "Optional[String]"
22-
}
23-
}
9+
"supports_noop": false
2410
}

Diff for: tasks/check_pe_master_rules.rb

+53-4
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,67 @@ def check_rules_updated(rules)
8787
false
8888
end
8989

90+
def https_pdb_client(port = 8081)
91+
client = Net::HTTP.new(Puppet.settings[:certname], port)
92+
client.use_ssl = true
93+
client.cert = @cert ||= OpenSSL::X509::Certificate.new(File.read(Puppet.settings[:hostcert]))
94+
client.key = @key ||= OpenSSL::PKey::RSA.new(File.read(Puppet.settings[:hostprivkey]))
95+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
96+
client.ca_file = Puppet.settings[:localcacert]
97+
client
98+
end
99+
100+
def check_nodes_with_legacy_compiler_oid
101+
pdb = https_pdb_client
102+
pdb_request = Net::HTTP::Get.new('/pdb/query/v4')
103+
pdb_request.set_form_data({
104+
'query' => 'inventory[certname,trusted.extensions] {
105+
trusted.extensions."1.3.6.1.4.1.34380.1.1.9814" is not null
106+
}'
107+
})
108+
109+
response = pdb.request(pdb_request)
110+
111+
unless response.code == '200'
112+
raise "Failed to query PuppetDB: HTTP #{response.code} - #{response.body}"
113+
end
114+
115+
nodes = JSON.parse(response.body)
116+
117+
{
118+
'nodes_found' => !nodes.empty?,
119+
'count' => nodes.size,
120+
'nodes' => nodes.map { |n| n['certname'] }
121+
}
122+
rescue JSON::ParserError => e
123+
raise "Invalid JSON response from PuppetDB: #{e.message}"
124+
rescue StandardError => e
125+
raise "Error checking for legacy compiler OID: #{e.message}"
126+
end
127+
90128
def execute!
91129
begin
92130
group_id = get_pe_master_group_id
93131
current_rules = get_current_rules(group_id)
94132

95-
is_updated = check_rules_updated(current_rules)
133+
rules_updated = check_rules_updated(current_rules)
134+
legacy_compiler_nodes = check_nodes_with_legacy_compiler_oid
135+
136+
# Overall status is updated only if rules are updated AND no nodes have legacy compiler OID
137+
is_updated = rules_updated && !legacy_compiler_nodes['nodes_found']
138+
139+
message = if !rules_updated
140+
'PE Master rules need to be updated to support pe_compiler_legacy'
141+
elsif legacy_compiler_nodes['nodes_found']
142+
'PE Master rules are updated, but nodes with legacy compiler OID still exist'
143+
else
144+
'PE Master rules have been updated with pe_compiler_legacy support and no legacy compiler OIDs found'
145+
end
96146

97147
result = {
98148
'updated' => is_updated,
99-
'message' => is_updated ?
100-
'PE Master rules have already been updated with pe_compiler_legacy support' :
101-
'PE Master rules need to be updated to support pe_compiler_legacy'
149+
'message' => message,
150+
'legacy_compiler_oid' => legacy_compiler_nodes
102151
}
103152

104153
puts result.to_json

Diff for: tasks/get_peadm_config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def compilers
107107
def legacy_compilers
108108
@legacy_compilers ||=
109109
pdb_query('inventory[certname,trusted.extensions] {
110-
trusted.extensions.pp_auth_role = "legacy_compiler"
110+
trusted.extensions.pp_auth_role = "pe_compiler_legacy"
111111
}').map do |c|
112112
{
113113
'certname' => c['certname'],

0 commit comments

Comments
 (0)