From d9591f694ee98396efc580678ec59edfd66f0001 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Mon, 2 Dec 2024 16:28:56 -0800 Subject: [PATCH] fix: azure admin list-buckets There were two issues that were preventing correct behavior here. One was that we need to specifically request the container metadata when listing containers, and then we also need to handle the case where the container does not include the acl metadata. This fixes both of these cases by adding in the metadata request option for this container listing, and will return a default acl if not provided in the container metadaata. Fixes #948 --- backend/azure/azure.go | 11 +++++++---- tests/integration/group-tests.go | 2 ++ tests/integration/tests.go | 12 ++++++++++++ tests/integration/utils.go | 12 ++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/backend/azure/azure.go b/backend/azure/azure.go index 6c602e1..413cf3b 100644 --- a/backend/azure/azure.go +++ b/backend/azure/azure.go @@ -196,7 +196,6 @@ func (az *Azure) CreateBucket(ctx context.Context, input *s3.CreateBucketInput, } func (az *Azure) ListBuckets(ctx context.Context, input s3response.ListBucketsInput) (s3response.ListAllMyBucketsResult, error) { - fmt.Printf("%+v\n", input) pager := az.client.NewListContainersPager( &service.ListContainersOptions{ Include: service.ListContainersInclude{ @@ -1459,7 +1458,10 @@ func (az *Azure) ChangeBucketOwner(ctx context.Context, bucket string, acl []byt // The action actually returns the containers owned by the user, who initialized the gateway // TODO: Not sure if there's a way to list all the containers and owners? func (az *Azure) ListBucketsAndOwners(ctx context.Context) (buckets []s3response.Bucket, err error) { - pager := az.client.NewListContainersPager(nil) + opts := &service.ListContainersOptions{ + Include: service.ListContainersInclude{Metadata: true}, + } + pager := az.client.NewListContainersPager(opts) for pager.More() { resp, err := pager.NextPage(ctx) @@ -1735,9 +1737,11 @@ func (az *Azure) deleteContainerMetaData(ctx context.Context, bucket, key string } func getAclFromMetadata(meta map[string]*string, key key) (*auth.ACL, error) { + var acl auth.ACL + data, ok := meta[string(key)] if !ok { - return nil, s3err.GetAPIError(s3err.ErrInternalError) + return &acl, nil } value, err := decodeString(*data) @@ -1745,7 +1749,6 @@ func getAclFromMetadata(meta map[string]*string, key key) (*auth.ACL, error) { return nil, err } - var acl auth.ACL if len(value) == 0 { return &acl, nil } diff --git a/tests/integration/group-tests.go b/tests/integration/group-tests.go index a09cc03..259c045 100644 --- a/tests/integration/group-tests.go +++ b/tests/integration/group-tests.go @@ -534,6 +534,7 @@ func TestIAM(s *S3Conf) { IAM_userplus_CreateBucket(s) IAM_admin_ChangeBucketOwner(s) IAM_ChangeBucketOwner_back_to_root(s) + IAM_ListBuckets(s) } func TestAccessControl(s *S3Conf) { @@ -956,6 +957,7 @@ func GetIntTests() IntTests { "IAM_userplus_CreateBucket": IAM_userplus_CreateBucket, "IAM_admin_ChangeBucketOwner": IAM_admin_ChangeBucketOwner, "IAM_ChangeBucketOwner_back_to_root": IAM_ChangeBucketOwner_back_to_root, + "IAM_ListBuckets": IAM_ListBuckets, "AccessControl_default_ACL_user_access_denied": AccessControl_default_ACL_user_access_denied, "AccessControl_default_ACL_userplus_access_denied": AccessControl_default_ACL_userplus_access_denied, "AccessControl_default_ACL_admin_successful_access": AccessControl_default_ACL_admin_successful_access, diff --git a/tests/integration/tests.go b/tests/integration/tests.go index 1378992..276b9e8 100644 --- a/tests/integration/tests.go +++ b/tests/integration/tests.go @@ -11060,6 +11060,18 @@ func IAM_ChangeBucketOwner_back_to_root(s *S3Conf) error { }) } +func IAM_ListBuckets(s *S3Conf) error { + testName := "IAM_ListBuckets" + return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + err := listBuckets(s) + if err != nil { + return err + } + + return nil + }) +} + // Posix related tests func PutObject_overwrite_dir_obj(s *S3Conf) error { testName := "PutObject_overwrite_dir_obj" diff --git a/tests/integration/utils.go b/tests/integration/utils.go index e1e1d15..aa50c50 100644 --- a/tests/integration/utils.go +++ b/tests/integration/utils.go @@ -803,6 +803,18 @@ func changeBucketsOwner(s *S3Conf, buckets []string, owner string) error { return nil } +func listBuckets(s *S3Conf) error { + out, err := execCommand("admin", "-a", s.awsID, "-s", s.awsSecret, "-er", s.endpoint, "list-buckets") + if err != nil { + return err + } + if strings.Contains(string(out), adminErrorPrefix) { + return fmt.Errorf("failed to list buckets, %s", out) + } + + return nil +} + const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" func genRandString(length int) string {