Skip to content

Commit a4acbc8

Browse files
committed
(#396) Add support for adding hooks after cert creation
certbot supports different hooks. They are executed during the certificate renewal. Those hooks are configured per-certificate. Previously you had to specify all hooks during the initial certificate creation. If a hook was added afterwards in Puppet, it was written to disk as a shell script, but it wasn't added to the configuration file. The config file wasn't managed with openvox at all, it was created by certbot. certbot has no cli options to update an existing config file. Because of that, we added an ini_setting resource to ensure that all hooks are added to the config file. Fixes #396
1 parent a42ea99 commit a4acbc8

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

manifests/certonly.pp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@
257257
}
258258
}
259259

260+
# certbot uses --cert-name to generate the file path
261+
$live_path_certname = regsubst($cert_name, '^\*\.', '')
262+
$live_path = "${config_dir}/live/${live_path_certname}/cert.pem"
263+
260264
$hook_args = ['pre', 'post', 'deploy'].map | String $type | {
261265
$commands = getvar("${type}_hook_commands")
262266
if (!empty($commands)) {
@@ -267,17 +271,29 @@
267271
commands => $commands,
268272
before => Exec["letsencrypt certonly ${title}"],
269273
}
274+
# if ensure is set to present, ensure that the hooks exist in the config file for the domain
275+
# this has to happen after the exec, because `certbot certonly` creates the initial config file
276+
# certbot won't update the config. But an update is required if new hooks are added afterwards
277+
#
278+
# we cannot add it to letsencrypt::hook because the defined resource runs before the Exec, not afterwards
279+
if $ensure == 'present' {
280+
ini_setting { "${title}-${type}":
281+
ensure => 'present',
282+
path => "${config_dir}/renewal/${live_path_certname}.conf",
283+
section => 'renewalparams',
284+
setting => "${type}_hook",
285+
value => $hook_file,
286+
require => Exec["letsencrypt certonly ${title}"],
287+
}
288+
}
289+
270290
"--${type}-hook \"${hook_file}\""
271291
}
272292
else {
273293
undef
274294
}
275295
}
276296

277-
# certbot uses --cert-name to generate the file path
278-
$live_path_certname = regsubst($cert_name, '^\*\.', '')
279-
$live_path = "${config_dir}/live/${live_path_certname}/cert.pem"
280-
281297
$_command = flatten(
282298
[
283299
$letsencrypt_command,

0 commit comments

Comments
 (0)