-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
crypto/x509: Convenient, efficient way to reload a certificate pool after on-disk changes #35887
Comments
CC @golang/security. |
Have a scenario where I am running with a set of internal CAs that can change (updates, removes, etc). These are not system CAs rather instance-specific CAs.
Adding a function field that can be set ( |
Remember that you can't modify most of tls.Config after it's in use. Anyway, you can make GetConfigForClient a closure that has access to the lexical scope in which the tls.Config is defined, so it can access it and Clone it. Is the performance motivation for not fully reloading the CertPool still there since we redid the certificate parser? It should be significantly faster now. |
A closure would work for accessing the
Performance isn't motivating me. My motivation is to avoid disconnecting clients that have persistent connections. As far as I knew, the only way to provide a new |
I faced a similar problem but not about CA but for server certificates. I can't just update the I just wrote an util function func ListenAndServeTLS(srv *http.Server, certFile, keyFile string) error {
cert, certErr := tls.LoadX509KeyPair(certFile, keyFile)
if certErr != nil {
return certErr
}
tlsCfg := &tls.Config{
NextProtos: []string{"h2", "http/1.1"},
Certificates: []tls.Certificate{cert},
}
addr := srv.Addr
if addr == "" {
addr = ":https"
}
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
}
defer ln.Close()
tlsListener := tls.NewListener(ln, tlsCfg)
servErr := srv.Serve(tlsListener)
return servErr
} I tested and added new certs on the fly and it worked well. I had to omit some logic from the original The current recommended workaround is to use So while I have a working and simple workaround it looks like I violated some contract and can't be sure that it will continue to work in future. So could the |
@andrewpmartinez |
Here is an example. This isn't meant to run as is, the In my solution, we have a backing library for loading x509 certificates/private keys from file/inline PEM/hardware (HSMs, etc.) that wraps this logic up nicely and doesn't use globals. Instead, we have an instance of a struct that we can call
|
@andrewpmartinez I have a client where the ca bundle are changing in background and I need to trust the new |
@FiloSottile Sorry if I'm abusing this issue but i think it is also related to #22836 It looks like Kubernetes client-go's library has hit this limitation as well. Just checking in if something has changed since your last comment that would be in favour of adding a callback function for reloading |
From #24254:
One use case is long-running processes that now have to jump through hoops to update their view of the system cert pool (e.g. openshift/cloud-credential-operator#113). On Unix, the loading logic is expensive, traversing multiple directories. But for processes who know they can load certs from a single file, it would be nice to have a way to reload if the backing file had changed but not otherwise. For example, something like:
Obviously the "don't bother
Stat
ing again" time could be configurable if that seemed important. Or maybe checking the current time is about as expensive as running theStat
, so we should just callStat
on everycontains
. Or maybe there would be no auto-refresh incontains
, butCertPool
would become aninterface
:In which case there could be a from-file
CertPool
implementation with aRefresh
method to trigger theStat
check and possible reload. Or something ;). But having something in the stdlib that could be dropped intotls.Config.RootCAs
to get efficient reloads without the caller having to babysit theCertPool
would be great. Thoughts?The text was updated successfully, but these errors were encountered: