Browse Source

Merge pull request #871 from smallstep/fix/renewer

Attempt to fix TestBootstrapClientServerRotation
Mariano Cano 4 năm trước cách đây
mục cha
commit
a7959ac563
1 tập tin đã thay đổi với 5 bổ sung và 2 xóa
  1. 5 2
      ca/renew.go

+ 5 - 2
ca/renew.go

@@ -60,7 +60,10 @@ func NewTLSRenewer(cert *tls.Certificate, fn RenewFunc, opts ...tlsRenewerOption
 		}
 		}
 	}
 	}
 
 
-	period := cert.Leaf.NotAfter.Sub(cert.Leaf.NotBefore)
+	// Use the current time to calculate the initial period. Using a notBefore
+	// in the past might set a renewBefore too large, causing continuous
+	// renewals due to the negative values in nextRenewDuration.
+	period := cert.Leaf.NotAfter.Sub(time.Now().Truncate(time.Second))
 	if period < minCertDuration {
 	if period < minCertDuration {
 		return nil, errors.Errorf("period must be greater than or equal to %s, but got %v.", minCertDuration, period)
 		return nil, errors.Errorf("period must be greater than or equal to %s, but got %v.", minCertDuration, period)
 	}
 	}
@@ -181,7 +184,7 @@ func (r *TLSRenewer) renewCertificate() {
 }
 }
 
 
 func (r *TLSRenewer) nextRenewDuration(notAfter time.Time) time.Duration {
 func (r *TLSRenewer) nextRenewDuration(notAfter time.Time) time.Duration {
-	d := time.Until(notAfter) - r.renewBefore
+	d := time.Until(notAfter).Truncate(time.Second) - r.renewBefore
 	n := rand.Int63n(int64(r.renewJitter))
 	n := rand.Int63n(int64(r.renewJitter))
 	d -= time.Duration(n)
 	d -= time.Duration(n)
 	if d < 0 {
 	if d < 0 {