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

Prevent editing disabled spaces #2856

Merged
merged 4 commits into from
May 13, 2022
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/prevent-editing-disabled-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Do not allow to edit disabled spaces

Previously managers could still upload to disabled spaces. This is now forbidden

https://github.com/cs3org/reva/pull/2856
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (lu *Lookup) NodeFromID(ctx context.Context, id *provider.ResourceId) (n *n
// The Resource references the root of a space
return lu.NodeFromSpaceID(ctx, id)
}
return node.ReadNode(ctx, lu, id.StorageId, id.OpaqueId)
return node.ReadNode(ctx, lu, id.StorageId, id.OpaqueId, false)
}

// Pathify segments the beginning of a string into depth segments of width length
Expand All @@ -95,7 +95,7 @@ func Pathify(id string, depth, width int) string {

// NodeFromSpaceID converts a resource id without an opaque id into a Node
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error) {
node, err := node.ReadNode(ctx, lu, id.StorageId, id.StorageId)
node, err := node.ReadNode(ctx, lu, id.StorageId, id.StorageId, false)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ func (n *Node) WriteOwner(owner *userpb.UserId) error {
}

// ReadNode creates a new instance from an id and checks if it exists
// FIXME check if user is allowed to access disabled spaces
func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string) (n *Node, err error) {
func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string, canListDisabledSpace bool) (n *Node, err error) {

// read space root
r := &Node{
Expand All @@ -202,6 +201,11 @@ func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string) (n *No
}
r.Exists = true

if !canListDisabledSpace && r.IsDisabled() {
// no permission = not found
return nil, errtypes.NotFound(spaceID)
}

// check if this is a space root
if spaceID == nodeID {
return r, nil
Expand Down Expand Up @@ -336,7 +340,7 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
}

var c *Node
c, err = ReadNode(ctx, n.lu, spaceID, nodeID)
c, err = ReadNode(ctx, n.lu, spaceID, nodeID, false)
if err != nil {
return nil, errors.Wrap(err, "could not read child node")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var _ = Describe("Node", func() {
})
Expect(err).ToNot(HaveOccurred())

n, err := node.ReadNode(env.Ctx, env.Lookup, lookupNode.SpaceID, lookupNode.ID)
n, err := node.ReadNode(env.Ctx, env.Lookup, lookupNode.SpaceID, lookupNode.ID, false)
Expect(err).ToNot(HaveOccurred())
Expect(n.BlobID).To(Equal("file1-blobid"))
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (fs *Decomposedfs) DownloadRevision(ctx context.Context, ref *provider.Refe

spaceID := ref.ResourceId.OpaqueId
// check if the node is available and has not been deleted
n, err := node.ReadNode(ctx, fs.lu, spaceID, kp[0])
n, err := node.ReadNode(ctx, fs.lu, spaceID, kp[0], false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func (fs *Decomposedfs) RestoreRevision(ctx context.Context, ref *provider.Refer

spaceID := ref.ResourceId.StorageId
// check if the node is available and has not been deleted
n, err := node.ReadNode(ctx, fs.lu, spaceID, kp[0])
n, err := node.ReadNode(ctx, fs.lu, spaceID, kp[0], false)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
alias = templates.WithSpacePropertiesAndUser(u, req.Type, req.Name, fs.o.PersonalSpaceAliasTemplate)
}

root, err := node.ReadNode(ctx, fs.lu, spaceID, spaceID)
root, err := node.ReadNode(ctx, fs.lu, spaceID, spaceID, true) // will fall into `Exists` case below
if err == nil && root.Exists {
return nil, errtypes.AlreadyExists("decomposedfs: spaces: space already exists")
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide

if spaceID != spaceIDAny && nodeID != spaceIDAny {
// try directly reading the node
n, err := node.ReadNode(ctx, fs.lu, spaceID, nodeID)
n, err := node.ReadNode(ctx, fs.lu, spaceID, nodeID, true) // permission to read disabled space is checked later
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("id", nodeID).Msg("could not read node")
return nil, err
Expand Down Expand Up @@ -345,7 +345,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
continue
}

n, err := node.ReadNode(ctx, fs.lu, spaceID, nodeID)
n, err := node.ReadNode(ctx, fs.lu, spaceID, nodeID, true)
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("id", nodeID).Msg("could not read node, skipping")
continue
Expand Down Expand Up @@ -378,7 +378,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
// if there are no matches (or they happened to be spaces for the owner) and the node is a child return a space
if len(matches) <= numShares && nodeID != spaceID {
// try node id
n, err := node.ReadNode(ctx, fs.lu, spaceID, nodeID)
n, err := node.ReadNode(ctx, fs.lu, spaceID, nodeID, true) // permission to read disabled space is checked in storageSpaceFromNode
if err != nil {
return nil, err
}
Expand All @@ -405,7 +405,7 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
space := req.StorageSpace
spaceID, _, _ := storagespace.SplitID(space.Id.OpaqueId)

node, err := node.ReadNode(ctx, fs.lu, spaceID, spaceID)
node, err := node.ReadNode(ctx, fs.lu, spaceID, spaceID, true) // permission to read disabled space will be checked later
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -506,7 +506,7 @@ func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.De

spaceID := req.Id.OpaqueId

n, err := node.ReadNode(ctx, fs.lu, spaceID, spaceID)
n, err := node.ReadNode(ctx, fs.lu, spaceID, spaceID, true) // permission to read disabled space is checked later
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/testhelpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (t *TestEnv) CreateTestStorageSpace(typ string, quota *providerv1beta1.Quot
ref := buildRef(space.StorageSpace.Id.OpaqueId, "")

// the space name attribute is the stop condition in the lookup
h, err := node.ReadNode(t.Ctx, t.Lookup, space.StorageSpace.Id.OpaqueId, space.StorageSpace.Id.OpaqueId)
h, err := node.ReadNode(t.Ctx, t.Lookup, space.StorageSpace.Id.OpaqueId, space.StorageSpace.Id.OpaqueId, false)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, erro
continue
}

child, err := node.ReadNode(ctx, t.lookup, n.SpaceID, nodeID)
child, err := node.ReadNode(ctx, t.lookup, n.SpaceID, nodeID, false)
if err != nil {
// TODO log
continue
Expand Down Expand Up @@ -826,7 +826,7 @@ func (t *Tree) readRecycleItem(ctx context.Context, spaceID, key, path string) (
}

recycleNode = node.New(spaceID, nodeID, "", "", 0, "", nil, t.lookup)
recycleNode.SpaceRoot, err = node.ReadNode(ctx, t.lookup, spaceID, spaceID)
recycleNode.SpaceRoot, err = node.ReadNode(ctx, t.lookup, spaceID, spaceID, false)
if err != nil {
return
}
Expand Down