From 6c85706c242a4bc20555abb4bd8f0f8b5dc1e62a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 2 Jul 2018 14:40:18 -0700 Subject: [PATCH] Use GetSourceIP for source ip as request params (#6109) Fixes #6108 --- cmd/bucket-handlers.go | 8 ++++---- cmd/handler-utils.go | 3 ++- cmd/object-handlers-common.go | 3 ++- cmd/object-handlers.go | 11 ++++++----- cmd/utils.go | 9 ++++++++- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index cff3fa9e1..6e387aa70 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -34,14 +34,14 @@ import ( "github.com/gorilla/mux" + "github.com/minio/minio-go/pkg/set" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/dns" "github.com/minio/minio/pkg/event" + "github.com/minio/minio/pkg/handlers" "github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/policy" "github.com/minio/minio/pkg/sync/errgroup" - - "github.com/minio/minio-go/pkg/set" ) // Check if there are buckets on server without corresponding entry in etcd backend and @@ -375,7 +375,7 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, // Get host and port from Request.RemoteAddr failing which // fill them with empty strings. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } @@ -648,7 +648,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h w.Header().Set("Location", location) // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } diff --git a/cmd/handler-utils.go b/cmd/handler-utils.go index 67c179e3f..b990b2ced 100644 --- a/cmd/handler-utils.go +++ b/cmd/handler-utils.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/minio/minio/cmd/logger" + "github.com/minio/minio/pkg/handlers" httptracer "github.com/minio/minio/pkg/handlers" ) @@ -167,7 +168,7 @@ func extractReqParams(r *http.Request) map[string]string { // Success. return map[string]string{ - "sourceIPAddress": r.RemoteAddr, + "sourceIPAddress": handlers.GetSourceIP(r), // Add more fields here. } } diff --git a/cmd/object-handlers-common.go b/cmd/object-handlers-common.go index 2079ece5f..722b5dba8 100644 --- a/cmd/object-handlers-common.go +++ b/cmd/object-handlers-common.go @@ -24,6 +24,7 @@ import ( "time" "github.com/minio/minio/pkg/event" + "github.com/minio/minio/pkg/handlers" ) // Validates the preconditions for CopyObjectPart, returns true if CopyObjectPart @@ -243,7 +244,7 @@ func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, } // Get host and port from Request.RemoteAddr. - host, port, _ := net.SplitHostPort(r.RemoteAddr) + host, port, _ := net.SplitHostPort(handlers.GetSourceIP(r)) // Notify object deleted event. sendEvent(eventArgs{ diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index d42158571..61cfbfe40 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -37,6 +37,7 @@ import ( "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/dns" "github.com/minio/minio/pkg/event" + "github.com/minio/minio/pkg/handlers" "github.com/minio/minio/pkg/hash" "github.com/minio/minio/pkg/ioutil" "github.com/minio/minio/pkg/policy" @@ -197,7 +198,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req } // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } @@ -293,7 +294,7 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re w.WriteHeader(http.StatusOK) // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } @@ -617,7 +618,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re writeSuccessResponseXML(w, encodedSuccessResponse) // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } @@ -823,7 +824,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req writeSuccessResponseHeadersOnly(w) // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } @@ -1494,7 +1495,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite writeSuccessResponseXML(w, encodedSuccessResponse) // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(r.RemoteAddr) + host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) if err != nil { host, port = "", "" } diff --git a/cmd/utils.go b/cmd/utils.go index 8fd35958a..ed08ce0b9 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -34,6 +34,7 @@ import ( "time" "github.com/minio/minio/cmd/logger" + "github.com/minio/minio/pkg/handlers" humanize "github.com/dustin/go-humanize" "github.com/gorilla/mux" @@ -335,7 +336,13 @@ func newContext(r *http.Request, api string) context.Context { if prefix != "" { object = prefix } - reqInfo := &logger.ReqInfo{RemoteHost: r.RemoteAddr, UserAgent: r.Header.Get("user-agent"), API: api, BucketName: bucket, ObjectName: object} + reqInfo := &logger.ReqInfo{ + RemoteHost: handlers.GetSourceIP(r), + UserAgent: r.Header.Get("user-agent"), + API: api, + BucketName: bucket, + ObjectName: object, + } return logger.SetReqInfo(context.Background(), reqInfo) }