mirror of
https://github.com/openziti/zrok.git
synced 2025-08-17 11:21:07 +02:00
extract real ip address when behind a load balancer (#68)
This commit is contained in:
@ -11,6 +11,8 @@ import (
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_util"
|
||||
"github.com/pkg/errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ZrokAuthenticate(token string) (*rest_model_zrok.Principal, error) {
|
||||
@ -60,3 +62,17 @@ func hashPassword(raw string) string {
|
||||
hash.Write([]byte(raw))
|
||||
return hex.EncodeToString(hash.Sum(nil))
|
||||
}
|
||||
|
||||
func realRemoteAddress(req *http.Request) string {
|
||||
ip := strings.Split(req.RemoteAddr, ":")[0]
|
||||
fwdAddress := req.Header.Get("X-Forwarded-For")
|
||||
if fwdAddress != "" {
|
||||
ip = fwdAddress
|
||||
|
||||
ips := strings.Split(fwdAddress, ", ")
|
||||
if len(ips) > 1 {
|
||||
ip = ips[0]
|
||||
}
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
Reference in New Issue
Block a user