Dynamic identity file reloading support for API Client#29139
Dynamic identity file reloading support for API Client#29139strideynet merged 15 commits intomasterfrom
Conversation
…identity-file-credential
…identity-file-credential
| cert, err := keys.X509KeyPair(id.Certs.TLS, id.PrivateKey) | ||
| if err != nil { | ||
| return trace.Wrap(err) | ||
| } | ||
| pool := x509.NewCertPool() | ||
| for _, caCerts := range id.CACerts.TLS { | ||
| if !pool.AppendCertsFromPEM(caCerts) { | ||
| return trace.BadParameter("invalid CA cert PEM") | ||
| } | ||
| } |
There was a problem hiding this comment.
nit: just personal preference. I would prefer calling id.TLSConfig and taking cert and pool from there or maybe saving the identityTLSConfig and using that later instead of "manually" doing it here.
There was a problem hiding this comment.
I think I'd prefer to keep it as is. The reason for this is that tls.Config is a poor way of passing just a key/cert/CAs around - it has other fields that the underlying implementation could start using instead of the Certificates or RootCAs fields and I can easily see a future refactor to underlying parts breaking the DynamicIdentityFileCreds - the .CACerts and .Certs fields are much stricter and it's much more likely to be clearer that changing this risks breaking an upstream.
I have a somewhat long-term plan to try and convince folks that we should stop returning tls.Config and ssh.ClientConfig from the client.Credentials type. These configs are for more than just carrying certs/keys around and it's creating a conflict of responsibility for what the Credential should do and what the Client should do.
|
@strideynet See the table below for backport results.
|
Part of #23341
For now, this just introduces the new credential loader type. It doesn't implement the usage of this. I've left the reload strategy as an exercise to the consumer for now - we can wrap around this with inotify or an interval based reloader - but it'll be more natural to work out how to use this in the context of the consumer. I also didn't want to bring any further dependencies into the API package (e.g https://github.com/fsnotify/fsnotify)
Example usage:
I manually tested by:
This is in contrast to using the old
client.LoadIdentityFile- which upon severing the connection resulted in the errors regarding trying to connect with an expired certificate.