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 <noreply@anthropic.com>
This commit is contained in:
Roman PerekhodandClaude Opus 5.5 committed 2026-10-29 13:55:13 +01:00
1 parent ef9b4f7fc9
commit f456f905c8
16 files changed
+481 -43

No files matched your search

@@ -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
+1 -1
View File
@@ -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
+2 -4
View File
@@ -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=
+52
View File
@@ -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())
}
}
+66
View File
@@ -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)
})
}
}
+35 -2
View File
@@ -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:
@@ -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() {
+4 -3
View File
@@ -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)
+4 -3
View File
@@ -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
}
+41
View File
@@ -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")
+182
View File
@@ -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())
})
})
@@ -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
@@ -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
+1 -1
View File
@@ -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
@@ -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 })
)
@@ -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<Resource>({ ...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({