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

Check for SetProjectSpaceQuota permission #3690

Merged
merged 1 commit into from
Mar 16, 2023
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
5 changes: 5 additions & 0 deletions changelog/unreleased/check-project-quota-permission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Check set project space quota permission

Instead of checking for `set-space-quota` we now check for `Drive.ReadWriteQuota.Project` when changing project space quotas.

https://github.com/cs3org/reva/pull/3690
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {

u := ctxpkg.ContextMustGetUser(ctx)
res, err := fs.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{
Type: spaceTypePersonal,
Type: _spaceTypePersonal,
Owner: u,
})
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions pkg/storage/utils/decomposedfs/spacepermissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ func (p Permissions) CreateSpace(ctx context.Context, spaceid string) bool {
}

// SetSpaceQuota returns true when the user is allowed to change the spaces quota
func (p Permissions) SetSpaceQuota(ctx context.Context, spaceid string) bool {
return p.checkPermission(ctx, "set-space-quota", spaceRef(spaceid))
func (p Permissions) SetSpaceQuota(ctx context.Context, spaceid string, spaceType string) bool {
switch spaceType {
default:
return false // only quotas of personal and project space may be changed
case _spaceTypePersonal:
return p.checkPermission(ctx, "set-space-quota", spaceRef(spaceid))
case _spaceTypeProject:
return p.checkPermission(ctx, "Drive.ReadWriteQuota.Project", spaceRef(spaceid))
}
}

// ManageSpaceProperties returns true when the user is allowed to change space properties (name/subtitle)
Expand Down
36 changes: 24 additions & 12 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ import (
)

const (
spaceTypePersonal = "personal"
// spaceTypeProject = "project"
spaceTypeShare = "share"
spaceTypeAny = "*"
spaceIDAny = "*"
userIDAny = "*"
_spaceTypePersonal = "personal"
_spaceTypeProject = "project"
spaceTypeShare = "share"
spaceTypeAny = "*"
spaceIDAny = "*"
userIDAny = "*"

quotaUnrestricted = 0
)
Expand All @@ -78,7 +78,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
}
// TODO enforce a uuid?
// TODO clarify if we want to enforce a single personal storage space or if we want to allow sending the spaceid
if req.Type == spaceTypePersonal {
if req.Type == _spaceTypePersonal {
spaceID = req.GetOwner().GetId().GetOpaqueId()
alias = templates.WithSpacePropertiesAndUser(u, req.Type, req.Name, fs.o.PersonalSpaceAliasTemplate)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr

ctx = context.WithValue(ctx, utils.SpaceGrant, struct{ SpaceType string }{SpaceType: req.Type})

if req.Type != spaceTypePersonal {
if req.Type != _spaceTypePersonal {
u := ctxpkg.ContextMustGetUser(ctx)
if err := fs.AddGrant(ctx, &provider.Reference{
ResourceId: &provider.ResourceId{
Expand Down Expand Up @@ -531,10 +531,22 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
}
}

if mapHasKey(metadata, prefixes.QuotaAttr) && !fs.p.SetSpaceQuota(ctx, spaceID) {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
}, nil
if mapHasKey(metadata, prefixes.QuotaAttr) {
typ, err := spaceNode.SpaceRoot.Xattr(prefixes.SpaceTypeAttr)
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{
Code: v1beta11.Code_CODE_INTERNAL,
Message: "space has no type",
},
}, nil
}

if !fs.p.SetSpaceQuota(ctx, spaceID, string(typ)) {
return &provider.UpdateStorageSpaceResponse{
Status: &v1beta11.Status{Code: v1beta11.Code_CODE_PERMISSION_DENIED},
}, nil
}
}

err = spaceNode.SetXattrs(metadata, true)
Expand Down