Skip to content
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

pkg/transport: reload TLS certificates for every use #7784

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions pkg/transport/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,26 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) {
return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile)
}

tlsCert, err := tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc)
if err != nil {
return nil, err
cfg := &tls.Config{
MinVersion: tls.VersionTLS12,
ServerName: info.ServerName,
}

cfg := &tls.Config{
Certificates: []tls.Certificate{*tlsCert},
MinVersion: tls.VersionTLS12,
ServerName: info.ServerName,
cfg.GetCertificate = func(clientHello *tls.ClientHelloInfo) (
*tls.Certificate, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this extra empty line at 172

// Load the certificate from disk every time so when it is replaced we
// will be using the latest version
return tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you benchmarked the overhead of doing this?

if this brings a huge overhead, we probably need to do caching. (inotify + caching parsed result or simply pull based caching)

}
cfg.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (
*tls.Certificate, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line.

// Load the certificate from disk every time so when it is replaced we
// will be using the latest version
return tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also consider caching?

}

return cfg, nil
}

Expand Down