fs: Do not return reservedBucket names in ListBuckets() (#3754)

Make sure to skip reserved bucket names in `ListBuckets()`
current code didn't skip this properly and also generalize
this behavior for both XL and FS.
This commit is contained in:
Harshavardhana
2017-02-16 14:52:14 -08:00
committed by GitHub
parent 8816b08aae
commit 50b4e54a75
28 changed files with 85 additions and 104 deletions
+12 -11
View File
@@ -68,7 +68,8 @@ func (h requestSizeLimitHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
// Reserved bucket.
const (
reservedBucket = "/minio"
minioReservedBucket = "minio"
minioReservedBucketPath = "/" + minioReservedBucket
)
// Adds redirect rules for incoming requests.
@@ -86,8 +87,8 @@ func setBrowserRedirectHandler(h http.Handler) http.Handler {
// serves only limited purpose on redirect-handler for
// browser requests.
func getRedirectLocation(urlPath string) (rLocation string) {
if urlPath == reservedBucket {
rLocation = reservedBucket + "/"
if urlPath == minioReservedBucketPath {
rLocation = minioReservedBucketPath + "/"
}
if contains([]string{
"/",
@@ -95,7 +96,7 @@ func getRedirectLocation(urlPath string) (rLocation string) {
"/login",
"/favicon.ico",
}, urlPath) {
rLocation = reservedBucket + urlPath
rLocation = minioReservedBucketPath + urlPath
}
return rLocation
}
@@ -143,8 +144,8 @@ func setBrowserCacheControlHandler(h http.Handler) http.Handler {
func (h cacheControlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == httpGET && guessIsBrowserReq(r) && globalIsBrowserEnabled {
// For all browser requests set appropriate Cache-Control policies
if hasPrefix(r.URL.Path, reservedBucket+"/") {
if hasSuffix(r.URL.Path, ".js") || r.URL.Path == reservedBucket+"/favicon.ico" {
if hasPrefix(r.URL.Path, minioReservedBucketPath+"/") {
if hasSuffix(r.URL.Path, ".js") || r.URL.Path == minioReservedBucketPath+"/favicon.ico" {
// For assets set cache expiry of one year. For each release, the name
// of the asset name will change and hence it can not be served from cache.
w.Header().Set("Cache-Control", "max-age=31536000")
@@ -160,17 +161,17 @@ func (h cacheControlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Adds verification for incoming paths.
type minioPrivateBucketHandler struct {
handler http.Handler
reservedBucket string
handler http.Handler
reservedBucketPath string
}
func setPrivateBucketHandler(h http.Handler) http.Handler {
return minioPrivateBucketHandler{handler: h, reservedBucket: reservedBucket}
return minioPrivateBucketHandler{h, minioReservedBucketPath}
}
func (h minioPrivateBucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// For all non browser requests, reject access to 'reservedBucket'.
if !guessIsBrowserReq(r) && path.Clean(r.URL.Path) == reservedBucket {
// For all non browser requests, reject access to 'reservedBucketPath'.
if !guessIsBrowserReq(r) && path.Clean(r.URL.Path) == h.reservedBucketPath {
writeErrorResponse(w, ErrAllAccessDisabled, r.URL)
return
}