Skip to content

Commit 57f6239

Browse files
committed
allow sharemanager to disable reshares
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
1 parent cdf127f commit 57f6239

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: the sharemanager can now reject grants with resharing permissions
2+
3+
When disabling resharing we also need to prevent grants from allowing any grant permissions.
4+
5+
https://github.com/cs3org/reva/pull/4516

internal/grpc/services/usershareprovider/usershareprovider.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type config struct {
5555
Drivers map[string]map[string]interface{} `mapstructure:"drivers"`
5656
GatewayAddr string `mapstructure:"gateway_addr"`
5757
AllowedPathsForShares []string `mapstructure:"allowed_paths_for_shares"`
58+
DisableResharing bool `mapstructure:"disable_resharing"`
5859
}
5960

6061
func (c *config) init() {
@@ -67,6 +68,7 @@ type service struct {
6768
sm share.Manager
6869
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
6970
allowedPathsForShares []*regexp.Regexp
71+
disableResharing bool
7072
}
7173

7274
func getShareManager(c *config) (share.Manager, error) {
@@ -127,15 +129,16 @@ func NewDefault(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error
127129
return nil, err
128130
}
129131

130-
return New(gatewaySelector, sm, allowedPathsForShares), nil
132+
return New(gatewaySelector, sm, allowedPathsForShares, c.DisableResharing), nil
131133
}
132134

133135
// New creates a new user share provider svc
134-
func New(gatewaySelector pool.Selectable[gateway.GatewayAPIClient], sm share.Manager, allowedPathsForShares []*regexp.Regexp) rgrpc.Service {
136+
func New(gatewaySelector pool.Selectable[gateway.GatewayAPIClient], sm share.Manager, allowedPathsForShares []*regexp.Regexp, disableResharing bool) rgrpc.Service {
135137
service := &service{
136138
sm: sm,
137139
gatewaySelector: gatewaySelector,
138140
allowedPathsForShares: allowedPathsForShares,
141+
disableResharing: disableResharing,
139142
}
140143

141144
return service
@@ -157,6 +160,13 @@ func (s *service) CreateShare(ctx context.Context, req *collaboration.CreateShar
157160
log := appctx.GetLogger(ctx)
158161
user := ctxpkg.ContextMustGetUser(ctx)
159162

163+
// when resharing is disabled grants must not allow grant permissions
164+
if s.disableResharing && HasGrantPermissions(req.GetGrant().GetPermissions().GetPermissions()) {
165+
return &collaboration.CreateShareResponse{
166+
Status: status.NewInvalidArg(ctx, "resharing not supported"),
167+
}, nil
168+
}
169+
160170
gatewayClient, err := s.gatewaySelector.Next()
161171
if err != nil {
162172
return nil, err
@@ -235,6 +245,10 @@ func (s *service) CreateShare(ctx context.Context, req *collaboration.CreateShar
235245
}, nil
236246
}
237247

248+
func HasGrantPermissions(p *provider.ResourcePermissions) bool {
249+
return p.GetAddGrant() || p.GetUpdateGrant() || p.GetRemoveGrant() || p.GetDenyGrant()
250+
}
251+
238252
func (s *service) RemoveShare(ctx context.Context, req *collaboration.RemoveShareRequest) (*collaboration.RemoveShareResponse, error) {
239253
log := appctx.GetLogger(ctx)
240254
user := ctxpkg.ContextMustGetUser(ctx)
@@ -327,6 +341,14 @@ func (s *service) ListShares(ctx context.Context, req *collaboration.ListSharesR
327341
func (s *service) UpdateShare(ctx context.Context, req *collaboration.UpdateShareRequest) (*collaboration.UpdateShareResponse, error) {
328342
log := appctx.GetLogger(ctx)
329343
user := ctxpkg.ContextMustGetUser(ctx)
344+
345+
// when resharing is disabled grants must not allow grant permissions
346+
if s.disableResharing && HasGrantPermissions(req.GetShare().GetPermissions().GetPermissions()) {
347+
return &collaboration.UpdateShareResponse{
348+
Status: status.NewInvalidArg(ctx, "resharing not supported"),
349+
}, nil
350+
}
351+
330352
gatewayClient, err := s.gatewaySelector.Next()
331353
if err != nil {
332354
return nil, err

internal/grpc/services/usershareprovider/usershareprovider_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var _ = Describe("user share provider service", func() {
112112
}
113113
manager.On("GetShare", mock.Anything, mock.Anything).Return(getShareResponse, nil)
114114

115-
rgrpcService := usershareprovider.New(gatewaySelector, manager, []*regexp.Regexp{})
115+
rgrpcService := usershareprovider.New(gatewaySelector, manager, []*regexp.Regexp{}, false)
116116

117117
provider = rgrpcService.(collaborationpb.CollaborationAPIServer)
118118
Expect(provider).ToNot(BeNil())

0 commit comments

Comments
 (0)