From 5cfb0fca1a4e368f145468abefa713f043364b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 10 Nov 2026 15:56:52 +0100 Subject: [PATCH 1/2] fix(graph): list permissions when public shares are inaccessible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the public share manager cannot access its metadata space, e.g. after an upgrade, listing public shares fails with an already exists error and the whole permissions request ended in a 500. The space members dialog in web then just keeps spinning. We now log a warning, skip the link permissions and still return the user and space permissions. Our reva currently replaces the original error with a generic "error listing public shares", so this only takes effect together with the port of `owncloud/reva#264`, which passes the error message through. ported from `owncloud/ocis#11245` Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer --- .../service/v0/api_driveitem_permissions.go | 8 +++- .../v0/api_driveitem_permissions_test.go | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/services/graph/pkg/service/v0/api_driveitem_permissions.go b/services/graph/pkg/service/v0/api_driveitem_permissions.go index 1bc0ac7e60..0a95df033c 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions.go @@ -23,6 +23,7 @@ import ( "github.com/go-chi/render" libregraph "github.com/opencloud-eu/libre-graph-api-go" revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/errtypes" "github.com/opencloud-eu/reva/v2/pkg/publicshare" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" "github.com/opencloud-eu/reva/v2/pkg/share" @@ -633,7 +634,12 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID driveItems, err = s.listPublicShares(ctx, []*link.ListPublicSharesRequest_Filter{ publicshare.ResourceIDFilter(itemID), }, driveItems) - if err != nil { + switch { + case err != nil && strings.Contains(err.Error(), errtypes.AlreadyExists("").Error()): + // the public share manager reports an already exists error when its metadata space is + // not accessible, e.g. after an upgrade. Still list the user and space permissions. + logger.Warn().Err(err).Str(_logKeyItemID, storagespace.FormatResourceID(itemID)).Msg("could not list public shares, skipping link permissions") + case err != nil: errorEvent(&logger, err).Str(_logKeyItemID, storagespace.FormatResourceID(itemID)).Msg("could not list public shares") return collectionOfPermissions, err } 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 c5bce19f34..c7743aef48 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions_test.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions_test.go @@ -42,6 +42,7 @@ import ( roleconversions "github.com/opencloud-eu/reva/v2/pkg/conversions" revactx "github.com/opencloud-eu/reva/v2/pkg/ctx" + "github.com/opencloud-eu/reva/v2/pkg/errtypes" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/status" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" "github.com/opencloud-eu/reva/v2/pkg/storagespace" @@ -1771,6 +1772,48 @@ var _ = Describe("DriveItemPermissionsService", func() { Expect(len(permissions.LibreGraphPermissionsRolesAllowedValues)).ToNot(BeZero()) Expect(len(permissions.Value)).To(Equal(2)) }) + It("still returns the user shares when listing public shares reports an already exists error", func() { + statResponse.Info.PermissionSet = roleconversions.NewEditorRole().CS3ResourcePermissions() + listSharesResponse.Shares = []*collaboration.Share{ + { + Id: &collaboration.ShareId{OpaqueId: "1"}, + Permissions: &collaboration.SharePermissions{ + Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(), + }, + ResourceId: &provider.ResourceId{ + StorageId: "1", + SpaceId: "2", + OpaqueId: "3", + }, + Grantee: &provider.Grantee{ + Type: provider.GranteeType_GRANTEE_TYPE_USER, + Id: &provider.Grantee_UserId{ + UserId: &userpb.UserId{ + OpaqueId: "user-id", + }, + }, + }, + }, + } + listPublicSharesResponse.Status = status.NewInternal(ctx, errtypes.AlreadyExists("user service-user does not have access to metadata space jsoncs3-public-share-manager-metadata, but it exists").Error()) + + gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil) + gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil) + gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil) + gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil) + permissions, err := driveItemPermissionsService.ListPermissions(context.Background(), itemID, svc.ListPermissionsQueryOptions{}) + Expect(err).ToNot(HaveOccurred()) + Expect(len(permissions.Value)).To(Equal(1)) + }) + It("fails when listing public shares fails for other reasons", func() { + listPublicSharesResponse.Status = status.NewInternal(ctx, "error listing public shares") + + gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil) + gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil) + gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil) + _, err := driveItemPermissionsService.ListPermissions(context.Background(), itemID, svc.ListPermissionsQueryOptions{}) + Expect(err).To(HaveOccurred()) + }) It("returns role denied", func() { statResponse.Info.PermissionSet = roleconversions.NewManagerRole().CS3ResourcePermissions() statResponse.Info.Type = provider.ResourceType_RESOURCE_TYPE_CONTAINER From 8a56177b82079c9e8e56d9626e8d4d9d5c18b72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 10 Nov 2026 15:58:19 +0100 Subject: [PATCH 2/2] fix(graph): reject links on the shares space root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creating a link on the root of the Shares drive was only caught later by the permission check, and an internal link with the internal role was not rejected at all. We now answer with a 400 "cannot create link on shares space root" before even looking at the request body, just like we do for the personal space root. The acceptance scenarios now expect the new message for the Shares drive, and the internal link scenario covers the Shares drive again. ported from `owncloud/ocis#11543` Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer --- .../v0/api_driveitem_permissions_links.go | 8 ++++++- .../v0/api_driveitem_permissions_test.go | 21 +++++++++++++++++++ .../createLinkShare.feature | 17 ++++++++------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/services/graph/pkg/service/v0/api_driveitem_permissions_links.go b/services/graph/pkg/service/v0/api_driveitem_permissions_links.go index aaf664239a..54c7343fe1 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions_links.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions_links.go @@ -153,12 +153,18 @@ func (api DriveItemPermissionsApi) CreateLink(w http.ResponseWriter, r *http.Req logger := api.logger.SubloggerWithRequestID(r.Context()) logger.Info().Msg("calling create link") - _, driveItemID, err := GetDriveAndItemIDParam(r, &logger) + driveID, driveItemID, err := GetDriveAndItemIDParam(r, &logger) if err != nil { errorcode.RenderError(w, r, err) return } + if IsShareJail(driveID) && driveID.GetSpaceId() == driveItemID.GetOpaqueId() { + logger.Debug().Interface("driveItemID", driveItemID).Msg("cannot create link on shares space root") + errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "cannot create link on shares space root") + return + } + var createLink libregraph.DriveItemCreateLink if err = StrictJSONUnmarshal(r.Body, &createLink); err != nil { logger.Error().Err(err).Interface("body", r.Body).Msg("could not create link: invalid body schema definition") 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 c7743aef48..3efb505098 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions_test.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions_test.go @@ -3762,6 +3762,27 @@ var _ = Describe("DriveItemPermissionsApi", func() { Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest)) }) }) + Describe("CreateLink", func() { + It("rejects links on the shares space root", func() { + shareJailID := utils.ShareStorageProviderID + "$" + utils.ShareStorageSpaceID + rCTX = chi.NewRouteContext() + rCTX.URLParams.Add("driveID", shareJailID) + rCTX.URLParams.Add("itemID", shareJailID+"!"+utils.ShareStorageSpaceID) + + responseRecorder := httptest.NewRecorder() + request := httptest.NewRequest(http.MethodPost, "/", bytes.NewBufferString(`{"type":"view"}`)). + WithContext( + context.WithValue(context.Background(), chi.RouteCtxKey, rCTX), + ) + + httpAPI.CreateLink(responseRecorder, request) + + Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest)) + jsonData := gjson.Get(responseRecorder.Body.String(), "error") + Expect(jsonData.Get("message").String()).To(Equal("cannot create link on shares space root")) + }) + }) + Describe("ListPermissions", func() { It("calls the ListPermissions provider with the correct arguments", func() { rCTX.URLParams.Add("itemID", "1$2!3") diff --git a/tests/acceptance/features/apiSharingNgLinkSharePermission/createLinkShare.feature b/tests/acceptance/features/apiSharingNgLinkSharePermission/createLinkShare.feature index 662dbff45d..89317d8b93 100644 --- a/tests/acceptance/features/apiSharingNgLinkSharePermission/createLinkShare.feature +++ b/tests/acceptance/features/apiSharingNgLinkSharePermission/createLinkShare.feature @@ -1279,10 +1279,10 @@ Feature: Create a link share for a resource """ Examples: | permissions-role | drive | message | - | view | Shares | no share permission | - | edit | Shares | no share permission | - | upload | Shares | no share permission | - | createOnly | Shares | no share permission | + | view | Shares | cannot create link on shares space root | + | edit | Shares | cannot create link on shares space root | + | upload | Shares | cannot create link on shares space root | + | createOnly | Shares | cannot create link on shares space root | | view | Personal | cannot create link on personal space root | | edit | Personal | cannot create link on personal space root | | upload | Personal | cannot create link on personal space root | @@ -1394,6 +1394,7 @@ Feature: Create a link share for a resource Examples: | drive | message | | Personal | cannot create link on personal space root | + | Shares | cannot create link on shares space root | Scenario Outline: try to create an internal link share with password of a Personal and Shares drives using permissions endpoint @@ -1427,7 +1428,7 @@ Feature: Create a link share for a resource ] }, "message": { - "const": "password is redundant for the internal link" + "const": "" } } } @@ -1435,9 +1436,9 @@ Feature: Create a link share for a resource } """ Examples: - | drive | - | Personal | - | Shares | + | drive | message | + | Personal | password is redundant for the internal link | + | Shares | cannot create link on shares space root | Scenario: create an internal link share of a project-space using permissions endpoint