Skip to content

Commit

Permalink
Merge pull request #414 from Nordix/tls-cert-hot-reload-pr-for-upstream
Browse files Browse the repository at this point in the history
Implement hot-reload for TLS client certificate
  • Loading branch information
sysadmind authored Jun 4, 2021
2 parents 23ad1e7 + 1629eda commit a676d71
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ func createTLSConfig(pemFile, pemCertFile, pemPrivateKeyFile string, insecureSki
tlsConfig.RootCAs = rootCerts
}
if len(pemCertFile) > 0 && len(pemPrivateKeyFile) > 0 {
clientPrivateKey, err := loadPrivateKeyFrom(pemCertFile, pemPrivateKeyFile)
// Load files once to catch configuration error early.
_, err := loadPrivateKeyFrom(pemCertFile, pemPrivateKeyFile)
if err != nil {
log.Fatalf("Couldn't setup client authentication. Got %s.", err)
return nil
}
tlsConfig.Certificates = []tls.Certificate{*clientPrivateKey}
// Define a function to load certificate and key lazily at TLS handshake to
// ensure that the latest files are used in case they have been rotated.
tlsConfig.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
return loadPrivateKeyFrom(pemCertFile, pemPrivateKeyFile)
}
}
return &tlsConfig
}
Expand Down

0 comments on commit a676d71

Please sign in to comment.