Skip to content

Commit fc6b71d

Browse files
author
Lennart Betz
committed
add parameter ssl_key,ssl_cert, ssl_cacert to api feature
1 parent bddf8c7 commit fc6b71d

File tree

3 files changed

+150
-219
lines changed

3 files changed

+150
-219
lines changed

manifests/feature/api.pp

Lines changed: 86 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# 'puppet' copies the key, cert and CAcert from the Puppet ssl directory to the pki directory
1313
# /etc/icinga2/pki on Linux and C:/ProgramData/icinga2/etc/icinga2/pki on Windows.
1414
# 'none' does nothing and you either have to manage the files yourself as file resources
15-
# or use the ssl_key, ssl_cert, ssl_ca parameters. Defaults to puppet.
15+
# or use the ssl_key, ssl_cert, ssl_cacert parameters. Defaults to puppet.
1616
#
1717
# [*ssl_key_path*]
1818
# Location of the private key. Default depends on platform:
@@ -26,22 +26,22 @@
2626
# C:/ProgramData/icinga2/etc/icinga2/pki/NodeName.crt on Windows
2727
# The Value of NodeName comes from the corresponding constant.
2828
#
29-
# [*ssl_ca_path*]
29+
# [*ssl_cacert_path*]
3030
# Location of the CA certificate. Default is:
3131
# /etc/icinga2/pki/ca.crt on Linux
3232
# C:/ProgramData/icinga2/etc/icinga2/pki/ca.crt on Windows
3333
#
34-
# [*ssl_key*] NOT IMPLEMENTED
35-
# The private key in a base64 encoded string to store in pki directory, file is named to the constants 'NodeName'
36-
# with the suffix '.key'. For use 'pki' must set to 'none'. Defaults to undef.
34+
# [*ssl_key*]
35+
# The private key in a base64 encoded string to store in pki directory, file is stored to
36+
# path spicified in ssl_key_path. To affect this parameter pki has to set to 'none'.
3737
#
38-
# [*ssl_cert*] NOT IMPLEMENTED
39-
# The certificate in a base64 encoded string to store in pki directory, file is named to the constants 'NodeName'
40-
# with the suffix '.crt'. For use 'pki' must set to 'none'. Defaults to undef.
38+
# [*ssl_cert*]
39+
# The certificate in a base64 encoded string to store in pki directory, file is stored to
40+
# path spicified in ssl_cert_path. To affect this parameter pki has to set to 'none'.
4141
#
42-
# [*ssl_ca*] NOT IMPLEMENTED
43-
# The CA root certificate in a base64 encoded string to store in pki directory, file is named to 'ca.crt'.
44-
# For use 'pki' must set to 'none'. Defaults to undef.
42+
# [*ssl_cacert*]
43+
# The CA root certificate in a base64 encoded string to store in pki directory, file is stored
44+
# to path spicified in ssl_cacert_path. To affect this parameter pki has to set to 'none'.
4545
#
4646
# [*accept_config*]
4747
# Accept zone configuration. Defaults to false.
@@ -71,7 +71,7 @@
7171
# [*_ssl_cert_path*]
7272
# Validated path to certificate file.
7373
#
74-
# [*_ssl_ca_path*]
74+
# [*_ssl_casert_path*]
7575
# Validated path to root CA certificate file.
7676
#
7777
# === Examples
@@ -105,7 +105,7 @@
105105
#
106106
# class { 'icinga2::feature::api':
107107
# pki => 'none',
108-
# ssl_ca_cert => '-----BEGIN CERTIFICATE----- ...',
108+
# ssl_cacert => '-----BEGIN CERTIFICATE----- ...',
109109
# ssl_key => '-----BEGIN RSA PRIVATE KEY----- ...',
110110
# ssl_cert => '-----BEGIN CERTIFICATE----- ...',
111111
# }
@@ -119,12 +119,15 @@
119119
$pki = 'puppet',
120120
$ssl_key_path = undef,
121121
$ssl_cert_path = undef,
122-
$ssl_ca_path = undef,
122+
$ssl_cacert_path = undef,
123123
$accept_config = false,
124124
$accept_commands = false,
125125
$ticket_salt = 'TicketSalt',
126126
$endpoints = { 'NodeName' => {} },
127127
$zones = { 'ZoneName' => { endpoints => [ 'NodeName' ] } },
128+
$ssl_key = undef,
129+
$ssl_cert = undef,
130+
$ssl_cacert = undef,
128131
) {
129132

130133
include ::icinga2::params
@@ -162,42 +165,83 @@
162165
$_ssl_cert_path = $ssl_cert_path }
163166
else {
164167
$_ssl_cert_path = "${pki_dir}/${node_name}.crt" }
165-
if $ssl_ca_path {
166-
validate_absolute_path($ssl_ca_path)
167-
$_ssl_ca_path = $ssl_ca_path }
168+
if $ssl_cacert_path {
169+
validate_absolute_path($ssl_cacert_path)
170+
$_ssl_cacert_path = $ssl_cacert_path }
168171
else {
169-
$_ssl_ca_path = "${pki_dir}/ca.crt" }
172+
$_ssl_cacert_path = "${pki_dir}/ca.crt" }
170173

171174
# handle the certificate's stuff
172-
if $pki == 'puppet' {
173-
file { $_ssl_key_path:
174-
ensure => file,
175-
mode => $::kernel ? {
176-
'windows' => undef,
177-
default => '0600',
178-
},
179-
source => $::settings::hostprivkey,
180-
tag => 'icinga2::config::file',
181-
}
182-
183-
file { $_ssl_cert_path:
184-
ensure => file,
185-
source => $::settings::hostcert,
186-
tag => 'icinga2::config::file',
187-
}
188-
189-
file { $_ssl_ca_path:
190-
ensure => file,
191-
source => $::settings::localcacert,
192-
tag => 'icinga2::config::file',
193-
}
194-
}
175+
case $pki {
176+
'puppet': {
177+
file { $_ssl_key_path:
178+
ensure => file,
179+
mode => $::kernel ? {
180+
'windows' => undef,
181+
default => '0600',
182+
},
183+
source => $::settings::hostprivkey,
184+
tag => 'icinga2::config::file',
185+
}
186+
187+
file { $_ssl_cert_path:
188+
ensure => file,
189+
source => $::settings::hostcert,
190+
tag => 'icinga2::config::file',
191+
}
192+
193+
file { $_ssl_cacert_path:
194+
ensure => file,
195+
source => $::settings::localcacert,
196+
tag => 'icinga2::config::file',
197+
}
198+
} # puppet
199+
200+
'none': {
201+
if $ssl_key {
202+
file { $_ssl_key_path:
203+
ensure => file,
204+
mode => $::kernel ? {
205+
'windows' => undef,
206+
default => '0600',
207+
},
208+
content => $::osfamily ? {
209+
'windows' => regsubst($ssl_key, '\n', "\r\n", 'EMG'),
210+
default => $ssl_key,
211+
},
212+
tag => 'icinga2::config::file',
213+
}
214+
}
215+
216+
if $ssl_cert {
217+
file { $_ssl_cert_path:
218+
ensure => file,
219+
content => $::osfamily ? {
220+
'windows' => regsubst($ssl_cert, '\n', "\r\n", 'EMG'),
221+
default => $ssl_cert,
222+
},
223+
tag => 'icinga2::config::file',
224+
}
225+
}
226+
227+
if $ssl_cacert {
228+
file { $_ssl_cacert_path:
229+
ensure => file,
230+
content => $::osfamily ? {
231+
'windows' => regsubst($ssl_cacert, '\n', "\r\n", 'EMG'),
232+
default => $ssl_cacert,
233+
},
234+
tag => 'icinga2::config::file',
235+
}
236+
}
237+
} # none
238+
} # pki
195239

196240
# compose attributes
197241
$attrs = {
198242
cert_path => $_ssl_cert_path,
199243
key_path => $_ssl_key_path,
200-
ca_path => $_ssl_ca_path,
244+
ca_path => $_ssl_cacert_path,
201245
accept_commands => $accept_commands,
202246
accept_config => $accept_config,
203247
ticket_salt => $ticket_salt,

manifests/object.pp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,23 @@
6464
validate_absolute_path($target)
6565
validate_string($order)
6666

67-
ensure_resource('concat', $target, {
68-
ensure => present,
69-
owner => $user,
70-
group => $group,
71-
tag => 'icinga2::config::file',
72-
warn => true,
73-
})
67+
if !defined(Concat[$target]) {
68+
concat { $target:
69+
ensure => present,
70+
owner => $user,
71+
group => $group,
72+
tag => 'icinga2::config::file',
73+
warn => true,
74+
}
75+
}
7476

7577
if $ensure != 'absent' {
7678
concat::fragment { "icinga2::object::${object_type}::${object_name}":
7779
target => $target,
78-
content => template('icinga2/object.conf.erb'),
80+
content => $::osfamily ? {
81+
'windows' => regsubst(template('icinga2/object.conf.erb'), '\n', "\r\n", 'EMG'),
82+
default => template('icinga2/object.conf.erb'),
83+
},
7984
order => $order,
8085
}
8186
}

0 commit comments

Comments
 (0)