Skip to content

Commit

Permalink
Separate permission checks when accessing shared resource's recycle bin
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 13, 2021
1 parent 8641587 commit 696c073
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
4 changes: 2 additions & 2 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRe
return nil, err
}
// if a key was sent as opaque id purge only that item
if req.Key != "" {
key, itemPath := router.ShiftPath(req.Key)
key, itemPath := router.ShiftPath(req.Key)
if key != "" {
if err := s.storage.PurgeRecycleItem(ctx, ref.GetPath(), key, itemPath); err != nil {
var st *rpc.Status
switch err.(type) {
Expand Down
58 changes: 36 additions & 22 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,9 +1467,32 @@ func (fs *eosfs) EmptyRecycle(ctx context.Context) error {
}

func (fs *eosfs) ListRecycle(ctx context.Context, basePath, key, relativePath string) ([]*provider.RecycleItem, error) {
auth, err := fs.getUserAuthForPath(ctx, basePath)
if err != nil {
return nil, err
var auth eosclient.Authorization

if !fs.conf.EnableHome && basePath != "/" {
// We need to access the recycle bin for a non-home reference.
// We'll get the owner of the particular resource and impersonate them
// if we have access to it.
md, err := fs.GetMD(ctx, &provider.Reference{Path: basePath}, nil)
if err != nil {
return nil, err
}
if md.PermissionSet.ListRecycle {
auth, err = fs.getUIDGateway(ctx, md.Owner)
if err != nil {
return nil, err
}
}
} else {
// We just act on the logged-in user's recycle bin
u, err := getUser(ctx)
if err != nil {
return nil, errors.Wrap(err, "eosfs: no user in ctx")
}
auth, err = fs.getUserAuth(ctx, u, "")
if err != nil {
return nil, err
}
}

eosDeletedEntries, err := fs.c.ListDeletedEntries(ctx, auth)
Expand All @@ -1493,44 +1516,35 @@ func (fs *eosfs) ListRecycle(ctx context.Context, basePath, key, relativePath st
}

func (fs *eosfs) RestoreRecycleItem(ctx context.Context, basePath, key, relativePath string, restoreRef *provider.Reference) error {
auth, err := fs.getUserAuthForPath(ctx, basePath)
if err != nil {
return err
}

return fs.c.RestoreDeletedEntry(ctx, auth, key)
}

func (fs *eosfs) getUserAuthForPath(ctx context.Context, path string) (eosclient.Authorization, error) {
var auth eosclient.Authorization

if !fs.conf.EnableHome && path != "/" {
// We need to list recycle for a non-home reference.
if !fs.conf.EnableHome && basePath != "/" {
// We need to access the recycle bin for a non-home reference.
// We'll get the owner of the particular resource and impersonate them
// if we have access to it.
md, err := fs.GetMD(ctx, &provider.Reference{Path: path}, nil)
md, err := fs.GetMD(ctx, &provider.Reference{Path: basePath}, nil)
if err != nil {
return auth, err
return err
}
if md.PermissionSet.ListRecycle {
if md.PermissionSet.RestoreRecycleItem {
auth, err = fs.getUIDGateway(ctx, md.Owner)
if err != nil {
return auth, err
return err
}
}
} else {
// We just list the logged-in user's recycle bin
// We just act on the logged-in user's recycle bin
u, err := getUser(ctx)
if err != nil {
return auth, errors.Wrap(err, "eosfs: no user in ctx")
return errors.Wrap(err, "eosfs: no user in ctx")
}
auth, err = fs.getUserAuth(ctx, u, "")
if err != nil {
return auth, err
return err
}
}

return auth, nil
return fs.c.RestoreDeletedEntry(ctx, auth, key)
}

func (fs *eosfs) ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter) ([]*provider.StorageSpace, error) {
Expand Down

0 comments on commit 696c073

Please sign in to comment.