Skip to content
Snippets Groups Projects
Commit cc772fcb authored by ale's avatar ale
Browse files

Fix an error where we'd constantly try to renew SSL certificates

Set the renewal timestamp on the initial certificate load.
parent e678f2d6
Branches
No related tags found
No related merge requests found
...@@ -80,6 +80,12 @@ func NewManager(ctx context.Context, cli *clientv3.Client, email, directoryURL s ...@@ -80,6 +80,12 @@ func NewManager(ctx context.Context, cli *clientv3.Client, email, directoryURL s
// validation tokens on etcd. // validation tokens on etcd.
acmeMgr := NewACME(email, directoryURL, newEtcdKeyStore(cli, keyPath), newEtcdTokenStore(cli)) acmeMgr := NewACME(email, directoryURL, newEtcdKeyStore(cli, keyPath), newEtcdTokenStore(cli))
m := &Manager{
ACME: acmeMgr,
names: certNames,
cli: cli,
}
// Try to fetch the existing certificate from etcd, or // Try to fetch the existing certificate from etcd, or
// generate a self-signed one. // generate a self-signed one.
cert, rev, err := fetchCert(ctx, cli, certPath) cert, rev, err := fetchCert(ctx, cli, certPath)
...@@ -92,17 +98,9 @@ func NewManager(ctx context.Context, cli *clientv3.Client, email, directoryURL s ...@@ -92,17 +98,9 @@ func NewManager(ctx context.Context, cli *clientv3.Client, email, directoryURL s
return nil, fmt.Errorf("failed to create self-signed certificate: %v", err) return nil, fmt.Errorf("failed to create self-signed certificate: %v", err)
} }
} }
tlsCert, err := cert.TLSCertificate()
if err != nil {
return nil, err
}
m := &Manager{ if err := m.setCert(cert); err != nil {
ACME: acmeMgr, return nil, err
names: certNames,
cli: cli,
cert: cert,
tlsCert: tlsCert,
} }
// Update m.cert using a watcher. // Update m.cert using a watcher.
...@@ -143,13 +141,15 @@ func (m *Manager) shouldRenew() bool { ...@@ -143,13 +141,15 @@ func (m *Manager) shouldRenew() bool {
func (m *Manager) renewLoop(ctx context.Context) { func (m *Manager) renewLoop(ctx context.Context) {
// Initial delay to stagger concurrent initialization. // Initial delay to stagger concurrent initialization.
time.Sleep(time.Duration(mrand.Intn(30)) * time.Second) time.Sleep(time.Duration(mrand.Intn(300)) * time.Second)
for { for {
if m.shouldRenew() { if m.shouldRenew() {
log.Printf("attempting to renew SSL certificate...") log.Printf("attempting to renew SSL certificate...")
if err := m.renew(ctx); err != nil { if err := m.renew(ctx); err != nil {
log.Printf("renewal failed: %v", err) log.Printf("renewal failed: %v", err)
} else {
log.Printf("successfully renewed SSL certificate")
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment