mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 22:32:10 +08:00
AccessControl: Implement a way to register fixed roles (#35641)
* AccessControl: Implement a way to register fixed roles * Add context to register func * Use FixedRoleGrantsMap instead of FixedRoleGrants * Removed FixedRoles map to sync.map * Wrote test for accesscontrol and provisioning * Use mutexes+map instead of sync maps * Create a sync map struct out of a Map and a Mutex * Create a sync map struct for grants as well * Validate builtin roles * Make validation public to access control * Handle errors consistently with what seeder does * Keep errors consistant amongst accesscontrol impl * Handle registration error * Reverse the registration direction thanks to a RoleRegistrant interface * Removed sync map in favor for simple maps since registration now happens during init * Work on the Registrant interface * Remove the Register Role from the interface to have services returning their registrations instead * Adding context to RegisterRegistrantsRoles and update descriptions * little bit of cosmetics * Making sure provisioning is ran after role registration * test for role registration * Change the accesscontrol interface to use a variadic * check if accesscontrol is enabled * Add a new test for RegisterFixedRoles and fix assign which was buggy * Moved RegistrationList def to roles.go * Change provisioning role's description * Better comment on RegisterFixedRoles * Correct comment on ValidateFixedRole * Simplify helper func to removeRoleHelper * Add log to saveFixedRole and assignFixedRole Co-authored-by: Vardan Torosyan <vardants@gmail.com> Co-authored-by: Jeremy Price <Jeremy.price@grafana.com>
This commit is contained in:
@ -39,7 +39,7 @@ import (
|
||||
_ "github.com/grafana/grafana/pkg/services/login/loginservice"
|
||||
_ "github.com/grafana/grafana/pkg/services/ngalert"
|
||||
_ "github.com/grafana/grafana/pkg/services/notifications"
|
||||
_ "github.com/grafana/grafana/pkg/services/provisioning"
|
||||
"github.com/grafana/grafana/pkg/services/provisioning"
|
||||
_ "github.com/grafana/grafana/pkg/services/rendering"
|
||||
_ "github.com/grafana/grafana/pkg/services/search"
|
||||
_ "github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
@ -73,6 +73,11 @@ func (r *globalServiceRegistry) GetServices() []*registry.Descriptor {
|
||||
return registry.GetServices()
|
||||
}
|
||||
|
||||
type roleRegistry interface {
|
||||
// RegisterFixedRoles registers all roles declared to AccessControl
|
||||
RegisterFixedRoles() error
|
||||
}
|
||||
|
||||
// New returns a new instance of Server.
|
||||
func New(cfg Config) (*Server, error) {
|
||||
s := newServer(cfg)
|
||||
@ -130,7 +135,9 @@ type Server struct {
|
||||
|
||||
serviceRegistry serviceRegistry
|
||||
|
||||
HTTPServer *api.HTTPServer `inject:""`
|
||||
HTTPServer *api.HTTPServer `inject:""`
|
||||
AccessControl roleRegistry `inject:""`
|
||||
ProvisioningService provisioning.ProvisioningService `inject:""`
|
||||
}
|
||||
|
||||
// init initializes the server and its services.
|
||||
@ -167,7 +174,12 @@ func (s *Server) init() error {
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
// Register all fixed roles
|
||||
if err := s.AccessControl.RegisterFixedRoles(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.ProvisioningService.RunInitProvisioners()
|
||||
}
|
||||
|
||||
// Run initializes and starts services. This will block until all services have
|
||||
|
Reference in New Issue
Block a user