Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return default bucket acl if none exists #1067

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading