Skip to content

Commit

Permalink
added debug log to ip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMHD committed Nov 4, 2023
1 parent 90dc25b commit 7a72d5a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"context"
"math/rand"
"net"
"net/http"
"path/filepath"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 7a72d5a

Please sign in to comment.