unistore: wire the authz client (#96632)
* unistore: wire the authz client * rename dashboards.grafana.app into dashboard.grafana.app * wire the authz client * wire the authz client * resuse the Standalone constructor * configure default migration for resource folder * add tests * cleanup * add logging
This commit is contained in:
@@ -17,7 +17,7 @@ func (a RuntimeConfig) String() string {
|
||||
|
||||
// Supported options are:
|
||||
//
|
||||
// <group>/<version>=true|false for a specific API group and version (e.g. dashboards.grafana.app/v0alpha1=true)
|
||||
// <group>/<version>=true|false for a specific API group and version (e.g. dashboard.grafana.app/v0alpha1=true)
|
||||
// api/all=true|false controls all API versions
|
||||
// api/ga=true|false controls all API versions of the form v[0-9]+
|
||||
// api/beta=true|false controls all API versions of the form v[0-9]+beta[0-9]+
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
func TestReadRuntimeCOnfig(t *testing.T) {
|
||||
out, err := ReadRuntimeConfig("all/all=true,dashboards.grafana.app/v0alpha1=false")
|
||||
out, err := ReadRuntimeConfig("all/all=true,dashboard.grafana.app/v0alpha1=false")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []RuntimeConfig{
|
||||
{Group: "all", Version: "all", Enabled: true},
|
||||
{Group: "dashboards.grafana.app", Version: "v0alpha1", Enabled: false},
|
||||
{Group: "dashboard.grafana.app", Version: "v0alpha1", Enabled: false},
|
||||
}, out)
|
||||
require.Equal(t, "all/all=true", fmt.Sprintf("%v", out[0]))
|
||||
|
||||
|
||||
@@ -88,7 +88,10 @@ func ProvideStandaloneAuthZClient(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newGrpcLegacyClient(authCfg)
|
||||
if cfg.StackID == "" {
|
||||
return newGrpcLegacyClient(authCfg)
|
||||
}
|
||||
return newCloudLegacyClient(authCfg)
|
||||
}
|
||||
|
||||
func newInProcLegacyClient(server *legacyServer) (authzlib.AccessChecker, error) {
|
||||
|
||||
@@ -2,10 +2,10 @@ package mappers
|
||||
|
||||
type VerbToAction map[string]string // e.g. "get" -> "read"
|
||||
type ResourceVerbToAction map[string]VerbToAction // e.g. "dashboards" -> VerbToAction
|
||||
type GroupResourceVerbToAction map[string]ResourceVerbToAction // e.g. "dashboards.grafana.app" -> ResourceVerbToAction
|
||||
type GroupResourceVerbToAction map[string]ResourceVerbToAction // e.g. "dashboard.grafana.app" -> ResourceVerbToAction
|
||||
|
||||
type ResourceToAttribute map[string]string // e.g. "dashboards" -> "uid"
|
||||
type GroupResourceToAttribute map[string]ResourceToAttribute // e.g. "dashboards.grafana.app" -> ResourceToAttribute
|
||||
type GroupResourceToAttribute map[string]ResourceToAttribute // e.g. "dashboard.grafana.app" -> ResourceToAttribute
|
||||
|
||||
type K8sRbacMapper struct {
|
||||
DefaultActions VerbToAction
|
||||
@@ -28,8 +28,8 @@ func NewK8sRbacMapper() *K8sRbacMapper {
|
||||
},
|
||||
DefaultAttribute: "uid",
|
||||
Actions: GroupResourceVerbToAction{
|
||||
"dashboards.grafana.app": ResourceVerbToAction{"dashboards": VerbToAction{}},
|
||||
"folders.grafana.app": ResourceVerbToAction{"folders": VerbToAction{}},
|
||||
"dashboard.grafana.app": ResourceVerbToAction{"dashboards": VerbToAction{}},
|
||||
"folder.grafana.app": ResourceVerbToAction{"folders": VerbToAction{}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Name: "dash1",
|
||||
Namespace: "org-2",
|
||||
@@ -74,7 +74,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Name: "dash1",
|
||||
Namespace: "org-2",
|
||||
@@ -88,7 +88,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Name: "dash1",
|
||||
Namespace: "org-2",
|
||||
@@ -106,7 +106,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Namespace: "org-2",
|
||||
},
|
||||
@@ -131,7 +131,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Name: "dash1",
|
||||
Namespace: "org-2",
|
||||
},
|
||||
@@ -141,7 +141,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
name: "should return error when verb is not set",
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Name: "dash1",
|
||||
Namespace: "org-2",
|
||||
@@ -152,7 +152,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
name: "should return error when subject is not set",
|
||||
req: &authzv1.CheckRequest{
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Name: "dash1",
|
||||
Namespace: "org-2",
|
||||
@@ -164,7 +164,7 @@ func Test_legacyServer_Check(t *testing.T) {
|
||||
req: &authzv1.CheckRequest{
|
||||
Subject: "user:1",
|
||||
Verb: "get",
|
||||
Group: "dashboards.grafana.app",
|
||||
Group: "dashboard.grafana.app",
|
||||
Resource: "dashboards",
|
||||
Name: "dash1",
|
||||
Namespace: "stacks-2",
|
||||
|
||||
@@ -31,7 +31,7 @@ func newBatch(subject, group, resource string, items []*authzextv1.BatchCheckIte
|
||||
}
|
||||
|
||||
func testBatchCheck(t *testing.T, server *Server) {
|
||||
t.Run("user:1 should only be able to read resource:dashboards.grafana.app/dashboards/1", func(t *testing.T) {
|
||||
t.Run("user:1 should only be able to read resource:dashboard.grafana.app/dashboards/1", func(t *testing.T) {
|
||||
groupPrefix := zanzana.FormatGroupResource(dashboardGroup, dashboardResource)
|
||||
res, err := server.BatchCheck(context.Background(), newBatch("user:1", dashboardGroup, dashboardResource, []*authzextv1.BatchCheckItem{
|
||||
{Name: "1", Folder: "1"},
|
||||
@@ -44,7 +44,7 @@ func testBatchCheck(t *testing.T, server *Server) {
|
||||
assert.False(t, res.Groups[groupPrefix].Items["2"])
|
||||
})
|
||||
|
||||
t.Run("user:2 should be able to read resource:dashboards.grafana.app/dashboards/{1,2} through namespace", func(t *testing.T) {
|
||||
t.Run("user:2 should be able to read resource:dashboard.grafana.app/dashboards/{1,2} through namespace", func(t *testing.T) {
|
||||
groupPrefix := zanzana.FormatGroupResource(dashboardGroup, dashboardResource)
|
||||
res, err := server.BatchCheck(context.Background(), newBatch("user:2", dashboardGroup, dashboardResource, []*authzextv1.BatchCheckItem{
|
||||
{Name: "1", Folder: "1"},
|
||||
@@ -54,7 +54,7 @@ func testBatchCheck(t *testing.T, server *Server) {
|
||||
assert.Len(t, res.Groups[groupPrefix].Items, 2)
|
||||
})
|
||||
|
||||
t.Run("user:3 should be able to read resource:dashboards.grafana.app/dashboards/1 with set relation", func(t *testing.T) {
|
||||
t.Run("user:3 should be able to read resource:dashboard.grafana.app/dashboards/1 with set relation", func(t *testing.T) {
|
||||
groupPrefix := zanzana.FormatGroupResource(dashboardGroup, dashboardResource)
|
||||
res, err := server.BatchCheck(context.Background(), newBatch("user:3", dashboardGroup, dashboardResource, []*authzextv1.BatchCheckItem{
|
||||
{Name: "1", Folder: "1"},
|
||||
@@ -67,7 +67,7 @@ func testBatchCheck(t *testing.T, server *Server) {
|
||||
assert.False(t, res.Groups[groupPrefix].Items["2"])
|
||||
})
|
||||
|
||||
t.Run("user:4 should be able to read all dashboards.grafana.app/dashboards in folder 1 and 3", func(t *testing.T) {
|
||||
t.Run("user:4 should be able to read all dashboard.grafana.app/dashboards in folder 1 and 3", func(t *testing.T) {
|
||||
groupPrefix := zanzana.FormatGroupResource(dashboardGroup, dashboardResource)
|
||||
res, err := server.BatchCheck(context.Background(), newBatch("user:4", dashboardGroup, dashboardResource, []*authzextv1.BatchCheckItem{
|
||||
{Name: "1", Folder: "1"},
|
||||
@@ -82,7 +82,7 @@ func testBatchCheck(t *testing.T, server *Server) {
|
||||
assert.False(t, res.Groups[groupPrefix].Items["3"])
|
||||
})
|
||||
|
||||
t.Run("user:5 should be able to read resource:dashboards.grafana.app/dashboards/1 through folder with set relation", func(t *testing.T) {
|
||||
t.Run("user:5 should be able to read resource:dashboard.grafana.app/dashboards/1 through folder with set relation", func(t *testing.T) {
|
||||
groupPrefix := zanzana.FormatGroupResource(dashboardGroup, dashboardResource)
|
||||
res, err := server.BatchCheck(context.Background(), newBatch("user:5", dashboardGroup, dashboardResource, []*authzextv1.BatchCheckItem{
|
||||
{Name: "1", Folder: "1"},
|
||||
|
||||
@@ -24,7 +24,7 @@ func testCheck(t *testing.T, server *Server) {
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("user:1 should only be able to read resource:dashboards.grafana.app/dashboards/1", func(t *testing.T) {
|
||||
t.Run("user:1 should only be able to read resource:dashboard.grafana.app/dashboards/1", func(t *testing.T) {
|
||||
res, err := server.Check(context.Background(), newRead("user:1", dashboardGroup, dashboardResource, "1", "1"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, res.GetAllowed())
|
||||
@@ -35,13 +35,13 @@ func testCheck(t *testing.T, server *Server) {
|
||||
assert.False(t, res.GetAllowed())
|
||||
})
|
||||
|
||||
t.Run("user:2 should be able to read resource:dashboards.grafana.app/dashboards/1 through namespace", func(t *testing.T) {
|
||||
t.Run("user:2 should be able to read resource:dashboard.grafana.app/dashboards/1 through namespace", func(t *testing.T) {
|
||||
res, err := server.Check(context.Background(), newRead("user:2", dashboardGroup, dashboardResource, "1", "1"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, res.GetAllowed())
|
||||
})
|
||||
|
||||
t.Run("user:3 should be able to read resource:dashboards.grafana.app/dashboards/1 with set relation", func(t *testing.T) {
|
||||
t.Run("user:3 should be able to read resource:dashboard.grafana.app/dashboards/1 with set relation", func(t *testing.T) {
|
||||
res, err := server.Check(context.Background(), newRead("user:3", dashboardGroup, dashboardResource, "1", "1"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, res.GetAllowed())
|
||||
@@ -52,7 +52,7 @@ func testCheck(t *testing.T, server *Server) {
|
||||
assert.False(t, res.GetAllowed())
|
||||
})
|
||||
|
||||
t.Run("user:4 should be able to read all dashboards.grafana.app/dashboards in folder 1 and 3", func(t *testing.T) {
|
||||
t.Run("user:4 should be able to read all dashboard.grafana.app/dashboards in folder 1 and 3", func(t *testing.T) {
|
||||
res, err := server.Check(context.Background(), newRead("user:4", dashboardGroup, dashboardResource, "1", "1"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, res.GetAllowed())
|
||||
@@ -71,7 +71,7 @@ func testCheck(t *testing.T, server *Server) {
|
||||
assert.False(t, res.GetAllowed())
|
||||
})
|
||||
|
||||
t.Run("user:5 should be able to read resource:dashboards.grafana.app/dashboards/1 through folder with set relation", func(t *testing.T) {
|
||||
t.Run("user:5 should be able to read resource:dashboard.grafana.app/dashboards/1 through folder with set relation", func(t *testing.T) {
|
||||
res, err := server.Check(context.Background(), newRead("user:5", dashboardGroup, dashboardResource, "1", "1"))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, res.GetAllowed())
|
||||
|
||||
@@ -22,7 +22,7 @@ func testList(t *testing.T, server *Server) {
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("user:1 should list resource:dashboards.grafana.app/dashboards/1", func(t *testing.T) {
|
||||
t.Run("user:1 should list resource:dashboard.grafana.app/dashboards/1", func(t *testing.T) {
|
||||
res, err := server.List(context.Background(), newList("user:1", dashboardGroup, dashboardResource))
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.GetItems(), 1)
|
||||
@@ -38,7 +38,7 @@ func testList(t *testing.T, server *Server) {
|
||||
assert.Len(t, res.GetFolders(), 0)
|
||||
})
|
||||
|
||||
t.Run("user:3 should be able to list resource:dashboards.grafana.app/dashboards/1 with set relation", func(t *testing.T) {
|
||||
t.Run("user:3 should be able to list resource:dashboard.grafana.app/dashboards/1 with set relation", func(t *testing.T) {
|
||||
res, err := server.List(context.Background(), newList("user:3", dashboardGroup, dashboardResource))
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -47,7 +47,7 @@ func testList(t *testing.T, server *Server) {
|
||||
assert.Equal(t, res.GetItems()[0], "1")
|
||||
})
|
||||
|
||||
t.Run("user:4 should be able to list all dashboards.grafana.app/dashboards in folder 1 and 3", func(t *testing.T) {
|
||||
t.Run("user:4 should be able to list all dashboard.grafana.app/dashboards in folder 1 and 3", func(t *testing.T) {
|
||||
res, err := server.List(context.Background(), newList("user:4", dashboardGroup, dashboardResource))
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.GetItems(), 0)
|
||||
@@ -64,7 +64,7 @@ func testList(t *testing.T, server *Server) {
|
||||
assert.Equal(t, second, "3")
|
||||
})
|
||||
|
||||
t.Run("user:5 should be get list all dashboards.grafana.app/dashboards in folder 1 with set relation", func(t *testing.T) {
|
||||
t.Run("user:5 should be get list all dashboard.grafana.app/dashboards in folder 1 with set relation", func(t *testing.T) {
|
||||
res, err := server.List(context.Background(), newList("user:5", dashboardGroup, dashboardResource))
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, res.GetItems(), 0)
|
||||
|
||||
Reference in New Issue
Block a user