Skip to content

Commit f42c202

Browse files
Merge pull request #1067 from versity/ben/default_bucket_acl
fix: return default bucket acl if none exists
2 parents 34f60f1 + a3338db commit f42c202

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

auth/acl.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,25 @@ func ParseACL(data []byte) (ACL, error) {
193193
return acl, nil
194194
}
195195

196-
func ParseACLOutput(data []byte) (GetBucketAclOutput, error) {
196+
func ParseACLOutput(data []byte, owner string) (GetBucketAclOutput, error) {
197+
grants := []Grant{}
198+
199+
if len(data) == 0 {
200+
return GetBucketAclOutput{
201+
Owner: &types.Owner{
202+
ID: &owner,
203+
},
204+
AccessControlList: AccessControlList{
205+
Grants: grants,
206+
},
207+
}, nil
208+
}
209+
197210
var acl ACL
198211
if err := json.Unmarshal(data, &acl); err != nil {
199212
return GetBucketAclOutput{}, fmt.Errorf("parse acl: %w", err)
200213
}
201214

202-
grants := []Grant{}
203-
204215
for _, elem := range acl.Grantees {
205216
acs := elem.Access
206217
grants = append(grants, Grant{

s3api/controllers/base.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ func (c S3ApiController) ListActions(ctx *fiber.Ctx) error {
921921
})
922922
}
923923

924-
res, err := auth.ParseACLOutput(data)
924+
res, err := auth.ParseACLOutput(data, parsedAcl.Owner)
925925
return SendXMLResponse(ctx, res, err,
926926
&MetaOpts{
927927
Logger: c.logger,

s3api/middlewares/acl-parser.go

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func AclParser(be backend.Backend, logger s3log.AuditLogger, readonly bool) fibe
7474
return controllers.SendResponse(ctx, err, &controllers.MetaOpts{Logger: logger})
7575
}
7676

77+
// if owner is not set, set default owner to root account
78+
if parsedAcl.Owner == "" {
79+
parsedAcl.Owner = ctx.Locals("rootAccess").(string)
80+
}
81+
7782
ctx.Locals("parsedAcl", parsedAcl)
7883
return ctx.Next()
7984
}

s3api/middlewares/authentication.go

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func VerifyV4Signature(root RootUserConfig, iam auth.IAMService, logger s3log.Au
7676
}
7777

7878
ctx.Locals("isRoot", authData.Access == root.Access)
79+
ctx.Locals("rootAccess", root.Access)
7980

8081
account, err := acct.getAccount(authData.Access)
8182
if err == auth.ErrNoSuchUser {

s3api/middlewares/presign-auth.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func VerifyPresignedV4Signature(root RootUserConfig, iam auth.IAMService, logger
4343
}
4444

4545
ctx.Locals("isRoot", authData.Access == root.Access)
46+
ctx.Locals("rootAccess", root.Access)
47+
4648
account, err := acct.getAccount(authData.Access)
4749
if err == auth.ErrNoSuchUser {
4850
return sendResponse(ctx, s3err.GetAPIError(s3err.ErrInvalidAccessKeyID), logger, mm)

0 commit comments

Comments
 (0)