Skip to content

Commit

Permalink
Inherit ACLs for files from parent directories (#2174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Oct 14, 2021
1 parent 8a5e96f commit 7f4abff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/eos-file-perms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Inherit ACLs for files from parent directories

https://github.com/cs3org/reva/pull/2174
24 changes: 21 additions & 3 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (c *Client) GetFileInfoByInode(ctx context.Context, auth eosclient.Authoriz
info.Inode = inode
}

return info, nil
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

// GetFileInfoByFXID returns the FileInfo by the given file id in hexadecimal
Expand All @@ -472,7 +472,13 @@ func (c *Client) GetFileInfoByFXID(ctx context.Context, auth eosclient.Authoriza
if err != nil {
return nil, err
}
return c.parseFileInfo(stdout)

info, err := c.parseFileInfo(stdout)
if err != nil {
return nil, err
}

return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

// GetFileInfoByPath returns the FilInfo at the given path
Expand All @@ -493,7 +499,19 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, auth eosclient.Authoriza
}
}

return info, nil
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

func (c *Client) mergeParentACLsForFiles(ctx context.Context, auth eosclient.Authorization, info *eosclient.FileInfo) *eosclient.FileInfo {
// We need to inherit the ACLs for the parent directory as these are not available for files
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(ctx, auth, path.Dir(info.File))
// Even if this call fails, at least return the current file object
if err == nil {
info.SysACL.Entries = append(info.SysACL.Entries, parentInfo.SysACL.Entries...)
}
}
return info
}

// SetAttr sets an extended attributes on a path.
Expand Down
17 changes: 15 additions & 2 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,19 @@ func (c *Client) GetFileInfoByInode(ctx context.Context, auth eosclient.Authoriz
}

log.Debug().Str("func", "GetFileInfoByInode").Uint64("inode", inode).Msg("")
return info, nil
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

func (c *Client) mergeParentACLsForFiles(ctx context.Context, auth eosclient.Authorization, info *eosclient.FileInfo) *eosclient.FileInfo {
// We need to inherit the ACLs for the parent directory as these are not available for files
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(ctx, auth, path.Dir(info.File))
// Even if this call fails, at least return the current file object
if err == nil {
info.SysACL.Entries = append(info.SysACL.Entries, parentInfo.SysACL.Entries...)
}
}
return info
}

// SetAttr sets an extended attributes on a path.
Expand Down Expand Up @@ -627,7 +639,8 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, auth eosclient.Authoriza
}
info.Inode = inode
}
return info, nil

return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

// GetFileInfoByFXID returns the FileInfo by the given file id in hexadecimal
Expand Down

0 comments on commit 7f4abff

Please sign in to comment.