Skip to content

Conversation

@nemchik
Copy link
Member

@nemchik nemchik commented Sep 27, 2021

This supersedes #89

The changes here use the default location that already exists for hooks (/config/etc/letsencrypt/renewal-hooks) and remove the suggestions in the documentation for users to make changes.

Essentially, the feature will exist undocumented.

Will need to rebase after #169

@nemchik nemchik requested a review from aptalca September 27, 2021 22:30
@LinuxServer-CI
Copy link
Contributor

@LinuxServer-CI
Copy link
Contributor

@LinuxServer-CI
Copy link
Contributor

@LinuxServer-CI
Copy link
Contributor

@NemesisRE
Copy link

This would be great, first of all it is the proper way and clean way to do it.
Additionally it would give experienced users the possibility to reuse the certificates on other services or run other task.

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@LinuxServer-CI
Copy link
Contributor

@nemchik nemchik force-pushed the renewal-hooks branch 2 times, most recently from eb7426d to e76759b Compare October 1, 2022 15:24
@LinuxServer-CI
Copy link
Contributor

1 similar comment
@LinuxServer-CI
Copy link
Contributor

@LinuxServer-CI
Copy link
Contributor

@LinuxServer-CI
Copy link
Contributor

opt_param_usage_include_env: true
opt_param_env_vars:
- { 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)" }
- { 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)" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdownlint change

- { 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`." }
- { env_var: "PROPAGATION", env_value: "", desc: "Optionally override (in seconds) the default propagation time for the dns plugins." }
- { env_var: "DUCKDNSTOKEN", env_value: "", desc: "Required if `VALIDATION` is set to `duckdns`. Retrieve your token from https://www.duckdns.org" }
- { env_var: "DUCKDNSTOKEN", env_value: "", desc: "Required if `VALIDATION` is set to `duckdns`. Retrieve your token from <https://www.duckdns.org>" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdownlint change

* You can check the status of a specific jail via `docker exec -it swag fail2ban-client status <jail name>`
* You can unban an IP via `docker exec -it swag fail2ban-client set <jail name> unbanip <IP>`
* A list of commands can be found here: https://www.fail2ban.org/wiki/index.php/Commands
* A list of commands can be found here: <https://www.fail2ban.org/wiki/index.php/Commands>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdownlint change

* You can check the new sample and adjust your active config as needed.
### Migration from the old `linuxserver/letsencrypt` image
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdownlint change

- { date: "20.11.21:", desc: "Added support for dnspod validation." }
- { date: "15.11.21:", desc: "Added support for deSEC DNS for wildcard certificate generation." }
- { 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" }
- { 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>" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdownlint change

@@ -1,27 +1,8 @@
#!/usr/bin/with-contenv bash

. /config/.donoteditthisfile.conf
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are no longer used in this file (they are used in the hooks).

# copy dns default configs
cp -n /defaults/dns-conf/* /config/dns-conf/
chown -R abc:abc /config/dns-conf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not removed, just relocated below the next if statement.

sed -i 's|^certbot_dns_domeneshop:||g' /config/dns-conf/domeneshop.ini
sed -i 's|^certbot_dns_inwx:||g' /config/dns-conf/inwx.ini
sed -i 's|^certbot_dns_transip:||g' /config/dns-conf/transip.ini

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not removed, just relocated up under where the dns-conf files are copied from /defaults just to keep them together.

fi
rm -rf /config/etc/letsencrypt
mkdir -p /config/etc/letsencrypt
rm -rf /config/etc/letsencrypt/{live,renewal}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing what actually happens when you run certbot delete, these two folders are the only things touched. Normally certbot delete is used to remove one cert at a time, and this assumes you have the required .conf file in the renewal folder, and the fullchain.pem and other files in the live folder. In case these things get messed up, it's safer to remove the whole live and renewal folder.

certbot doesn't recommend this, but in the two scenarios where this script decides to remove these folders it makes sense, and will be more consistent with fixing user issues compared to using certbot delete in the recommended way.

p.s. I did write up the code changes to iterate through the output of certbot certificates and then use certbot delete on each one, but if the user's files and folders are messed up at all certbot delete won't handle it nicely, and the next run of certbot renew could attempt to renew a certificate with issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, the reason for removing these subfolders and not the parent folder:
I want to keep the /config/etc/letsencrypt/renewal-hooks folder, which should allow for user modifications. I reviewed the other folders in /config/etc/letsencrypt and they don't seem like they will cause any issues being left behind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added removing the /config/etc/letsencrypt/archive folder after testing it is required to remove it as well.

if [ -d /config/keys/letsencrypt ]; then
cd /config/keys/letsencrypt || exit
else
certbot certonly --non-interactive --renew-by-default --server $ACMESERVER $ZEROSSL_EAB $PREFCHAL --rsa-key-size 4096 $EMAILPARAM --agree-tos $URL_REAL
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added --non-interactive

@LinuxServer-CI
Copy link
Contributor

@nemchik
Copy link
Member Author

nemchik commented Oct 3, 2022

I did some extra research and testing and ran a bunch of certbot commands from inside one of my swag containers to confirm that all this works, and is the best way (that I can think of) to handle these changes.

@LinuxServer-CI
Copy link
Contributor

@LinuxServer-CI
Copy link
Contributor

Copy link
Member

@thespad thespad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LinuxServer-CI
Copy link
Contributor

@nemchik nemchik merged commit e2d02de into master Oct 5, 2022
@nemchik nemchik deleted the renewal-hooks branch October 5, 2022 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants