Skip to content

Commit

Permalink
fix: azure admin list-buckets
Browse files Browse the repository at this point in the history
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
  • Loading branch information
benmcclelland committed Dec 3, 2024
1 parent 80b316f commit d9591f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1735,17 +1737,18 @@ 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)
if err != nil {
return nil, err
}

var acl auth.ACL
if len(value) == 0 {
return &acl, nil
}
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/group-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d9591f6

Please sign in to comment.