From f456f905c8baaf76d9a2dbc10474ff73ddabe868 Mon Sep 17 00:00:00 2001 From: Roman Perekhod <2403905@gmail.com> Date: Wed, 28 Oct 2026 12:17:53 +0100 Subject: [PATCH] feat: [OCISDEV-1516] allow group shares in the vault - web: the share dialog searches for groups in vault mode. - notifications, userlog: send vault notifications only to the users who hold the VaultMode permission. A group can contain other users. - ocis-pkg/vault: add the shared helpers for the vault checks. - acceptance: a group invitation to a vault resource now succeeds. The gateway change is in owncloud/reva#787. Co-Authored-By: Claude Opus 5.5 --- .../enhancement-vault-group-share.md | 11 ++ go.mod | 2 +- go.sum | 6 +- ocis-pkg/vault/vault.go | 52 +++++ ocis-pkg/vault/vault_test.go | 66 +++++++ services/notifications/pkg/service/service.go | 37 +++- .../notifications/pkg/service/service_test.go | 62 ++++++ services/notifications/pkg/service/shares.go | 7 +- services/notifications/pkg/service/spaces.go | 7 +- services/userlog/pkg/service/service.go | 41 ++++ services/userlog/pkg/service/vault_test.go | 182 ++++++++++++++++++ .../features/apiVault/vault.feature | 29 +-- .../services/gateway/usershareprovider.go | 10 +- vendor/modules.txt | 2 +- .../InviteCollaboratorForm.vue | 6 +- .../InviteCollaboratorForm.spec.ts | 4 +- 16 files changed, 481 insertions(+), 43 deletions(-) create mode 100644 changelog/unreleased/enhancement-vault-group-share.md create mode 100644 ocis-pkg/vault/vault.go create mode 100644 ocis-pkg/vault/vault_test.go create mode 100644 services/userlog/pkg/service/vault_test.go diff --git a/changelog/unreleased/enhancement-vault-group-share.md b/changelog/unreleased/enhancement-vault-group-share.md new file mode 100644 index 00000000000..f3b4ee24df8 --- /dev/null +++ b/changelog/unreleased/enhancement-vault-group-share.md @@ -0,0 +1,11 @@ +Enhancement: Allow group shares in the vault + +Users can now invite a group to a resource in the vault (Safe). Before this +change, the server accepted only users as vault share recipients. The share +dialog in Web now also searches for groups in vault mode. The +notifications and userlog services now send a vault notification only to the +group members who have the permission to use the vault. The other group +members get no email and no in-app notification. + +https://github.com/owncloud/ocis/pull/13259 +https://github.com/owncloud/reva/pull/787 diff --git a/go.mod b/go.mod index 73f95acfa2a..4b9aee44472 100644 --- a/go.mod +++ b/go.mod @@ -67,7 +67,7 @@ require ( github.com/open-policy-agent/opa v1.21.1 github.com/orcaman/concurrent-map v1.0.0 github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 - github.com/owncloud/reva/v2 v2.0.0-20261022133635-764ed1d17629 + github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e github.com/pkg/errors v0.9.1 github.com/pkg/xattr v0.4.12 github.com/prometheus/client_golang v1.25.0 diff --git a/go.sum b/go.sum index f5e222ebef5..309401221b3 100644 --- a/go.sum +++ b/go.sum @@ -736,10 +736,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI= github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII= github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og= -github.com/owncloud/reva/v2 v2.0.0-20261019155447-90c24c1b3575 h1:GOsblJHW/dvNdxxXmCb/PZOGRIg1ci4SVs+pA7hw6t4= -github.com/owncloud/reva/v2 v2.0.0-20261019155447-90c24c1b3575/go.mod h1:cgqg+UTe4ekjMbJj8hgoXSTxQ9fQramKcOUdvsFUrzc= -github.com/owncloud/reva/v2 v2.0.0-20261022133635-764ed1d17629 h1:h0jekinxPFEwKl0IkGT8iYOca9ZdIXJDixIIFI/yhfY= -github.com/owncloud/reva/v2 v2.0.0-20261022133635-764ed1d17629/go.mod h1:cgqg+UTe4ekjMbJj8hgoXSTxQ9fQramKcOUdvsFUrzc= +github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e h1:AkjvcOkHg2W4Kin3iMd1rl4/LXSPXkGUeMPUS4cfvhg= +github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e/go.mod h1:cgqg+UTe4ekjMbJj8hgoXSTxQ9fQramKcOUdvsFUrzc= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pablodz/inotifywaitgo v0.0.12 h1:DVJJTFMDlSAdO46yisPF2vzozs/r+4k6ih8MVghq78M= diff --git a/ocis-pkg/vault/vault.go b/ocis-pkg/vault/vault.go new file mode 100644 index 00000000000..b5e1a62b2ac --- /dev/null +++ b/ocis-pkg/vault/vault.go @@ -0,0 +1,52 @@ +// Package vault provides helpers for resources in the vault storage provider. +package vault + +import ( + "context" + "fmt" + + gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" + "github.com/owncloud/reva/v2/pkg/permission" + "github.com/owncloud/reva/v2/pkg/storagespace" + "github.com/owncloud/reva/v2/pkg/utils" +) + +// IsVaultStorage reports whether the storage ID belongs to the vault storage provider. +func IsVaultStorage(storageID string) bool { + return storageID == utils.VaultStorageProviderID +} + +// IsVaultSpace reports whether the space ID belongs to the vault storage provider. +// It returns true for a space ID that it cannot parse, so that callers fail closed. +func IsVaultSpace(spaceID string) bool { + rid, err := storagespace.ParseID(spaceID) + if err != nil { + return true + } + return IsVaultStorage(rid.GetStorageId()) +} + +// HasVaultMode reports whether the user holds the VaultMode permission. +// A non-nil error means undetermined, so callers must treat the user as not allowed. +func HasVaultMode(ctx context.Context, gwc gateway.GatewayAPIClient, userID *user.UserId) (bool, error) { + res, err := gwc.CheckPermission(ctx, &permissions.CheckPermissionRequest{ + SubjectRef: &permissions.SubjectReference{ + Spec: &permissions.SubjectReference_UserId{UserId: userID}, + }, + Permission: permission.VaultMode, + }) + if err != nil { + return false, err + } + switch code := res.GetStatus().GetCode(); code { + case rpc.Code_CODE_OK: + return true, nil + case rpc.Code_CODE_PERMISSION_DENIED: + return false, nil + default: + return false, fmt.Errorf("vault permission check returned status %q: %s", code, res.GetStatus().GetMessage()) + } +} diff --git a/ocis-pkg/vault/vault_test.go b/ocis-pkg/vault/vault_test.go new file mode 100644 index 00000000000..a22b5c759b4 --- /dev/null +++ b/ocis-pkg/vault/vault_test.go @@ -0,0 +1,66 @@ +package vault + +import ( + "context" + "errors" + "testing" + + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" + "github.com/owncloud/reva/v2/pkg/permission" + "github.com/owncloud/reva/v2/pkg/utils" + cs3mocks "github.com/owncloud/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" +) + +func TestIsVaultSpace(t *testing.T) { + tests := []struct { + name string + spaceID string + want bool + }{ + {"vault space", utils.VaultStorageProviderID + "$space-id", true}, + {"regular space", "storage-id$space-id", false}, + {"unparsable space id fails closed", "", true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsVaultSpace(tt.spaceID); got != tt.want { + t.Errorf("IsVaultSpace(%q) = %v, want %v", tt.spaceID, got, tt.want) + } + }) + } +} + +func TestHasVaultMode(t *testing.T) { + tests := []struct { + name string + res *permissions.CheckPermissionResponse + err error + want bool + wantErr bool + }{ + {"ok grants", &permissions.CheckPermissionResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}}, nil, true, false}, + {"permission denied denies", &permissions.CheckPermissionResponse{Status: &rpc.Status{Code: rpc.Code_CODE_PERMISSION_DENIED}}, nil, false, false}, + {"internal status fails closed", &permissions.CheckPermissionResponse{Status: &rpc.Status{Code: rpc.Code_CODE_INTERNAL}}, nil, false, true}, + {"transport error fails closed", nil, errors.New("unavailable"), false, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gwc := &cs3mocks.GatewayAPIClient{} + gwc.On("CheckPermission", mock.Anything, mock.MatchedBy(func(req *permissions.CheckPermissionRequest) bool { + return req.GetPermission() == permission.VaultMode && req.GetSubjectRef().GetUserId().GetOpaqueId() == "alice" + })).Return(tt.res, tt.err) + + got, err := HasVaultMode(context.Background(), gwc, &user.UserId{OpaqueId: "alice"}) + if (err != nil) != tt.wantErr { + t.Fatalf("HasVaultMode() error = %v, wantErr %v", err, tt.wantErr) + } + if got != tt.want { + t.Errorf("HasVaultMode() = %v, want %v", got, tt.want) + } + gwc.AssertExpectations(t) + }) + } +} diff --git a/services/notifications/pkg/service/service.go b/services/notifications/pkg/service/service.go index 20ce95b3d10..ca4a17640b1 100644 --- a/services/notifications/pkg/service/service.go +++ b/services/notifications/pkg/service/service.go @@ -26,6 +26,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/l10n" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/middleware" + "github.com/owncloud/ocis/v2/ocis-pkg/vault" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" "github.com/owncloud/ocis/v2/services/notifications/pkg/channels" "github.com/owncloud/ocis/v2/services/notifications/pkg/email" @@ -196,17 +197,49 @@ func (s eventsNotifier) send(ctx context.Context, emails []*channels.Message) { } } -func (s eventsNotifier) ensureGranteeList(ctx context.Context, executant, u *user.UserId, g *group.GroupId) []*user.User { +// ensureGranteeList resolves the grantee to the users who get the notification. +// For a vault resource it keeps only the users who hold the VaultMode permission. +func (s eventsNotifier) ensureGranteeList(ctx context.Context, executant, u *user.UserId, g *group.GroupId, inVault bool) []*user.User { granteeList, err := s.getGranteeList(ctx, executant, u, g) if err != nil { s.logger.Error().Err(err).Str("event", "ensureGranteeList").Msg("Could not get grantee list") return nil - } else if len(granteeList) == 0 { + } + if inVault { + granteeList = s.filterVaultGrantees(ctx, granteeList) + } + if len(granteeList) == 0 { return nil } return granteeList } +// filterVaultGrantees removes the users who do not hold the VaultMode permission. +// A group can contain such users, because the gateway does not check the group members. +func (s eventsNotifier) filterVaultGrantees(ctx context.Context, users []*user.User) []*user.User { + if len(users) == 0 { + return users + } + gatewayClient, err := s.gatewaySelector.Next() + if err != nil { + s.logger.Error().Err(err).Str("event", "filterVaultGrantees").Msg("could not select next gateway client") + return nil + } + + filtered := make([]*user.User, 0, len(users)) + for _, u := range users { + allowed, err := vault.HasVaultMode(ctx, gatewayClient, u.GetId()) + if err != nil { + s.logger.Error().Err(err).Str("event", "filterVaultGrantees").Str("userId", u.GetId().GetOpaqueId()).Msg("could not check vault permission, skipped") + continue + } + if allowed { + filtered = append(filtered, u) + } + } + return filtered +} + func (s eventsNotifier) getGranteeList(ctx context.Context, executant, u *user.UserId, g *group.GroupId) ([]*user.User, error) { switch { case u != nil: diff --git a/services/notifications/pkg/service/service_test.go b/services/notifications/pkg/service/service_test.go index feefc1d988c..084cecbb907 100644 --- a/services/notifications/pkg/service/service_test.go +++ b/services/notifications/pkg/service/service_test.go @@ -24,6 +24,7 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" . "github.com/onsi/ginkgo/v2" @@ -292,6 +293,7 @@ https://owncloud.com DescribeTable("Vault resources are redacted in notifications", func(ev events.Event, mustNotContain string) { + gatewayClient.On("CheckPermission", mock.Anything, mock.Anything).Return(&permissions.CheckPermissionResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}}, nil) received := make(chan *channels.Message, 1) ch := make(chan events.Event) evts := NewEventsNotifier(trace.NewNoopTracerProvider(), ch, capturingChannel{out: received}, log.NewLogger(), gatewaySelector, vs, "", @@ -365,6 +367,66 @@ https://owncloud.com }, }, "vault space"), ) + + DescribeTable("Vault group grantees are filtered by the vault mode permission", + func(ev events.Event) { + outsider := &user.User{ + Id: &user.UserId{OpaqueId: "outsider"}, + Mail: "outsider@owncloud.com", + DisplayName: "Otto Outsider", + } + gatewayClient.On("GetGroup", mock.Anything, mock.Anything).Return(&group.GetGroupResponse{ + Status: &rpc.Status{Code: rpc.Code_CODE_OK}, + Group: &group.Group{Members: []*user.UserId{sharee.GetId(), outsider.GetId()}}, + }, nil) + gatewayClient.On("GetUser", mock.Anything, mock.MatchedBy(func(r *user.GetUserRequest) bool { + return r.GetUserId().GetOpaqueId() == outsider.GetId().GetOpaqueId() + })).Return(&user.GetUserResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: outsider}, nil) + gatewayClient.On("CheckPermission", mock.Anything, mock.Anything).Return(func(_ context.Context, r *permissions.CheckPermissionRequest, _ ...grpc.CallOption) (*permissions.CheckPermissionResponse, error) { + code := rpc.Code_CODE_PERMISSION_DENIED + if r.GetSubjectRef().GetUserId().GetOpaqueId() == sharee.GetId().GetOpaqueId() { + code = rpc.Code_CODE_OK + } + return &permissions.CheckPermissionResponse{Status: &rpc.Status{Code: code}}, nil + }) + + received := make(chan *channels.Message, 2) + ch := make(chan events.Event) + evts := NewEventsNotifier(trace.NewNoopTracerProvider(), ch, capturingChannel{out: received}, log.NewLogger(), gatewaySelector, vs, "", + "", "", "", "", "", "", + store.Create(), nil, nil) + go evts.Run() + + ch <- ev + + var msg *channels.Message + select { + case msg = <-received: + case <-time.Tick(3 * time.Second): + Fail("timeout waiting for notification") + } + Expect(msg.Recipient).To(Equal([]string{sharee.GetMail()})) + Consistently(received, 200*time.Millisecond).ShouldNot(Receive()) + }, + + Entry("Share Created", events.Event{ + Event: events.ShareCreated{ + Sharer: sharer.GetId(), + GranteeGroupID: &group.GroupId{OpaqueId: "vaultgroup"}, + CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)), + ItemID: vaultResourceID, + }, + }), + + Entry("Added to Space", events.Event{ + Event: events.SpaceShared{ + Executant: sharer.GetId(), + Creator: sharer.GetId(), + GranteeGroupID: &group.GroupId{OpaqueId: "vaultgroup"}, + ID: vaultSpaceID, + }, + }), + ) }) var _ = Describe("Notifications X-Site Scripting", func() { diff --git a/services/notifications/pkg/service/shares.go b/services/notifications/pkg/service/shares.go index 30ecd8ad1fd..70d5fa79cbd 100644 --- a/services/notifications/pkg/service/shares.go +++ b/services/notifications/pkg/service/shares.go @@ -4,6 +4,7 @@ import ( "context" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + "github.com/owncloud/ocis/v2/ocis-pkg/vault" "github.com/owncloud/ocis/v2/services/notifications/pkg/email" "github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults" "github.com/owncloud/reva/v2/pkg/events" @@ -33,7 +34,7 @@ func (s eventsNotifier) handleShareCreated(baseCtx context.Context, e events.Sha return } - granteeList := s.ensureGranteeList(ctx, owner.GetId(), e.GranteeUserID, e.GranteeGroupID) + granteeList := s.ensureGranteeList(ctx, owner.GetId(), e.GranteeUserID, e.GranteeGroupID, vault.IsVaultStorage(e.ItemID.GetStorageId())) filteredGrantees := s.filter.execute(ctx, granteeList, defaults.SettingUUIDProfileEventShareCreated) recipientsInstant, recipientsDaily, recipientsInstantWeekly := s.splitter.execute(ctx, filteredGrantees) @@ -123,7 +124,7 @@ func (s eventsNotifier) handleShareExpired(baseCtx context.Context, e events.Sha return } - granteeList := s.ensureGranteeList(ctx, owner.GetId(), e.GranteeUserID, e.GranteeGroupID) + granteeList := s.ensureGranteeList(ctx, owner.GetId(), e.GranteeUserID, e.GranteeGroupID, vault.IsVaultStorage(e.ItemID.GetStorageId())) filteredGrantees := s.filter.execute(ctx, granteeList, defaults.SettingUUIDProfileEventShareExpired) recipientsInstant, recipientsDaily, recipientsInstantWeekly := s.splitter.execute(ctx, filteredGrantees) @@ -183,7 +184,7 @@ func (s eventsNotifier) handleShareRemoved(baseCtx context.Context, e events.Sha return } - granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID) + granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID, vault.IsVaultStorage(e.ItemID.GetStorageId())) filteredGrantees := s.filter.execute(ctx, granteeList, defaults.SettingUUIDProfileEventShareRemoved) recipientsInstant, recipientsDaily, recipientsInstantWeekly := s.splitter.execute(ctx, filteredGrantees) diff --git a/services/notifications/pkg/service/spaces.go b/services/notifications/pkg/service/spaces.go index ad4a04a2174..8505f842190 100644 --- a/services/notifications/pkg/service/spaces.go +++ b/services/notifications/pkg/service/spaces.go @@ -4,6 +4,7 @@ import ( "context" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + "github.com/owncloud/ocis/v2/ocis-pkg/vault" "github.com/owncloud/ocis/v2/services/notifications/pkg/email" "github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults" "github.com/owncloud/reva/v2/pkg/events" @@ -23,7 +24,7 @@ func (s eventsNotifier) handleSpaceShared(baseCtx context.Context, e events.Spac return } - granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID) + granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID, vault.IsVaultSpace(e.ID.GetOpaqueId())) filteredGrantees := s.filter.execute(ctx, granteeList, defaults.SettingUUIDProfileEventSpaceShared) recipientsInstant, recipientsDaily, recipientsInstantWeekly := s.splitter.execute(ctx, filteredGrantees) @@ -108,7 +109,7 @@ func (s eventsNotifier) handleSpaceUnshared(baseCtx context.Context, e events.Sp return } - granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID) + granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID, vault.IsVaultSpace(e.ID.GetOpaqueId())) filteredGrantees := s.filter.execute(ctx, granteeList, defaults.SettingUUIDProfileEventSpaceUnshared) recipientsInstant, recipientsDaily, recipientsInstantWeekly := s.splitter.execute(ctx, filteredGrantees) @@ -207,7 +208,7 @@ func (s eventsNotifier) handleSpaceMembershipExpired(baseCtx context.Context, e return } - granteeList := s.ensureGranteeList(ctx, owner.GetId(), e.GranteeUserID, e.GranteeGroupID) + granteeList := s.ensureGranteeList(ctx, owner.GetId(), e.GranteeUserID, e.GranteeGroupID, vault.IsVaultSpace(e.SpaceID.GetOpaqueId())) if granteeList == nil { return } diff --git a/services/userlog/pkg/service/service.go b/services/userlog/pkg/service/service.go index de1c162794a..e4ea0804469 100644 --- a/services/userlog/pkg/service/service.go +++ b/services/userlog/pkg/service/service.go @@ -21,6 +21,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/l10n" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/roles" + "github.com/owncloud/ocis/v2/ocis-pkg/vault" ehmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/eventhistory/v0" ehsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" @@ -207,6 +208,9 @@ func (ul *UserlogService) processEvent(event events.Event) { // II) filter users who want to receive the event users = ul.filter.execute(ctx, event, executant, users) + if isVaultEvent(event) { + users = ul.filterVaultUsers(ctx, gwc, users) + } // III) store the eventID for each user for _, id := range users { @@ -224,6 +228,43 @@ func (ul *UserlogService) processEvent(event events.Event) { } } +// isVaultEvent reports whether the event is about a share or a space membership in the vault. +func isVaultEvent(event events.Event) bool { + switch e := event.Event.(type) { + case events.ShareCreated: + return vault.IsVaultStorage(e.ItemID.GetStorageId()) + case events.ShareRemoved: + return vault.IsVaultStorage(e.ItemID.GetStorageId()) + case events.ShareExpired: + return vault.IsVaultStorage(e.ItemID.GetStorageId()) + case events.SpaceShared: + return vault.IsVaultSpace(e.ID.GetOpaqueId()) + case events.SpaceUnshared: + return vault.IsVaultSpace(e.ID.GetOpaqueId()) + case events.SpaceMembershipExpired: + return vault.IsVaultSpace(e.SpaceID.GetOpaqueId()) + default: + return false + } +} + +// filterVaultUsers removes the users who do not hold the VaultMode permission. +// A group can contain such users, because the gateway does not check the group members. +func (ul *UserlogService) filterVaultUsers(ctx context.Context, gwc gateway.GatewayAPIClient, users []string) []string { + filtered := make([]string, 0, len(users)) + for _, u := range users { + allowed, err := vault.HasVaultMode(ctx, gwc, &user.UserId{OpaqueId: u}) + if err != nil { + ul.log.Error().Err(err).Str("userId", u).Msg("could not check vault permission, skipped") + continue + } + if allowed { + filtered = append(filtered, u) + } + } + return filtered +} + // GetEvents allows retrieving events from the eventhistory by userid func (ul *UserlogService) GetEvents(ctx context.Context, userid string) ([]*ehmsg.Event, error) { ctx, span := ul.tracer.Start(ctx, "GetEvents") diff --git a/services/userlog/pkg/service/vault_test.go b/services/userlog/pkg/service/vault_test.go new file mode 100644 index 00000000000..f6826b2c701 --- /dev/null +++ b/services/userlog/pkg/service/vault_test.go @@ -0,0 +1,182 @@ +package service_test + +import ( + "context" + "encoding/json" + "time" + + gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" + permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1" + rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" + provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/go-chi/chi/v5" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/owncloud/reva/v2/pkg/events" + "github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool" + "github.com/owncloud/reva/v2/pkg/store" + "github.com/owncloud/reva/v2/pkg/storagespace" + "github.com/owncloud/reva/v2/pkg/utils" + cs3mocks "github.com/owncloud/reva/v2/tests/cs3mocks/mocks" + "github.com/stretchr/testify/mock" + "go-micro.dev/v4/client" + microstore "go-micro.dev/v4/store" + "go.opentelemetry.io/otel/trace" + "google.golang.org/grpc" + + "github.com/owncloud/ocis/v2/ocis-pkg/log" + settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" + "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0/mocks" + settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" + "github.com/owncloud/ocis/v2/services/userlog/pkg/config" + "github.com/owncloud/ocis/v2/services/userlog/pkg/service" +) + +var _ = Describe("UserlogService vault events", func() { + const ( + member = "member" + outsider = "outsider" + ) + + var ( + bus testBus + sto microstore.Store + + gatewayClient *cs3mocks.GatewayAPIClient + checkedUsers chan string + + vaultResourceID = &provider.ResourceId{ + StorageId: utils.VaultStorageProviderID, + SpaceId: "spaceid", + OpaqueId: "itemid", + } + regularResourceID = &provider.ResourceId{ + StorageId: "storageid", + SpaceId: "spaceid", + OpaqueId: "itemid", + } + vaultSpaceID = &provider.StorageSpaceId{ + OpaqueId: storagespace.FormatResourceID(&provider.ResourceId{ + StorageId: utils.VaultStorageProviderID, + SpaceId: "vaultspaceid", + OpaqueId: "vaultspaceid", + }), + } + vaultGroup = &group.GroupId{OpaqueId: "vaultgroup"} + ) + + BeforeEach(func() { + sto = store.Create() + bus = testBus(make(chan events.Event)) + checkedUsers = make(chan string, 10) + + pool.RemoveSelector("GatewaySelector" + "com.owncloud.api.gateway") + gatewayClient = &cs3mocks.GatewayAPIClient{} + gatewaySelector := pool.GetSelector[gateway.GatewayAPIClient]( + "GatewaySelector", + "com.owncloud.api.gateway", + func(cc grpc.ClientConnInterface) gateway.GatewayAPIClient { + return gatewayClient + }, + ) + + gatewayClient.On("Authenticate", mock.Anything, mock.Anything).Return(&gateway.AuthenticateResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}}, nil) + gatewayClient.On("GetGroup", mock.Anything, mock.Anything).Return(&group.GetGroupResponse{ + Status: &rpc.Status{Code: rpc.Code_CODE_OK}, + Group: &group.Group{Members: []*user.UserId{{OpaqueId: member}, {OpaqueId: outsider}}}, + }, nil) + gatewayClient.On("CheckPermission", mock.Anything, mock.Anything).Return(func(_ context.Context, r *permissions.CheckPermissionRequest, _ ...grpc.CallOption) (*permissions.CheckPermissionResponse, error) { + id := r.GetSubjectRef().GetUserId().GetOpaqueId() + checkedUsers <- id + code := rpc.Code_CODE_PERMISSION_DENIED + if id == member { + code = rpc.Code_CODE_OK + } + return &permissions.CheckPermissionResponse{Status: &rpc.Status{Code: code}}, nil + }) + + vc := &settingssvc.MockValueService{} + vc.GetValueByUniqueIdentifiersFunc = func(ctx context.Context, req *settingssvc.GetValueByUniqueIdentifiersRequest, opts ...client.CallOption) (*settingssvc.GetValueResponse, error) { + return &settingssvc.GetValueResponse{ + Value: &settingsmsg.ValueWithIdentifier{ + Value: &settingsmsg.Value{ + Value: &settingsmsg.Value_CollectionValue{ + CollectionValue: &settingsmsg.CollectionValue{ + Values: []*settingsmsg.CollectionOption{ + { + Key: "in-app", + Option: &settingsmsg.CollectionOption_BoolValue{BoolValue: true}, + }, + }, + }, + }, + }, + }, + }, nil + } + + _, err := service.NewUserlogService( + service.Config(&config.Config{MaxConcurrency: 5, DisableSSE: true}), + service.Stream(bus), + service.Store(sto), + service.Logger(log.NewLogger()), + service.Mux(chi.NewMux()), + service.GatewaySelector(gatewaySelector), + service.HistoryClient(&mocks.EventHistoryService{}), + service.ValueClient(vc), + service.RegisteredEvents([]events.Unmarshaller{ + events.ShareCreated{}, + events.SpaceShared{}, + }), + service.TraceProvider(trace.NewNoopTracerProvider()), + ) + Expect(err).ToNot(HaveOccurred()) + }) + + AfterEach(func() { + close(bus) + }) + + storedEvents := func(userID string) []string { + recs, err := sto.Read(userID) + if err != nil { + return nil + } + var ids []string + Expect(json.Unmarshal(recs[0].Value, &ids)).To(Succeed()) + return ids + } + + DescribeTable("stores the event only for group members with the vault mode permission", + func(ev interface{}) { + id := bus.publish(ev) + + Eventually(func() []string { return storedEvents(member) }, time.Second).Should(ConsistOf(id)) + Consistently(func() []string { return storedEvents(outsider) }, 200*time.Millisecond).Should(BeEmpty()) + }, + Entry("Share Created", events.ShareCreated{ + Executant: &user.UserId{OpaqueId: "sharer"}, + GranteeGroupID: vaultGroup, + ItemID: vaultResourceID, + }), + Entry("Added to Space", events.SpaceShared{ + Executant: &user.UserId{OpaqueId: "sharer"}, + GranteeGroupID: vaultGroup, + ID: vaultSpaceID, + }), + ) + + It("does not check the vault mode permission for a regular resource", func() { + id := bus.publish(events.ShareCreated{ + Executant: &user.UserId{OpaqueId: "sharer"}, + GranteeGroupID: vaultGroup, + ItemID: regularResourceID, + }) + + Eventually(func() []string { return storedEvents(member) }, time.Second).Should(ConsistOf(id)) + Eventually(func() []string { return storedEvents(outsider) }, time.Second).Should(ConsistOf(id)) + Expect(checkedUsers).To(BeEmpty()) + }) +}) diff --git a/tests/acceptance/features/apiVault/vault.feature b/tests/acceptance/features/apiVault/vault.feature index d60e5c58ed2..09268c0c23b 100644 --- a/tests/acceptance/features/apiVault/vault.feature +++ b/tests/acceptance/features/apiVault/vault.feature @@ -1191,7 +1191,7 @@ Feature: vault | vaultFile.txt | File Editor | - Scenario: try to send share invitation for a resource in vault to a group + Scenario: send share invitation for a resource in vault to a group Given these groups have been created: | groupname | | vault-group | @@ -1207,28 +1207,11 @@ Feature: vault | shareType | group | | permissionsRole | Viewer | | storage | vault | - Then the HTTP status code should be "403" - And the JSON data of the response should match - """ - { - "type": "object", - "required": ["error"], - "properties": { - "error": { - "type": "object", - "required": ["code", "message"], - "properties": { - "code": { - "const": "accessDenied" - }, - "message": { - "const": "grantee is not allowed to access vault resources" - } - } - } - } - } - """ + Then the HTTP status code should be "200" + And user "Brian" should have a share in vault "vaultFile.txt" synced + And user "Brian" should have the following resource shares: + | resource | permissionsRole | sharer | space | storage | + | vaultFile.txt | Viewer | Alice | Personal | vault | Scenario Outline: server sets a default 30-day expiration when a user share is created without one diff --git a/vendor/github.com/owncloud/reva/v2/internal/grpc/services/gateway/usershareprovider.go b/vendor/github.com/owncloud/reva/v2/internal/grpc/services/gateway/usershareprovider.go index 5a7b07fc5c7..eab7c1f4217 100644 --- a/vendor/github.com/owncloud/reva/v2/internal/grpc/services/gateway/usershareprovider.go +++ b/vendor/github.com/owncloud/reva/v2/internal/grpc/services/gateway/usershareprovider.go @@ -78,6 +78,13 @@ func (s *svc) CreateShare(ctx context.Context, req *collaboration.CreateShareReq // granteeMayAccessVault reports whether the grantee may be granted access to a vault resource. // A non-nil error means undetermined, never denied, so callers must fail closed. func (s *svc) granteeMayAccessVault(ctx context.Context, g *provider.Grantee) (bool, error) { + // Groups are allowed without a VaultMode check. Role assignments belong to single accounts, + // and group membership can change after the share exists. The notification services filter + // the group members by VaultMode instead, and every member still needs MFA to open the vault. + if g.GetType() == provider.GranteeType_GRANTEE_TYPE_GROUP { + return g.GetGroupId().GetOpaqueId() != "", nil + } + ref := vaultPermissionSubject(g) if ref == nil { return false, nil @@ -93,7 +100,8 @@ func (s *svc) granteeMayAccessVault(ctx context.Context, g *provider.Grantee) (b return vaultPermissionGranted(res.GetStatus()) } -// vaultPermissionSubject returns the subject to check VaultMode for, or nil for grantees that can never hold it, like groups. +// vaultPermissionSubject returns the subject to check VaultMode for, or nil for grantees that cannot hold it. +// Groups cannot hold it, because role assignments belong to single accounts. func vaultPermissionSubject(g *provider.Grantee) *permissions.SubjectReference { if g.GetType() != provider.GranteeType_GRANTEE_TYPE_USER { return nil diff --git a/vendor/modules.txt b/vendor/modules.txt index 645cd3cec14..76e702e2d4e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1321,7 +1321,7 @@ github.com/orcaman/concurrent-map # github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 ## explicit; go 1.18 github.com/owncloud/libre-graph-api-go -# github.com/owncloud/reva/v2 v2.0.0-20261022133635-764ed1d17629 +# github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e ## explicit; go 1.26.0 github.com/owncloud/reva/v2/cmd/revad/internal/grace github.com/owncloud/reva/v2/cmd/revad/runtime diff --git a/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue b/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue index 9ce6aeb74d9..389ee9f2066 100644 --- a/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue +++ b/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue @@ -356,9 +356,9 @@ const fetchRecipientsTask = useTask(function* (signal, query: string) { ) let groupData: Group[] - if (!unref(isExternalShareRoleType) && !unref(isVaultResource)) { - // groups are only available for internal shares, and never for vault resources: the - // vault permission is assigned per account, so a group can never hold it + if (!unref(isExternalShareRoleType)) { + // groups are only available for internal shares. For vault resources the server checks + // the vault permission of each group member when it sends the share notifications groupData = yield* call( client.groups.listGroups({ orderBy: ['displayName'], search: `"${query}"` }, { signal }) ) diff --git a/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts b/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts index d4c34cb7b16..68e1512a78b 100644 --- a/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts +++ b/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts @@ -122,7 +122,7 @@ describe('InviteCollaboratorForm', () => { vault: { enabled: true, vault_storage_provider: '' } } - it('only asks for users that may access the vault, and for no groups at all', async () => { + it('asks for users that may access the vault, and for groups', async () => { const { wrapper, mocks } = getWrapper({ capabilities: vaultCapabilities, resource: mock({ ...folderMock, storageId: VAULT_STORAGE_PROVIDER_ID }) @@ -133,7 +133,7 @@ describe('InviteCollaboratorForm', () => { expect.objectContaining({ filter: 'vaultEligible eq true' }), expect.anything() ) - expect(mocks.$clientService.graphAuthenticated.groups.listGroups).not.toHaveBeenCalled() + expect(mocks.$clientService.graphAuthenticated.groups.listGroups).toHaveBeenCalled() }) it('recognizes a vault space resource, which carries the full drive id', async () => { const { wrapper, mocks } = getWrapper({