Skip to content

Commit

Permalink
Fix: Refactor auth flow and ensure HAproxy v2 config check
Browse files Browse the repository at this point in the history
Add conditional check for HAproxy v2 support before processing the client IP and XClientPort in auth.go. Also simplify auth call chain in http.go by removing redundant withClientInfo call.

Signed-off-by: Christian Roessner <c@roessner.co>
  • Loading branch information
Christian Roessner committed Nov 27, 2024
1 parent 1b880c2 commit 111e558
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions server/core/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2384,12 +2384,14 @@ func (a *AuthState) withClientInfo(ctx *gin.Context) *AuthState {

if a.ClientIP == "" {
// This might be valid if HAproxy v2 support is enabled
a.ClientIP, a.XClientPort, err = net.SplitHostPort(ctx.Request.RemoteAddr)
if err != nil {
level.Error(log.Logger).Log(definitions.LogKeyGUID, a.GUID, definitions.LogKeyMsg, err.Error())
}
if config.LoadableConfig.Server.HAproxyV2 {
a.ClientIP, a.XClientPort, err = net.SplitHostPort(ctx.Request.RemoteAddr)
if err != nil {
level.Error(log.Logger).Log(definitions.LogKeyGUID, a.GUID, definitions.LogKeyMsg, err.Error())
}

util.ProcessXForwardedFor(ctx, &a.ClientIP, &a.XClientPort, &a.XSSL)
util.ProcessXForwardedFor(ctx, &a.ClientIP, &a.XClientPort, &a.XSSL)
}
}

if config.LoadableConfig.Server.DNS.ResolveClientIP {
Expand Down
2 changes: 1 addition & 1 deletion server/core/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func requestHandler(ctx *gin.Context) {
if found, reject := auth.preproccessAuthRequest(ctx); reject {
return
} else if found {
auth.withClientInfo(ctx).withLocalInfo(ctx).withUserAgent(ctx).withXSSL(ctx)
auth.withLocalInfo(ctx).withUserAgent(ctx).withXSSL(ctx)
}

switch ctx.Param("service") {
Expand Down

0 comments on commit 111e558

Please sign in to comment.