Skip to content

Commit

Permalink
Merge pull request #1067 from versity/ben/default_bucket_acl
Browse files Browse the repository at this point in the history
fix: return default bucket acl if none exists
  • Loading branch information
benmcclelland authored Feb 13, 2025
2 parents 34f60f1 + a3338db commit f42c202
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
17 changes: 14 additions & 3 deletions auth/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,25 @@ func ParseACL(data []byte) (ACL, error) {
return acl, nil
}

func ParseACLOutput(data []byte) (GetBucketAclOutput, error) {
func ParseACLOutput(data []byte, owner string) (GetBucketAclOutput, error) {
grants := []Grant{}

if len(data) == 0 {
return GetBucketAclOutput{
Owner: &types.Owner{
ID: &owner,
},
AccessControlList: AccessControlList{
Grants: grants,
},
}, nil
}

var acl ACL
if err := json.Unmarshal(data, &acl); err != nil {
return GetBucketAclOutput{}, fmt.Errorf("parse acl: %w", err)
}

grants := []Grant{}

for _, elem := range acl.Grantees {
acs := elem.Access
grants = append(grants, Grant{
Expand Down
2 changes: 1 addition & 1 deletion s3api/controllers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ func (c S3ApiController) ListActions(ctx *fiber.Ctx) error {
})
}

res, err := auth.ParseACLOutput(data)
res, err := auth.ParseACLOutput(data, parsedAcl.Owner)
return SendXMLResponse(ctx, res, err,
&MetaOpts{
Logger: c.logger,
Expand Down
5 changes: 5 additions & 0 deletions s3api/middlewares/acl-parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func AclParser(be backend.Backend, logger s3log.AuditLogger, readonly bool) fibe
return controllers.SendResponse(ctx, err, &controllers.MetaOpts{Logger: logger})
}

// if owner is not set, set default owner to root account
if parsedAcl.Owner == "" {
parsedAcl.Owner = ctx.Locals("rootAccess").(string)
}

ctx.Locals("parsedAcl", parsedAcl)
return ctx.Next()
}
Expand Down
1 change: 1 addition & 0 deletions s3api/middlewares/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func VerifyV4Signature(root RootUserConfig, iam auth.IAMService, logger s3log.Au
}

ctx.Locals("isRoot", authData.Access == root.Access)
ctx.Locals("rootAccess", root.Access)

account, err := acct.getAccount(authData.Access)
if err == auth.ErrNoSuchUser {
Expand Down
2 changes: 2 additions & 0 deletions s3api/middlewares/presign-auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func VerifyPresignedV4Signature(root RootUserConfig, iam auth.IAMService, logger
}

ctx.Locals("isRoot", authData.Access == root.Access)
ctx.Locals("rootAccess", root.Access)

account, err := acct.getAccount(authData.Access)
if err == auth.ErrNoSuchUser {
return sendResponse(ctx, s3err.GetAPIError(s3err.ErrInvalidAccessKeyID), logger, mm)
Expand Down

0 comments on commit f42c202

Please sign in to comment.