From 2deb185550e8452b065ccf6f764d13930ed03eb2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 14 Jan 2023 23:27:34 +0100 Subject: [PATCH 1/2] internal: fix empty scheme field Signed-off-by: Jens Langhammer --- internal/utils/web/middleware.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/utils/web/middleware.go b/internal/utils/web/middleware.go index 8688e6c73..d061e666d 100644 --- a/internal/utils/web/middleware.go +++ b/internal/utils/web/middleware.go @@ -14,10 +14,9 @@ import ( // responseLogger is wrapper of http.ResponseWriter that keeps track of its HTTP status // code and body size type responseLogger struct { - w http.ResponseWriter - status int - size int - upstream string + w http.ResponseWriter + status int + size int } // Header returns the ResponseWriter's Header @@ -98,15 +97,18 @@ func (h loggingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { responseLogger := &responseLogger{w: w} h.handler.ServeHTTP(responseLogger, req) duration := float64(time.Since(t)) / float64(time.Millisecond) + scheme := "http" + if req.TLS != nil { + scheme = "https" + } h.afterHandler(h.logger.WithFields(log.Fields{ "remote": req.RemoteAddr, "host": GetHost(req), "runtime": fmt.Sprintf("%0.3f", duration), "method": req.Method, - "scheme": req.URL.Scheme, + "scheme": scheme, "size": responseLogger.Size(), "status": responseLogger.Status(), - "upstream": responseLogger.upstream, "user_agent": req.UserAgent(), }), req).Info(url.RequestURI()) } From 9b2ceb0d44ecc9600e79a9f6abbf51efbe28aecc Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 14 Jan 2023 23:29:51 +0100 Subject: [PATCH 2/2] outposts/proxy: make logged user more consistent, set FlushInterval Signed-off-by: Jens Langhammer --- internal/outpost/proxyv2/application/application.go | 4 ++-- internal/outpost/proxyv2/application/mode_proxy.go | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/outpost/proxyv2/application/application.go b/internal/outpost/proxyv2/application/application.go index cb9e9b0de..4c6402253 100644 --- a/internal/outpost/proxyv2/application/application.go +++ b/internal/outpost/proxyv2/application/application.go @@ -113,9 +113,9 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, cs *ak.CryptoStore return l } if c.PreferredUsername != "" { - return l.WithField("request_username", c.PreferredUsername) + return l.WithField("user", c.PreferredUsername) } - return l.WithField("request_username", c.Sub) + return l.WithField("user", c.Sub) })) mux.Use(func(inner http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { diff --git a/internal/outpost/proxyv2/application/mode_proxy.go b/internal/outpost/proxyv2/application/mode_proxy.go index 79ad0ad5a..0d687b657 100644 --- a/internal/outpost/proxyv2/application/mode_proxy.go +++ b/internal/outpost/proxyv2/application/mode_proxy.go @@ -27,11 +27,14 @@ func (a *Application) configureProxy() error { if err != nil { return err } - rp := &httputil.ReverseProxy{Director: a.proxyModifyRequest(u)} rsp := sentry.StartSpan(context.TODO(), "authentik.outposts.proxy.application_transport") - rp.Transport = web.NewTracingTransport(rsp.Context(), a.getUpstreamTransport()) - rp.ErrorHandler = a.newProxyErrorHandler() - rp.ModifyResponse = a.proxyModifyResponse + rp := &httputil.ReverseProxy{ + Director: a.proxyModifyRequest(u), + Transport: web.NewTracingTransport(rsp.Context(), a.getUpstreamTransport()), + ErrorHandler: a.newProxyErrorHandler(), + ModifyResponse: a.proxyModifyResponse, + FlushInterval: -1, + } a.mux.PathPrefix("/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { defer func() { err := recover()