From 7a72d5a6edae88f654ae38bcb30a2c57e9f6ede8 Mon Sep 17 00:00:00 2001 From: Saman Mahdanian Date: Sat, 4 Nov 2023 21:36:29 +0330 Subject: [PATCH] added debug log to ip tests --- pkg/auth/authenticator.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/auth/authenticator.go b/pkg/auth/authenticator.go index 3f3c6af..7952697 100644 --- a/pkg/auth/authenticator.go +++ b/pkg/auth/authenticator.go @@ -2,6 +2,7 @@ package auth import ( "context" + "math/rand" "net" "net/http" "path/filepath" @@ -250,6 +251,8 @@ func (a *Authenticator) UpdateCache(c client.Client, ctx context.Context, readOn // TestAccess will check if given AccessToken (identified by raw token in the request) // has access to given Webservice (identified by its name) and returns proper CerberusReason func (a *Authenticator) TestAccess(request *Request, wsvc ServicesCacheEntry) (bool, CerberusReason, ExtraHeaders) { + debug := (rand.Intn(100) < 1) + newExtraHeaders := make(ExtraHeaders) ok, reason, token := a.readToken(request, wsvc) if !ok { @@ -273,6 +276,17 @@ func (a *Authenticator) TestAccess(request *Request, wsvc ServicesCacheEntry) (b // Retrieve "remoteAddr" from the requeset remoteAddr := request.Request.RemoteAddr + + if debug { + a.logger.Info("testing request", + "x-forward-for", xForwardedFor, + "ipList", ipList, + "referrer", referrer, + "remoteAddr", remoteAddr, + "ipAllowList", (*a.accessCache)[token].Spec.IpAllowList, + ) + } + host, _, err := net.SplitHostPort(remoteAddr) if err != nil { return false, CerberusReasonInvalidSourceIp, newExtraHeaders