From 847734d421d219f1b12b144fcb0d08a6556e1485 Mon Sep 17 00:00:00 2001 From: DianaNites <5275194+DianaNites@users.noreply.github.com> Date: Tue, 2 Dec 2025 15:13:00 -0600 Subject: [PATCH] b2: Fix listing root buckets with unrestricted API key Fixes previous pull request #8978 An oversight meant that unrestricted API keys never called b2_list_buckets, meaning the root remote could not be listed. The call is now made in the event there are no allowed buckets, indicating an unrestricted API key Fixes #9007 --- backend/b2/b2.go | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/backend/b2/b2.go b/backend/b2/b2.go index a21d63dac..22c5e079a 100644 --- a/backend/b2/b2.go +++ b/backend/b2/b2.go @@ -1081,21 +1081,10 @@ type listBucketFn func(*api.Bucket) error func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBucketFn) error { responses := make([]api.ListBucketsResponse, len(f.info.APIs.Storage.Allowed.Buckets))[:0] - for i := range f.info.APIs.Storage.Allowed.Buckets { - b := &f.info.APIs.Storage.Allowed.Buckets[i] - // Empty names indicate a bucket that no longer exists, this is non-fatal - // for multi-bucket API keys. - if b.Name == "" { - continue - } - // When requesting a specific bucket skip over non-matching names - if bucketName != "" && b.Name != bucketName { - continue - } - + call := func(id string) error { var account = api.ListBucketsRequest{ AccountID: f.info.AccountID, - BucketID: b.ID, + BucketID: id, } if bucketName != "" && account.BucketID == "" { account.BucketName = f.opt.Enc.FromStandardName(bucketName) @@ -1114,6 +1103,32 @@ func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBuck return err } responses = append(responses, response) + return nil + } + + for i := range f.info.APIs.Storage.Allowed.Buckets { + b := &f.info.APIs.Storage.Allowed.Buckets[i] + // Empty names indicate a bucket that no longer exists, this is non-fatal + // for multi-bucket API keys. + if b.Name == "" { + continue + } + // When requesting a specific bucket skip over non-matching names + if bucketName != "" && b.Name != bucketName { + continue + } + + err := call(b.ID) + if err != nil { + return err + } + } + + if len(f.info.APIs.Storage.Allowed.Buckets) == 0 { + err := call("") + if err != nil { + return err + } } f.bucketIDMutex.Lock()