mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-07 11:58:12 +02:00
use x-forwarded-for to get client ip
This commit is contained in:
parent
dda4a878bc
commit
9ba7ead459
2 changed files with 17 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package authenticate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
|
@ -61,7 +62,8 @@ func (a *Authenticate) logAuthenticateEvent(r *http.Request, profile *identity.P
|
|||
log.Warn(ctx).Err(err).Msg("log authenticate event: failed to decrypt request params")
|
||||
}
|
||||
|
||||
evt := log.Info(ctx).
|
||||
evt := log.Info(context.Background()).
|
||||
Str("ip", httputil.GetClientIP(r)).
|
||||
Str("pomerium_version", params.Get(urlutil.QueryVersion)).
|
||||
Str("pomerium_request_uuid", params.Get(urlutil.QueryRequestUUID)).
|
||||
Str("pomerium_pub", pub.String())
|
||||
|
|
14
internal/httputil/ip.go
Normal file
14
internal/httputil/ip.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetClientIP returns the client IP address from the request.
|
||||
func GetClientIP(r *http.Request) string {
|
||||
if clientIP := r.Header.Get("X-Forwarded-For"); clientIP != "" {
|
||||
return strings.Split(clientIP, ",")[0]
|
||||
}
|
||||
return strings.Split(r.RemoteAddr, ":")[0]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue