From 84d400487f0a467f4cec20c06d5da392bfbfa8b4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 9 Feb 2021 09:53:07 -0800 Subject: [PATCH] fix: accountInfo API to cater for federated setups (#11484) when MinIO is deployed in a federated setup, use etcd based listing of buckets to provide appropriate filtering of buckets per user. --- cmd/admin-handlers-users.go | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/cmd/admin-handlers-users.go b/cmd/admin-handlers-users.go index f4dade622..8dda69eb6 100644 --- a/cmd/admin-handlers-users.go +++ b/cmd/admin-handlers-users.go @@ -23,8 +23,10 @@ import ( "io/ioutil" "net/http" "path" + "sort" "github.com/gorilla/mux" + "github.com/minio/minio/cmd/config/dns" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/auth" iampolicy "github.com/minio/minio/pkg/iam/policy" @@ -688,12 +690,6 @@ func (a adminAPIHandlers) AccountInfoHandler(w http.ResponseWriter, r *http.Requ return rd, wr } - buckets, err := objectAPI.ListBuckets(ctx) - if err != nil { - writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) - return - } - // Load the latest calculated data usage dataUsageInfo, err := loadDataUsageFromBackend(ctx, objectAPI) if err != nil { @@ -701,6 +697,33 @@ func (a adminAPIHandlers) AccountInfoHandler(w http.ResponseWriter, r *http.Requ logger.LogIf(ctx, err) } + // If etcd, dns federation configured list buckets from etcd. + var buckets []BucketInfo + if globalDNSConfig != nil && globalBucketFederation { + dnsBuckets, err := globalDNSConfig.List() + if err != nil && !IsErrIgnored(err, + dns.ErrNoEntriesFound, + dns.ErrDomainMissing) { + writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) + return + } + for _, dnsRecords := range dnsBuckets { + buckets = append(buckets, BucketInfo{ + Name: dnsRecords[0].Key, + Created: dnsRecords[0].CreationDate, + }) + } + sort.Slice(buckets, func(i, j int) bool { + return buckets[i].Name < buckets[j].Name + }) + } else { + buckets, err = objectAPI.ListBuckets(ctx) + if err != nil { + writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) + return + } + } + accountName := cred.AccessKey if cred.ParentUser != "" { accountName = cred.ParentUser