-
Notifications
You must be signed in to change notification settings - Fork 73
Fix ListenAndServe certificate expiration by preloading certs #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6c57f83 to
ba42cc3
Compare
Signed-off-by: Brad Davidson <[email protected]>
ba42cc3 to
91ca9c0
Compare
Signed-off-by: Brad Davidson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! The design lines up with what we discussed, so this LGTM.
| } | ||
|
|
||
| if !factory.IsStatic(secret) && !factory.NeedsUpdate(l.maxSANs, secret, cn...) { | ||
| if factory.IsStatic(secret) || !factory.NeedsUpdate(l.maxSANs, secret, cn...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
| if err := l.updateCert(h); err != nil { | ||
| logrus.Errorf("failed to update cert with HTTP request Host header: %v", err) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another good catch
| if err != nil && !errors.IsAlreadyExists(err) { | ||
| logrus.Warnf("Failed to create Kubernetes secret: %v", err) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add retry logic here or will the warning log suffice? I'm led the believe that a non-"IsNotFound" error will likely reappear upon retry, so I'm good with this "as-is", but thought I'd ask if you considered it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Kubernetes Secret also gets watched in the background, and the sync from the watch plus the write-back of any local updates to the secret will ensure that it is eventually consistent.
This change fixes an issue with how
server.ListenAndServeloads certificates. It sets up a memory -> kubernetes -> memory Secret storage stack, which combined with lazy (on-demand) loading of certificate data, caused the certificate to not be properly renewed when it expired.It also resolves a regression from #38 - while IPv6 addresses are no longer rejected by the CN regex, they cannot actually be stored in the CN annotation, as semicolons are not allowed in annotation keys. This also fixes handling of hostnames that are more than 41 characters long.