Skip to content

Commit 20e8893

Browse files
committed
Allow custom ACME server (Draft fix of #186)
1 parent fe294dd commit 20e8893

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

Diff for: readme-vars.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ cap_add_param_vars:
5050
opt_param_usage_include_env: true
5151
opt_param_env_vars:
5252
- { 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` and `duckdns` validation only)" }
53-
- { 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+
- { 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). Set to `custom` to use a custom ACME server. Defaults to Let's Encrypt unless `ACMESERVER` is set. " }
5454
- { env_var: "DNSPLUGIN", env_value: "cloudflare", desc: "Required if `VALIDATION` is set to `dns`. Options are `acmedns`,`aliyun`, `azure`, `cloudflare`, `cloudxns`, `cpanel`, `desec`, `digitalocean`, `directadmin`, `dnsimple`, `dnsmadeeasy`, `dnspod`, `do`, `domeneshop`, `dynu`, `gandi`, `gehirn`, `google`, `he`, `hetzner`, `infomaniak`, `inwx`, `ionos`, `linode`, `loopia`, `luadns`, `netcup`, `njalla`, `nsone`, `ovh`, `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+
- { env_var: "ACMESERVER", env_value: "", desc: "The URL of a custom ACME server to use." }
56+
- { 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." }
5557
- { env_var: "PROPAGATION", env_value: "", desc: "Optionally override (in seconds) the default propagation time for the dns plugins." }
5658
- { env_var: "DUCKDNSTOKEN", env_value: "", desc: "Required if `VALIDATION` is set to `duckdns`. Retrieve your token from https://www.duckdns.org" }
5759
- { env_var: "EMAIL", env_value: "", desc: "Optional e-mail address used for cert expiration notifications (Required for ZeroSSL)." }
@@ -155,6 +157,7 @@ app_setup_nginx_reverse_proxy_block: ""
155157

156158
# changelog
157159
changelogs:
160+
- { date: "26.09.22:", desc: "Allow custom ACME servers. Supply URL and CA bundle" }
158161
- { date: "22.09.22:", desc: "Added support for DO DNS validation." }
159162
- { date: "22.09.22:", desc: "Added certbot-dns-acmedns for DNS01 validation." }
160163
- { date: "20.08.22:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) nginx.conf - Rebasing to alpine 3.15 with php8. Restructure nginx configs ([see changes announcement](https://info.linuxserver.io/issues/2022-08-20-nginx-base))." }

Diff for: root/app/le-renew.sh

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ echo
77
echo "<------------------------------------------------->"
88
echo "cronjob running on "$(date)
99
echo "Running certbot renew"
10+
11+
if [ -f "/config/cabundle.pem" ]; then
12+
export REQUESTS_CA_BUNDLE="/config/cabundle.pem"
13+
fi
14+
1015
if [ "$ORIGVALIDATION" = "dns" ] || [ "$ORIGVALIDATION" = "duckdns" ]; then
1116
certbot -n renew \
1217
--post-hook "if ps aux | grep [n]ginx: > /dev/null; then s6-svc -h /var/run/s6/services/nginx; fi; \

Diff for: root/etc/cont-init.d/50-certbot

+35-20
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ EXTRA_DOMAINS=${EXTRA_DOMAINS}\\n\
1111
ONLY_SUBDOMAINS=${ONLY_SUBDOMAINS}\\n\
1212
VALIDATION=${VALIDATION}\\n\
1313
CERTPROVIDER=${CERTPROVIDER}\\n\
14+
ACMESERVER=${ACMESERVER}\\n\
15+
ACMECABUNDLE=${ACMECABUNDLE}\\n\
1416
DNSPLUGIN=${DNSPLUGIN}\\n\
1517
EMAIL=${EMAIL}\\n\
1618
STAGING=${STAGING}\\n"
1719

1820
# Sanitize variables
19-
SANED_VARS=( DNSPLUGIN EMAIL EXTRA_DOMAINS ONLY_SUBDOMAINS STAGING SUBDOMAINS URL VALIDATION CERTPROVIDER )
21+
SANED_VARS=( DNSPLUGIN EMAIL EXTRA_DOMAINS ONLY_SUBDOMAINS STAGING SUBDOMAINS URL VALIDATION CERTPROVIDER ACMESERVER ACMECABUNDLE )
2022
for i in "${SANED_VARS[@]}"
2123
do
2224
export echo "$i"="${!i//\"/}"
@@ -39,7 +41,7 @@ if [ -f "/config/donoteditthisfile.conf" ]; then
3941
mv /config/donoteditthisfile.conf /config/.donoteditthisfile.conf
4042
fi
4143
if [ ! -f "/config/.donoteditthisfile.conf" ]; then
42-
echo -e "ORIGURL=\"$URL\" ORIGSUBDOMAINS=\"$SUBDOMAINS\" ORIGONLY_SUBDOMAINS=\"$ONLY_SUBDOMAINS\" ORIGEXTRA_DOMAINS=\"$EXTRA_DOMAINS\" ORIGVALIDATION=\"$VALIDATION\" ORIGDNSPLUGIN=\"$DNSPLUGIN\" ORIGPROPAGATION=\"$PROPAGATION\" ORIGSTAGING=\"$STAGING\" ORIGDUCKDNSTOKEN=\"$DUCKDNSTOKEN\" ORIGCERTPROVIDER=\"$CERTPROVIDER\" ORIGEMAIL=\"$EMAIL\"" > /config/.donoteditthisfile.conf
44+
echo -e "ORIGURL=\"$URL\" ORIGSUBDOMAINS=\"$SUBDOMAINS\" ORIGONLY_SUBDOMAINS=\"$ONLY_SUBDOMAINS\" ORIGEXTRA_DOMAINS=\"$EXTRA_DOMAINS\" ORIGVALIDATION=\"$VALIDATION\" ORIGDNSPLUGIN=\"$DNSPLUGIN\" ORIGPROPAGATION=\"$PROPAGATION\" ORIGSTAGING=\"$STAGING\" ORIGDUCKDNSTOKEN=\"$DUCKDNSTOKEN\" ORIGCERTPROVIDER=\"$CERTPROVIDER\" ORIGACMESERVER=\"$ACMESERVER\" ORIGACMECABUNDLE=\"$ACMECABUNDLE\" ORIGEMAIL=\"$EMAIL\"" > /config/.donoteditthisfile.conf
4345
echo "Created .donoteditthisfile.conf"
4446
fi
4547

@@ -53,23 +55,36 @@ if [ -z "$VALIDATION" ]; then
5355
echo "VALIDATION parameter not set; setting it to http"
5456
fi
5557

56-
# if zerossl is selected or staging is set to true, use the relevant server
57-
if [ "$CERTPROVIDER" = "zerossl" ] && [ "$STAGING" = "true" ]; then
58-
echo "ZeroSSL does not support staging mode, ignoring STAGING variable"
59-
fi
60-
if [ "$CERTPROVIDER" = "zerossl" ] && [ -n "$EMAIL" ]; then
61-
echo "ZeroSSL is selected as the cert provider, registering cert with $EMAIL"
62-
ACMESERVER="https://acme.zerossl.com/v2/DV90"
63-
elif [ "$CERTPROVIDER" = "zerossl" ] && [ -z "$EMAIL" ]; then
64-
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"
65-
sleep infinity
66-
elif [ "$STAGING" = "true" ]; then
67-
echo "NOTICE: Staging is active"
68-
echo "Using Let's Encrypt as the cert provider"
69-
ACMESERVER="https://acme-staging-v02.api.letsencrypt.org/directory"
58+
# Choose the relevant CA server
59+
if [ -n "$ACMESERVER" ]; then
60+
if [ -z "$EMAIL" ]; then
61+
echo 'A custom $ACMESERVER URL requires an account $EMAIL to be supplied'
62+
sleep infinity
63+
fi
64+
echo "Using $ACMESERVER as the cert provider; registering cert with $EMAIL"
65+
elif [ "$CERTPROVIDER" = "zerossl" ]; then
66+
ACMESERVER="https://acme.zerossl.com/v2/DV90"
67+
if [ "$STAGING" = "true" ]; then
68+
echo "ZeroSSL cert provider does not support staging mode, ignoring STAGING variable"
69+
fi
70+
if [ -z "$EMAIL" ]; then
71+
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"
72+
sleep infinity
73+
fi
74+
echo "Using ZeroSSL as the cert provider; registering cert with $EMAIL"
7075
else
71-
echo "Using Let's Encrypt as the cert provider"
72-
ACMESERVER="https://acme-v02.api.letsencrypt.org/directory"
76+
if [ "$STAGING" = "true" ]; then
77+
echo "NOTICE: Staging is active"
78+
ACMESERVER="https://acme-staging-v02.api.letsencrypt.org/directory"
79+
else
80+
ACMESERVER="https://acme-v02.api.letsencrypt.org/directory"
81+
fi
82+
echo "Using Let's Encrypt as the cert provider"
83+
fi
84+
85+
if [ -n "$ACMECABUNDLE" ]; then
86+
echo "$ACMECABUNDLE" | base64 -d - > /config/cabundle.pem
87+
export REQUESTS_CA_BUNDLE="/config/cabundle.pem"
7388
fi
7489

7590
# figuring out url only vs url & subdomains vs subdomains only
@@ -219,7 +234,7 @@ if [ ! "$URL" = "$ORIGURL" ] || [ ! "$SUBDOMAINS" = "$ORIGSUBDOMAINS" ] || [ ! "
219234
fi
220235

221236
# saving new variables
222-
echo -e "ORIGURL=\"$URL\" ORIGSUBDOMAINS=\"$SUBDOMAINS\" ORIGONLY_SUBDOMAINS=\"$ONLY_SUBDOMAINS\" ORIGEXTRA_DOMAINS=\"$EXTRA_DOMAINS\" ORIGVALIDATION=\"$VALIDATION\" ORIGDNSPLUGIN=\"$DNSPLUGIN\" ORIGPROPAGATION=\"$PROPAGATION\" ORIGSTAGING=\"$STAGING\" ORIGDUCKDNSTOKEN=\"$DUCKDNSTOKEN\" ORIGCERTPROVIDER=\"$CERTPROVIDER\" ORIGEMAIL=\"$EMAIL\"" > /config/.donoteditthisfile.conf
237+
echo -e "ORIGURL=\"$URL\" ORIGSUBDOMAINS=\"$SUBDOMAINS\" ORIGONLY_SUBDOMAINS=\"$ONLY_SUBDOMAINS\" ORIGEXTRA_DOMAINS=\"$EXTRA_DOMAINS\" ORIGVALIDATION=\"$VALIDATION\" ORIGDNSPLUGIN=\"$DNSPLUGIN\" ORIGPROPAGATION=\"$PROPAGATION\" ORIGSTAGING=\"$STAGING\" ORIGDUCKDNSTOKEN=\"$DUCKDNSTOKEN\" ORIGCERTPROVIDER=\"$CERTPROVIDER\" ORIGACMESERVER=\"$ACMESERVER\" ORIGACMECABUNDLE=\"$ACMECABUNDLE\" ORIGEMAIL=\"$EMAIL\"" > /config/.donoteditthisfile.conf
223238

224239
# alter extension for error message
225240
if [ "$DNSPLUGIN" = "google" ]; then
@@ -229,7 +244,7 @@ else
229244
fi
230245

231246
# Check if the cert is using the old LE root cert, revoke and regen if necessary
232-
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
247+
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
233248
echo "The cert seems to be using the old LE root cert, which is no longer valid. Deleting and revoking."
234249
REV_ACMESERVER="https://acme-v02.api.letsencrypt.org/directory"
235250
certbot revoke --non-interactive --cert-path /config/etc/letsencrypt/live/"$ORIGDOMAIN"/fullchain.pem --server $REV_ACMESERVER

0 commit comments

Comments
 (0)