From f6e8dbfb5e82998d0b0b5166789cecfbee805fe9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 2 Oct 2021 22:00:37 +0200 Subject: [PATCH] outposts/proxy: show full error message when user is authenticated Signed-off-by: Jens Langhammer --- internal/outpost/proxyv2/application/error.go | 7 ++++++- internal/outpost/proxyv2/application/mode_proxy.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/outpost/proxyv2/application/error.go b/internal/outpost/proxyv2/application/error.go index 1c4f75cdf..d2f50b8e4 100644 --- a/internal/outpost/proxyv2/application/error.go +++ b/internal/outpost/proxyv2/application/error.go @@ -1,6 +1,7 @@ package application import ( + "fmt" "html/template" "net/http" @@ -8,8 +9,9 @@ import ( ) // NewProxyErrorHandler creates a ProxyErrorHandler using the template given. -func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) { +func (a *Application) newProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) { return func(rw http.ResponseWriter, req *http.Request, proxyErr error) { + claims, _ := a.getClaims(req) log.WithError(proxyErr).Warning("Error proxying to upstream server") rw.WriteHeader(http.StatusBadGateway) data := struct { @@ -21,6 +23,9 @@ func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWr Message: "Error proxying to upstream server", ProxyPrefix: "/akprox", } + if claims != nil { + data.Message = fmt.Sprintf("Error proxying to upstream server: %s", proxyErr.Error()) + } err := errorTemplate.Execute(rw, data) if err != nil { http.Error(rw, "Internal Server Error", http.StatusInternalServerError) diff --git a/internal/outpost/proxyv2/application/mode_proxy.go b/internal/outpost/proxyv2/application/mode_proxy.go index 6630d1687..7c25f0932 100644 --- a/internal/outpost/proxyv2/application/mode_proxy.go +++ b/internal/outpost/proxyv2/application/mode_proxy.go @@ -29,7 +29,7 @@ func (a *Application) configureProxy() error { } rp := &httputil.ReverseProxy{Director: a.proxyModifyRequest(u)} rp.Transport = ak.NewTracingTransport(context.TODO(), a.getUpstreamTransport()) - rp.ErrorHandler = NewProxyErrorHandler(templates.GetTemplates()) + rp.ErrorHandler = a.newProxyErrorHandler(templates.GetTemplates()) rp.ModifyResponse = a.proxyModifyResponse a.mux.PathPrefix("/").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { claims, err := a.getClaims(r)