Zanzana: Allow resources to derive permissions from folders by default (#114820)

This commit is contained in:
Alexander Zobnin
2025-12-04 11:27:59 +01:00
committed by GitHub
parent 73b9a8c3af
commit ed91ada3c0
2 changed files with 4 additions and 10 deletions
@@ -12,7 +12,6 @@ import (
"go.opentelemetry.io/otel/codes"
"google.golang.org/protobuf/types/known/structpb"
dashboardV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
"github.com/grafana/grafana/pkg/services/authz/zanzana/common"
)
@@ -149,7 +148,7 @@ func (s *Server) checkGeneric(ctx context.Context, subject, relation string, res
folderRelation = common.SubresourceRelation(relation)
)
if isFolderPermissionBasedResource(resource.GroupResource()) {
if folderIdent != "" && isFolderPermissionBasedResource(resource.GroupResource()) {
// Check if resource inherits permissions from the folder (like dashboards in a folder)
res, err := s.openfgaCheck(ctx, store, subject, relation, folderIdent, contextuals, resourceCtx)
if err != nil {
@@ -210,11 +209,10 @@ func (s *Server) openfgaCheck(ctx context.Context, store *storeInfo, subject, re
return res, nil
}
var folderPermissionBasedResources = map[string]bool{
// dashboard.grafana.app/dashboards
common.FormatGroupResource(dashboardV1.DashboardResourceInfo.GroupResource().Group, dashboardV1.DashboardResourceInfo.GroupResource().Resource, ""): true,
var folderPermissionBasedResourceExceptions = map[string]bool{
// allow all resources to inherit permissions from the folder
}
func isFolderPermissionBasedResource(resource string) bool {
return folderPermissionBasedResources[resource]
return !folderPermissionBasedResourceExceptions[resource]
}
@@ -211,9 +211,5 @@ func testCheck(t *testing.T, server *Server) {
res, err = server.Check(newContextWithNamespace(), newReq("user:17", utils.VerbGet, dashboardGroup, dashboardResource, "", "6", "1"))
require.NoError(t, err)
assert.True(t, res.GetAllowed(), "user should be able to view dashboards in folder 6")
res, err = server.Check(newContextWithNamespace(), newReq("user:17", utils.VerbGet, "foo.grafana.app", "bar", "", "4", "1"))
require.NoError(t, err)
assert.False(t, res.GetAllowed(), "user should not be able to view other resources in folder 4")
})
}