mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-26 11:36:26 -08:00
kube/certs: use Let's Encrypt's recommended retry schedule
Replace the doubling backoff (1m, 2m, 4m, ...) with LE's recommended 1m, 10m, 100m, daily. The old schedule burned retry attempts inside the rate-limit window without speeding recovery.
This commit is contained in:
1 parent
6e1de5b651
commit
bccda836b4
1 file changed
+22
-17
+22
-17
@@ -94,22 +94,30 @@ func (cm *CertManager) EnsureCertLoops(ctx context.Context, sc *ipn.ServeConfig)
|
||||
return nil
|
||||
}
|
||||
|
||||
// retrySchedule is the wait between successive failed issuance attempts.
|
||||
// It follows the schedule that Let's Encrypt's rate-limit adjustment guidance
|
||||
// recommends ("1 minute, then 10 minutes, then 100 minutes, then once per
|
||||
// day"). Anything more aggressive burns attempts inside the same 168h window
|
||||
// during a genuine rate-limit event without improving recovery time.
|
||||
// https://letsencrypt.org/docs/integration-guide/#retrying-failures
|
||||
var retrySchedule = []time.Duration{
|
||||
1 * time.Minute,
|
||||
10 * time.Minute,
|
||||
100 * time.Minute,
|
||||
24 * time.Hour,
|
||||
}
|
||||
|
||||
// runCertLoop:
|
||||
// - calls localAPI certificate endpoint to ensure that certs are issued for the
|
||||
// given domain name
|
||||
// - calls localAPI certificate endpoint daily to ensure that certs are renewed
|
||||
// - if certificate issuance failed retries after an exponential backoff period
|
||||
// starting at 1 minute and capped at 24 hours. Reset the backoff once issuance succeeds.
|
||||
// - if certificate issuance failed, retries on the schedule defined by
|
||||
// [retrySchedule]; resets to the start once issuance succeeds.
|
||||
// Note that renewal check also happens when the node receives an HTTPS request and it is possible that certs get
|
||||
// renewed at that point. Renewal here is needed to prevent the shared certs from expiry in edge cases where the 'write'
|
||||
// replica does not get any HTTPS requests.
|
||||
// https://letsencrypt.org/docs/integration-guide/#retrying-failures
|
||||
func (cm *CertManager) runCertLoop(ctx context.Context, domain string) {
|
||||
const (
|
||||
normalInterval = 24 * time.Hour // regular renewal check
|
||||
initialRetry = 1 * time.Minute // initial backoff after a failure
|
||||
maxRetryInterval = 24 * time.Hour // max backoff period
|
||||
)
|
||||
const normalInterval = 24 * time.Hour // regular renewal check
|
||||
|
||||
if err := cm.waitForCertDomain(ctx, domain); err != nil {
|
||||
// Best-effort, log and continue with the issuing loop.
|
||||
@@ -148,21 +156,18 @@ func (cm *CertManager) runCertLoop(ctx context.Context, domain string) {
|
||||
}
|
||||
var nextInterval time.Duration
|
||||
// TODO(irbekrm): distinguish between LE rate limit errors and other
|
||||
// error types like transient network errors.
|
||||
// error types like transient network errors, and honour any
|
||||
// Retry-After hint returned by LE on a 429.
|
||||
if err == nil {
|
||||
retryCount = 0
|
||||
nextInterval = normalInterval
|
||||
} else {
|
||||
retryCount++
|
||||
// Calculate backoff: initialRetry * 2^(retryCount-1)
|
||||
// For retryCount=1: 1min * 2^0 = 1min
|
||||
// For retryCount=2: 1min * 2^1 = 2min
|
||||
// For retryCount=3: 1min * 2^2 = 4min
|
||||
backoff := initialRetry * time.Duration(1<<(retryCount-1))
|
||||
if backoff > maxRetryInterval {
|
||||
backoff = maxRetryInterval
|
||||
idx := retryCount - 1
|
||||
if idx >= len(retrySchedule) {
|
||||
idx = len(retrySchedule) - 1
|
||||
}
|
||||
nextInterval = backoff
|
||||
nextInterval = retrySchedule[idx]
|
||||
cm.logf("Error refreshing certificate for %s (retry %d): %v. Will retry in %v\n",
|
||||
domain, retryCount, err, nextInterval)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user