Skip to content

Commit

Permalink
Make AddACL only recursive when it is passed a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Geens committed Oct 23, 2024
1 parent 10664f4 commit 5964f8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/addacl-recursive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: make AddACL only recursive on directories

The current implementation of AddACL in the EOS gRPC client always sets msg.Recursive = true. This causes issues on the EOS side, because it will try running a recursive find on a file, which fails. This PR fixes this bug in Reva.

https://github.com/cs3org/reva/pull/4898
26 changes: 22 additions & 4 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat
log := appctx.GetLogger(ctx)
log.Info().Str("func", "AddACL").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// First, we need to figure out if the path is a directory
// to know whether our request should be recursive
fileInfo, err := c.GetFileInfoByPath(ctx, auth, path)
if err != nil {
return err
}

// Init a new NSRequest
rq, err := c.initNSRequest(ctx, rootAuth, "")
if err != nil {
Expand All @@ -272,7 +279,7 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat
msg := new(erpc.NSRequest_AclRequest)
msg.Cmd = erpc.NSRequest_AclRequest_ACL_COMMAND(erpc.NSRequest_AclRequest_ACL_COMMAND_value["MODIFY"])
msg.Type = erpc.NSRequest_AclRequest_ACL_TYPE(erpc.NSRequest_AclRequest_ACL_TYPE_value["SYS_ACL"])
msg.Recursive = true
msg.Recursive = fileInfo.IsDir
msg.Rule = a.CitrineSerialize()

msg.Id = new(erpc.MDId)
Expand Down Expand Up @@ -302,11 +309,17 @@ func (c *Client) RemoveACL(ctx context.Context, auth, rootAuth eosclient.Authori
log := appctx.GetLogger(ctx)
log.Info().Str("func", "RemoveACL").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

acls, err := c.getACLForPath(ctx, auth, path)
// First, we need to figure out if the path is a directory
// to know whether our request should be recursive
fileInfo, err := c.GetFileInfoByPath(ctx, auth, path)
if err != nil {
return err
}

acls, err := c.getACLForPath(ctx, auth, path)
if err != nil {
return err
}
acls.DeleteEntry(a.Type, a.Qualifier)
sysACL := acls.Serialize()

Expand All @@ -319,7 +332,7 @@ func (c *Client) RemoveACL(ctx context.Context, auth, rootAuth eosclient.Authori
msg := new(erpc.NSRequest_AclRequest)
msg.Cmd = erpc.NSRequest_AclRequest_ACL_COMMAND(erpc.NSRequest_AclRequest_ACL_COMMAND_value["MODIFY"])
msg.Type = erpc.NSRequest_AclRequest_ACL_TYPE(erpc.NSRequest_AclRequest_ACL_TYPE_value["SYS_ACL"])
msg.Recursive = true
msg.Recursive = fileInfo.IsDir
msg.Rule = sysACL

msg.Id = new(erpc.MDId)
Expand Down Expand Up @@ -387,6 +400,11 @@ func (c *Client) getACLForPath(ctx context.Context, auth eosclient.Authorization
log := appctx.GetLogger(ctx)
log.Info().Str("func", "GetACLForPath").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

fileInfo, err := c.GetFileInfoByPath(ctx, auth, path)
if err != nil {
return nil, err
}

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
Expand All @@ -396,7 +414,7 @@ func (c *Client) getACLForPath(ctx context.Context, auth eosclient.Authorization
msg := new(erpc.NSRequest_AclRequest)
msg.Cmd = erpc.NSRequest_AclRequest_ACL_COMMAND(erpc.NSRequest_AclRequest_ACL_COMMAND_value["LIST"])
msg.Type = erpc.NSRequest_AclRequest_ACL_TYPE(erpc.NSRequest_AclRequest_ACL_TYPE_value["SYS_ACL"])
msg.Recursive = true
msg.Recursive = fileInfo.IsDir

msg.Id = new(erpc.MDId)
msg.Id.Path = []byte(path)
Expand Down

0 comments on commit 5964f8f

Please sign in to comment.