Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

Permalink
pkg/transport: reload TLS certificates for every use
Browse files Browse the repository at this point in the history
This changes the baseConfig used when creating tls Configs to utilize
the GetCertificate and GetClientCertificate functions to always reload
the certificates from disk whenever they are needed.

Always reloading the certificates allows changing the certificates via
an external process without interrupting etcd.

Fixes etcd-io#7576
  • Loading branch information
Tony Grosinger authored and gyuho committed Apr 26, 2017
1 parent 633a0a8 commit 40cae65
Showing 1 changed file with 17 additions and 7 deletions.
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) {

// 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)
}
cfg.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (
*tls.Certificate, error) {

// 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)
}

return cfg, nil
}

Expand Down

0 comments on commit 40cae65

Please sign in to comment.