mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-27 10:34:42 -05:00
fix(vendor): add graph support to the public share scope and filters
This commit is contained in:
1 parent
21123271d3
commit
685d82b17b
3 files changed
+96
-33
No files matched your search
Generated
Vendored
+3
-32
@@ -23,7 +23,6 @@ package publicstorageprovider
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
@@ -37,6 +36,7 @@ import (
|
||||
"github.com/opencloud-eu/reva/v3/pkg/appctx"
|
||||
ctxpkg "github.com/opencloud-eu/reva/v3/pkg/ctx"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/errtypes"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/publicshare"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/rgrpc"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/rgrpc/status"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/rgrpc/todo/pool"
|
||||
@@ -769,15 +769,7 @@ func (s *service) augmentStatResponse(ctx context.Context, statInfo *provider.Re
|
||||
appctx.GetLogger(ctx).Error().Err(err).Interface("share", share).Interface("info", statInfo).Msg("error when adding share")
|
||||
}
|
||||
|
||||
var sharePath string
|
||||
if shareInfo.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
|
||||
sharePath = path.Base(shareInfo.Path)
|
||||
} else {
|
||||
sharePath = strings.TrimPrefix(statInfo.Path, shareInfo.Path)
|
||||
}
|
||||
|
||||
statInfo.Path = path.Join("/", sharePath)
|
||||
filterPermissions(statInfo.PermissionSet, shareInfo.PermissionSet)
|
||||
publicshare.FilterResourceInfo(statInfo, shareInfo, shareInfo.GetPermissionSet())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -843,7 +835,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
|
||||
for i := range listContainerR.Infos {
|
||||
// FIXME how do we reduce permissions to what is granted by the public link?
|
||||
// only a problem for id based access -> middleware
|
||||
filterPermissions(listContainerR.Infos[i].PermissionSet, info.PermissionSet)
|
||||
publicshare.FilterPermissions(listContainerR.Infos[i].PermissionSet, info.PermissionSet)
|
||||
if err := addShare(listContainerR.Infos[i], share); err != nil {
|
||||
appctx.GetLogger(ctx).Error().Err(err).Interface("share", share).Interface("info", listContainerR.Infos[i]).Msg("error when adding share")
|
||||
}
|
||||
@@ -852,27 +844,6 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
|
||||
return listContainerR, nil
|
||||
}
|
||||
|
||||
func filterPermissions(l *provider.ResourcePermissions, r *provider.ResourcePermissions) {
|
||||
l.AddGrant = l.AddGrant && r.AddGrant
|
||||
l.CreateContainer = l.CreateContainer && r.CreateContainer
|
||||
l.Delete = l.Delete && r.Delete
|
||||
l.GetPath = l.GetPath && r.GetPath
|
||||
l.GetQuota = l.GetQuota && r.GetQuota
|
||||
l.InitiateFileDownload = l.InitiateFileDownload && r.InitiateFileDownload
|
||||
l.InitiateFileUpload = l.InitiateFileUpload && r.InitiateFileUpload
|
||||
l.ListContainer = l.ListContainer && r.ListContainer
|
||||
l.ListFileVersions = l.ListFileVersions && r.ListFileVersions
|
||||
l.ListGrants = l.ListGrants && r.ListGrants
|
||||
l.ListRecycle = l.ListRecycle && r.ListRecycle
|
||||
l.Move = l.Move && r.Move
|
||||
l.PurgeRecycle = l.PurgeRecycle && r.PurgeRecycle
|
||||
l.RemoveGrant = l.RemoveGrant && r.RemoveGrant
|
||||
l.RestoreFileVersion = l.RestoreFileVersion && r.RestoreFileVersion
|
||||
l.RestoreRecycleItem = l.RestoreRecycleItem && r.RestoreRecycleItem
|
||||
l.Stat = l.Stat && r.Stat
|
||||
l.UpdateGrant = l.UpdateGrant && r.UpdateGrant
|
||||
}
|
||||
|
||||
func (s *service) ListFileVersions(ctx context.Context, req *provider.ListFileVersionsRequest) (*provider.ListFileVersionsResponse, error) {
|
||||
return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented")
|
||||
}
|
||||
|
||||
+24
-1
@@ -20,6 +20,7 @@ package scope
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
|
||||
@@ -34,6 +35,7 @@ import (
|
||||
registry "github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1"
|
||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/errtypes"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/storagespace"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/utils"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
@@ -143,7 +145,7 @@ func publicshareScope(ctx context.Context, scope *authpb.Scope, resource interfa
|
||||
// public links must not leak info about collaborative shares
|
||||
return false, nil
|
||||
case string:
|
||||
return checkResourcePath(v), nil
|
||||
return checkResourcePath(v) || checkGraphDrivesPath(v, share.Token), nil
|
||||
}
|
||||
|
||||
msg := "public resource type assertion failed"
|
||||
@@ -151,6 +153,27 @@ func publicshareScope(ctx context.Context, scope *authpb.Scope, resource interfa
|
||||
return false, errtypes.InternalError(msg)
|
||||
}
|
||||
|
||||
var graphDrivesRoutes = []string{"/graph/v1.0/drives/", "/graph/v1beta1/drives/"}
|
||||
|
||||
// checkGraphDrivesPath opens the graph routes of the link's own public drive only.
|
||||
func checkGraphDrivesPath(p, token string) bool {
|
||||
if token == "" {
|
||||
return false
|
||||
}
|
||||
p = path.Clean(p)
|
||||
drive := storagespace.FormatResourceID(&provider.ResourceId{
|
||||
StorageId: utils.PublicStorageProviderID,
|
||||
SpaceId: utils.PublicStorageSpaceID,
|
||||
OpaqueId: token,
|
||||
})
|
||||
for _, route := range graphDrivesRoutes {
|
||||
if p == route+drive || strings.HasPrefix(p, route+drive+"/") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func checkStorageRef(ctx context.Context, s *link.PublicShare, r *provider.Reference) bool {
|
||||
// r: <resource_id:<storage_id:$storageID space_id:$spaceID opaque_id:$opaqueID> path:$path > >
|
||||
if utils.ResourceIDEqual(s.ResourceId, r.GetResourceId()) {
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// Copyright 2018-2026 CERN
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package publicshare
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
)
|
||||
|
||||
// FilterResourceInfo rewrites a resource info for a public link consumer: the
|
||||
// path becomes share-root relative, the permissions are cut to the grant.
|
||||
func FilterResourceInfo(info, shareRoot *provider.ResourceInfo, grant *provider.ResourcePermissions) {
|
||||
if info == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var sharePath string
|
||||
if shareRoot.GetType() == provider.ResourceType_RESOURCE_TYPE_FILE {
|
||||
sharePath = path.Base(shareRoot.GetPath())
|
||||
} else {
|
||||
sharePath = strings.TrimPrefix(info.GetPath(), shareRoot.GetPath())
|
||||
}
|
||||
info.Path = path.Join("/", sharePath)
|
||||
|
||||
if info.PermissionSet != nil {
|
||||
FilterPermissions(info.PermissionSet, grant)
|
||||
}
|
||||
}
|
||||
|
||||
// FilterPermissions reduces l to what r also grants. A nil r clears l.
|
||||
func FilterPermissions(l, r *provider.ResourcePermissions) {
|
||||
l.AddGrant = l.AddGrant && r.GetAddGrant()
|
||||
l.CreateContainer = l.CreateContainer && r.GetCreateContainer()
|
||||
l.Delete = l.Delete && r.GetDelete()
|
||||
l.DenyGrant = l.DenyGrant && r.GetDenyGrant()
|
||||
l.GetPath = l.GetPath && r.GetGetPath()
|
||||
l.GetQuota = l.GetQuota && r.GetGetQuota()
|
||||
l.InitiateFileDownload = l.InitiateFileDownload && r.GetInitiateFileDownload()
|
||||
l.InitiateFileUpload = l.InitiateFileUpload && r.GetInitiateFileUpload()
|
||||
l.ListContainer = l.ListContainer && r.GetListContainer()
|
||||
l.ListFileVersions = l.ListFileVersions && r.GetListFileVersions()
|
||||
l.ListGrants = l.ListGrants && r.GetListGrants()
|
||||
l.ListRecycle = l.ListRecycle && r.GetListRecycle()
|
||||
l.Move = l.Move && r.GetMove()
|
||||
l.PurgeRecycle = l.PurgeRecycle && r.GetPurgeRecycle()
|
||||
l.RemoveGrant = l.RemoveGrant && r.GetRemoveGrant()
|
||||
l.RestoreFileVersion = l.RestoreFileVersion && r.GetRestoreFileVersion()
|
||||
l.RestoreRecycleItem = l.RestoreRecycleItem && r.GetRestoreRecycleItem()
|
||||
l.Stat = l.Stat && r.GetStat()
|
||||
l.UpdateGrant = l.UpdateGrant && r.GetUpdateGrant()
|
||||
}
|
||||
Reference in new issue
Block a user