Skip to content

Commit 0423c7d

Browse files
committed
Fixes #29803 - Move --certs* to hooks/
1 parent 826d106 commit 0423c7d

File tree

4 files changed

+102
-98
lines changed

4 files changed

+102
-98
lines changed

hooks/boot/20-certs_update.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Add options around regenerating certificates
2+
if module_enabled?('katello')
3+
app_option(
4+
'--certs-update-server',
5+
:flag,
6+
"This option will enforce an update of the HTTPS certificates",
7+
:default => false
8+
)
9+
app_option(
10+
'--certs-update-server-ca',
11+
:flag,
12+
"This option will enforce an update of the CA used for HTTPS certificates.",
13+
:default => false
14+
)
15+
app_option(
16+
'--certs-update-all',
17+
:flag,
18+
"This option will enforce an update of all the certificates for given host",
19+
:default => false
20+
)
21+
app_option(
22+
'--certs-reset',
23+
:flag,
24+
"This option will reset any custom certificates and use the self-signed CA " \
25+
"instead. Note that any clients will need to be updated with the latest " \
26+
"katello-ca-consumer RPM, and any external proxies will need to have the " \
27+
"certs updated by generating a new certs tarball.",
28+
:default => false
29+
)
30+
app_option(
31+
'--certs-skip-check',
32+
:flag,
33+
"This option will cause skipping the certificates sanity check. Use with caution",
34+
:default => false
35+
)
36+
end

hooks/pre/20-certs_update.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'fileutils'
2+
require 'English'
3+
4+
if module_enabled?('katello')
5+
SSL_BUILD_DIR = param('certs', 'ssl_build_dir').value
6+
CHECK_SCRIPT = `which katello-certs-check`.strip
7+
8+
def mark_for_update(cert_name, hostname = nil)
9+
path = File.join(*[SSL_BUILD_DIR, hostname, cert_name].compact)
10+
if app_value(:noop)
11+
puts "Marking certificate #{path} for update (noop)"
12+
else
13+
puts "Marking certificate #{path} for update"
14+
FileUtils.touch("#{path}.update")
15+
end
16+
end
17+
18+
ca_file = param('certs', 'server_ca_cert').value
19+
cert_file = param('certs', 'server_cert').value
20+
key_file = param('certs', 'server_key').value
21+
22+
if app_value('certs_update_server_ca') && !module_enabled?('katello')
23+
fail_and_exit("--certs-update-server-ca needs to be used with katello", 101)
24+
end
25+
26+
if param('foreman_proxy_certs', 'foreman_proxy_fqdn')
27+
hostname = param('foreman_proxy_certs', 'foreman_proxy_fqdn').value
28+
else
29+
hostname = param('certs', 'node_fqdn').value
30+
end
31+
32+
if app_value('certs_update_server')
33+
mark_for_update("#{hostname}-apache", hostname)
34+
mark_for_update("#{hostname}-foreman-proxy", hostname)
35+
end
36+
37+
if app_value('certs_update_all') || app_value('certs_update_default_ca') || app_value('certs_reset')
38+
all_cert_names = Dir.glob(File.join(SSL_BUILD_DIR, hostname, '*.noarch.rpm')).map do |rpm|
39+
File.basename(rpm).sub(/-1\.0-\d+\.noarch\.rpm/, '')
40+
end.uniq
41+
42+
all_cert_names.each do |cert_name|
43+
mark_for_update(cert_name, hostname)
44+
end
45+
end
46+
47+
if app_value('certs_update_server_ca') || app_value('certs_reset')
48+
mark_for_update('katello-server-ca')
49+
end
50+
51+
if !app_value('certs_skip_check') &&
52+
cert_file.to_s != "" &&
53+
(app_value('certs_update_server_ca') || app_value('certs_update_server'))
54+
check_cmd = %(#{CHECK_SCRIPT} -c "#{cert_file}" -k "#{key_file}" -b "#{ca_file}")
55+
output = `#{check_cmd} 2>&1`
56+
unless $CHILD_STATUS.success?
57+
fail_and_exit("Command '#{check_cmd}' exited with #{$CHILD_STATUS.exitstatus}:\n #{output}", 101)
58+
end
59+
end
60+
61+
if app_value('certs_reset') && !app_value(:noop)
62+
param('certs', 'server_cert').unset_value
63+
param('certs', 'server_key').unset_value
64+
param('certs', 'server_ca_cert').unset_value
65+
end
66+
end

katello/hooks/boot/20-certs_update.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

katello/hooks/pre/20-certs_update.rb

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)