Automatic Letsencrypt certificate refresh#2730
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an automated Let's Encrypt certificate renewal/refresh mechanism for the Edge (proxy) certificate, including admin email notifications (with logs attached) on ACME failures, and refactors shared ACME helper code into a dedicated core module.
Changes:
- Add periodic (daily) LetsEncrypt certificate expiry checks in the utility thread and trigger ACME refresh when within a threshold.
- Introduce a new
defguard_core::letsencryptmodule that encapsulates ACME trigger, timeout handling, cert persistence, and notification logic. - Add a new mail template + DB migration entries to notify admins when automatic certificate refresh fails (including logs attachment).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| migrations/20260417073540_[2.0.0]_letsencrypt_cert_refresh.up.sql | Adds mail_context rows for the new failure notification template. |
| migrations/20260417073540_[2.0.0]_letsencrypt_cert_refresh.down.sql | Removes the inserted mail_context rows for rollback. |
| crates/defguard_mail/templates/letsencrypt-cert-refresh-failed.text | Adds plaintext template for refresh-failure notification. |
| crates/defguard_mail/templates/letsencrypt-cert-refresh-failed.mjml | Adds MJML template for refresh-failure notification. |
| crates/defguard_mail/src/templates.rs | Adds mail-sending function for refresh-failure notifications (with log attachment). |
| crates/defguard_mail/src/mail.rs | Adds new MailMessage variant and wires it to templates + subject. |
| crates/defguard_core/src/utility_thread.rs | Schedules daily LE expiry checks and triggers refresh. |
| crates/defguard_core/src/lib.rs | Exposes new letsencrypt module. |
| crates/defguard_core/src/letsencrypt.rs | Implements refresh logic, proxy ACME trigger, cert persistence, and admin notification (plus tests). |
| crates/defguard_core/src/handlers/component_setup.rs | Reuses the shared LE/ACME helpers from the new module for the SSE setup flow. |
| crates/defguard_common/src/db/models/settings.rs | Adds Settings::proxy_hostname() helper + new SettingsUrlError variants. |
| crates/defguard/src/main.rs | Updates utility thread startup to pass proxy_control_tx. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prevents accidentally skipping utility jobs placed after the enterprise status check.
moubctez
reviewed
Apr 20, 2026
moubctez
reviewed
Apr 20, 2026
moubctez
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2390.