Skip to content

Commit add2e08

Browse files
andrewmzhangtashian
authored andcommitted
Implements custom ACME servers
Code mostly taken from: tashian@564e0d8 Co-authored-by: Carl Tashian <[email protected]>
1 parent dc1bc6d commit add2e08

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

readme-vars.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ opt_param_usage_include_env: true
5050
opt_param_env_vars:
5151
- { env_var: "SUBDOMAINS", env_value: "www,", desc: "Subdomains you'd like the cert to cover (comma separated, no spaces) ie. `www,ftp,cloud`. For a wildcard cert, set this *exactly* to `wildcard` (wildcard cert is available via `dns` validation only)" }
5252
- { env_var: "CERTPROVIDER", env_value: "", desc: "Optionally define the cert provider. Set to `zerossl` for ZeroSSL certs (requires existing [ZeroSSL account](https://app.zerossl.com/signup) and the e-mail address entered in `EMAIL` env var). Otherwise defaults to Let's Encrypt." }
53+
<<<<<<< HEAD
5354
- { env_var: "DNSPLUGIN", env_value: "cloudflare", desc: "Required if `VALIDATION` is set to `dns`. Options are `acmedns`, `aliyun`, `azure`, `bunny`, `cloudflare`, `cpanel`, `desec`, `digitalocean`, `directadmin`, `dnsimple`, `dnsmadeeasy`, `dnspod`, `do`, `domeneshop`, `dreamhost`, `duckdns`, `dynudns`, `freedns`, `gandi`, `gehirn`, `glesys`, `godaddy`, `google`, `google-domains`, `he`, `hetzner`, `infomaniak`, `inwx`, `ionos`, `linode`, `loopia`, `luadns`, `namecheap`, `netcup`, `njalla`, `nsone`, `ovh`, `porkbun`, `rfc2136`, `route53`, `sakuracloud`, `standalone`, `transip`, and `vultr`. Also need to enter the credentials into the corresponding ini (or json for some plugins) file under `/config/dns-conf`." }
55+
=======
56+
- { env_var: "DNSPLUGIN", env_value: "cloudflare", desc: "Required if `VALIDATION` is set to `dns`. Options are `acmedns`, `aliyun`, `azure`, `bunny`, `cloudflare`, `cpanel`, `desec`, `digitalocean`, `directadmin`, `dnsimple`, `dnsmadeeasy`, `dnspod`, `do`, `domeneshop`, `dreamhost`, `duckdns`, `freedns`, `gandi`, `gehirn`, `glesys`, `godaddy`, `google`, `google-domains`, `he`, `hetzner`, `infomaniak`, `inwx`, `ionos`, `linode`, `loopia`, `luadns`, `namecheap`, `netcup`, `njalla`, `nsone`, `ovh`, `porkbun`, `rfc2136`, `route53`, `sakuracloud`, `standalone`, `transip`, and `vultr`. Also need to enter the credentials into the corresponding ini (or json for some plugins) file under `/config/dns-conf`." }
57+
- { env_var: "ACMESERVER", env_value: "", desc: "The URL of a custom ACME server to use." }
58+
- { env_var: "ACMECABUNDLE", env_value: "", desc: "A base64-encoded PEM file containing a CA bundle to trust, for use with an internal ACME CA. Required for a custom ACME CA." }
59+
>>>>>>> 2314a03 (Implements custom ACME servers)
5460
- { env_var: "PROPAGATION", env_value: "", desc: "Optionally override (in seconds) the default propagation time for the dns plugins." }
5561
- { env_var: "EMAIL", env_value: "", desc: "Optional e-mail address used for cert expiration notifications (Required for ZeroSSL)." }
5662
- { env_var: "ONLY_SUBDOMAINS", env_value: "false", desc: "If you wish to get certs only for certain subdomains, but not the main domain (main domain may be hosted on another machine and cannot be validated), set this to `true`" }
@@ -184,6 +190,7 @@ changelogs:
184190
- { date: "07.08.23:", desc: "Add Bunny DNS Configuration." }
185191
- { date: "27.07.23:", desc: "Added support for dreamhost validation." }
186192
- { date: "25.05.23:", desc: "Rebase to Alpine 3.18, deprecate armhf." }
193+
- { date: "21.05.23:", desc: "Allow custom ACME servers. Supply URL and CA bundle" }
187194
- { date: "27.04.23:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) authelia-location.conf, authelia-server.conf, authentik-location.conf, authentik-server.conf - Simplify auth configs and fix Set-Cookie header bug." }
188195
- { date: "13.04.23:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) nginx.conf, authelia-location.conf, authentik-location.conf, and site-confs/default.conf - Move ssl.conf include to default.conf. Remove Authorization headers in authelia. Sort proxy_set_header in authelia and authentik." }
189196
- { date: "25.03.23:", desc: "Fix renewal post hook." }

root/app/le-renew.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4+
if [[ -f "/config/cabundle.pem" ]]; then
5+
export REQUESTS_CA_BUNDLE="/config/cabundle.pem"
6+
fi
7+
48
echo "<------------------------------------------------->"
59
echo
610
echo "<------------------------------------------------->"

root/etc/s6-overlay/s6-rc.d/init-certbot-config/run

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ EXTRA_DOMAINS=${EXTRA_DOMAINS}\\n\
1212
ONLY_SUBDOMAINS=${ONLY_SUBDOMAINS}\\n\
1313
VALIDATION=${VALIDATION}\\n\
1414
CERTPROVIDER=${CERTPROVIDER}\\n\
15+
ACMESERVER=${ACMESERVER}\\n\
16+
ACMECABUNDLE=${ACMECABUNDLE}\\n\
1517
DNSPLUGIN=${DNSPLUGIN}\\n\
1618
EMAIL=${EMAIL}\\n\
1719
STAGING=${STAGING}\\n"
@@ -81,7 +83,7 @@ if [[ -f "/config/donoteditthisfile.conf" ]]; then
8183
mv /config/donoteditthisfile.conf /config/.donoteditthisfile.conf
8284
fi
8385
if [[ ! -f "/config/.donoteditthisfile.conf" ]]; then
84-
echo -e "ORIGURL=\"${URL}\" ORIGSUBDOMAINS=\"${SUBDOMAINS}\" ORIGONLY_SUBDOMAINS=\"${ONLY_SUBDOMAINS}\" ORIGEXTRA_DOMAINS=\"${EXTRA_DOMAINS}\" ORIGVALIDATION=\"${VALIDATION}\" ORIGDNSPLUGIN=\"${DNSPLUGIN}\" ORIGPROPAGATION=\"${PROPAGATION}\" ORIGSTAGING=\"${STAGING}\" ORIGCERTPROVIDER=\"${CERTPROVIDER}\" ORIGEMAIL=\"${EMAIL}\"" >/config/.donoteditthisfile.conf
86+
echo -e "ORIGURL=\"${URL}\" ORIGSUBDOMAINS=\"${SUBDOMAINS}\" ORIGONLY_SUBDOMAINS=\"${ONLY_SUBDOMAINS}\" ORIGEXTRA_DOMAINS=\"${EXTRA_DOMAINS}\" ORIGVALIDATION=\"${VALIDATION}\" ORIGDNSPLUGIN=\"${DNSPLUGIN}\" ORIGPROPAGATION=\"${PROPAGATION}\" ORIGSTAGING=\"${STAGING}\" ORIGCERTPROVIDER=\"${CERTPROVIDER}\" ORIGACMESERVER=\"$ACMESERVER\" ORIGACMECABUNDLE=\"$ACMECABUNDLE\" ORIGEMAIL=\"${EMAIL}\"" >/config/.donoteditthisfile.conf
8587
echo "Created .donoteditthisfile.conf"
8688
fi
8789

@@ -214,10 +216,10 @@ if [[ ! "${URL}" = "${ORIGURL}" ]] ||
214216
fi
215217

216218
# saving new variables
217-
echo -e "ORIGURL=\"${URL}\" ORIGSUBDOMAINS=\"${SUBDOMAINS}\" ORIGONLY_SUBDOMAINS=\"${ONLY_SUBDOMAINS}\" ORIGEXTRA_DOMAINS=\"${EXTRA_DOMAINS}\" ORIGVALIDATION=\"${VALIDATION}\" ORIGDNSPLUGIN=\"${DNSPLUGIN}\" ORIGPROPAGATION=\"${PROPAGATION}\" ORIGSTAGING=\"${STAGING}\" ORIGCERTPROVIDER=\"${CERTPROVIDER}\" ORIGEMAIL=\"${EMAIL}\"" >/config/.donoteditthisfile.conf
219+
echo -e "ORIGURL=\"${URL}\" ORIGSUBDOMAINS=\"${SUBDOMAINS}\" ORIGONLY_SUBDOMAINS=\"${ONLY_SUBDOMAINS}\" ORIGEXTRA_DOMAINS=\"${EXTRA_DOMAINS}\" ORIGVALIDATION=\"${VALIDATION}\" ORIGDNSPLUGIN=\"${DNSPLUGIN}\" ORIGPROPAGATION=\"${PROPAGATION}\" ORIGSTAGING=\"${STAGING}\" ORIGCERTPROVIDER=\"${CERTPROVIDER}\" ORIGACMESERVER=\"$ACMESERVER\" ORIGACMECABUNDLE=\"$ACMECABUNDLE\" ORIGEMAIL=\"${EMAIL}\"" >/config/.donoteditthisfile.conf
218220

219221
# Check if the cert is using the old LE root cert, revoke and regen if necessary
220-
if [[ -f "/config/keys/letsencrypt/chain.pem" ]] && { [[ "${CERTPROVIDER}" == "letsencrypt" ]] || [[ "${CERTPROVIDER}" == "" ]]; } && [[ "${STAGING}" != "true" ]] && ! openssl x509 -in /config/keys/letsencrypt/chain.pem -noout -issuer | grep -q "ISRG Root X"; then
222+
if [[ -f "/config/keys/letsencrypt/chain.pem" ]] && { [[ "${CERTPROVIDER}" == "letsencrypt" ]] || ([[ "${CERTPROVIDER}" == "" ]] && [[ -z "$ACMECABUNDLE" ]]); } && [[ "${STAGING}" != "true" ]] && ! openssl x509 -in /config/keys/letsencrypt/chain.pem -noout -issuer | grep -q "ISRG Root X"; then
221223
echo "The cert seems to be using the old LE root cert, which is no longer valid. Deleting and revoking."
222224
REV_ACMESERVER=("https://acme-v02.api.letsencrypt.org/directory")
223225
if [[ -f /config/etc/letsencrypt/live/"${ORIGDOMAIN}"/fullchain.pem ]]; then
@@ -232,12 +234,24 @@ fi
232234
if [[ "${CERTPROVIDER}" = "zerossl" ]] && [[ "${STAGING}" = "true" ]]; then
233235
echo "ZeroSSL does not support staging mode, ignoring STAGING variable"
234236
fi
237+
if [[ "${CERTPROVIDER}" = "custom" ]] && [[ "${STAGING}" = "true" ]]; then
238+
echo "Custom ACME does not support staging mode, ignoring STAGING variable"
239+
fi
235240
if [[ "${CERTPROVIDER}" = "zerossl" ]] && [[ -n "${EMAIL}" ]]; then
236241
echo "ZeroSSL is selected as the cert provider, registering cert with ${EMAIL}"
237242
ACMESERVER="https://acme.zerossl.com/v2/DV90"
238243
elif [[ "${CERTPROVIDER}" = "zerossl" ]] && [[ -z "${EMAIL}" ]]; then
239244
echo "ZeroSSL is selected as the cert provider, but the e-mail address has not been entered. Please visit https://zerossl.com, register a new account and set the account e-mail address in the EMAIL environment variable"
240245
sleep infinity
246+
elif [[ "${CERTPROVIDER}" = "custom" ]] && [[ -n "${EMAIL}" ]]; then
247+
echo "Using $ACMESERVER as the cert provider; registering cert with $EMAIL"
248+
if [ -n "$ACMECABUNDLE" ]; then
249+
echo "$ACMECABUNDLE" | base64 -d - > /config/cabundle.pem
250+
export REQUESTS_CA_BUNDLE="/config/cabundle.pem"
251+
fi
252+
elif [[ "${CERTPROVIDER}" = "custom" ]] && [[ -z "${EMAIL}" ]]; then
253+
echo "A custom ACME server is selected as the cert provider, but the e-email address has not been entered."
254+
sleep infinity
241255
elif [[ "${STAGING}" = "true" ]]; then
242256
echo "NOTICE: Staging is active"
243257
echo "Using Let's Encrypt as the cert provider"

0 commit comments

Comments
 (0)