Skip to content

Commit

Permalink
Fix EOS grants conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 18, 2021
1 parent 6b67d5e commit e8d0f1a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
5 changes: 2 additions & 3 deletions pkg/cbox/storage/eoswrapper/eoswrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
}

const (
eosProjectsNamespace = "/eos/project/"
eosProjectsNamespace = "/eos/project"

// We can use a regex for these, but that might have inferior performance
projectSpaceGroupsPrefix = "cernbox-project-"
Expand Down Expand Up @@ -147,8 +147,7 @@ func (w *wrapper) setProjectSharingPermissions(ctx context.Context, r *provider.
if strings.HasPrefix(w.conf.Namespace, eosProjectsNamespace) {

// Extract project name from the path resembling /c/cernbox or /c/cernbox/minutes/..
path := strings.TrimPrefix(r.Path, eosProjectsNamespace)
parts := strings.SplitN(path, "/", 4)
parts := strings.SplitN(r.Path, "/", 4)
if len(parts) != 4 && len(parts) != 3 {
return errtypes.BadRequest("eoswrapper: path does not follow the allowed format")
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,8 @@ func (c *Client) parseFind(dirPath, raw string) ([]*eosclient.FileInfo, error) {
rawLines := strings.FieldsFunc(raw, func(c rune) bool {
return c == '\n'
})

var parent *eosclient.FileInfo
for _, rl := range rawLines {
if rl == "" {
continue
Expand All @@ -887,10 +889,20 @@ func (c *Client) parseFind(dirPath, raw string) ([]*eosclient.FileInfo, error) {
// we skip the current directory as eos find will return the directory we
// ask to find
if fi.File == path.Clean(dirPath) {
parent = fi
continue
}

finfos = append(finfos, fi)
}

for _, fi := range finfos {
// For files, inherit ACLs from the parent
if !fi.IsDir && parent != nil {
fi.SysACL.Entries = append(fi.SysACL.Entries, parent.SysACL.Entries...)
}
}

return finfos, nil
}

Expand Down
27 changes: 18 additions & 9 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,13 +1113,14 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, dpath s
}

var mylst []*eosclient.FileInfo
var parent *eosclient.FileInfo
i := 0
for {
rsp, err := resp.Recv()
if err != nil {
if err == io.EOF {
log.Debug().Str("path", dpath).Int("nitems", i).Msg("OK, no more items, clean exit")
return mylst, nil
break
}

// We got an error while reading items. We log this as an error and we return
Expand All @@ -1136,14 +1137,6 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, dpath s
return nil, errtypes.NotFound(dpath)
}

i++

// The first item is the directory itself... skip
if i == 1 {
log.Debug().Str("func", "List").Str("path", dpath).Str("skipping first item resp:", fmt.Sprintf("%#v", rsp)).Msg("grpc response")
continue
}

log.Debug().Str("func", "List").Str("path", dpath).Str("item resp:", fmt.Sprintf("%#v", rsp)).Msg("grpc response")

myitem, err := c.grpcMDResponseToFileInfo(rsp, dpath)
Expand All @@ -1153,9 +1146,25 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, dpath s
return nil, err
}

i++
// The first item is the directory itself... skip
if i == 1 {
parent = myitem
log.Debug().Str("func", "List").Str("path", dpath).Str("skipping first item resp:", fmt.Sprintf("%#v", rsp)).Msg("grpc response")
continue
}

mylst = append(mylst, myitem)
}

for _, info := range mylst {
if !info.IsDir && parent != nil {
info.SysACL.Entries = append(info.SysACL.Entries, parent.SysACL.Entries...)
}
}

return mylst, nil

}

// Read reads a file from the mgm and returns a handle to read it
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,8 @@ func (fs *eosfs) ListRecycle(ctx context.Context, basePath, key, relativePath st
if err != nil {
return nil, err
}
} else {
return nil, errtypes.PermissionDenied("eosfs: user doesn't have permissions to restore recycled items")
}
} else {
// We just act on the logged-in user's recycle bin
Expand Down Expand Up @@ -1531,6 +1533,8 @@ func (fs *eosfs) RestoreRecycleItem(ctx context.Context, basePath, key, relative
if err != nil {
return err
}
} else {
return errtypes.PermissionDenied("eosfs: user doesn't have permissions to restore recycled items")
}
} else {
// We just act on the logged-in user's recycle bin
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/utils/grants/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,26 @@ func GetGrantPermissionSet(perm string, isDir bool) *provider.ResourcePermission
if strings.Contains(perm, "w") && !strings.Contains(perm, "!w") {
rp.Move = true
rp.Delete = true
rp.PurgeRecycle = true
rp.InitiateFileUpload = true
rp.RestoreFileVersion = true
rp.RestoreRecycleItem = true
if isDir {
rp.CreateContainer = true
}
}

if strings.Contains(perm, "x") && !strings.Contains(perm, "!x") {
rp.ListFileVersions = true
rp.ListRecycle = true
if isDir {
rp.ListContainer = true
}
}

if strings.Contains(perm, "!d") {
rp.Delete = false
rp.PurgeRecycle = false
}

if strings.Contains(perm, "m") && !strings.Contains(perm, "!m") {
Expand Down

0 comments on commit e8d0f1a

Please sign in to comment.