Handle HEAD/GET requests for virtual DNS requests (#7839)

r.URL.Path is empty when HEAD bucket with virtual
DNS requests come in since bucket is now part of
r.Host, we should use our domain names and fetch
the right bucket/object names.

This fixes an really old issue in our federation
setups.
master
Harshavardhana 5 years ago committed by kannappanr
parent be72609d1f
commit c1d2b3d5c3
  1. 7
      cmd/generic-handlers.go
  2. 12
      cmd/utils.go

@ -294,7 +294,7 @@ func (h minioReservedBucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
default: default:
// For all other requests reject access to reserved // For all other requests reject access to reserved
// buckets // buckets
bucketName, _ := urlPath2BucketObjectName(r.URL.Path) bucketName, _ := request2BucketObjectName(r)
if isMinioReservedBucket(bucketName) || isMinioMetaBucket(bucketName) { if isMinioReservedBucket(bucketName) || isMinioMetaBucket(bucketName) {
writeErrorResponse(context.Background(), w, errorCodes.ToAPIErr(ErrAllAccessDisabled), r.URL, guessIsBrowserReq(r)) writeErrorResponse(context.Background(), w, errorCodes.ToAPIErr(ErrAllAccessDisabled), r.URL, guessIsBrowserReq(r))
return return
@ -494,7 +494,7 @@ var notimplementedObjectResourceNames = map[string]bool{
// Resource handler ServeHTTP() wrapper // Resource handler ServeHTTP() wrapper
func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
bucketName, objectName := urlPath2BucketObjectName(r.URL.Path) bucketName, objectName := request2BucketObjectName(r)
// If bucketName is present and not objectName check for bucket level resource queries. // If bucketName is present and not objectName check for bucket level resource queries.
if bucketName != "" && objectName == "" { if bucketName != "" && objectName == "" {
@ -696,7 +696,8 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return return
} }
bucket, object := urlPath2BucketObjectName(r.URL.Path) bucket, object := request2BucketObjectName(r)
// ListBucket requests should be handled at current endpoint as // ListBucket requests should be handled at current endpoint as
// all buckets data can be fetched from here. // all buckets data can be fetched from here.
if r.Method == http.MethodGet && bucket == "" && object == "" { if r.Method == http.MethodGet && bucket == "" && object == "" {

@ -71,8 +71,20 @@ func cloneHeader(h http.Header) http.Header {
return h2 return h2
} }
func request2BucketObjectName(r *http.Request) (bucketName, objectName string) {
path, err := getResource(r.URL.Path, r.Host, globalDomainNames)
if err != nil {
logger.CriticalIf(context.Background(), err)
}
return urlPath2BucketObjectName(path)
}
// Convert url path into bucket and object name. // Convert url path into bucket and object name.
func urlPath2BucketObjectName(path string) (bucketName, objectName string) { func urlPath2BucketObjectName(path string) (bucketName, objectName string) {
if path == "" || path == slashSeparator {
return "", ""
}
// Trim any preceding slash separator. // Trim any preceding slash separator.
urlPath := strings.TrimPrefix(path, slashSeparator) urlPath := strings.TrimPrefix(path, slashSeparator)

Loading…
Cancel
Save