
* prepare client auth with inbuilt server Signed-off-by: Jens Langhammer <jens@goauthentik.io> * introduce better IPC auth Signed-off-by: Jens Langhammer <jens@goauthentik.io> * init Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start stage Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only allow trusted proxies to set MTLS headers Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more stage progress Signed-off-by: Jens Langhammer <jens@goauthentik.io> * dont fail if ipc_key doesn't exist Signed-off-by: Jens Langhammer <jens@goauthentik.io> * actually install app Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add some tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update API Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix unquote Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix int serial number not jsonable Signed-off-by: Jens Langhammer <jens@goauthentik.io> * init ui Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add UI Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated: fix git pull in makefile Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix parse helper Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add test for outpost Signed-off-by: Jens Langhammer <jens@goauthentik.io> * more tests and improvements Signed-off-by: Jens Langhammer <jens@goauthentik.io> * improve labels Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add support for multiple CAs on brand Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add support for multiple CAs to MTLS stage Signed-off-by: Jens Langhammer <jens@goauthentik.io> * dont log ipcuser secret views Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix go mod Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package web
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
|
|
"github.com/pires/go-proxyproto"
|
|
|
|
"goauthentik.io/internal/config"
|
|
"goauthentik.io/internal/crypto"
|
|
"goauthentik.io/internal/utils"
|
|
"goauthentik.io/internal/utils/web"
|
|
)
|
|
|
|
func (ws *WebServer) GetCertificate() func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
|
|
fallback, err := crypto.GenerateSelfSignedCert()
|
|
if err != nil {
|
|
ws.log.WithError(err).Error("failed to generate default cert")
|
|
}
|
|
return func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
|
|
cfg := utils.GetTLSConfig()
|
|
if ch.ServerName == "" {
|
|
cfg.Certificates = []tls.Certificate{fallback}
|
|
return cfg, nil
|
|
}
|
|
if ws.ProxyServer != nil {
|
|
appCert := ws.ProxyServer.GetCertificate(ch.ServerName)
|
|
if appCert != nil {
|
|
cfg.Certificates = []tls.Certificate{*appCert}
|
|
return cfg, nil
|
|
}
|
|
}
|
|
if ws.BrandTLS != nil {
|
|
bcert := ws.BrandTLS.GetCertificate(ch)
|
|
cfg.Certificates = []tls.Certificate{*bcert.Web}
|
|
ws.log.Trace("using brand web Certificate")
|
|
if bcert.Client != nil {
|
|
cfg.ClientCAs = bcert.Client
|
|
cfg.ClientAuth = tls.RequestClientCert
|
|
ws.log.Trace("using brand client Certificate")
|
|
}
|
|
return cfg, nil
|
|
}
|
|
ws.log.Trace("using default, self-signed certificate")
|
|
cfg.Certificates = []tls.Certificate{fallback}
|
|
return cfg, nil
|
|
}
|
|
}
|
|
|
|
// ServeHTTPS constructs a net.Listener and starts handling HTTPS requests
|
|
func (ws *WebServer) listenTLS() {
|
|
tlsConfig := utils.GetTLSConfig()
|
|
tlsConfig.GetConfigForClient = ws.GetCertificate()
|
|
|
|
ln, err := net.Listen("tcp", config.Get().Listen.HTTPS)
|
|
if err != nil {
|
|
ws.log.WithError(err).Warning("failed to listen (TLS)")
|
|
return
|
|
}
|
|
proxyListener := &proxyproto.Listener{
|
|
Listener: web.TCPKeepAliveListener{
|
|
TCPListener: ln.(*net.TCPListener),
|
|
},
|
|
ConnPolicy: utils.GetProxyConnectionPolicy(),
|
|
}
|
|
defer func() {
|
|
err := proxyListener.Close()
|
|
if err != nil {
|
|
ws.log.WithError(err).Warning("failed to close proxy listener")
|
|
}
|
|
}()
|
|
|
|
tlsListener := tls.NewListener(proxyListener, tlsConfig)
|
|
ws.log.WithField("listen", config.Get().Listen.HTTPS).Info("Starting HTTPS server")
|
|
ws.serve(tlsListener)
|
|
ws.log.WithField("listen", config.Get().Listen.HTTPS).Info("Stopping HTTPS server")
|
|
}
|