From 3677b4b41df3101e3f84aa6786ba52fc6463450d Mon Sep 17 00:00:00 2001 From: muphoff Date: Fri, 8 Dec 2023 15:18:16 +0100 Subject: [PATCH] core: add x-forwarded-for header --- README.md | 3 --- pkg/server/server.go | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2224336..89374cd 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,6 @@ full support for all functionalities provided by the Ingress API Object. - [ ] Https redirect/rewrite - [ ] Install as a Helm Chart -Find an example of implementing this controller in -[Guardgress-Example](https://github.com/h3adex/guardgress-example). - ## Images - [ghcr.io/h3adex/guardgress:latest](https://github.com/h3adex/guardgress/pkgs/container/guardgress) diff --git a/pkg/server/server.go b/pkg/server/server.go index d0c2adc..56984a2 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -92,7 +92,10 @@ func (s Server) ServeHttps(ctx *gin.Context) { return } - ctx.Header("Access-Control-Allow-Origin", "*") + req, err := httputil.DumpRequest(ctx.Request, true) + log.Debug("request coming from ip: ", ctx.ClientIP()) + log.Debug("request dump: ", string(req)) + svcUrl, parsedAnnotations, routingError := s.RoutingTable.GetBackend( ctx.Request.Host, ctx.Request.RequestURI, @@ -149,6 +152,7 @@ func (s Server) ServeHttps(ctx *gin.Context) { } } + ctx.Request.Header.Add("X-Forwarded-For", ctx.ClientIP()) proxy.Director = func(req *http.Request) { req.Header = ctx.Request.Header req.Host = ctx.Request.Host @@ -166,7 +170,8 @@ func (s Server) ServeHTTP(ctx *gin.Context) { return } - ctx.Header("Access-Control-Allow-Origin", "*") + log.Debug("request coming from ip: ", ctx.ClientIP()) + svcUrl, _, routingError := s.RoutingTable.GetBackend( ctx.Request.Host, ctx.Request.RequestURI, @@ -188,6 +193,7 @@ func (s Server) ServeHTTP(ctx *gin.Context) { } } + ctx.Request.Header.Add("X-Forwarded-For", ctx.ClientIP()) proxy.Director = func(req *http.Request) { req.Header = ctx.Request.Header req.Host = ctx.Request.Host