RBAC: only query folder service when fetching parent folders (#99893)

* only query folder service when fetching parent folders
* Perform validation and inehrited scopes solvers as service instead of caller
This commit is contained in:
Karl Persson
2025-02-03 13:56:25 +01:00
committed by GitHub
parent a0901456ae
commit c85a175212
4 changed files with 19 additions and 24 deletions
@@ -2,9 +2,9 @@ package ossaccesscontrol
import (
"context"
"errors"
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
@@ -84,7 +84,7 @@ func registerFolderRoles(cfg *setting.Cfg, features featuremgmt.FeatureToggles,
func ProvideFolderPermissions(
cfg *setting.Cfg, features featuremgmt.FeatureToggles, router routing.RouteRegister, sql db.DB, accesscontrol accesscontrol.AccessControl,
license licensing.Licensing, dashboardStore dashboards.Store, folderService folder.Service, service accesscontrol.Service,
license licensing.Licensing, folderService folder.Service, service accesscontrol.Service,
teamService team.Service, userService user.Service, actionSetService resourcepermissions.ActionSetService,
) (*FolderPermissionsService, error) {
if err := registerFolderRoles(cfg, features, service); err != nil {
@@ -98,19 +98,21 @@ func ProvideFolderPermissions(
ctx, span := tracer.Start(ctx, "accesscontrol.ossaccesscontrol.ProvideFolderPermissions.ResourceValidator")
defer span.End()
query := &dashboards.GetDashboardQuery{UID: resourceID, OrgID: orgID}
queryResult, err := dashboardStore.GetDashboard(ctx, query)
ctx, ident := identity.WithServiceIdentitiy(ctx, orgID)
_, err := folderService.Get(ctx, &folder.GetFolderQuery{
UID: &resourceID,
OrgID: orgID,
SignedInUser: ident,
})
if err != nil {
return err
}
if !queryResult.IsFolder {
return errors.New("not found")
}
return nil
},
InheritedScopesSolver: func(ctx context.Context, orgID int64, resourceID string) ([]string, error) {
ctx, _ = identity.WithServiceIdentitiy(ctx, orgID)
return dashboards.GetInheritedScopes(ctx, orgID, resourceID, folderService)
},
Assignments: resourcepermissions.Assignments{