-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(systemd): Add certhub-cert-send service with configurable destin…
…ations (#42)
- Loading branch information
Showing
15 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
certhub-cert-send@.service | ||
========================== | ||
|
||
Synopsis | ||
-------- | ||
|
||
**certhub-cert-send@.service** | ||
|
||
**certhub-cert-send@.path** | ||
|
||
|
||
Description | ||
----------- | ||
|
||
A service which a sends certificate to predefined destinations. The specified | ||
command line is executed once for each destination with the certificate piped | ||
to stdin. | ||
|
||
A path unit which runs the service unit whenever the exported certificate has | ||
changed on the filesystem. | ||
|
||
The instance name (systemd instance string specifier ``%i``) is used as the | ||
basename of the configuration and the certificate file. | ||
|
||
|
||
Environment | ||
----------- | ||
|
||
.. envvar:: CERTHUB_CERT_SEND_SRC | ||
|
||
Path to the certificate file to be sent. Defaults to: | ||
``/var/lib/certhub/certs/%i.fullchain.pem`` | ||
|
||
.. envvar:: CERTHUB_CERT_SEND_CONFIG | ||
|
||
Path to a file containing destinations for the certificate send service. | ||
``/etc/certhub/%i.destinations-send.txt`` | ||
|
||
.. envvar:: CERTHUB_CERT_SEND_COMMAND | ||
|
||
Command to execute for each predefined destination. Use ``%i`` to reference | ||
the instance name. The command is run once for each line in the | ||
``%i.destinations-send.txt`` config file, the line can be referenced with | ||
the ``{DESTINATION}}`` placeholder. | ||
|
||
Defaults to: ``mail -s '[Certhub] Issue/renew %i' {DESTINATION}`` | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
Configuration file (placed in ``/etc/certhub/%i.destinations-send.txt``) | ||
containing one destination to send the certificate to ``root@localhost`` | ||
whenever a new one has been exported. | ||
|
||
:: | ||
|
||
root@localhost | ||
|
||
|
||
Files | ||
----- | ||
|
||
.. envfile:: /etc/certhub/env | ||
|
||
Optional environment file shared by all instances and certhub services. | ||
|
||
.. envfile:: /etc/certhub/%i.env | ||
|
||
Optional per-instance environment file shared by all certhub services. | ||
|
||
.. envfile:: /etc/certhub/certhub-cert-send.env | ||
|
||
Optional per-service environment file shared by all certhub service | ||
instances. | ||
|
||
.. envfile:: /etc/certhub/%i.certhub-cert-send.env | ||
|
||
Optional per-instance and per-service environment file. | ||
|
||
|
||
See Also | ||
-------- | ||
|
||
:manpage:`certhub-cert-export@.service(8)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -u | ||
set -x | ||
|
||
MAILBIN=/usr/local/bin/mail | ||
test ! -e "${MAILBIN}" | ||
|
||
WORKDIR=$(mktemp -d) | ||
MAILOUT="${WORKDIR}/mail.out" | ||
cleanup() { | ||
# Show logs from systemd unit | ||
journalctl -u certhub-cert-send@send-test-with-multi.service | ||
# Remove working directory | ||
rm -rf "${WORKDIR}" | ||
rm -f "${MAILBIN}" | ||
} | ||
trap cleanup EXIT | ||
|
||
chgrp certhub "${WORKDIR}" | ||
chmod 770 "${WORKDIR}" | ||
|
||
systemctl daemon-reload | ||
|
||
# Generate fake self-signed certificates. | ||
openssl req -x509 -nodes -batch -newkey rsa:1024 -keyout /dev/null -out "/var/lib/certhub/certs/send-test-with-multi.fullchain.pem" | ||
|
||
# Generate a fake mail-command. | ||
cat <<EOF > "${MAILBIN}" | ||
#!/bin/sh | ||
echo "Fake mail-command called with args: \${@}" >&2 | ||
set -e | ||
set -u | ||
{ | ||
printf "%q " "\${@}" | ||
echo | ||
cat | ||
} >> "${MAILOUT}" | ||
EOF | ||
chmod +x "${MAILBIN}" | ||
|
||
# Generate expected output from fake-mail. | ||
MAILEXPECT="${WORKDIR}/mail.expect" | ||
{ | ||
printf "%q " "-s" "[Certhub] Issue/renew send-test-with-multi" "root@localhost" | ||
echo | ||
cat "/var/lib/certhub/certs/send-test-with-multi.fullchain.pem" | ||
printf "%q " "-s" "[Certhub] Issue/renew send-test-with-multi" "admin@example.com" | ||
echo | ||
cat "/var/lib/certhub/certs/send-test-with-multi.fullchain.pem" | ||
} > "${MAILEXPECT}" | ||
|
||
# Configuration file. | ||
cat <<EOF > /etc/certhub/send-test-with-multi.destinations-send.txt | ||
root@localhost | ||
admin@example.com | ||
EOF | ||
|
||
# Expect send output for send-test-with-multi absent | ||
test ! -e "${MAILOUT}" | ||
|
||
# Run certhub-cert-send | ||
systemctl start certhub-cert-send@send-test-with-multi.service | ||
|
||
# Expect send output for send-test-with-multi present | ||
diff -s "${MAILOUT}" "${MAILEXPECT}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[Unit] | ||
Description=Send certificates to predefined destinations when certificate changed | ||
|
||
[Install] | ||
WantedBy=paths.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dropins/export.path.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Send certificates to predefined destinations | ||
|
||
[Service] | ||
Type=oneshot | ||
|
||
ExecStart=/usr/bin/env \ | ||
xargs -a ${CERTHUB_CERT_SEND_CONFIG} -I{DESTINATION} \ | ||
certhub-send-file ${CERTHUB_CERT_SEND_SRC} $CERTHUB_CERT_SEND_COMMAND | ||
|
||
SyslogIdentifier=certhub-cert-send | ||
StandardOutput=syslog | ||
StandardError=syslog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dropins/certhub-paths.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dropins/certhub-user.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../dropins/send.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Service] | ||
|
||
# CERTHUB_CERT_SEND_COMMAND | ||
# Command to execute for each predefined destination. Use ``%i`` to reference | ||
# the instance name. The command is run once for each line in the | ||
# ``%i.destinations-send.txt`` config file, the line can be referenced with the | ||
# ``{DESTINATION}}`` placeholder. | ||
Environment="CERTHUB_CERT_SEND_COMMAND=mail -s '[Certhub] Issue/renew %i' {DESTINATION}" |