Skip to content

Commit dc92400

Browse files
committed
Don't generate a CA if a tar file is provided
The tar file contains both the default and server CA files that are needed. It actually overwrote the files from the tar file.
1 parent a236b33 commit dc92400

File tree

3 files changed

+140
-35
lines changed

3 files changed

+140
-35
lines changed

manifests/ca.pp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,43 @@
2424
$default_ca_path = "${certs::ssl_build_dir}/${default_ca_name}.crt"
2525
$server_ca_path = "${certs::ssl_build_dir}/${server_ca_name}.crt"
2626

27-
file { $ca_key_password_file:
28-
ensure => file,
29-
content => $ca_key_password,
30-
owner => 'root',
31-
group => 'root',
32-
mode => '0400',
33-
show_diff => false,
34-
} ~>
35-
ca { $default_ca_name:
36-
ensure => present,
37-
common_name => $ca_common_name,
38-
country => $country,
39-
state => $state,
40-
city => $city,
41-
org => $org,
42-
org_unit => $org_unit,
43-
expiration => $ca_expiration,
44-
generate => $generate,
45-
password_file => $ca_key_password_file,
46-
build_dir => $certs::ssl_build_dir,
47-
}
27+
unless $certs::tar_file {
28+
file { $ca_key_password_file:
29+
ensure => file,
30+
content => $ca_key_password,
31+
owner => 'root',
32+
group => 'root',
33+
mode => '0400',
34+
show_diff => false,
35+
} ~>
36+
ca { $default_ca_name:
37+
ensure => present,
38+
common_name => $ca_common_name,
39+
country => $country,
40+
state => $state,
41+
city => $city,
42+
org => $org,
43+
org_unit => $org_unit,
44+
expiration => $ca_expiration,
45+
generate => $generate,
46+
password_file => $ca_key_password_file,
47+
build_dir => $certs::ssl_build_dir,
48+
}
4849

49-
file { $server_ca_path:
50-
ensure => file,
51-
source => pick($certs::server_ca_cert, $default_ca_path),
52-
owner => 'root',
53-
group => 'root',
54-
mode => '0644',
55-
}
50+
file { $server_ca_path:
51+
ensure => file,
52+
source => pick($certs::server_ca_cert, $default_ca_path),
53+
owner => 'root',
54+
group => 'root',
55+
mode => '0644',
56+
}
5657

57-
if $generate {
58-
file { "${certs::ssl_build_dir}/KATELLO-TRUSTED-SSL-CERT":
59-
ensure => link,
60-
target => $server_ca_path,
61-
require => File[$server_ca_path],
58+
if $generate {
59+
file { "${certs::ssl_build_dir}/KATELLO-TRUSTED-SSL-CERT":
60+
ensure => link,
61+
target => $server_ca_path,
62+
require => File[$server_ca_path],
63+
}
6264
}
6365
}
6466

manifests/init.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113
certs::tar_extract { $tar_file:
114114
before => Class['certs::install'],
115115
}
116+
$default_ca = undef
117+
} else {
118+
$default_ca = Ca[$default_ca_name]
116119
}
117120

118121
contain certs::install
@@ -122,6 +125,4 @@
122125
Class['certs::install'] ->
123126
Class['certs::config'] ->
124127
Class['certs::ca']
125-
126-
$default_ca = Ca[$default_ca_name]
127128
}

spec/acceptance/certs_spec.rb

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

0 commit comments

Comments
 (0)