From 7fd6be5abb0eba32058d6f1accc5f4a1e83e8259 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 30 Jan 2022 21:35:08 +0100 Subject: [PATCH] providers/proxy: add backend_override Signed-off-by: Jens Langhammer --- internal/outpost/proxyv2/application/claims.go | 3 ++- .../outpost/proxyv2/application/mode_proxy.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/outpost/proxyv2/application/claims.go b/internal/outpost/proxyv2/application/claims.go index 4ff89dbff..15af36eb2 100644 --- a/internal/outpost/proxyv2/application/claims.go +++ b/internal/outpost/proxyv2/application/claims.go @@ -1,7 +1,8 @@ package application type ProxyClaims struct { - UserAttributes map[string]interface{} `json:"user_attributes"` + UserAttributes map[string]interface{} `json:"user_attributes"` + BackendOverride string `json:"backend_override"` } type Claims struct { diff --git a/internal/outpost/proxyv2/application/mode_proxy.go b/internal/outpost/proxyv2/application/mode_proxy.go index 0271b0201..66a7569b1 100644 --- a/internal/outpost/proxyv2/application/mode_proxy.go +++ b/internal/outpost/proxyv2/application/mode_proxy.go @@ -60,7 +60,7 @@ func (a *Application) configureProxy() error { } metrics.UpstreamTiming.With(prometheus.Labels{ "outpost_name": a.outpostName, - "upstream_host": u.String(), + "upstream_host": r.URL.Host, "scheme": r.URL.Scheme, "method": r.Method, "path": r.URL.Path, @@ -72,9 +72,17 @@ func (a *Application) configureProxy() error { } func (a *Application) proxyModifyRequest(u *url.URL) func(req *http.Request) { - return func(req *http.Request) { - req.URL.Scheme = u.Scheme - req.URL.Host = u.Host + return func(r *http.Request) { + claims, _ := a.getClaims(r) + if claims.Proxy.BackendOverride != "" { + var err error + u, err = url.Parse(claims.Proxy.BackendOverride) + if err != nil { + a.log.WithField("backend_override", claims.Proxy.BackendOverride).WithError(err).Warning("failed parse user backend override") + } + } + r.URL.Scheme = u.Scheme + r.URL.Host = u.Host } }