Skip to content

Commit 340c8ee

Browse files
committed
Generate a ca-bundle of the default and server certificates
1 parent 376c05c commit 340c8ee

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fixtures:
22
repositories:
3+
concat: "https://github.com/puppetlabs/puppetlabs-concat"
34
extlib: "https://github.com/voxpupuli/puppet-extlib"
45
foreman: "https://github.com/theforeman/puppet-foreman"
56
redis: "https://github.com/voxpupuli/puppet-redis"

manifests/ca.pp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
) {
2121
$default_ca_path = "${certs::ssl_build_dir}/${default_ca_name}.crt"
2222
$server_ca_path = "${certs::ssl_build_dir}/${server_ca_name}.crt"
23+
$ca_bundle_path = "${certs::ssl_build_dir}/ca-bundle.crt"
2324

2425
file { $ca_key_password_file:
2526
ensure => file,
@@ -51,6 +52,28 @@
5152
group => 'root',
5253
mode => '0644',
5354
}
55+
56+
concat { $ca_bundle_path:
57+
ensure => present,
58+
}
59+
60+
concat::fragment { 'default-ca':
61+
target => $ca_bundle_path,
62+
source => $default_ca_path,
63+
order => '01',
64+
}
65+
66+
if $certs::server_ca_cert {
67+
concat::fragment { 'server-ca':
68+
target => $ca_bundle_path,
69+
source => $server_ca_path,
70+
order => '02',
71+
}
72+
}
73+
74+
file { "${certs::ssl_build_dir}/KATELLO-TRUSTED-SSL-CERT":
75+
ensure => absent,
76+
}
5477
}
5578

5679
if $deploy {

spec/acceptance/certs_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
its(:keylength) { should be >= 4096 }
3333
end
3434

35+
describe ca_bundle('/root/ssl-build/ca-bundle.crt') do
36+
it { should exist }
37+
its(:size) { should equal 1 }
38+
it { should have_cert('/root/ssl-build/katello-default-ca.crt') }
39+
end
40+
3541
describe x509_private_key('/root/ssl-build/katello-default-ca.key') do
3642
it { should be_encrypted }
3743
end
@@ -150,5 +156,12 @@ class { 'certs':
150156
its(:subject) { should match_without_whitespace(/CN = Fake LE Intermediate X1/) }
151157
its(:keylength) { should be >= 2048 }
152158
end
159+
160+
describe ca_bundle('/root/ssl-build/ca-bundle.crt') do
161+
it { should exist }
162+
its(:size) { should equal 1 }
163+
it { should have_cert('/root/ssl-build/katello-default-ca.crt') }
164+
it { should have_cert('/root/ssl-build/katello-server-ca.crt') }
165+
end
153166
end
154167
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
begin
2+
require 'serverspec'
3+
rescue LoadError
4+
# Not using acceptance tests
5+
else
6+
module Serverspec
7+
module Type
8+
class CaBundle < Base
9+
def content
10+
if @content.nil?
11+
@content = load_fullchain(@runner.get_file_content(@name).stdout)
12+
end
13+
@content
14+
end
15+
16+
def exist?
17+
@runner.check_file_exists(@name)
18+
end
19+
20+
def size
21+
content.length
22+
end
23+
24+
def has_cert?(file_path)
25+
target_cert = OpenSSL::X509::Certificate.new(@runner.get_file_content(file_path).stdout)
26+
content.any? do |actual_cert|
27+
target_cert = actual_cert
28+
end
29+
end
30+
31+
def load_fullchain(bundle_pem)
32+
bundle_pem.
33+
lines.
34+
slice_after(/^-----END CERTIFICATE-----/).
35+
filter { |pem| pem.join.include?('-----END CERTIFICATE-----') }.
36+
map { |pem| OpenSSL::X509::Certificate.new(pem.join) }
37+
end
38+
end
39+
end
40+
41+
module Helper
42+
module Type
43+
def ca_bundle(*args)
44+
Serverspec::Type::CaBundle.new(*args)
45+
end
46+
end
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)