18 changed files with 96 additions and 65 deletions
@ -1,3 +1,3 @@ |
|||||
LEGO_GLOBAL_ARGS=-a -m nicolas.masse@itix.fr -d changeme.example.tld --http |
LEGO_GLOBAL_ARGS=-a -m nicolas.masse@itix.fr -d changeme.example.tld --http |
||||
LEGO_RUN_ARGS= |
LEGO_RUN_ARGS= |
||||
LEGO_RENEW_ARGS=--days 30 --renew-hook=/etc/lego/hooks/flag-as-renewed.sh |
LEGO_RENEW_ARGS=--days 30 --renew-hook=/etc/lego/renew-hook/flag-as-renewed.sh |
||||
|
|||||
@ -0,0 +1,19 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
set -Eeuo pipefail |
||||
|
|
||||
|
# In development mode, it is not possible to get a certificate from Let's Encrypt, so we just create a self-signed certificate for localhost, so that other services can still use it. |
||||
|
mkdir -p /var/lib/quadlets/lego/certificates |
||||
|
if [ -f /var/lib/quadlets/lego/certificates/localhost.crt ] && [ -f /var/lib/quadlets/lego/certificates/localhost.key ]; then |
||||
|
renewal="yes" |
||||
|
else |
||||
|
renewal="no" |
||||
|
fi |
||||
|
|
||||
|
echo "Generating self-signed certificate for localhost..." |
||||
|
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /var/lib/quadlets/lego/certificates/localhost.key -out /var/lib/quadlets/lego/certificates/localhost.crt -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost" |
||||
|
|
||||
|
if [[ "$renewal" == "yes" ]]; then |
||||
|
echo "Flagging certificate as renewed..." |
||||
|
touch /var/lib/quadlets/lego/certificates/localhost.renewed |
||||
|
fi |
||||
@ -0,0 +1,18 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
set -Eeuo pipefail |
||||
|
|
||||
|
for hook in /etc/quadlets/lego/renew-hooks.d/*.sh; do |
||||
|
if [[ -x "$hook" ]]; then |
||||
|
echo "Running renew hook: $hook" |
||||
|
if ! "$hook"; then |
||||
|
echo "Error: Renew hook failed: $hook" >&2 |
||||
|
fi |
||||
|
else |
||||
|
echo "Skipping non-executable hook: $hook" |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
rm -f /var/lib/quadlets/lego/certificates/*.renewed |
||||
|
|
||||
|
exit 0 |
||||
@ -0,0 +1,7 @@ |
|||||
|
[Container] |
||||
|
# When in development mode, it is not possible to renew a certificate from Let's Encrypt, so we just skip the entrypoint. |
||||
|
Entrypoint=/bin/true |
||||
|
|
||||
|
[Service] |
||||
|
# And we update the self-signed certificate and flag it as renewed. |
||||
|
ExecStartPost=/etc/quadlets/lego/lego-dev.sh |
||||
@ -0,0 +1,7 @@ |
|||||
|
[Container] |
||||
|
# When in development mode, it is not possible to get a certificate from Let's Encrypt, so we just skip the entrypoint. |
||||
|
Entrypoint=/bin/true |
||||
|
|
||||
|
[Service] |
||||
|
# And we create a self-signed certificate for localhost, so that other services can still use it. |
||||
|
ExecStartPost=/etc/quadlets/lego/lego-dev.sh |
||||
@ -0,0 +1,5 @@ |
|||||
|
# Lego renewal hooks
|
||||
|
TARGET_LEGO_FILES = $(patsubst other/lego/%.sh, $(TARGET_CHROOT)/etc/quadlets/lego/renew-hooks.d/%.sh, $(wildcard other/lego/*.sh)) |
||||
|
TARGET_EXAMPLE_FILES += $(TARGET_LEGO_FILES) |
||||
|
$(TARGET_CHROOT)/etc/quadlets/lego/renew-hooks.d/%.sh: other/lego/%.sh |
||||
|
install -D -m 0755 -o root -g root $< $@ |
||||
@ -0,0 +1,12 @@ |
|||||
|
[Unit] |
||||
|
Description=Process Lego certificate renewal hooks |
||||
|
# Lego touches .renewed files when renewed certificates are available |
||||
|
ConditionPathExistsGlob=/var/lib/quadlets/lego/certificates/*.renewed |
||||
|
After=lego-renew.service |
||||
|
|
||||
|
[Service] |
||||
|
Type=oneshot |
||||
|
ExecStart=/etc/quadlets/lego/process-hooks.sh |
||||
|
|
||||
|
[Install] |
||||
|
WantedBy=lego-renew.service |
||||
@ -0,0 +1,6 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
set -Eeuo pipefail |
||||
|
|
||||
|
/etc/quadlets/quay/quay_load_tls_certs.sh |
||||
|
systemctl --no-block restart quay-app.service |
||||
@ -1,15 +0,0 @@ |
|||||
[Unit] |
|
||||
Description=Initialize Quay TLS certificates if not already present |
|
||||
Before=quay-app.service |
|
||||
After=lego.target |
|
||||
|
|
||||
# Start/stop this unit when the target is started/stopped |
|
||||
PartOf=quay.target |
|
||||
|
|
||||
[Service] |
|
||||
Type=oneshot |
|
||||
RemainAfterExit=yes |
|
||||
ExecStart=/etc/quadlets/quay/quay_load_tls_certs.sh |
|
||||
|
|
||||
[Install] |
|
||||
WantedBy=quay.target |
|
||||
@ -1,17 +0,0 @@ |
|||||
[Unit] |
|
||||
Description=Reload Quay TLS certificate after Lego renewal |
|
||||
# Lego touches .renewed files when renewed certificates are available |
|
||||
ConditionPathExistsGlob=/var/lib/quadlets/lego/certificates/*.renewed |
|
||||
After=lego-renew.service |
|
||||
|
|
||||
[Service] |
|
||||
Type=oneshot |
|
||||
# Copy the renewed certificates to the Quay TLS directory |
|
||||
ExecStart=/etc/quadlets/quay/quay_load_tls_certs.sh |
|
||||
# Restart Quay to load the new certificate |
|
||||
ExecStart=systemctl --no-block restart quay-app.service |
|
||||
# Remove the flag files after restarting Quay |
|
||||
ExecStartPost=/bin/sh -Eeuo pipefail -c 'rm -f /var/lib/quadlets/lego/certificates/*.renewed' |
|
||||
|
|
||||
[Install] |
|
||||
WantedBy=lego-renew.service |
|
||||
@ -0,0 +1,6 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
set -Eeuo pipefail |
||||
|
|
||||
|
install -o 10015 -g 10000 -m 0600 -t /run/quadlets/vsftpd/tls /var/lib/quadlets/lego/certificates/*.crt /var/lib/quadlets/lego/certificates/*.key |
||||
|
systemctl --no-block restart vsftpd.service |
||||
@ -1,17 +0,0 @@ |
|||||
[Unit] |
|
||||
Description=Restart Vsftpd if a new TLS certificate is available |
|
||||
# Lego touch .renewed files when renewed certificates are available |
|
||||
ConditionPathExistsGlob=/var/lib/quadlets/lego/certificates/*.renewed |
|
||||
After=lego-renew.service |
|
||||
|
|
||||
[Service] |
|
||||
Type=oneshot |
|
||||
# Copy the renewed certificates to the vsftpd /run directory |
|
||||
ExecStartPre=/bin/sh -Eeuo pipefail -c 'install -o 10015 -g 10000 -m 0600 -t /run/quadlets/vsftpd/tls /var/lib/quadlets/lego/certificates/*.crt /var/lib/quadlets/lego/certificates/*.key' |
|
||||
# Restart vsftpd to load the new certificates |
|
||||
ExecStart=systemctl --no-block restart vsftpd.service |
|
||||
# Remove the flag files after restarting vsftpd |
|
||||
ExecStartPost=/bin/sh -Eeuo pipefail -c 'rm -f /var/lib/quadlets/lego/certificates/*.renewed' |
|
||||
|
|
||||
[Install] |
|
||||
WantedBy=lego-renew.service |
|
||||
Loading…
Reference in new issue