Skip to content

Commit

Permalink
Use GetSourceIP for source ip as request params
Browse files Browse the repository at this point in the history
Fixes #6108
  • Loading branch information
harshavardhana committed Jul 1, 2018
1 parent 92a6676 commit c7a287e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cmd/bucket-handlers.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "", ""
}
Expand Down Expand Up @@ -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 = "", ""
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/handler-utils.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/object-handlers-common.go
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
11 changes: 6 additions & 5 deletions cmd/object-handlers.go
Expand Up @@ -36,6 +36,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"
Expand Down Expand Up @@ -196,7 +197,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 = "", ""
}
Expand Down Expand Up @@ -292,7 +293,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 = "", ""
}
Expand Down Expand Up @@ -616,7 +617,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 = "", ""
}
Expand Down Expand Up @@ -822,7 +823,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 = "", ""
}
Expand Down Expand Up @@ -1493,7 +1494,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 = "", ""
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/utils.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit c7a287e

Please sign in to comment.