Skip to content

Commit

Permalink
Reload serving certs
Browse files Browse the repository at this point in the history
  • Loading branch information
stlaz authored and marun committed Mar 3, 2020
1 parent 9d9b136 commit 658cafa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions http.go
@@ -1,6 +1,7 @@
package main

import (
"context"
"crypto/tls"
"log"
"net"
Expand All @@ -10,6 +11,7 @@ import (

oscrypto "github.com/openshift/library-go/pkg/crypto"

"github.com/openshift/oauth-proxy/dynamiccertificates"
"github.com/openshift/oauth-proxy/util"
)

Expand Down Expand Up @@ -75,11 +77,19 @@ func (s *Server) ServeHTTPS() {
}

var err error
config.Certificates = make([]tls.Certificate, 1)
config.Certificates[0], err = tls.LoadX509KeyPair(s.Opts.TLSCertFile, s.Opts.TLSKeyFile)
servingCertProvider, err := dynamiccertificates.NewDynamicServingContentFromFiles("serving", s.Opts.TLSCertFile, s.Opts.TLSKeyFile)
if err != nil {
log.Fatalf("FATAL: loading tls config (%s, %s) failed - %s", s.Opts.TLSCertFile, s.Opts.TLSKeyFile, err)
}
go servingCertProvider.Run(1, context.TODO().Done())

config.GetCertificate = func(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
// this disregards information from ClientHello but we're not doing SNI anyway
cert, key := servingCertProvider.CurrentCertKeyContent()

certKeyPair, err := tls.X509KeyPair(cert, key)
return &certKeyPair, err
}

if len(s.Opts.TLSClientCAFile) > 0 {
config.ClientAuth = tls.RequestClientCert
Expand Down

0 comments on commit 658cafa

Please sign in to comment.