Skip to content

Commit

Permalink
Merge user ACLs from EOS to sys ACLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Nov 8, 2021
1 parent 80f5ec9 commit 524c98f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 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 @@
Bugfix: Merge user ACLs from EOS to sys ACLs

https://github.com/cs3org/reva/pull/2247
4 changes: 2 additions & 2 deletions pkg/cbox/storage/eoswrapper/eoswrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ func (w *wrapper) getMountID(ctx context.Context, r *provider.ResourceInfo) stri

func (w *wrapper) setProjectSharingPermissions(ctx context.Context, r *provider.ResourceInfo) error {
// Check if this storage provider corresponds to a project spaces instance
if strings.HasPrefix(w.conf.Namespace, eosProjectsNamespace) {
if strings.HasPrefix(r.Path, eosProjectsNamespace) {

// Extract project name from the path resembling /c/cernbox or /c/cernbox/minutes/..
parts := strings.SplitN(r.Path, "/", 4)
parts := strings.SplitN(strings.TrimPrefix(r.Path, eosProjectsNamespace), "/", 4)
if len(parts) != 4 && len(parts) != 3 {
return errtypes.BadRequest("eoswrapper: path does not follow the allowed format")
}
Expand Down
28 changes: 23 additions & 5 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
const (
versionPrefix = ".sys.v#."
lwShareAttrKey = "reva.lwshare"
userACLEvalKey = "eval.useracl"
)

const (
Expand Down Expand Up @@ -296,7 +297,7 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat

if a.Type == acl.TypeLightweight {
sysACL := ""
aclStr, ok := finfo.Attrs[lwShareAttrKey]
aclStr, ok := finfo.Attrs["sys."+lwShareAttrKey]
if ok {
acls, err := acl.Parse(aclStr, acl.ShortTextForm)
if err != nil {
Expand Down Expand Up @@ -330,7 +331,7 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat
args = append(args, "--user")
userACLAttr := &eosclient.Attribute{
Type: SystemAttr,
Key: "eval.useracl",
Key: userACLEvalKey,
Val: "1",
}
if err = c.SetAttr(ctx, auth, userACLAttr, false, path); err != nil {
Expand Down Expand Up @@ -360,7 +361,7 @@ func (c *Client) RemoveACL(ctx context.Context, auth, rootAuth eosclient.Authori

if a.Type == acl.TypeLightweight {
sysACL := ""
aclStr, ok := finfo.Attrs[lwShareAttrKey]
aclStr, ok := finfo.Attrs["sys."+lwShareAttrKey]
if ok {
acls, err := acl.Parse(aclStr, acl.ShortTextForm)
if err != nil {
Expand Down Expand Up @@ -1090,8 +1091,25 @@ func (c *Client) mapToFileInfo(kv, attrs map[string]string) (*eosclient.FileInfo
if err != nil {
return nil, err
}
lwACLStr, ok := attrs[lwShareAttrKey]
if ok {

// Read user ACLs if sys.eval.useracl is set
if userACLEval, ok := attrs["sys."+userACLEvalKey]; ok && userACLEval == "1" {
if userACL, ok := attrs["user.acl"]; ok {
userAcls, err := acl.Parse(userACL, acl.ShortTextForm)
if err != nil {
return nil, err
}
for _, e := range userAcls.Entries {
err = sysACL.SetEntry(e.Type, e.Qualifier, e.Permissions)
if err != nil {
return nil, err
}
}
}
}

// Read lightweight ACLs recognized by the sys.reva.lwshare attr
if lwACLStr, ok := attrs["sys."+lwShareAttrKey]; ok {
lwAcls, err := acl.Parse(lwACLStr, acl.ShortTextForm)
if err != nil {
return nil, err
Expand Down

0 comments on commit 524c98f

Please sign in to comment.