Auto-reload TLS certificates on SIGHUP

This commit is contained in:
Cody Soyland 2019-10-02 17:10:32 -05:00
parent 74b1bb853e
commit 4324059325
3 changed files with 8 additions and 2 deletions

1
go.mod
View file

@ -25,6 +25,7 @@ require (
github.com/prometheus/client_golang v0.9.3
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001 // indirect
github.com/robustirc/bridge v1.7.3
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect

4
go.sum
View file

@ -110,6 +110,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001 h1:YDeskXpkNDhPdWN3REluVa46HQOVuVkjkd2sWnrABNQ=
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/robustirc/bridge v1.7.3 h1:rNeZw+W/SSyU8jF7FYbCqg2M4fGPQj/3HaePcEBws9k=
github.com/robustirc/bridge v1.7.3/go.mod h1:/BC0GGix13AzZKm99Hb80m3OEp4Q3GS6hkwSAN16VBw=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
@ -119,6 +121,8 @@ github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMT
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sorcix/irc v1.1.4-0.20170501124343-8becc86e7db2 h1:s9tGJyZAss54vMNYrMVOoLTHVdPVtbjqA85lb2v6cxE=
github.com/sorcix/irc v1.1.4-0.20170501124343-8becc86e7db2/go.mod h1:MhzbySH63tDknqfvAAFK3ps/942g4z9EeJ/4lGgHyZc=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=

View file

@ -51,6 +51,7 @@ import (
"github.com/pilosa/pilosa/statsd"
"github.com/pilosa/pilosa/syswrap"
"github.com/pkg/errors"
"github.com/robustirc/bridge/tlsutil"
)
type loggerLogger interface {
@ -477,15 +478,15 @@ func (f *filteredWriter) Write(p []byte) (n int, err error) {
func GetTLSConfig(tlsConfig *TLSConfig) (TLSConfig *tls.Config, err error) {
if tlsConfig.CertificatePath != "" && tlsConfig.CertificateKeyPath != "" {
cert, err := tls.LoadX509KeyPair(tlsConfig.CertificatePath, tlsConfig.CertificateKeyPath)
kpr, err := tlsutil.NewKeypairReloader(tlsConfig.CertificatePath, tlsConfig.CertificateKeyPath)
if err != nil {
return nil, errors.Wrap(err, "loading keypair")
}
TLSConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: tlsConfig.SkipVerify,
PreferServerCipherSuites: true,
MinVersion: tls.VersionTLS12,
GetCertificate: kpr.GetCertificateFunc(),
}
if tlsConfig.CACertPath != "" {
b, err := ioutil.ReadFile(tlsConfig.CACertPath)