Pass Client IP address to MinIO on x-forwarded-for header (#2864)

This commit is contained in:
Daniel Valdivia
2023-06-14 12:36:48 -07:00
committed by GitHub
parent fc4263e2f9
commit 4a172fae97
53 changed files with 382 additions and 590 deletions

View File

@@ -17,6 +17,7 @@
package utils
import (
"context"
"encoding/base64"
"github.com/google/uuid"
@@ -51,4 +52,15 @@ const (
ContextRequestHost = key("request-host")
ContextRequestRemoteAddr = key("request-remote-addr")
ContextAuditKey = key("request-audit-entry")
ContextClientIP = key("client-ip")
)
// ClientIPFromContext attempts to get the Client IP from a context, if it's not present, it returns
// 127.0.0.1
func ClientIPFromContext(ctx context.Context) string {
val := ctx.Value(ContextClientIP)
if val != nil {
return val.(string)
}
return "127.0.0.1"
}