Skip to content

Commit 3dc3c6d

Browse files
committed
Manager certificate permissions if manage_certificates true
Signed-off-by: Eric D. Helms <[email protected]>
1 parent af23995 commit 3dc3c6d

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

manifests/config.pp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,60 @@
133133
}
134134
}
135135
}
136+
137+
if $foreman_proxy::manage_certificates {
138+
file { "${foreman_proxy::config_dir}/ssl_ca.pem":
139+
ensure => file,
140+
source => $foreman_proxy::ssl_ca,
141+
owner => 'root',
142+
group => $foreman_proxy::group,
143+
mode => '0440',
144+
}
145+
146+
file { "${foreman_proxy::config_dir}/ssl_cert.pem":
147+
ensure => file,
148+
source => $foreman_proxy::ssl_cert,
149+
owner => 'root',
150+
group => $foreman_proxy::group,
151+
mode => '0440',
152+
}
153+
154+
file { "${foreman_proxy::config_dir}/ssl_key.pem":
155+
ensure => file,
156+
source => $foreman_proxy::ssl_key,
157+
owner => 'root',
158+
group => $foreman_proxy::group,
159+
mode => '0440',
160+
}
161+
162+
if $foreman_proxy::foreman_ssl_ca {
163+
file { "${foreman_proxy::config_dir}/foreman_ssl_ca.pem":
164+
ensure => file,
165+
source => $foreman_proxy::foreman_ssl_ca,
166+
owner => 'root',
167+
group => $foreman_proxy::group,
168+
mode => '0440',
169+
}
170+
}
171+
172+
if $foreman_proxy::foreman_ssl_cert {
173+
file { "${foreman_proxy::config_dir}/foreman_ssl_cert.pem":
174+
ensure => file,
175+
source => $foreman_proxy::foreman_ssl_cert,
176+
owner => 'root',
177+
group => $foreman_proxy::group,
178+
mode => '0440',
179+
}
180+
}
181+
182+
if $foreman_proxy::foreman_ssl_key {
183+
file { "${foreman_proxy::config_dir}/foreman_ssl_key.pem":
184+
ensure => file,
185+
source => $foreman_proxy::foreman_ssl_key,
186+
owner => 'root',
187+
group => $foreman_proxy::group,
188+
mode => '0440',
189+
}
190+
}
191+
}
136192
}

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@
282282
# $manage_service:: control the service, whether it should be started / enabled or not. useful, if the
283283
# service should be managed by a cluster software e.g. corosync / pacemaker
284284
#
285+
# $manage_certificates:: control the location, ownership and permissions of the certificates
286+
#
287+
#
285288
class foreman_proxy (
286289
String $version = 'present',
287290
Enum['latest', 'present', 'installed', 'absent'] $ensure_packages_version = 'installed',
@@ -420,6 +423,7 @@
420423
String $oauth_consumer_key = $foreman_proxy::params::oauth_consumer_key,
421424
String $oauth_consumer_secret = $foreman_proxy::params::oauth_consumer_secret,
422425
Optional[Stdlib::HTTPUrl] $registration_url = undef,
426+
Boolean $manage_certificates = false,
423427
) inherits foreman_proxy::params {
424428
if $bind_host =~ String {
425429
warning('foreman_proxy::bind_host should be changed to an array, support for string only is deprecated')

spec/classes/foreman_proxy__spec.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,76 @@ class { 'foreman_proxy::globals':
10471047

10481048
it { should contain_user("#{proxy_user_name}").with_shell('/dne/foo') }
10491049
end
1050+
1051+
describe 'manage_certificates' do
1052+
let(:params) do
1053+
super().merge(
1054+
manage_certificates: true,
1055+
)
1056+
end
1057+
1058+
context 'when ssl_ca, ssl_cert and ssl_key are defined' do
1059+
it { should compile.with_all_deps }
1060+
1061+
it do
1062+
should contain_file('/etc/foreman-proxy/ssl_ca.pem')
1063+
.with_owner('root')
1064+
.with_group('foreman-proxy')
1065+
.with_mode('0440')
1066+
end
1067+
it do
1068+
should contain_file('/etc/foreman-proxy/ssl_cert.pem')
1069+
.with_owner('root')
1070+
.with_group('foreman-proxy')
1071+
.with_mode('0440')
1072+
end
1073+
it do
1074+
should contain_file('/etc/foreman-proxy/ssl_key.pem')
1075+
.with_owner('root')
1076+
.with_group('foreman-proxy')
1077+
.with_mode('0440')
1078+
end
1079+
1080+
it { should_not contain_file('/etc/foreman-proxy/foreman_ssl_ca.pem') }
1081+
it { should_not contain_file('/etc/foreman-proxy/foreman_ssl_cert.pem') }
1082+
it { should_not contain_file('/etc/foreman-proxy/foreman_ssl_key.pem') }
1083+
end
1084+
1085+
context 'when foreman_ssl_ca, foreman_ssl_cert and foreman_ssl_key are defined' do
1086+
let(:params) do
1087+
super().merge(
1088+
manage_certificates: true,
1089+
foreman_ssl_ca: '/root/certificates/ca.pem',
1090+
foreman_ssl_cert: '/root/certificates/cert.pem',
1091+
foreman_ssl_key: '/root/certificates/key.pem',
1092+
)
1093+
end
1094+
1095+
it { should compile.with_all_deps }
1096+
1097+
it do
1098+
should contain_file('/etc/foreman-proxy/foreman_ssl_ca.pem')
1099+
.with_source('/root/certificates/ca.pem')
1100+
.with_owner('root')
1101+
.with_group('foreman-proxy')
1102+
.with_mode('0440')
1103+
end
1104+
it do
1105+
should contain_file('/etc/foreman-proxy/foreman_ssl_cert.pem')
1106+
.with_source('/root/certificates/cert.pem')
1107+
.with_owner('root')
1108+
.with_group('foreman-proxy')
1109+
.with_mode('0440')
1110+
end
1111+
it do
1112+
should contain_file('/etc/foreman-proxy/foreman_ssl_key.pem')
1113+
.with_source('/root/certificates/key.pem')
1114+
.with_owner('root')
1115+
.with_group('foreman-proxy')
1116+
.with_mode('0440')
1117+
end
1118+
end
1119+
end
10501120
end
10511121
end
10521122
end

0 commit comments

Comments
 (0)