Compare commits
1 Commits
sriram/SQL
...
mhamid/rol
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3ae83a37a |
@@ -6,6 +6,8 @@ RoleSpec: {
|
|||||||
action: string
|
action: string
|
||||||
// RBAC scope (e.g: "dashboards:uid:dash1")
|
// RBAC scope (e.g: "dashboards:uid:dash1")
|
||||||
scope: string
|
scope: string
|
||||||
|
// When true, the permission is disabled and not granted to the role
|
||||||
|
disabled: bool | *false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display name of the role
|
// Display name of the role
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ type CoreRolespecPermission struct {
|
|||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
// RBAC scope (e.g: "dashboards:uid:dash1")
|
// RBAC scope (e.g: "dashboards:uid:dash1")
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
|
// When true, the permission is disabled and not granted to the role
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCoreRolespecPermission creates a new CoreRolespecPermission object.
|
// NewCoreRolespecPermission creates a new CoreRolespecPermission object.
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ type GlobalRolespecPermission struct {
|
|||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
// RBAC scope (e.g: "dashboards:uid:dash1")
|
// RBAC scope (e.g: "dashboards:uid:dash1")
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
|
// When true, the permission is disabled and not granted to the role
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGlobalRolespecPermission creates a new GlobalRolespecPermission object.
|
// NewGlobalRolespecPermission creates a new GlobalRolespecPermission object.
|
||||||
|
|||||||
2
apps/iam/pkg/apis/iam/v0alpha1/role_spec_gen.go
generated
2
apps/iam/pkg/apis/iam/v0alpha1/role_spec_gen.go
generated
@@ -8,6 +8,8 @@ type RolespecPermission struct {
|
|||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
// RBAC scope (e.g: "dashboards:uid:dash1")
|
// RBAC scope (e.g: "dashboards:uid:dash1")
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
|
// When true, the permission is disabled and not granted to the role
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRolespecPermission creates a new RolespecPermission object.
|
// NewRolespecPermission creates a new RolespecPermission object.
|
||||||
|
|||||||
@@ -17,10 +17,16 @@ import (
|
|||||||
|
|
||||||
// convertRolePermissionsToTuples converts role permissions (action/scope) to v1 TupleKey format
|
// convertRolePermissionsToTuples converts role permissions (action/scope) to v1 TupleKey format
|
||||||
// using the shared zanzana.ConvertRolePermissionsToTuples utility and common.ToAuthzExtTupleKeys
|
// using the shared zanzana.ConvertRolePermissionsToTuples utility and common.ToAuthzExtTupleKeys
|
||||||
|
// Disabled permissions are filtered out and not converted to tuples
|
||||||
func convertRolePermissionsToTuples(roleUID string, permissions []iamv0.CoreRolespecPermission) ([]*v1.TupleKey, error) {
|
func convertRolePermissionsToTuples(roleUID string, permissions []iamv0.CoreRolespecPermission) ([]*v1.TupleKey, error) {
|
||||||
// Convert IAM permissions to zanzana.RolePermission format
|
// Convert IAM permissions to zanzana.RolePermission format, filtering out disabled permissions
|
||||||
rolePerms := make([]zanzana.RolePermission, 0, len(permissions))
|
rolePerms := make([]zanzana.RolePermission, 0, len(permissions))
|
||||||
for _, perm := range permissions {
|
for _, perm := range permissions {
|
||||||
|
// Skip disabled permissions - they should not be added to Zanzana
|
||||||
|
if perm.Disabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Split the scope to get kind, attribute, identifier
|
// Split the scope to get kind, attribute, identifier
|
||||||
kind, _, identifier := accesscontrol.SplitScope(perm.Scope)
|
kind, _, identifier := accesscontrol.SplitScope(perm.Scope)
|
||||||
rolePerms = append(rolePerms, zanzana.RolePermission{
|
rolePerms = append(rolePerms, zanzana.RolePermission{
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ func (s *AccessControlStore) GetUserPermissions(ctx context.Context, query acces
|
|||||||
permission.scope
|
permission.scope
|
||||||
FROM permission
|
FROM permission
|
||||||
INNER JOIN role ON role.id = permission.role_id
|
INNER JOIN role ON role.id = permission.role_id
|
||||||
` + filter
|
` + filter + `
|
||||||
|
AND (permission.disabled = 0 OR permission.disabled IS NULL)
|
||||||
|
`
|
||||||
|
|
||||||
if len(query.RolePrefixes) > 0 {
|
if len(query.RolePrefixes) > 0 {
|
||||||
rolePrefixesFilter, filterParams := accesscontrol.RolePrefixesFilter(query.RolePrefixes)
|
rolePrefixesFilter, filterParams := accesscontrol.RolePrefixesFilter(query.RolePrefixes)
|
||||||
@@ -132,6 +134,7 @@ func (s *AccessControlStore) GetTeamsPermissions(ctx context.Context, query acce
|
|||||||
WHERE tr.team_id IN(?` + strings.Repeat(", ?", len(teams)-1) + `)
|
WHERE tr.team_id IN(?` + strings.Repeat(", ?", len(teams)-1) + `)
|
||||||
AND tr.org_id = ?
|
AND tr.org_id = ?
|
||||||
) as all_role ON role.id = all_role.role_id
|
) as all_role ON role.id = all_role.role_id
|
||||||
|
WHERE (permission.disabled = 0 OR permission.disabled IS NULL)
|
||||||
`
|
`
|
||||||
|
|
||||||
params := make([]any, 0)
|
params := make([]any, 0)
|
||||||
|
|||||||
@@ -203,10 +203,11 @@ type BuiltinRole struct {
|
|||||||
|
|
||||||
// Permission is the model for access control permissions
|
// Permission is the model for access control permissions
|
||||||
type Permission struct {
|
type Permission struct {
|
||||||
ID int64 `json:"-" xorm:"pk autoincr 'id'"`
|
ID int64 `json:"-" xorm:"pk autoincr 'id'"`
|
||||||
RoleID int64 `json:"-" xorm:"role_id"`
|
RoleID int64 `json:"-" xorm:"role_id"`
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
|
Disabled bool `json:"disabled" xorm:"disabled"`
|
||||||
|
|
||||||
Kind string `json:"-"`
|
Kind string `json:"-"`
|
||||||
Attribute string `json:"-"`
|
Attribute string `json:"-"`
|
||||||
|
|||||||
@@ -218,4 +218,9 @@ func AddMigration(mg *migrator.Migrator) {
|
|||||||
mg.AddMigration("Remove permission role_id index", migrator.NewDropIndexMigration(permissionV1, &migrator.Index{
|
mg.AddMigration("Remove permission role_id index", migrator.NewDropIndexMigration(permissionV1, &migrator.Index{
|
||||||
Cols: []string{"role_id"},
|
Cols: []string{"role_id"},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// Add disabled column to permission table
|
||||||
|
mg.AddMigration("add column disabled to permission table", migrator.NewAddColumnMigration(permissionV1, &migrator.Column{
|
||||||
|
Name: "disabled", Type: migrator.DB_Bool, Nullable: false, Default: "0",
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user