Skip to content

Commit 3ac4e25

Browse files
committed
Fixes #37817: Only copy server CA in build root if generate is true
1 parent 142df44 commit 3ac4e25

File tree

2 files changed

+128
-17
lines changed

2 files changed

+128
-17
lines changed

manifests/ca.pp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@
4545
build_dir => $certs::ssl_build_dir,
4646
}
4747

48-
if $certs::server_ca_cert {
49-
file { $server_ca_path:
50-
ensure => file,
51-
source => $certs::server_ca_cert,
52-
owner => 'root',
53-
group => 'root',
54-
mode => '0644',
55-
}
56-
} else {
57-
file { $server_ca_path:
58-
ensure => file,
59-
source => "${certs::ssl_build_dir}/${default_ca_name}.crt",
60-
owner => 'root',
61-
group => 'root',
62-
mode => '0644',
48+
if $generate {
49+
if $certs::server_ca_cert {
50+
file { $server_ca_path:
51+
ensure => file,
52+
source => $certs::server_ca_cert,
53+
owner => 'root',
54+
group => 'root',
55+
mode => '0644',
56+
}
57+
} else {
58+
file { $server_ca_path:
59+
ensure => file,
60+
source => "${certs::ssl_build_dir}/${default_ca_name}.crt",
61+
owner => 'root',
62+
group => 'root',
63+
mode => '0644',
64+
}
6365
}
64-
}
6566

66-
if $generate {
6767
file { "${certs::ssl_build_dir}/KATELLO-TRUSTED-SSL-CERT":
6868
ensure => link,
6969
target => $server_ca_path,

spec/acceptance/certs_spec.rb

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,115 @@ class { 'certs':
151151
its(:keylength) { should be >= 2048 }
152152
end
153153
end
154+
155+
context 'with tar file' do
156+
before(:context) do
157+
['crt', 'key'].each do |ext|
158+
source_path = "fixtures/example.partial.solutions.#{ext}"
159+
dest_path = "/server.#{ext}"
160+
scp_to(hosts, source_path, dest_path)
161+
end
162+
end
163+
164+
context 'with default ca' do
165+
before(:context) do
166+
manifest = <<~PUPPET
167+
class { 'certs':
168+
generate => true,
169+
deploy => false,
170+
}
171+
172+
class { 'certs::foreman_proxy_content':
173+
foreman_proxy_fqdn => 'foreman-proxy.example.com',
174+
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
175+
}
176+
PUPPET
177+
178+
apply_manifest(manifest, catch_failures: true)
179+
180+
on default, 'rm -rf /root/ssl-build'
181+
end
182+
183+
describe 'deploy certificates' do
184+
manifest = <<-PUPPET
185+
class { 'certs':
186+
tar_file => '/root/foreman-proxy.example.com.tar.gz',
187+
}
188+
PUPPET
189+
# tar extraction is not idempotent
190+
it { apply_manifest(manifest, catch_failures: true) }
191+
end
192+
193+
describe 'default and server ca certs match' do
194+
it { expect(file('/etc/pki/katello/certs/katello-default-ca.crt').content).to eq(file('/etc/pki/katello/certs/katello-server-ca.crt').content) }
195+
end
196+
197+
describe x509_certificate('/etc/pki/katello/certs/katello-default-ca.crt') do
198+
it { should be_certificate }
199+
it { should be_valid }
200+
it { should have_purpose 'SSL server CA' }
201+
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
202+
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
203+
its(:keylength) { should be >= 4096 }
204+
end
205+
end
206+
207+
context 'with custom certificates' do
208+
before(:context) do
209+
manifest = <<~PUPPET
210+
class { 'certs':
211+
server_cert => '/server.crt',
212+
server_key => '/server.key',
213+
server_ca_cert => '/server-ca.crt',
214+
generate => true,
215+
deploy => false,
216+
}
217+
218+
class { 'certs::foreman_proxy_content':
219+
foreman_proxy_fqdn => 'foreman-proxy.example.com',
220+
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
221+
}
222+
PUPPET
223+
224+
apply_manifest(manifest, catch_failures: true)
225+
226+
on default, 'rm -rf /root/ssl-build'
227+
end
228+
229+
describe 'deploy certificates' do
230+
manifest = <<-PUPPET
231+
class { 'certs':
232+
generate => false,
233+
tar_file => '/root/foreman-proxy.example.com.tar.gz',
234+
}
235+
PUPPET
236+
# tar extraction is not idempotent
237+
it { apply_manifest(manifest, catch_failures: true) }
238+
end
239+
240+
describe 'default and server ca certs match' do
241+
it { expect(file('/etc/pki/katello/certs/katello-default-ca.crt').content).not_to eq(file('/etc/pki/katello/certs/katello-server-ca.crt').content) }
242+
end
243+
244+
describe x509_certificate('/etc/pki/katello/certs/katello-default-ca.crt') do
245+
it { should be_certificate }
246+
it { should be_valid }
247+
it { should have_purpose 'SSL server CA' }
248+
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
249+
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
250+
its(:keylength) { should be >= 4096 }
251+
end
252+
253+
describe x509_certificate('/etc/pki/katello/certs/katello-server-ca.crt') do
254+
it { should be_certificate }
255+
it { should be_valid }
256+
it { should have_purpose 'SSL server CA' }
257+
# These don't match since we only configure it with the intermediate
258+
# and not the actual root
259+
its(:issuer) { should match_without_whitespace(/CN = Fake LE Root X1/) }
260+
its(:subject) { should match_without_whitespace(/CN = Fake LE Intermediate X1/) }
261+
its(:keylength) { should be >= 2048 }
262+
end
263+
end
264+
end
154265
end

0 commit comments

Comments
 (0)