extract real ip address when behind a load balancer (#68)

This commit is contained in:
Michael Quigley
2022-09-26 16:21:49 -04:00
parent e58fd0760f
commit 9cbbb40105
2 changed files with 19 additions and 5 deletions

View File

@ -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
}