From 34d5ffe17308abb2e46f878825e0d5d8a458c844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 17 Nov 2026 12:42:32 +0100 Subject: [PATCH] feat(sharing): allow disabling the creation of new shares MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now have two global opt-out switches that stop users from creating new shares while everything that already exists keeps working: OC_DISABLE_NEW_USER_SHARES rejects new user, group and federated shares in graph and reva. Adding members to a space is still possible: graph skips space roots, based on the stat result, like reva does. OC_DISABLE_NEW_PUBLIC_LINKS rejects new public links and turning an internal link into a public link in reva. The frontend, graph, sharing and ocm services read them. Both default to false. We bump reva to 37496dc6abd3, which contains https://github.com/opencloud-eu/reva/pull/1022 Ported from `owncloud/ocis#12542`, with the flags inverted. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 4 +- services/frontend/pkg/config/config.go | 3 ++ services/frontend/pkg/revaconfig/config.go | 6 ++- services/graph/pkg/config/config.go | 1 + .../service/v0/api_driveitem_permissions.go | 5 +++ .../v0/api_driveitem_permissions_test.go | 44 +++++++++++++++++++ services/ocm/pkg/config/config.go | 9 ++-- services/ocm/pkg/revaconfig/config.go | 11 ++--- services/sharing/README.md | 9 ++++ services/sharing/pkg/config/config.go | 2 + services/sharing/pkg/revaconfig/config.go | 4 +- .../ocmshareprovider/ocmshareprovider.go | 23 ++++++---- .../publicshareprovider.go | 15 +++++++ .../sharesstorageprovider.go | 6 +++ .../usershareprovider/usershareprovider.go | 14 +++++- .../services/owncloud/ocs/config/config.go | 2 + .../handlers/apps/sharing/sharees/sharees.go | 17 +++++++ .../cloud/capabilities/capabilities.go | 10 +++++ .../reva/v3/pkg/conversions/role.go | 2 +- .../reva/v3/pkg/owncloud/ocs/capabilities.go | 1 + .../fs/nextcloud/nextcloud_server_mock.go | 4 +- .../reva/v3/pkg/storage/utils/ace/ace.go | 13 +++--- vendor/modules.txt | 2 +- 24 files changed, 173 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 8dec8586f1..f61082d7a0 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( github.com/open-policy-agent/opa v1.21.1 github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89 github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261016073229-17ed3d5dd346 - github.com/opencloud-eu/reva/v3 v3.0.1 + github.com/opencloud-eu/reva/v3 v3.0.2-0.20261117134925-37496dc6abd3 github.com/opensearch-project/opensearch-go/v4 v4.7.3 github.com/orcaman/concurrent-map v1.0.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 6279d6ce35..4d9ac64246 100644 --- a/go.sum +++ b/go.sum @@ -761,8 +761,8 @@ github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89 h1:W1ms+l github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89/go.mod h1:vigJkNss1N2QEceCuNw/ullDehncuJNFB6mEnzfq9UI= github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261016073229-17ed3d5dd346 h1:3ptbiFhSK4fzY/rC3idcYUveiwepMoOov1sBpc7Rg3k= github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261016073229-17ed3d5dd346/go.mod h1:lTM8JeGblNpoMySTW7Lui2+c5TTLI95mwxtdUIHHrhU= -github.com/opencloud-eu/reva/v3 v3.0.1 h1:4GBnBLRFFKrF00gC6TUQYY/qzibRy8fW1ouzRVB3Qt8= -github.com/opencloud-eu/reva/v3 v3.0.1/go.mod h1:GYVaPfxKgmER65YvpN0uwYL8QSXnwXbR4Qr3iwsYlPU= +github.com/opencloud-eu/reva/v3 v3.0.2-0.20261117134925-37496dc6abd3 h1:fXAGn3HwuyQGRSw64i49FrzoOci6wwgJ57OONGST0fk= +github.com/opencloud-eu/reva/v3 v3.0.2-0.20261117134925-37496dc6abd3/go.mod h1:GYVaPfxKgmER65YvpN0uwYL8QSXnwXbR4Qr3iwsYlPU= github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4 h1:l2oB/RctH+t8r7QBj5p8thfEHCM/jF35aAY3WQ3hADI= github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= diff --git a/services/frontend/pkg/config/config.go b/services/frontend/pkg/config/config.go index 366b6c876f..0ec2630bd7 100644 --- a/services/frontend/pkg/config/config.go +++ b/services/frontend/pkg/config/config.go @@ -61,6 +61,9 @@ type Config struct { ConfigurableNotifications bool `yaml:"configurable_notifications" env:"FRONTEND_CONFIGURABLE_NOTIFICATIONS" desc:"Allow configuring notifications via web client." introductionVersion:"1.0.0"` + DisableNewUserShares bool `yaml:"disable_new_user_shares" env:"OC_DISABLE_NEW_USER_SHARES" desc:"Reject the creation of new user, group and federated shares. Existing shares keep working. Adding members to spaces is not affected. The sharee search returns no results and the capabilities announce that user sharing is disabled." introductionVersion:"%%NEXT%%"` + DisableNewPublicLinks bool `yaml:"disable_new_public_links" env:"OC_DISABLE_NEW_PUBLIC_LINKS" desc:"Reject the creation of new public links and turning internal links into public links. Internal links and existing public links keep working." introductionVersion:"%%NEXT%%"` + ServerManagedSpaces bool `yaml:"server_managed_spaces" env:"OC_CLAIM_MANAGED_SPACES_ENABLED" desc:"Mark spaces as managed by the server. Clients like the web UI then block adding or removing users to or from spaces. See the text description for more details." introductionVersion:"9.2.0"` Groupware Groupware `yaml:"groupware"` diff --git a/services/frontend/pkg/revaconfig/config.go b/services/frontend/pkg/revaconfig/config.go index 989661adce..698b17e5e0 100644 --- a/services/frontend/pkg/revaconfig/config.go +++ b/services/frontend/pkg/revaconfig/config.go @@ -357,8 +357,10 @@ func FrontendConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string "productversion": version.GetString(), }, }, - "include_ocm_sharees": cfg.OCS.IncludeOCMSharees, - "show_email_in_results": cfg.OCS.ShowUserEmailInResults, + "include_ocm_sharees": cfg.OCS.IncludeOCMSharees, + "show_email_in_results": cfg.OCS.ShowUserEmailInResults, + "disable_new_user_shares": cfg.DisableNewUserShares, + "disable_new_public_links": cfg.DisableNewPublicLinks, }, "ocdav": map[string]any{ "prefix": cfg.OCDav.Prefix, diff --git a/services/graph/pkg/config/config.go b/services/graph/pkg/config/config.go index 39df259d9f..80b95a3b93 100644 --- a/services/graph/pkg/config/config.go +++ b/services/graph/pkg/config/config.go @@ -139,6 +139,7 @@ type API struct { AssignDefaultUserRole bool `yaml:"graph_assign_default_user_role" env:"GRAPH_ASSIGN_DEFAULT_USER_ROLE" desc:"Whether to assign newly created users the default role 'User'. Set this to 'false' if you want to assign roles manually, or if the role assignment should happen at first login. Set this to 'true' (the default) to assign the role 'User' when creating a new user." introductionVersion:"1.0.0"` IdentitySearchMinLength int `yaml:"graph_identity_search_min_length" env:"GRAPH_IDENTITY_SEARCH_MIN_LENGTH" desc:"The minimum length the search term needs to have for unprivileged users when searching for users or groups." introductionVersion:"1.0.0"` ShowUserEmailInResults bool `yaml:"show_email_in_results" env:"OC_SHOW_USER_EMAIL_IN_RESULTS" desc:"Include user email addresses in responses. If absent or set to false emails will be omitted from results. Please note that admin users can always see all email addresses." introductionVersion:"1.0.0"` + DisableNewUserShares bool `yaml:"disable_new_user_shares" env:"OC_DISABLE_NEW_USER_SHARES" desc:"Reject the creation of new user, group and federated shares. Existing shares keep working. Adding members to spaces is not affected." introductionVersion:"%%NEXT%%"` ExportPersonalDataRateLimit int `yaml:"export_personal_data_rate_limit" env:"GRAPH_EXPORT_PERSONAL_DATA_RATE_LIMIT" desc:"The maximum number of personal data exports a user can start per minute. Each instance of the graph service counts on its own, so with several instances, a user can start up to this number of exports on each of them. Set it to 0 to disable the limit." introductionVersion:"9.2.0"` } diff --git a/services/graph/pkg/service/v0/api_driveitem_permissions.go b/services/graph/pkg/service/v0/api_driveitem_permissions.go index 38fc483f45..f72c40dc9d 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions.go @@ -226,6 +226,11 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId *sto return libregraph.Permission{}, err } + // adding members to a space is not a new share + if s.config.API.DisableNewUserShares && !utils.IsSpaceRoot(statResponse.GetInfo()) { + return libregraph.Permission{}, errorcode.New(errorcode.NotAllowed, "creating new user shares is disabled") + } + var condition string if condition, err = roleConditionForResourceType(statResponse.GetInfo()); err != nil { logger.Debug().Err(err).Str(_logKeyItemID, storagespace.FormatResourceID(resourceId)).Msg("unsupported resource type") diff --git a/services/graph/pkg/service/v0/api_driveitem_permissions_test.go b/services/graph/pkg/service/v0/api_driveitem_permissions_test.go index 91534afe48..c042575426 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions_test.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions_test.go @@ -1183,6 +1183,20 @@ var _ = Describe("DriveItemPermissionsService", func() { _, err = service.Invite(ctx, driveItemId, driveItemInvite) Expect(err).To(MatchError(unifiedrole.ErrUnknownRole)) }) + + It("rejects new user shares when they are disabled", func() { + cfg := defaults.FullDefaultConfig() + cfg.API.DisableNewUserShares = true + service, err := svc.NewDriveItemPermissionsService(log.NewLogger(), gatewaySelector, cache, cfg, nil) + Expect(err).ToNot(HaveOccurred()) + + driveItemInvite.Recipients = []libregraph.DriveRecipient{ + {ObjectId: libregraph.PtrString("1"), LibreGraphRecipientType: libregraph.PtrString("user")}, + } + _, err = service.Invite(ctx, driveItemId, driveItemInvite) + Expect(err).To(MatchError(errorcode.New(errorcode.NotAllowed, "creating new user shares is disabled"))) + gatewayClient.AssertNotCalled(GinkgoT(), "CreateShare", mock.Anything, mock.Anything) + }) }) Describe("SpaceRootInvite", func() { var ( @@ -1256,6 +1270,36 @@ var _ = Describe("DriveItemPermissionsService", func() { Expect(permission.GrantedToV2.User.GetDisplayName()).To(Equal(getUserResponse.User.DisplayName)) Expect(permission.GrantedToV2.User.GetId()).To(Equal("1")) }) + It("still adds a user to a space when new user shares are disabled", func() { + cfg := defaults.FullDefaultConfig() + cfg.API.DisableNewUserShares = true + service, err := svc.NewDriveItemPermissionsService(log.NewLogger(), gatewaySelector, cache, cfg, nil) + Expect(err).ToNot(HaveOccurred()) + + listSpacesResponse.StorageSpaces[0].SpaceType = "project" + listSpacesResponse.StorageSpaces[0].Root = &provider.ResourceId{ + StorageId: "1", + SpaceId: "2", + OpaqueId: "3", + } + statResponse.Info.Id = listSpacesResponse.StorageSpaces[0].Root + statResponse.Info.Space = &provider.StorageSpace{ + Root: listSpacesResponse.StorageSpaces[0].Root, + } + + gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(listSpacesResponse, nil) + gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil) + gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil) + gatewayClient.On("CreateShare", mock.Anything, mock.Anything).Return(createShareResponse, nil) + driveItemInvite.Recipients = []libregraph.DriveRecipient{ + {ObjectId: libregraph.PtrString("1"), LibreGraphRecipientType: libregraph.PtrString("user")}, + } + createShareResponse.Share = &collaboration.Share{Id: &collaboration.ShareId{OpaqueId: "123"}} + + permission, err := service.SpaceRootInvite(ctx, driveId, driveItemInvite) + Expect(err).ToNot(HaveOccurred()) + Expect(permission.GetId()).To(Equal("123")) + }) It("records a SpaceRootInvite span as the parent of the Invite span", func() { sr, tp := newSpanRecorder() service, err := svc.NewDriveItemPermissionsService(log.NewLogger(), gatewaySelector, cache, cfg, tp) diff --git a/services/ocm/pkg/config/config.go b/services/ocm/pkg/config/config.go index 14163987c7..44319eb816 100644 --- a/services/ocm/pkg/config/config.go +++ b/services/ocm/pkg/config/config.go @@ -137,10 +137,11 @@ type OCMCoreJSONDriver struct { } type OCMShareProvider struct { - Driver string `yaml:"driver" env:"OCM_OCM_SHARE_PROVIDER_DRIVER" desc:"Driver to be used for the OCM share provider. Supported value is only 'json'." introductionVersion:"1.0.0"` - Drivers OCMShareProviderDrivers `yaml:"drivers"` - Insecure bool `yaml:"insecure" env:"OCM_OCM_SHARE_PROVIDER_INSECURE" desc:"Disable TLS certificate validation for the OCM connections. Do not set this in production environments." introductionVersion:"1.0.0"` - WebappTemplate string `yaml:"webapp_template" env:"OCM_WEBAPP_TEMPLATE" desc:"Template for the webapp url." introductionVersion:"1.0.0"` + Driver string `yaml:"driver" env:"OCM_OCM_SHARE_PROVIDER_DRIVER" desc:"Driver to be used for the OCM share provider. Supported value is only 'json'." introductionVersion:"1.0.0"` + Drivers OCMShareProviderDrivers `yaml:"drivers"` + Insecure bool `yaml:"insecure" env:"OCM_OCM_SHARE_PROVIDER_INSECURE" desc:"Disable TLS certificate validation for the OCM connections. Do not set this in production environments." introductionVersion:"1.0.0"` + WebappTemplate string `yaml:"webapp_template" env:"OCM_WEBAPP_TEMPLATE" desc:"Template for the webapp url." introductionVersion:"1.0.0"` + DisableNewUserShares bool `yaml:"disable_new_user_shares" env:"OC_DISABLE_NEW_USER_SHARES" desc:"Reject the creation of new federated shares. Existing shares keep working." introductionVersion:"%%NEXT%%"` } type OCMShareProviderDrivers struct { diff --git a/services/ocm/pkg/revaconfig/config.go b/services/ocm/pkg/revaconfig/config.go index 765d162989..4483d9c950 100644 --- a/services/ocm/pkg/revaconfig/config.go +++ b/services/ocm/pkg/revaconfig/config.go @@ -162,11 +162,12 @@ func OCMConfigFromStruct(cfg *config.Config, logger log.Logger) map[string]any { "file": cfg.OCMShareProvider.Drivers.JSON.File, }, }, - "gatewaysvc": cfg.Reva.Address, - "provider_domain": providerDomain, - "webdav_endpoint": cfg.Commons.OpenCloudURL, - "webapp_template": cfg.OCMShareProvider.WebappTemplate, - "client_insecure": cfg.OCMShareProvider.Insecure, + "gatewaysvc": cfg.Reva.Address, + "provider_domain": providerDomain, + "webdav_endpoint": cfg.Commons.OpenCloudURL, + "webapp_template": cfg.OCMShareProvider.WebappTemplate, + "client_insecure": cfg.OCMShareProvider.Insecure, + "disable_new_user_shares": cfg.OCMShareProvider.DisableNewUserShares, }, "ocmcore": map[string]any{ "driver": cfg.OCMCore.Driver, diff --git a/services/sharing/README.md b/services/sharing/README.md index eb62f71546..b8c7472967 100644 --- a/services/sharing/README.md +++ b/services/sharing/README.md @@ -42,6 +42,15 @@ incoming shares will be accepted automatically. Users can overwrite this setting individually in their profile. The deprecated `FRONTEND_AUTO_ACCEPT_SHARES` is still supported for backwards compatibility. +### Disable Creating New Shares + +Two global switches stop users from creating new shares. Everything that already exists keeps working: existing shares and links can still be used, changed and deleted. + +- `OC_DISABLE_NEW_USER_SHARES=true` rejects new user, group and federated shares. Adding members to a space is still possible. The OCS sharee search returns no results and the capabilities announce that user sharing is disabled. +- `OC_DISABLE_NEW_PUBLIC_LINKS=true` rejects new public links and turning an internal link into a public link. Internal links can still be created. The capabilities announce that public links are disabled, so the web UI hides the link section. + +Both are read by the `frontend`, `graph`, `sharing` and (for federated shares) `ocm` services. When the services run separately, set them for all of them. + ## Scalability The sharing service depends on the configured storage backends for share metadata. Scalability characteristics depend on the chosen storage backend configuration. diff --git a/services/sharing/pkg/config/config.go b/services/sharing/pkg/config/config.go index e999bd0319..bc35a0a3d4 100644 --- a/services/sharing/pkg/config/config.go +++ b/services/sharing/pkg/config/config.go @@ -31,6 +31,8 @@ type Config struct { PublicShareMustHavePassword bool `yaml:"public_sharing_share_must_have_password" env:"OC_SHARING_PUBLIC_SHARE_MUST_HAVE_PASSWORD;SHARING_PUBLIC_SHARE_MUST_HAVE_PASSWORD" desc:"Set this to true if you want to enforce passwords on all public shares." introductionVersion:"1.0.0"` EnableExpiredSharesCleanup bool `yaml:"enable_expired_shares_cleanup"` PasswordPolicy PasswordPolicy `yaml:"password_policy"` + DisableNewUserShares bool `yaml:"disable_new_user_shares" env:"OC_DISABLE_NEW_USER_SHARES" desc:"Reject the creation of new user and group shares. Existing shares keep working. Adding members to spaces is not affected." introductionVersion:"%%NEXT%%"` + DisableNewPublicLinks bool `yaml:"disable_new_public_links" env:"OC_DISABLE_NEW_PUBLIC_LINKS" desc:"Reject the creation of new public links and turning internal links into public links. Internal links and existing public links keep working." introductionVersion:"%%NEXT%%"` Context context.Context `yaml:"-"` } diff --git a/services/sharing/pkg/revaconfig/config.go b/services/sharing/pkg/revaconfig/config.go index 434a71ecee..5e0ab975d5 100644 --- a/services/sharing/pkg/revaconfig/config.go +++ b/services/sharing/pkg/revaconfig/config.go @@ -38,7 +38,8 @@ func SharingConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string] // TODO build services dynamically "services": map[string]any{ "usershareprovider": map[string]any{ - "driver": cfg.UserSharingDriver, + "driver": cfg.UserSharingDriver, + "disable_new_user_shares": cfg.DisableNewUserShares, "drivers": map[string]any{ "json": map[string]any{ "file": cfg.UserSharingDrivers.JSON.File, @@ -99,6 +100,7 @@ func SharingConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string] "public_share_must_have_password": cfg.PublicShareMustHavePassword, "password_policy": passwordPolicyCfg, "driver": cfg.PublicSharingDriver, + "disable_new_public_links": cfg.DisableNewPublicLinks, "drivers": map[string]any{ "json": map[string]any{ "file": cfg.PublicSharingDrivers.JSON.File, diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/ocmshareprovider/ocmshareprovider.go b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/ocmshareprovider/ocmshareprovider.go index e858f4ff0c..3bd3303c59 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/ocmshareprovider/ocmshareprovider.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/ocmshareprovider/ocmshareprovider.go @@ -58,14 +58,15 @@ func init() { } type config struct { - Driver string `mapstructure:"driver"` - Drivers map[string]map[string]interface{} `mapstructure:"drivers"` - ClientTimeout int `mapstructure:"client_timeout"` - ClientInsecure bool `mapstructure:"client_insecure"` - GatewaySVC string `mapstructure:"gatewaysvc" validate:"required"` - ProviderDomain string `mapstructure:"provider_domain" validate:"required" docs:"The same domain registered in the provider authorizer"` - WebDAVEndpoint string `mapstructure:"webdav_endpoint" validate:"required"` - WebappTemplate string `mapstructure:"webapp_template"` + Driver string `mapstructure:"driver"` + Drivers map[string]map[string]interface{} `mapstructure:"drivers"` + ClientTimeout int `mapstructure:"client_timeout"` + ClientInsecure bool `mapstructure:"client_insecure"` + GatewaySVC string `mapstructure:"gatewaysvc" validate:"required"` + ProviderDomain string `mapstructure:"provider_domain" validate:"required" docs:"The same domain registered in the provider authorizer"` + WebDAVEndpoint string `mapstructure:"webdav_endpoint" validate:"required"` + WebappTemplate string `mapstructure:"webapp_template"` + DisableNewUserShares bool `mapstructure:"disable_new_user_shares" docs:"false;Reject the creation of new federated shares. Existing shares are not affected."` } type service struct { @@ -219,6 +220,12 @@ func (s *service) getProtocols(ctx context.Context, share *ocm.Share) ocmd.Proto } func (s *service) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareRequest) (*ocm.CreateOCMShareResponse, error) { + if s.conf.DisableNewUserShares { + return &ocm.CreateOCMShareResponse{ + Status: status.NewPermissionDenied(ctx, nil, "creating new federated shares is disabled"), + }, nil + } + gatewayClient, err := s.gatewaySelector.Next() if err != nil { return nil, err diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/publicshareprovider/publicshareprovider.go b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/publicshareprovider/publicshareprovider.go index 46b52bdaf5..c660baf521 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/publicshareprovider/publicshareprovider.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/publicshareprovider/publicshareprovider.go @@ -67,6 +67,7 @@ type config struct { WriteableShareMustHavePassword bool `mapstructure:"writeable_share_must_have_password"` PublicShareMustHavePassword bool `mapstructure:"public_share_must_have_password"` PasswordPolicy map[string]interface{} `mapstructure:"password_policy"` + DisableNewPublicLinks bool `mapstructure:"disable_new_public_links" docs:"false;Reject the creation of new public links and turning internal links into public links. Internal links and existing public links are not affected."` } type passwordPolicy struct { @@ -213,6 +214,12 @@ func (s *service) CreatePublicShare(ctx context.Context, req *link.CreatePublicS isInternalLink := grants.PermissionsEqual(req.GetGrant().GetPermissions().GetPermissions(), &provider.ResourcePermissions{}) + if s.conf.DisableNewPublicLinks && !isInternalLink { + return &link.CreatePublicShareResponse{ + Status: status.NewPermissionDenied(ctx, nil, "creating new public links is disabled"), + }, nil + } + sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: req.GetResourceInfo().GetId()}}) if err != nil { log.Err(err).Interface("resource_id", req.GetResourceInfo().GetId()).Msg("failed to stat resource to share") @@ -492,6 +499,14 @@ func (s *service) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicS isInternalLink := isInternalLink(req, ps) + // an internal link that gets permissions is a new public link + if s.conf.DisableNewPublicLinks && !isInternalLink && + grants.PermissionsEqual(ps.GetPermissions().GetPermissions(), &provider.ResourcePermissions{}) { + return &link.UpdatePublicShareResponse{ + Status: status.NewPermissionDenied(ctx, nil, "creating new public links is disabled"), + }, nil + } + // check if the user has the permission in the user role if !publicshare.IsCreatedByUser(ps, user) { canWriteLink, err := utils.CheckPermission(ctx, permission.WritePublicLink, gatewayClient) diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go index 6690358298..50a57b7f2b 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go @@ -868,6 +868,12 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer SpaceId: utils.ShareStorageSpaceID, OpaqueId: share.GetShare().GetId().GetOpaqueId(), } + // overwrite parent id with the share jail root + info.ParentId = &provider.ResourceId{ + StorageId: utils.ShareStorageProviderID, + SpaceId: utils.ShareStorageSpaceID, + OpaqueId: utils.ShareStorageSpaceID, + } info.Path = filepath.Base(share.MountPoint.Path) info.Name = info.Path diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/usershareprovider/usershareprovider.go b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/usershareprovider/usershareprovider.go index 45d4b7c72b..7550a4a547 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/usershareprovider/usershareprovider.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/grpc/services/usershareprovider/usershareprovider.go @@ -71,6 +71,7 @@ type config struct { Drivers map[string]map[string]interface{} `mapstructure:"drivers"` GatewayAddr string `mapstructure:"gateway_addr"` AllowedPathsForShares []string `mapstructure:"allowed_paths_for_shares"` + DisableNewUserShares bool `mapstructure:"disable_new_user_shares" docs:"false;Reject the creation of new user and group shares. Existing shares and space memberships are not affected."` } func (c *config) init() { @@ -83,6 +84,7 @@ type service struct { sm share.Manager gatewaySelector pool.Selectable[gateway.GatewayAPIClient] allowedPathsForShares []*regexp.Regexp + disableNewUserShares bool } func getShareManager(c *config, logger *zerolog.Logger) (share.Manager, error) { @@ -143,15 +145,16 @@ func NewDefault(m map[string]any, ss *grpc.Server, logger *zerolog.Logger) (rgrp return nil, err } - return New(gatewaySelector, sm, allowedPathsForShares), nil + return New(gatewaySelector, sm, allowedPathsForShares, c.DisableNewUserShares), nil } // New creates a new user share provider svc -func New(gatewaySelector pool.Selectable[gateway.GatewayAPIClient], sm share.Manager, allowedPathsForShares []*regexp.Regexp) rgrpc.Service { +func New(gatewaySelector pool.Selectable[gateway.GatewayAPIClient], sm share.Manager, allowedPathsForShares []*regexp.Regexp, disableNewUserShares bool) rgrpc.Service { service := &service{ sm: sm, gatewaySelector: gatewaySelector, allowedPathsForShares: allowedPathsForShares, + disableNewUserShares: disableNewUserShares, } return service @@ -265,6 +268,13 @@ func (s *service) CreateShare(ctx context.Context, req *collaboration.CreateShar isSpaceRoot := utils.IsSpaceRoot(sRes.GetInfo()) var noEvent bool + // space memberships are managed via shares on the space root, they are not affected + if s.disableNewUserShares && !isSpaceRoot { + return &collaboration.CreateShareResponse{ + Status: status.NewPermissionDenied(ctx, nil, "creating new user shares is disabled"), + }, nil + } + if isSpaceRoot { if sRes.GetInfo().GetSpace().GetSpaceType() == _spaceTypePersonal || sRes.GetInfo().GetSpace().GetSpaceType() == _spaceTypeVirtual { return &collaboration.CreateShareResponse{Status: status.NewInvalid(ctx, "space type is not eligible for sharing")}, nil diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/config/config.go b/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/config/config.go index 4d949ad4d8..1d2ab18cdd 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/config/config.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/config/config.go @@ -49,6 +49,8 @@ type Config struct { Notifications map[string]interface{} `mapstructure:"notifications"` IncludeOCMSharees bool `mapstructure:"include_ocm_sharees"` ShowEmailInResults bool `mapstructure:"show_email_in_results"` + DisableNewUserShares bool `mapstructure:"disable_new_user_shares"` + DisableNewPublicLinks bool `mapstructure:"disable_new_public_links"` } // Init sets sane defaults diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go b/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go index 32f8334fb2..b168631ae2 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/apps/sharing/sharees/sharees.go @@ -41,6 +41,7 @@ type Handler struct { additionalInfoAttribute string includeOCMSharees bool showUserEmailInResults bool + disableNewUserShares bool } // Init initializes this and any contained handlers @@ -49,6 +50,7 @@ func (h *Handler) Init(c *config.Config) { h.additionalInfoAttribute = c.AdditionalInfoAttribute h.includeOCMSharees = c.IncludeOCMSharees h.showUserEmailInResults = c.ShowEmailInResults + h.disableNewUserShares = c.DisableNewUserShares } // FindSharees implements the /apps/files_sharing/api/v1/sharees endpoint @@ -61,6 +63,21 @@ func (h *Handler) FindSharees(w http.ResponseWriter, r *http.Request) { return } + // nobody can be shared with, so there is nobody to find + if h.disableNewUserShares { + response.WriteOCSSuccess(w, r, &conversions.ShareeData{ + Exact: &conversions.ExactMatchesData{ + Users: []*conversions.MatchData{}, + Groups: []*conversions.MatchData{}, + Remotes: []*conversions.MatchData{}, + }, + Users: []*conversions.MatchData{}, + Groups: []*conversions.MatchData{}, + Remotes: []*conversions.MatchData{}, + }) + return + } + gwc, err := pool.GetGatewayServiceClient(h.gatewayAddr) if err != nil { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting gateway grpc client", err) diff --git a/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/cloud/capabilities/capabilities.go b/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/cloud/capabilities/capabilities.go index 133cf340f9..e462ef8fa0 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/cloud/capabilities/capabilities.go +++ b/vendor/github.com/opencloud-eu/reva/v3/internal/http/services/owncloud/ocs/handlers/cloud/capabilities/capabilities.go @@ -144,6 +144,9 @@ func (h *Handler) Init(c *config.Config) { // h.c.Capabilities.FilesSharing.IsPublic.Enabled is boolean h.c.Capabilities.FilesSharing.Public.Enabled = true + if c.DisableNewPublicLinks { + h.c.Capabilities.FilesSharing.Public.Enabled = false + } if h.c.Capabilities.FilesSharing.Public.Password == nil { h.c.Capabilities.FilesSharing.Public.Password = &ocs.CapabilitiesFilesSharingPublicPassword{} @@ -175,6 +178,10 @@ func (h *Handler) Init(c *config.Config) { h.c.Capabilities.FilesSharing.User = &ocs.CapabilitiesFilesSharingUser{} } + h.c.Capabilities.FilesSharing.User.Enabled = true + if c.DisableNewUserShares { + h.c.Capabilities.FilesSharing.User.Enabled = false + } // h.c.Capabilities.FilesSharing.User.SendMail is boolean // h.c.Capabilities.FilesSharing.Resharing is boolean @@ -189,6 +196,9 @@ func (h *Handler) Init(c *config.Config) { } // h.c.Capabilities.FilesSharing.UserEnumeration.Enabled is boolean + if c.DisableNewUserShares { + h.c.Capabilities.FilesSharing.UserEnumeration.Enabled = false + } // h.c.Capabilities.FilesSharing.UserEnumeration.GroupMembersOnly is boolean if h.c.Capabilities.FilesSharing.DefaultPermissions == 0 { diff --git a/vendor/github.com/opencloud-eu/reva/v3/pkg/conversions/role.go b/vendor/github.com/opencloud-eu/reva/v3/pkg/conversions/role.go index 51ea43685c..0bfded45e7 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/pkg/conversions/role.go +++ b/vendor/github.com/opencloud-eu/reva/v3/pkg/conversions/role.go @@ -148,7 +148,7 @@ func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) s } if r.ocsPermissions.Contain(PermissionWrite) { // Single file public link shares cannot be renamed - if !isPublic || (isPublic && r.cS3ResourcePermissions != nil && r.cS3ResourcePermissions.Move) { + if r.cS3ResourcePermissions != nil && r.cS3ResourcePermissions.Move { fmt.Fprintf(&b, "NV") } if !isDir { diff --git a/vendor/github.com/opencloud-eu/reva/v3/pkg/owncloud/ocs/capabilities.go b/vendor/github.com/opencloud-eu/reva/v3/pkg/owncloud/ocs/capabilities.go index 6302d55a2a..afff934c03 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/pkg/owncloud/ocs/capabilities.go +++ b/vendor/github.com/opencloud-eu/reva/v3/pkg/owncloud/ocs/capabilities.go @@ -344,6 +344,7 @@ type CapabilitiesFilesSharingPublicExpireDate struct { // CapabilitiesFilesSharingUser TODO document type CapabilitiesFilesSharingUser struct { + Enabled ocsBool `json:"enabled" xml:"enabled"` SendMail ocsBool `json:"send_mail" xml:"send_mail" mapstructure:"send_mail"` ProfilePicture ocsBool `json:"profile_picture" xml:"profile_picture" mapstructure:"profile_picture"` Settings []*CapabilitiesUserSettings `json:"settings" xml:"settings" mapstructure:"settings"` diff --git a/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/fs/nextcloud/nextcloud_server_mock.go b/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/fs/nextcloud/nextcloud_server_mock.go index bd3207cd34..6d8c313a8b 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/fs/nextcloud/nextcloud_server_mock.go +++ b/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/fs/nextcloud/nextcloud_server_mock.go @@ -53,7 +53,7 @@ const serverStateMetadata = "METADATA" var serverState = serverStateEmpty var responses = map[string]Response{ - `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/AddGrant {"ref":{"path":"/subdir"},"g":{"grantee":{"type":1,"Id":{"UserId":{"opaque_id":"4c510ada-c86b-4815-8820-42cdf82c3d51"}}},"permissions":{"initiate_file_download":true,"move":true,"stat":true}}} EMPTY`: {200, ``, serverStateGrantAdded}, + `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/AddGrant {"ref":{"path":"/subdir"},"g":{"grantee":{"type":1,"Id":{"UserId":{"opaque_id":"4c510ada-c86b-4815-8820-42cdf82c3d51"}}},"permissions":{"delete":true,"initiate_file_download":true,"move":true,"stat":true}}} EMPTY`: {200, ``, serverStateGrantAdded}, `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/CreateDir {"path":"/subdir"} EMPTY`: {200, ``, serverStateSubdir}, `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/CreateDir {"path":"/subdir"} HOME`: {200, ``, serverStateSubdir}, @@ -142,7 +142,7 @@ var responses = map[string]Response{ `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/ListFolder {"ref":{"path":"/Shares"},"mdKeys":null} REFERENCE`: {200, `[{"opaque":{},"type":2,"id":{"opaque_id":"fileid-/some/path"},"checksum":{},"etag":"deadbeef","mime_type":"text/plain","mtime":{"seconds":1234567890},"path":"/subdir","permission_set":{},"size":12345,"canonical_metadata":{},"owner":{"opaque_id":"f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"},"arbitrary_metadata":{"metadata":{"da":"ta","some":"arbi","trary":"meta"}}}]`, serverStateReference}, `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/ListGrants {"path":"/subdir"} SUBDIR`: {200, `[]`, serverStateEmpty}, - `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/ListGrants {"path":"/subdir"} GRANT-ADDED`: {200, `[{"grantee":{"type":1,"Id":{"UserId":{"idp":"some-idp","opaque_id":"some-opaque-id","type":1}}},"permissions":{"add_grant":true,"create_container":true,"delete":false,"get_path":true,"get_quota":true,"initiate_file_download":true,"initiate_file_upload":true,"list_grants":true,"list_container":true,"list_file_versions":true,"list_recycle":true,"move":true,"remove_grant":true,"purge_recycle":true,"restore_file_version":true,"restore_recycle_item":true,"stat":true,"update_grant":true,"deny_grant":true}}]`, serverStateEmpty}, + `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/ListGrants {"path":"/subdir"} GRANT-ADDED`: {200, `[{"grantee":{"type":1,"Id":{"UserId":{"idp":"some-idp","opaque_id":"some-opaque-id","type":1}}},"permissions":{"add_grant":true,"create_container":true,"delete":true,"get_path":true,"get_quota":true,"initiate_file_download":true,"initiate_file_upload":true,"list_grants":true,"list_container":true,"list_file_versions":true,"list_recycle":true,"move":true,"remove_grant":true,"purge_recycle":true,"restore_file_version":true,"restore_recycle_item":true,"stat":true,"update_grant":true,"deny_grant":true}}]`, serverStateEmpty}, `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/ListGrants {"path":"/subdir"} GRANT-UPDATED`: {200, `[{"grantee":{"type":1,"Id":{"UserId":{"idp":"some-idp","opaque_id":"some-opaque-id","type":1}}},"permissions":{"add_grant":true,"create_container":true,"delete":true,"get_path":true,"get_quota":true,"initiate_file_download":true,"initiate_file_upload":true,"list_grants":true,"list_container":true,"list_file_versions":true,"list_recycle":true,"move":true,"remove_grant":true,"purge_recycle":true,"restore_file_version":true,"restore_recycle_item":true,"stat":true,"update_grant":true,"deny_grant":true}}]`, serverStateEmpty}, `POST /apps/sciencemesh/~f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c/api/storage/ListGrants {"path":"/subdir"} GRANT-REMOVED`: {200, `[]`, serverStateEmpty}, diff --git a/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/utils/ace/ace.go b/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/utils/ace/ace.go index ff6d4bd1ac..f6e423acb2 100644 --- a/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/utils/ace/ace.go +++ b/vendor/github.com/opencloud-eu/reva/v3/pkg/storage/utils/ace/ace.go @@ -350,10 +350,15 @@ func (e *ACE) grantPermissionSet() *provider.ResourcePermissions { p.InitiateFileDownload = true p.ListContainer = true } + // d + if strings.Contains(e.permissions, "d") { + p.Delete = true + } + // D ? // w if strings.Contains(e.permissions, "w") { p.InitiateFileUpload = true - if p.InitiateFileDownload { + if p.InitiateFileDownload && p.Delete { p.Move = true } } @@ -366,12 +371,6 @@ func (e *ACE) grantPermissionSet() *provider.ResourcePermissions { if strings.Contains(e.permissions, "x") { p.ListContainer = true } - // d - if strings.Contains(e.permissions, "d") { - p.Delete = true - } - // D ? - // sharing if strings.Contains(e.permissions, "C") { p.AddGrant = true diff --git a/vendor/modules.txt b/vendor/modules.txt index 3ae6d1c807..44ba192516 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1360,7 +1360,7 @@ github.com/opencloud-eu/icap-client # github.com/opencloud-eu/libre-graph-api-go v1.0.9-0.20261016073229-17ed3d5dd346 ## explicit; go 1.23 github.com/opencloud-eu/libre-graph-api-go -# github.com/opencloud-eu/reva/v3 v3.0.1 +# github.com/opencloud-eu/reva/v3 v3.0.2-0.20261117134925-37496dc6abd3 ## explicit; go 1.26.0 github.com/opencloud-eu/reva/v3/cmd/revad/internal/grace github.com/opencloud-eu/reva/v3/cmd/revad/runtime