Skip to content

Commit 51dc4ce

Browse files
Feilnernemchik
authored andcommitted
use certbot file hooks instead of command line hooks
1 parent 29a1c29 commit 51dc4ce

File tree

8 files changed

+80
-69
lines changed

8 files changed

+80
-69
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ This will *ask* Google et al not to index and list your site. Be careful with th
114114
* You can check which jails are active via `docker exec -it swag fail2ban-client status`
115115
* You can check the status of a specific jail via `docker exec -it swag fail2ban-client status <jail name>`
116116
* You can unban an IP via `docker exec -it swag fail2ban-client set <jail name> unbanip <IP>`
117-
* A list of commands can be found here: https://www.fail2ban.org/wiki/index.php/Commands
117+
* A list of commands can be found here: <https://www.fail2ban.org/wiki/index.php/Commands>
118118

119119
### Updating configs
120120

@@ -131,6 +131,7 @@ This will *ask* Google et al not to index and list your site. Be careful with th
131131
* You can check the new sample and adjust your active config as needed.
132132

133133
### Migration from the old `linuxserver/letsencrypt` image
134+
134135
Please follow the instructions [on this blog post](https://www.linuxserver.io/blog/2020-08-21-introducing-swag#migrate).
135136

136137
## Usage
@@ -211,11 +212,11 @@ Container images are configured using parameters passed at runtime (such as thos
211212
| `-e TZ=Europe/London` | Specify a timezone to use EG Europe/London. |
212213
| `-e URL=yourdomain.url` | Top url you have control over (`customdomain.com` if you own it, or `customsubdomain.ddnsprovider.com` if dynamic dns). |
213214
| `-e VALIDATION=http` | Certbot validation method to use, options are `http`, `dns` or `duckdns` (`dns` method also requires `DNSPLUGIN` variable set) (`duckdns` method requires `DUCKDNSTOKEN` variable set, and the `SUBDOMAINS` variable must be either empty or set to `wildcard`). |
214-
| `-e SUBDOMAINS=www,` | 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) |
215+
| `-e SUBDOMAINS=www,` | 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) |
215216
| `-e CERTPROVIDER=` | 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. |
216217
| `-e DNSPLUGIN=cloudflare` | 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`, `godaddy`, `google`, `he`, `hetzner`, `infomaniak`, `inwx`, `ionos`, `linode`, `loopia`, `luadns`, `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`. |
217218
| `-e PROPAGATION=` | Optionally override (in seconds) the default propagation time for the dns plugins. |
218-
| `-e DUCKDNSTOKEN=` | Required if `VALIDATION` is set to `duckdns`. Retrieve your token from https://www.duckdns.org |
219+
| `-e DUCKDNSTOKEN=` | Required if `VALIDATION` is set to `duckdns`. Retrieve your token from <https://www.duckdns.org> |
219220
| `-e EMAIL=` | Optional e-mail address used for cert expiration notifications (Required for ZeroSSL). |
220221
| `-e ONLY_SUBDOMAINS=false` | 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` |
221222
| `-e EXTRA_DOMAINS=` | Additional fully qualified domain names (comma separated, no spaces) ie. `extradomain.com,subdomain.anotherdomain.org,*.anotherdomain.org` |
@@ -335,6 +336,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
335336

336337
## Versions
337338

339+
* **05.10.22:** - Use certbot file hooks instead of command line hooks
338340
* **04.10.22:** - Add godaddy and porkbun dns plugins.
339341
* **03.10.22:** - Add default_server back to default site conf's https listen.
340342
* **22.09.22:** - Added support for DO DNS validation.
@@ -351,7 +353,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
351353
* **22.11.21:** - Added support for Infomaniak DNS for certificate generation.
352354
* **20.11.21:** - Added support for dnspod validation.
353355
* **15.11.21:** - Added support for deSEC DNS for wildcard certificate generation.
354-
* **26.10.21:** - [Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) proxy.conf - Mitigate https://httpoxy.org/ vulnerabilities. Ref: https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx#Defeating-the-Attack-using-NGINX-and-NGINX-Plus
356+
* **26.10.21:** - [Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) proxy.conf - Mitigate <https://httpoxy.org/> vulnerabilities. Ref: <https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx#Defeating-the-Attack-using-NGINX-and-NGINX-Plus>
355357
* **23.10.21:** - Fix Hurricane Electric (HE) DNS validation.
356358
* **12.10.21:** - Fix deprecated LE root cert check to fix failures when using `STAGING=true`, and failures in revoking.
357359
* **06.10.21:** - Added support for Hurricane Electric (HE) DNS validation. Added lxml build deps.

readme-vars.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ cap_add_param_vars:
4949
# optional container parameters
5050
opt_param_usage_include_env: true
5151
opt_param_env_vars:
52-
- { 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)" }
52+
- { 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)" }
5353
- { 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." }
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`, `godaddy`, `google`, `he`, `hetzner`, `infomaniak`, `inwx`, `ionos`, `linode`, `loopia`, `luadns`, `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`." }
5555
- { env_var: "PROPAGATION", env_value: "", desc: "Optionally override (in seconds) the default propagation time for the dns plugins." }
56-
- { env_var: "DUCKDNSTOKEN", env_value: "", desc: "Required if `VALIDATION` is set to `duckdns`. Retrieve your token from https://www.duckdns.org" }
56+
- { env_var: "DUCKDNSTOKEN", env_value: "", desc: "Required if `VALIDATION` is set to `duckdns`. Retrieve your token from <https://www.duckdns.org>" }
5757
- { env_var: "EMAIL", env_value: "", desc: "Optional e-mail address used for cert expiration notifications (Required for ZeroSSL)." }
5858
- { 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`" }
5959
- { env_var: "EXTRA_DOMAINS", env_value: "", desc: "Additional fully qualified domain names (comma separated, no spaces) ie. `extradomain.com,subdomain.anotherdomain.org,*.anotherdomain.org`" }
@@ -131,7 +131,7 @@ app_setup_block: |
131131
* You can check which jails are active via `docker exec -it swag fail2ban-client status`
132132
* You can check the status of a specific jail via `docker exec -it swag fail2ban-client status <jail name>`
133133
* You can unban an IP via `docker exec -it swag fail2ban-client set <jail name> unbanip <IP>`
134-
* A list of commands can be found here: https://www.fail2ban.org/wiki/index.php/Commands
134+
* A list of commands can be found here: <https://www.fail2ban.org/wiki/index.php/Commands>
135135
136136
### Updating configs
137137
@@ -148,13 +148,15 @@ app_setup_block: |
148148
* You can check the new sample and adjust your active config as needed.
149149
150150
### Migration from the old `linuxserver/letsencrypt` image
151+
151152
Please follow the instructions [on this blog post](https://www.linuxserver.io/blog/2020-08-21-introducing-swag#migrate).
152153
153154
app_setup_nginx_reverse_proxy_snippet: false
154155
app_setup_nginx_reverse_proxy_block: ""
155156

156157
# changelog
157158
changelogs:
159+
- { date: "05.10.22:", desc: "Use certbot file hooks instead of command line hooks" }
158160
- { date: "04.10.22:", desc: "Add godaddy and porkbun dns plugins." }
159161
- { date: "03.10.22:", desc: "Add default_server back to default site conf's https listen." }
160162
- { date: "22.09.22:", desc: "Added support for DO DNS validation." }
@@ -171,7 +173,7 @@ changelogs:
171173
- { date: "22.11.21:", desc: "Added support for Infomaniak DNS for certificate generation." }
172174
- { date: "20.11.21:", desc: "Added support for dnspod validation." }
173175
- { date: "15.11.21:", desc: "Added support for deSEC DNS for wildcard certificate generation." }
174-
- { date: "26.10.21:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) proxy.conf - Mitigate https://httpoxy.org/ vulnerabilities. Ref: https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx#Defeating-the-Attack-using-NGINX-and-NGINX-Plus" }
176+
- { date: "26.10.21:", desc: "[Existing users should update:](https://github.com/linuxserver/docker-swag/blob/master/README.md#updating-configs) proxy.conf - Mitigate <https://httpoxy.org/> vulnerabilities. Ref: <https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx#Defeating-the-Attack-using-NGINX-and-NGINX-Plus>" }
175177
- { date: "23.10.21:", desc: "Fix Hurricane Electric (HE) DNS validation." }
176178
- { date: "12.10.21:", desc: "Fix deprecated LE root cert check to fix failures when using `STAGING=true`, and failures in revoking." }
177179
- { date: "06.10.21:", desc: "Added support for Hurricane Electric (HE) DNS validation. Added lxml build deps." }

root/app/le-renew.sh

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
#!/usr/bin/with-contenv bash
22

3-
. /config/.donoteditthisfile.conf
4-
53
echo "<------------------------------------------------->"
64
echo
75
echo "<------------------------------------------------->"
8-
echo "cronjob running on "$(date)
6+
echo "cronjob running on $(date)"
97
echo "Running certbot renew"
10-
if [ "$ORIGVALIDATION" = "dns" ] || [ "$ORIGVALIDATION" = "duckdns" ]; then
11-
certbot -n renew \
12-
--post-hook "if ps aux | grep [n]ginx: > /dev/null; then s6-svc -h /var/run/s6/services/nginx; fi; \
13-
cd /config/keys/letsencrypt && \
14-
openssl pkcs12 -export -out privkey.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem -passout pass: && \
15-
sleep 1 && \
16-
cat privkey.pem fullchain.pem > priv-fullchain-bundle.pem && \
17-
chown -R abc:abc /config/etc/letsencrypt"
18-
else
19-
certbot -n renew \
20-
--pre-hook "if ps aux | grep [n]ginx: > /dev/null; then s6-svc -d /var/run/s6/services/nginx; fi" \
21-
--post-hook "if ps aux | grep 's6-supervise nginx' | grep -v grep > /dev/null; then s6-svc -u /var/run/s6/services/nginx; fi; \
22-
cd /config/keys/letsencrypt && \
23-
openssl pkcs12 -export -out privkey.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem -passout pass: && \
24-
sleep 1 && \
25-
cat privkey.pem fullchain.pem > priv-fullchain-bundle.pem && \
26-
chown -R abc:abc /config/etc/letsencrypt"
27-
fi
8+
certbot renew --non-interactive
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
cd /config/keys/letsencrypt || exit 1
4+
openssl pkcs12 -export -out privkey.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem -passout pass:
5+
sleep 1
6+
cat {privkey,fullchain}.pem >priv-fullchain-bundle.pem
7+
chown -R abc:abc /config/etc/letsencrypt
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
. /config/.donoteditthisfile.conf
4+
5+
if [ ! "$ORIGVALIDATION" = "dns" ] && [ ! "$ORIGVALIDATION" = "duckdns" ]; then
6+
if ps aux | grep 's6-supervise nginx' | grep -v grep >/dev/null; then
7+
s6-svc -u /run/service/nginx
8+
fi
9+
else
10+
if ps aux | grep [n]ginx: >/dev/null; then
11+
s6-svc -h /run/service/nginx
12+
fi
13+
fi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
. /config/.donoteditthisfile.conf
4+
5+
if [ ! "$ORIGVALIDATION" = "dns" ] && [ ! "$ORIGVALIDATION" = "duckdns" ]; then
6+
if ps aux | grep [n]ginx: >/dev/null; then
7+
s6-svc -d /run/service/nginx
8+
fi
9+
fi

root/etc/cont-init.d/40-folders

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# make our folders and links
44
mkdir -p \
55
/config/{fail2ban,crontabs,dns-conf} \
6-
/config/etc/letsencrypt \
6+
/config/etc/letsencrypt/renewal-hooks \
77
/config/log/{fail2ban,letsencrypt,nginx} \
88
/config/nginx/proxy-confs \
9-
/var/run/fail2ban
9+
/run/fail2ban
1010
rm -rf /etc/letsencrypt
1111
ln -s /config/etc/letsencrypt /etc/letsencrypt

0 commit comments

Comments
 (0)