@@ -290,43 +290,25 @@ func getBucketVersionedResponse(session *models.Principal, bucketName string) (*
290290}
291291
292292// getAccountBuckets fetches a list of all buckets allowed to that particular client from MinIO Servers
293- func getAccountBuckets (ctx context.Context , client MinioAdmin ) ([]* models.Bucket , error ) {
293+ func getAccountBuckets (ctx context.Context , client MinioAdmin , accessKey string ) ([]* models.Bucket , error ) {
294294 info , err := client .AccountInfo (ctx )
295295 if err != nil {
296296 return []* models.Bucket {}, err
297297 }
298-
299298 policyInfo , err := getAccountPolicy (ctx , client )
300299 if err != nil {
301300 return nil , err
302301 }
303-
304- bucketsPolicies := map [string ]minioIAMPolicy.ActionSet {}
305- for _ , statement := range policyInfo .Statements {
306- if statement .Effect == "Allow" {
307- for _ , resource := range statement .Resources .ToSlice () {
308- resourceName := resource .String ()
309- if actions , ok := bucketsPolicies [resourceName ]; ok {
310- mergedActions := append (actions .ToSlice (), statement .Actions .ToSlice ()... )
311- bucketsPolicies [resourceName ] = minioIAMPolicy .NewActionSet (mergedActions ... )
312- } else {
313- bucketsPolicies [resourceName ] = statement .Actions
314- }
315- }
316- }
317- }
318302 var bucketInfos []* models.Bucket
319303 for _ , bucket := range info .Buckets {
320304 var bucketAdminRole bool
321- bucketNameARN := fmt .Sprintf ("arn:aws:s3:::%s/*" , bucket .Name )
322- // match bucket name against policy that allows admin actions
323- if bucketPolicyActions , ok := bucketsPolicies [bucketNameARN ]; ok {
324- bucketAdminRoleActions := bucketPolicyActions .Intersection (acl .BucketAdminRole )
325- bucketAdminRole = len (bucketAdminRoleActions ) > 0
326- } else if bucketPolicyActions , ok := bucketsPolicies ["arn:aws:s3:::*" ]; ok {
327- bucketAdminRoleActions := bucketPolicyActions .Intersection (acl .BucketAdminRole )
328- bucketAdminRole = len (bucketAdminRoleActions ) > 0
305+ conditionValues := map [string ][]string {
306+ condition .AWSUsername .Name (): {accessKey },
329307 }
308+ bucketActions := policyInfo .IsAllowedActions (bucket .Name , "" , conditionValues )
309+ bucketAdminRoleActions := bucketActions .Intersection (acl .BucketAdminRole )
310+ bucketAdminRole = len (bucketAdminRoleActions ) > 0
311+
330312 bucketElem := & models.Bucket {
331313 CreationDate : bucket .Created .Format (time .RFC3339 ),
332314 Details : & models.BucketDetails {
@@ -376,7 +358,7 @@ func getListBucketsResponse(session *models.Principal) (*models.ListBucketsRespo
376358 // create a minioClient interface implementation
377359 // defining the client to be used
378360 adminClient := AdminClient {Client : mAdmin }
379- buckets , err := getAccountBuckets (ctx , adminClient )
361+ buckets , err := getAccountBuckets (ctx , adminClient , session . AccountAccessKey )
380362 if err != nil {
381363 return nil , prepareError (err )
382364 }
@@ -486,7 +468,7 @@ func setBucketAccessPolicy(ctx context.Context, client MinioClient, bucketName s
486468
487469 bucketAccessPolicy := policy.BucketAccessPolicy {Version : minioIAMPolicy .DefaultVersion }
488470 bucketAccessPolicy .Statements = policy .SetPolicy (bucketAccessPolicy .Statements ,
489- policy . BucketPolicy ( bucketPolicy ) , bucketName , "" )
471+ bucketPolicy , bucketName , "" )
490472 // implemented like minio/mc/ s3Client.SetAccess()
491473 if len (bucketAccessPolicy .Statements ) == 0 {
492474 return client .setBucketPolicyWithContext (ctx , bucketName , "" )
0 commit comments