Skip to content

Commit c4993f8

Browse files
committed
feat: allow runtime TLS cert updates
1 parent f0c7af5 commit c4993f8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

app/cmd/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ func (c *serverConfig) fillTLSConfig(hyConfig *server.Config) error {
252252
if c.TLS.Cert == "" || c.TLS.Key == "" {
253253
return configError{Field: "tls", Err: errors.New("empty cert or key path")}
254254
}
255-
cert, err := tls.LoadX509KeyPair(c.TLS.Cert, c.TLS.Key)
256-
if err != nil {
257-
return configError{Field: "tls", Err: err}
255+
// Use GetCertificate instead of Certificates so that
256+
// users can update the cert without restarting the server.
257+
hyConfig.TLSConfig.GetCertificate = func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
258+
cert, err := tls.LoadX509KeyPair(c.TLS.Cert, c.TLS.Key)
259+
return &cert, err
258260
}
259-
hyConfig.TLSConfig.Certificates = []tls.Certificate{cert}
260261
} else {
261262
// ACME
262263
dataDir := c.ACME.Dir

0 commit comments

Comments
 (0)