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

remove share jail check #3432

Merged
merged 4 commits into from
Nov 4, 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
6 changes: 6 additions & 0 deletions changelog/unreleased/remove-share-jail-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Remove share jail fix

We have removed the share jail check.

https://github.com/cs3org/reva/pull/3432
https://github.com/owncloud/ocis/issues/4945
82 changes: 1 addition & 81 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"path"
"path/filepath"
"strconv"
"strings"
"syscall"

cs3permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
Expand All @@ -53,7 +52,6 @@ import (
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/codes"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -403,85 +401,7 @@ func (fs *Decomposedfs) TouchFile(ctx context.Context, ref *provider.Reference)
// To mimic the eos and owncloud driver we only allow references as children of the "/Shares" folder
// FIXME: This comment should explain briefly what a reference is in this context.
func (fs *Decomposedfs) CreateReference(ctx context.Context, p string, targetURI *url.URL) (err error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer("reva").Start(ctx, "CreateReference")
defer span.End()

p = strings.Trim(p, "/")
parts := strings.Split(p, "/")

if len(parts) != 2 {
err := errtypes.PermissionDenied("Decomposedfs: references must be a child of the share folder: share_folder=" + fs.o.ShareFolder + " path=" + p)
span.SetStatus(codes.Error, err.Error())
return err
}

if parts[0] != strings.Trim(fs.o.ShareFolder, "/") {
err := errtypes.PermissionDenied("Decomposedfs: cannot create references outside the share folder: share_folder=" + fs.o.ShareFolder + " path=" + p)
span.SetStatus(codes.Error, err.Error())
return err
}

// create Shares folder if it does not exist
var parentNode *node.Node
var parentCreated, childCreated bool // defaults to false
if parentNode, err = fs.lu.NodeFromResource(ctx, &provider.Reference{Path: fs.o.ShareFolder}); err != nil {
err := errtypes.InternalError(err.Error())
span.SetStatus(codes.Error, err.Error())
return err
} else if !parentNode.Exists {
if err = fs.tp.CreateDir(ctx, parentNode); err != nil {
span.SetStatus(codes.Error, err.Error())
return err
}
parentCreated = true
}

var childNode *node.Node
// clean up directories created here on error
defer func() {
if err != nil {
// do not catch the error to not shadow the original error
if childCreated && childNode != nil {
if tmpErr := fs.tp.Delete(ctx, childNode); tmpErr != nil {
appctx.GetLogger(ctx).Error().Err(tmpErr).Str("node_id", childNode.ID).Msg("Can not clean up child node after error")
}
}
if parentCreated && parentNode != nil {
if tmpErr := fs.tp.Delete(ctx, parentNode); tmpErr != nil {
appctx.GetLogger(ctx).Error().Err(tmpErr).Str("node_id", parentNode.ID).Msg("Can not clean up parent node after error")
}

}
}
}()

if childNode, err = parentNode.Child(ctx, parts[1]); err != nil {
return errtypes.InternalError(err.Error())
}

if childNode.Exists {
// TODO append increasing number to mountpoint name
err := errtypes.AlreadyExists(p)
span.SetStatus(codes.Error, err.Error())
return err
}

if err := fs.tp.CreateDir(ctx, childNode); err != nil {
span.SetStatus(codes.Error, err.Error())
return err
}
childCreated = true

if err := childNode.SetMetadata(xattrs.ReferenceAttr, targetURI.String()); err != nil {
// the reference could not be set - that would result in an lost reference?
err := errors.Wrapf(err, "Decomposedfs: error setting the target %s on the reference file %s",
targetURI.String(),
childNode.InternalPath(),
)
span.SetStatus(codes.Error, err.Error())
return err
}
return nil
return errtypes.NotSupported("not implemented")
}

// Move moves a resource from one reference to another
Expand Down
5 changes: 0 additions & 5 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,3 @@ func (lu *Lookup) InternalRoot() string {
func (lu *Lookup) InternalPath(spaceID, nodeID string) string {
return filepath.Join(lu.Options.Root, "spaces", Pathify(spaceID, 1, 2), "nodes", Pathify(nodeID, 4, 2))
}

// ShareFolder returns the internal storage root directory
func (lu *Lookup) ShareFolder() string {
return lu.Options.ShareFolder
}
1 change: 0 additions & 1 deletion pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ type PathLookup interface {
InternalRoot() string
InternalPath(spaceID, nodeID string) string
Path(ctx context.Context, n *Node) (path string, err error)
ShareFolder() string
}

// New returns a new instance of Node
Expand Down
6 changes: 0 additions & 6 deletions pkg/storage/utils/decomposedfs/node/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,11 @@ func NewPermissions(lu PathLookup) *Permissions {
func (p *Permissions) AssemblePermissions(ctx context.Context, n *Node) (ap provider.ResourcePermissions, err error) {
u, ok := ctxpkg.ContextGetUser(ctx)
if !ok {
appctx.GetLogger(ctx).Debug().Interface("node", n.ID).Msg("no user in context, returning default permissions")
return NoPermissions(), nil
}

// check if the current user is the owner
if utils.UserIDEqual(u.Id, n.Owner()) {
lp, err := n.lu.Path(ctx, n)
if err == nil && lp == n.lu.ShareFolder() {
return ShareFolderPermissions(), nil
}
appctx.GetLogger(ctx).Debug().Str("node", n.ID).Msg("user is owner, returning owner permissions")
return OwnerPermissions(), nil
}
// determine root
Expand Down
9 changes: 0 additions & 9 deletions pkg/storage/utils/decomposedfs/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type Options struct {
// UserLayout describes the relative path from the storage's root node to the users home node.
UserLayout string `mapstructure:"user_layout"`

// TODO NodeLayout option to save nodes as eg. nodes/1d/d8/1dd84abf-9466-4e14-bb86-02fc4ea3abcf
ShareFolder string `mapstructure:"share_folder"`

// propagate mtime changes as tmtime (tree modification time) to the parent directory when user.ocis.propagation=1 is set on a node
TreeTimeAccounting bool `mapstructure:"treetime_accounting"`

Expand Down Expand Up @@ -73,12 +70,6 @@ func New(m map[string]interface{}) (*Options, error) {
// ensure user layout has no starting or trailing /
o.UserLayout = strings.Trim(o.UserLayout, "/")

if o.ShareFolder == "" {
o.ShareFolder = "/Shares"
}
// ensure share folder always starts with slash
o.ShareFolder = filepath.Join("/", o.ShareFolder)

// c.DataDirectory should never end in / unless it is the root
o.Root = filepath.Clean(o.Root)

Expand Down
1 change: 0 additions & 1 deletion pkg/storage/utils/decomposedfs/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var _ = Describe("Options", func() {
})

It("sets defaults", func() {
Expect(len(o.ShareFolder) > 0).To(BeTrue())
Expect(len(o.UserLayout) > 0).To(BeTrue())
})

Expand Down
1 change: 0 additions & 1 deletion pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type PathLookup interface {
InternalRoot() string
InternalPath(spaceID, nodeID string) string
Path(ctx context.Context, n *node.Node) (path string, err error)
ShareFolder() string
}

// Tree manages a hierarchical tree
Expand Down