Access Control: Remove built-in role assignment by default (#49058)

* Remove FF-bultins

* Add a param to test br-simplifying
This commit is contained in:
Gabriel MABILLE
2022-05-19 09:29:36 +02:00
committed by GitHub
parent a3c5834594
commit 5b6d20fbce
7 changed files with 7 additions and 18 deletions
@@ -32,7 +32,6 @@ export interface FeatureToggles {
tempoBackendSearch?: boolean; tempoBackendSearch?: boolean;
tempoServiceGraph?: boolean; tempoServiceGraph?: boolean;
lokiBackendMode?: boolean; lokiBackendMode?: boolean;
['accesscontrol-builtins']?: boolean;
prometheus_azure_auth?: boolean; prometheus_azure_auth?: boolean;
influxdbBackendMigration?: boolean; influxdbBackendMigration?: boolean;
newNavigation?: boolean; newNavigation?: boolean;
@@ -18,7 +18,7 @@ import (
func ProvideService(features featuremgmt.FeatureToggles, cfg *setting.Cfg, func ProvideService(features featuremgmt.FeatureToggles, cfg *setting.Cfg,
provider accesscontrol.PermissionsProvider, routeRegister routing.RouteRegister) (*OSSAccessControlService, error) { provider accesscontrol.PermissionsProvider, routeRegister routing.RouteRegister) (*OSSAccessControlService, error) {
var errDeclareRoles error var errDeclareRoles error
s := ProvideOSSAccessControl(features, cfg, provider) s := ProvideOSSAccessControl(cfg, provider)
if !s.IsDisabled() { if !s.IsDisabled() {
api := api.AccessControlAPI{ api := api.AccessControlAPI{
RouteRegister: routeRegister, RouteRegister: routeRegister,
@@ -32,9 +32,8 @@ func ProvideService(features featuremgmt.FeatureToggles, cfg *setting.Cfg,
return s, errDeclareRoles return s, errDeclareRoles
} }
func ProvideOSSAccessControl(features featuremgmt.FeatureToggles, cfg *setting.Cfg, provider accesscontrol.PermissionsProvider) *OSSAccessControlService { func ProvideOSSAccessControl(cfg *setting.Cfg, provider accesscontrol.PermissionsProvider) *OSSAccessControlService {
s := &OSSAccessControlService{ s := &OSSAccessControlService{
features: features,
cfg: cfg, cfg: cfg,
provider: provider, provider: provider,
log: log.New("accesscontrol"), log: log.New("accesscontrol"),
@@ -48,7 +47,6 @@ func ProvideOSSAccessControl(features featuremgmt.FeatureToggles, cfg *setting.C
// OSSAccessControlService is the service implementing role based access control. // OSSAccessControlService is the service implementing role based access control.
type OSSAccessControlService struct { type OSSAccessControlService struct {
log log.Logger log log.Logger
features featuremgmt.FeatureToggles
cfg *setting.Cfg cfg *setting.Cfg
scopeResolvers accesscontrol.ScopeResolvers scopeResolvers accesscontrol.ScopeResolvers
provider accesscontrol.PermissionsProvider provider accesscontrol.PermissionsProvider
@@ -158,7 +156,7 @@ func (ac *OSSAccessControlService) GetUserBuiltInRoles(user *models.SignedInUser
builtInRoles := []string{string(user.OrgRole)} builtInRoles := []string{string(user.OrgRole)}
// With built-in role simplifying, inheritance is performed upon role registration. // With built-in role simplifying, inheritance is performed upon role registration.
if !ac.features.IsEnabled(featuremgmt.FlagAccesscontrolBuiltins) { if ac.cfg.RBACBuiltInRoleAssignmentEnabled {
for _, br := range user.OrgRole.Children() { for _, br := range user.OrgRole.Children() {
builtInRoles = append(builtInRoles, string(br)) builtInRoles = append(builtInRoles, string(br))
} }
@@ -24,7 +24,6 @@ func setupTestEnv(t testing.TB) *OSSAccessControlService {
ac := &OSSAccessControlService{ ac := &OSSAccessControlService{
cfg: cfg, cfg: cfg,
features: featuremgmt.WithFeatures(),
log: log.New("accesscontrol"), log: log.New("accesscontrol"),
registrations: accesscontrol.RegistrationList{}, registrations: accesscontrol.RegistrationList{},
scopeResolvers: accesscontrol.NewScopeResolvers(), scopeResolvers: accesscontrol.NewScopeResolvers(),
-6
View File
@@ -94,12 +94,6 @@ var (
State: FeatureStateAlpha, State: FeatureStateAlpha,
FrontendOnly: true, FrontendOnly: true,
}, },
{
Name: "accesscontrol-builtins",
Description: "Simplify access control builtin roles",
State: FeatureStateAlpha,
RequiresDevMode: true,
},
{ {
Name: "prometheus_azure_auth", Name: "prometheus_azure_auth",
Description: "Experimental. Azure authentication for Prometheus datasource", Description: "Experimental. Azure authentication for Prometheus datasource",
-4
View File
@@ -71,10 +71,6 @@ const (
// Loki datasource works as backend datasource // Loki datasource works as backend datasource
FlagLokiBackendMode = "lokiBackendMode" FlagLokiBackendMode = "lokiBackendMode"
// FlagAccesscontrolBuiltins
// Simplify access control builtin roles
FlagAccesscontrolBuiltins = "accesscontrol-builtins"
// FlagPrometheusAzureAuth // FlagPrometheusAzureAuth
// Experimental. Azure authentication for Prometheus datasource // Experimental. Azure authentication for Prometheus datasource
FlagPrometheusAzureAuth = "prometheus_azure_auth" FlagPrometheusAzureAuth = "prometheus_azure_auth"
@@ -24,7 +24,6 @@ func TestFeatureToggleFiles(t *testing.T) {
"live-config": true, "live-config": true,
"live-pipeline": true, "live-pipeline": true,
"live-service-web-worker": true, "live-service-web-worker": true,
"accesscontrol-builtins": true,
"prometheus_azure_auth": true, "prometheus_azure_auth": true,
"disable_http_request_histogram": true, "disable_http_request_histogram": true,
} }
+4
View File
@@ -447,6 +447,9 @@ type Cfg struct {
// Access Control // Access Control
RBACEnabled bool RBACEnabled bool
RBACPermissionCache bool RBACPermissionCache bool
// Undocumented option as a backup in case removing builtin-role assignment
// fails
RBACBuiltInRoleAssignmentEnabled bool
} }
type CommandLineArgs struct { type CommandLineArgs struct {
@@ -1360,6 +1363,7 @@ func readAccessControlSettings(iniFile *ini.File, cfg *Cfg) {
rbac := iniFile.Section("rbac") rbac := iniFile.Section("rbac")
cfg.RBACEnabled = rbac.Key("enabled").MustBool(true) cfg.RBACEnabled = rbac.Key("enabled").MustBool(true)
cfg.RBACPermissionCache = rbac.Key("permission_cache").MustBool(true) cfg.RBACPermissionCache = rbac.Key("permission_cache").MustBool(true)
cfg.RBACBuiltInRoleAssignmentEnabled = rbac.Key("builtin_role_assignment_enabled").MustBool(false)
} }
func readUserSettings(iniFile *ini.File, cfg *Cfg) error { func readUserSettings(iniFile *ini.File, cfg *Cfg) error {