Skip to content

Commit cc07b39

Browse files
committed
Fixes #29803 - Move --certs* to hooks/
1 parent 4548bcc commit cc07b39

File tree

5 files changed

+97
-98
lines changed

5 files changed

+97
-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_present?('certs')
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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require 'fileutils'
2+
require 'English'
3+
4+
if module_enabled?('certs')
5+
SSL_BUILD_DIR = param('certs', 'ssl_build_dir').value
6+
7+
def mark_for_update(cert_name, hostname = nil)
8+
path = File.join(*[SSL_BUILD_DIR, hostname, cert_name].compact)
9+
if app_value(:noop)
10+
puts "Marking certificate #{path} for update (noop)"
11+
else
12+
puts "Marking certificate #{path} for update"
13+
FileUtils.touch("#{path}.update")
14+
end
15+
end
16+
17+
if param('foreman_proxy_certs', 'foreman_proxy_fqdn')
18+
hostname = param('foreman_proxy_certs', 'foreman_proxy_fqdn').value
19+
else
20+
hostname = param('certs', 'node_fqdn').value
21+
end
22+
23+
if app_value(:certs_update_server)
24+
mark_for_update("#{hostname}-apache", hostname)
25+
mark_for_update("#{hostname}-foreman-proxy", hostname)
26+
end
27+
28+
if app_value(:certs_update_all) || app_value(:certs_update_default_ca) || app_value(:certs_reset)
29+
all_cert_names = Dir.glob(File.join(SSL_BUILD_DIR, hostname, '*.noarch.rpm')).map do |rpm|
30+
File.basename(rpm).sub(/-1\.0-\d+\.noarch\.rpm/, '')
31+
end.uniq
32+
33+
all_cert_names.each do |cert_name|
34+
mark_for_update(cert_name, hostname)
35+
end
36+
end
37+
38+
if app_value(:certs_update_server_ca) || app_value(:certs_reset)
39+
mark_for_update(:katello-server-ca)
40+
end
41+
42+
if app_value(:certs_reset) && !app_value(:noop)
43+
param('certs', 'server_cert').unset_value
44+
param('certs', 'server_key').unset_value
45+
param('certs', 'server_ca_cert').unset_value
46+
end
47+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if module_enabled?('certs')
2+
if app_value(:certs_update_server_ca) && !module_enabled?('katello')
3+
fail_and_exit("--certs-update-server-ca needs to be used with katello", 101)
4+
end
5+
6+
ca_file = param('certs', 'server_ca_cert').value
7+
cert_file = param('certs', 'server_cert').value
8+
key_file = param('certs', 'server_key').value
9+
10+
if !app_value(:certs_skip_check) && !cert_file.to_s.empty? &&
11+
(app_value(:certs_update_server_ca) || app_value(:certs_update_server))
12+
execute_command(%(katello-certs-check -c "#{cert_file}" -k "#{key_file}" -b "#{ca_file}"))
13+
end
14+
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)