From: David Riley <d.riley@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: David Riley <d.riley@proxmox.com>
Subject: [PATCH pve-common v3 2/4] certificate: add helper for lifetime-based ACME renewal lead time
Date: Wed, 21 Oct 2026 11:52:27 +0200 [thread overview]
Message-ID: <20261021095229.50842-3-d.riley@proxmox.com> (raw)
In-Reply-To: <20261021095229.50842-1-d.riley@proxmox.com>
Add helper to calculate renewal lead time dynamically based on the
certificate's actual validity period.
The scaling mirrors the logic already used in Proxmox Backup Server
[0]: certificates living for less than 10 days are renewed once 1/2 of
their lifetime has elapsed, while longer-lived certificates are
renewed once 2/3 has elapsed [1]. A 3-day minimum floor is present to
ensure the daily update service has multiple chances to retry
transient failures.
[0] https://lore.proxmox.com/pbs-devel/20260423134607.105229-2-m.federanko@proxmox.com/
[1] https://letsencrypt.org/docs/integration-guide/#when-to-renew
Signed-off-by: David Riley <d.riley@proxmox.com>
Reviewed-by: Michael Köppl <m.koeppl@proxmox.com>
Tested-by: Michael Köppl <m.koeppl@proxmox.com>
---
src/PVE/Certificate.pm | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/PVE/Certificate.pm b/src/PVE/Certificate.pm
index 8406949..d2d0847 100644
--- a/src/PVE/Certificate.pm
+++ b/src/PVE/Certificate.pm
@@ -5,6 +5,7 @@ use warnings;
use Date::Parse;
use Encode qw(decode encode);
+use List::Util qw(max);
use MIME::Base64 qw(decode_base64 encode_base64);
use Net::SSLeay;
@@ -366,6 +367,28 @@ sub check_expiry {
return ($not_after < $timestamp) ? 1 : 0;
}
+# Long-lived certs are renewed once 2/3 of their lifetime has elapsed; short-lived ones (under
+# ten days) already at 1/2, following Let's Encrypt's integration guide. A 3-day floor still
+# applies so the daily-update service has a couple of chances to retry transient failures.
+sub get_cert_renew_lead_time {
+ my ($cert_path) = @_;
+
+ my ($not_before, $not_after) = get_validity_as_epoch($cert_path);
+ my $lifetime = $not_after - $not_before;
+
+ if ($lifetime <= 0) {
+ warn "Unexpected validity period ($lifetime s) for '$cert_path', falling back to a 30 day"
+ . " renewal lead time\n";
+
+ return 30 * 24 * 60 * 60;
+ }
+
+ my $scale = $lifetime < (10 * 24 * 60 * 60) ? 2 : 3;
+ my $lead = int($lifetime / $scale);
+
+ return max($lead, 3 * 24 * 60 * 60); # 3 day minimum
+}
+
# Create a CSR and certificate key for a given order
# returns path to CSR file or path to CSR and key files
sub generate_csr {
--
2.47.3
next prev parent reply other threads:[~2026-10-21 9:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 9:52 [PATCH common/manager v3 0/4] fix #8006: acme: lifetime-based certificate renewal threshold David Riley
2026-10-21 9:52 ` [PATCH pve-common v3 1/4] certificate: add helper to extract validity period David Riley
2026-10-21 9:52 ` David Riley [this message]
2026-10-21 9:52 ` [PATCH pve-manager v3 3/4] fix #8006: api: acme: use lifetime-based certificate renewal lead time David Riley
2026-10-21 9:52 ` [PATCH pve-manager v3 4/4] fix #8006: pveupdate: use lifetime-based " David Riley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261021095229.50842-3-d.riley@proxmox.com \
--to=d.riley@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.