forked from theforeman/puppet-certs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.pp
221 lines (202 loc) · 6.98 KB
/
init.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# == Class: certs
#
# Base for installing and configuring certs. It holds the basic configuration
# aournd certificates generation and deployment. The per-subsystem configuratoin
# of certificates should go into `subsystem_module/manifests/certs.pp`.
#
# === Parameters:
#
# $log_dir:: When the log files should go
#
# $node_fqdn:: The fqdn of the host the generated certificates
# should be for
#
# $generate:: Should the generation of the certs be part of the
# configuration
# type: boolean
#
# $regenerate:: Force regeneration of the certificates (excluding
# ca certificates)
# type: boolean
#
# $regenerate_ca:: Force regeneration of the ca certificate
# type: boolean
#
# $deploy:: Deploy the certs on the configured system. False means
# we want apply it on a different system
# type: boolean
#
# $ca_common_name:: Common name for the generated CA certificate
# type: string
#
# $country:: Country attribute for managed certificates
# type: string
#
# $state:: State attribute for managed certificates
# type: string
#
# $city:: City attribute for managed certificates
# type: string
#
# $org:: Org attribute for managed certificates
# type: string
#
# $org_unit:: Org unit attribute for managed certificates
# type: string
#
# $expiration:: Expiration attribute for managed certificates
# type: string
#
# $ca_expiration:: Ca expiration attribute for managed certificates
# type: string
#
# $server_ca_cert:: Path to the CA that issued the ssl certificates for https
# if not specified, the default CA will be used
#
# $server_cert:: Path to the ssl certificate for https
# if not specified, the default CA will generate one
#
# $server_key:: Path to the ssl key for https
# if not specified, the default CA will generate one
#
# $server_cert_req:: Path to the ssl certificate request for https
# if not specified, the default CA will generate one
#
# $pki_dir:: The PKI directory under which to place certs
#
# $ssl_build_dir:: The directory where SSL keys, certs and RPMs will be generated
#
# $user:: The system user name who should own the certs;
#
# $group:: The group who should own the certs;
#
# $password_file_dir:: The location to store password files
#
# $default_ca_name:: The name of the default CA
#
# $server_ca_name:: The name of the server CA (used for https)
#
class certs (
$log_dir = $certs::params::log_dir,
$node_fqdn = $certs::params::node_fqdn,
$generate = $certs::params::generate,
$regenerate = $certs::params::regenerate,
$regenerate_ca = $certs::params::regenerate_ca,
$deploy = $certs::params::deploy,
$ca_common_name = $certs::params::ca_common_name,
$country = $certs::params::country,
$state = $certs::params::state,
$city = $certs::params::city,
$org = $certs::params::org,
$org_unit = $certs::params::org_unit,
$expiration = $certs::params::expiration,
$ca_expiration = $certs::params::ca_expiration,
$server_cert = $certs::params::server_cert,
$server_key = $certs::params::server_key,
$server_cert_req = $certs::params::server_cert_req,
$server_ca_cert = $certs::params::server_ca_cert,
$pki_dir = $certs::params::pki_dir,
$ssl_build_dir = $certs::params::ssl_build_dir,
$password_file_dir = $certs::params::password_file_dir,
$user = $certs::params::user,
$group = $certs::params::group,
$default_ca_name = $certs::params::default_ca_name,
$server_ca_name = $certs::params::server_ca_name
) inherits certs::params {
if $server_cert {
validate_file_exists($server_cert, $server_cert_req, $server_key, $server_ca_cert)
}
$nss_db_dir = "${pki_dir}/nssdb"
$ca_key = "${certs::pki_dir}/private/${default_ca_name}.key"
$ca_cert = "${certs::pki_dir}/certs/${default_ca_name}.crt"
$ca_cert_stripped = "${certs::pki_dir}/certs/${default_ca_name}-stripped.crt"
$ca_key_password = cache_data('ca_key_password', generate_password())
$ca_key_password_file = "${certs::pki_dir}/private/${default_ca_name}.pwd"
$katello_server_ca_cert = "${certs::pki_dir}/certs/${server_ca_name}.crt"
class { 'certs::install': } ->
class { 'certs::config': } ->
file { $ca_key_password_file:
ensure => file,
content => $ca_key_password,
owner => 'root',
group => 'root',
mode => '0400'
} ~>
ca { $default_ca_name:
ensure => present,
common_name => $certs::ca_common_name,
country => $certs::country,
state => $certs::state,
city => $certs::city,
org => $certs::org,
org_unit => $certs::org_unit,
expiration => $certs::ca_expiration,
generate => $certs::generate,
deploy => $certs::deploy,
password_file => $ca_key_password_file
}
$default_ca = Ca[$default_ca_name]
if $certs::server_cert {
ca { $certs::server_ca_name:
ensure => present,
generate => $certs::generate,
deploy => $certs::deploy,
custom_pubkey => $certs::server_ca_cert,
}
} else {
ca { $certs::server_ca_name:
ensure => present,
generate => $certs::generate,
deploy => $certs::deploy,
ca => $certs::default_ca,
}
}
$server_ca = Ca[$certs::server_ca_name]
if $certs::generate {
file { "${ssl_build_dir}/KATELLO-TRUSTED-SSL-CERT":
ensure => link,
target => "${ssl_build_dir}/${certs::server_ca_name}.crt",
require => $server_ca,
}
}
if $deploy {
Ca[$default_ca_name] ~>
pubkey { $ca_cert:
key_pair => $default_ca
} ~>
pubkey { $ca_cert_stripped:
strip => true,
key_pair => $default_ca
} ~>
file { $ca_cert:
ensure => file,
owner => 'root',
group => $certs::group,
mode => '0644',
}
Ca[$server_ca_name] ~>
pubkey { $katello_server_ca_cert:
key_pair => $server_ca
} ~>
file { $katello_server_ca_cert:
ensure => file,
owner => 'root',
group => $certs::group,
mode => '0644',
}
if $generate {
Ca[$default_ca_name] ~>
privkey { $ca_key:
key_pair => $default_ca,
unprotect => true,
password_file => $ca_key_password_file
} ~>
file { $ca_key:
ensure => file,
owner => 'root',
group => $certs::group,
mode => '0440',
}
}
}
}