@@ -66,13 +66,28 @@ func autoCert(certModel *model.Cert) {
66
66
certAge := int (time .Since (certInfo .NotBefore ).Hours () / 24 )
67
67
// Calculate days until expiration
68
68
daysUntilExpiration := int (time .Until (certInfo .NotAfter ).Hours () / 24 )
69
+ // Calculate total certificate validity period
70
+ totalValidityDays := int (certInfo .NotAfter .Sub (certInfo .NotBefore ).Hours () / 24 )
69
71
70
- // Skip renewal only if:
71
- // 1. Certificate age is less than renewal interval AND
72
- // 2. Certificate has more than 6 days remaining before expiration
73
- if certAge < settings .CertSettings .GetCertRenewalInterval () && daysUntilExpiration > 6 {
74
- // Certificate is too young and not expiring soon, ignore
75
- return
72
+ renewalInterval := settings .CertSettings .GetCertRenewalInterval ()
73
+
74
+ // For certificates with short validity periods (less than renewal interval),
75
+ // use early renewal logic to prevent expiration
76
+ if totalValidityDays < renewalInterval {
77
+ // Renew when 2/3 of the certificate's lifetime remains
78
+ // This provides a safety buffer for short-lived certificates
79
+ earlyRenewalThreshold := 2 * totalValidityDays / 3
80
+ if daysUntilExpiration > earlyRenewalThreshold {
81
+ return
82
+ }
83
+ // If we reach here, proceed with renewal for short-lived certificate
84
+ } else {
85
+ // For normal certificates with validity >= renewal interval:
86
+ // Skip renewal if certificate age is less than the configured renewal interval
87
+ // This ensures we don't renew certificates too frequently
88
+ if certAge < renewalInterval {
89
+ return
90
+ }
76
91
}
77
92
78
93
// after 1 mo, reissue certificate
0 commit comments