-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[WIP] Add functionality to dynamically reload the VPA certs #3462
Conversation
Welcome @surajnarwade! |
6d80d0c
to
193fbfc
Compare
} | ||
}() | ||
|
||
if err := watcher.Add("/etc/tls-certs"); err != nil { |
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.
You probably don't want this hardcoded. You should get the directories of both the cert and key and set watches on them.
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.
+1 I think you want those as flags passed in to the KeyPairReloader
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.
sure, I will update it 👍
How about a test where an |
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.
Left some comments. I would also like this new behavior hidden behind the flag, so that the default behavior would still be not starting a watch for certs.
Can you describe how you tested this change?
} | ||
}() | ||
|
||
if err := watcher.Add("/etc/tls-certs"); err != nil { |
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.
+1 I think you want those as flags passed in to the KeyPairReloader
case event := <-watcher.Events: | ||
// fsnotify.create events will tell us if there are new certs | ||
if event.Op&fsnotify.Create == fsnotify.Create { | ||
klog.Info("Reloading certs") |
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.
Can you add verbosity level to the log? And the log could be "New certificate found, reloading certs"
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.
sure 👍
if event.Op&fsnotify.Create == fsnotify.Create { | ||
klog.Info("Reloading certs") | ||
if err := result.reload(); err != nil { | ||
klog.Infof("Could not load new certs: %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.
This should probably be Warning
@@ -99,7 +98,7 @@ func NewKeypairReloader(config certsConfig) (*KeypairReloader, error) { | |||
|
|||
// watch for errors | |||
case err := <-watcher.Errors: | |||
klog.Infof("error", err) | |||
klog.Infof("error: %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.
We need more descriptive log here. Probably also warning or error level.
Is there any action to be taken on observing errors from the watcher?
// load certs | ||
kpr, err := NewKeypairReloader(*certsConfiguration) | ||
if err != nil { | ||
klog.Fatal(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.
More info in the log needed, like "Failed to load certificate on startup: %v", err
} | ||
// this will check if there are new certs before every tls handshake | ||
t := &tls.Config{GetCertificate: kpr.GetCertificateFunc()} |
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.
server.TLSConfig = &tls.Config{GetCertificate: kpr.GetCertificateFunc()}
you can also do it above:
server := &http.Server{
Addr: fmt.Sprintf(":%d", *port),
TLSConfig: &tls.Config{GetCertificate: kpr.GetCertificateFunc()},
}
One more thing is that the KeypairReloader could have a GetTLSConfig function and then we could simply have:
server := &http.Server{
Addr: fmt.Sprintf(":%d", *port),
TLSConfig: kpr.GetTLSConfig(),
}
} | ||
// this will check if there are new certs before every tls handshake |
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.
Actually, this will return up-to-date cert before every handshake, right?
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.
yeah, that's correct, I've updated the comment :)
|
||
// GetCertificateFunc will return function which will be used as tls.Config.GetCertificate | ||
func (kpr *KeypairReloader) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certificate, error) { | ||
return func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { |
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.
Since clientHello is unused, you can replace it with underscore
Ping. |
193fbfc
to
8ad4683
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: surajnarwade The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Closing due to inactivity. The PR has been WIP for 3 months. |
Feel free to reopen if needed. |
This PR adds the functionality of dynamically reloading the tls certificates for VPA admission controller.
How does it work?
cert-manager or any other mechanism updates the certs in secrets,
fsnotify
watcher will watch at/etc/tls-certs
(where secrets are mounted) and triggers an event if certs are updatedOnce, certs are updated, reload function will again reload new certs
callback hook
GetCertificate
intls.Config
is used to get the new certsReference