2022-03-15 13:30:32 -05:00
package ngalert
import (
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/datasources"
2022-08-10 04:56:48 -05:00
"github.com/grafana/grafana/pkg/services/org"
2022-03-15 13:30:32 -05:00
)
const AlertRolesGroup = "Alerting"
var (
rulesReaderRole = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
Name : accesscontrol . FixedRolePrefix + "alerting.rules:reader" ,
DisplayName : "Rules Reader" ,
2022-06-09 07:29:27 -05:00
Description : "Read alert rules in all Grafana folders and external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingRuleRead ,
Scope : dashboards . ScopeFoldersAll ,
} ,
{
Action : accesscontrol . ActionAlertingRuleExternalRead ,
2022-03-16 10:18:45 -05:00
Scope : datasources . ScopeAll ,
2022-03-15 13:30:32 -05:00
} ,
2024-04-12 11:37:34 -05:00
{
Action : accesscontrol . ActionAlertingSilencesRead ,
Scope : dashboards . ScopeFoldersAll ,
} ,
2024-02-05 12:12:15 -06:00
// Following are needed for simplified notification policies
2024-02-01 14:17:13 -06:00
{
2024-02-05 12:12:15 -06:00
Action : accesscontrol . ActionAlertingNotificationsTimeIntervalsRead ,
} ,
{
Action : accesscontrol . ActionAlertingReceiversList ,
2024-02-01 14:17:13 -06:00
} ,
2022-03-15 13:30:32 -05:00
} ,
} ,
}
2022-06-09 07:29:27 -05:00
rulesWriterRole = accesscontrol . RoleRegistration {
2022-03-15 13:30:32 -05:00
Role : accesscontrol . RoleDTO {
2022-06-09 07:29:27 -05:00
Name : accesscontrol . FixedRolePrefix + "alerting.rules:writer" ,
DisplayName : "Rules Writer" ,
Description : "Add, update, and delete rules in any Grafana folder and external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : accesscontrol . ConcatPermissions ( rulesReaderRole . Role . Permissions , [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingRuleCreate ,
Scope : dashboards . ScopeFoldersAll ,
} ,
{
Action : accesscontrol . ActionAlertingRuleUpdate ,
Scope : dashboards . ScopeFoldersAll ,
} ,
{
Action : accesscontrol . ActionAlertingRuleDelete ,
Scope : dashboards . ScopeFoldersAll ,
} ,
{
Action : accesscontrol . ActionAlertingRuleExternalWrite ,
2022-03-16 10:18:45 -05:00
Scope : datasources . ScopeAll ,
2022-03-15 13:30:32 -05:00
} ,
2024-04-12 11:37:34 -05:00
{
Action : accesscontrol . ActionAlertingSilencesWrite ,
Scope : dashboards . ScopeFoldersAll ,
} ,
{
Action : accesscontrol . ActionAlertingSilencesCreate ,
Scope : dashboards . ScopeFoldersAll ,
} ,
2022-03-15 13:30:32 -05:00
} ) ,
} ,
}
instancesReaderRole = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
Name : accesscontrol . FixedRolePrefix + "alerting.instances:reader" ,
DisplayName : "Instances and Silences Reader" ,
2022-06-09 07:29:27 -05:00
Description : "Read instances and silences of Grafana and external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingInstanceRead ,
} ,
{
Action : accesscontrol . ActionAlertingInstancesExternalRead ,
2022-03-16 10:18:45 -05:00
Scope : datasources . ScopeAll ,
2022-03-15 13:30:32 -05:00
} ,
} ,
} ,
}
2022-06-09 07:29:27 -05:00
instancesWriterRole = accesscontrol . RoleRegistration {
2022-03-15 13:30:32 -05:00
Role : accesscontrol . RoleDTO {
2022-06-09 07:29:27 -05:00
Name : accesscontrol . FixedRolePrefix + "alerting.instances:writer" ,
DisplayName : "Silences Writer" ,
Description : "Add and update silences in Grafana and external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : accesscontrol . ConcatPermissions ( instancesReaderRole . Role . Permissions , [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingInstanceCreate ,
} ,
{
Action : accesscontrol . ActionAlertingInstanceUpdate ,
} ,
{
Action : accesscontrol . ActionAlertingInstancesExternalWrite ,
2022-03-16 10:18:45 -05:00
Scope : datasources . ScopeAll ,
2022-03-15 13:30:32 -05:00
} ,
} ) ,
} ,
}
notificationsReaderRole = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
Name : accesscontrol . FixedRolePrefix + "alerting.notifications:reader" ,
DisplayName : "Notifications Reader" ,
2022-06-09 07:29:27 -05:00
Description : "Read notification policies and contact points in Grafana and external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingNotificationsRead ,
} ,
{
Action : accesscontrol . ActionAlertingNotificationsExternalRead ,
2022-03-16 10:18:45 -05:00
Scope : datasources . ScopeAll ,
2022-03-15 13:30:32 -05:00
} ,
2024-02-01 14:17:13 -06:00
{
Action : accesscontrol . ActionAlertingNotificationsTimeIntervalsRead ,
} ,
2024-02-05 12:12:15 -06:00
{
Action : accesscontrol . ActionAlertingReceiversRead ,
} ,
2022-03-15 13:30:32 -05:00
} ,
} ,
}
2022-06-09 07:29:27 -05:00
notificationsWriterRole = accesscontrol . RoleRegistration {
2022-03-15 13:30:32 -05:00
Role : accesscontrol . RoleDTO {
2022-06-09 07:29:27 -05:00
Name : accesscontrol . FixedRolePrefix + "alerting.notifications:writer" ,
DisplayName : "Notifications Writer" ,
Description : "Add, update, and delete contact points and notification policies in Grafana and external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : accesscontrol . ConcatPermissions ( notificationsReaderRole . Role . Permissions , [ ] accesscontrol . Permission {
{
2022-05-20 09:55:07 -05:00
Action : accesscontrol . ActionAlertingNotificationsWrite ,
2022-03-15 13:30:32 -05:00
} ,
{
Action : accesscontrol . ActionAlertingNotificationsExternalWrite ,
2022-03-16 10:18:45 -05:00
Scope : datasources . ScopeAll ,
2022-03-15 13:30:32 -05:00
} ,
} ) ,
} ,
}
alertingReaderRole = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
Name : accesscontrol . FixedRolePrefix + "alerting:reader" ,
DisplayName : "Full read-only access" ,
2022-06-09 07:29:27 -05:00
Description : "Read alert rules, instances, silences, contact points, and notification policies in Grafana and all external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
Permissions : accesscontrol . ConcatPermissions ( rulesReaderRole . Role . Permissions , instancesReaderRole . Role . Permissions , notificationsReaderRole . Role . Permissions ) ,
} ,
2022-08-10 04:56:48 -05:00
Grants : [ ] string { string ( org . RoleViewer ) } ,
2022-03-15 13:30:32 -05:00
}
alertingWriterRole = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
2022-06-09 07:29:27 -05:00
Name : accesscontrol . FixedRolePrefix + "alerting:writer" ,
2022-03-15 13:30:32 -05:00
DisplayName : "Full access" ,
2022-06-09 07:29:27 -05:00
Description : "Add,update and delete alert rules, instances, silences, contact points, and notification policies in Grafana and all external providers" ,
2022-03-15 13:30:32 -05:00
Group : AlertRolesGroup ,
2022-06-09 07:29:27 -05:00
Permissions : accesscontrol . ConcatPermissions ( rulesWriterRole . Role . Permissions , instancesWriterRole . Role . Permissions , notificationsWriterRole . Role . Permissions ) ,
2022-03-15 13:30:32 -05:00
} ,
2022-08-10 04:56:48 -05:00
Grants : [ ] string { string ( org . RoleEditor ) , string ( org . RoleAdmin ) } ,
2022-03-15 13:30:32 -05:00
}
2022-06-09 02:18:57 -05:00
2022-06-09 07:29:27 -05:00
alertingProvisionerRole = accesscontrol . RoleRegistration {
2022-06-09 02:18:57 -05:00
Role : accesscontrol . RoleDTO {
2022-06-09 07:29:27 -05:00
Name : accesscontrol . FixedRolePrefix + "alerting.provisioning:writer" ,
2022-06-09 02:18:57 -05:00
DisplayName : "Access to alert rules provisioning API" ,
2022-06-09 07:29:27 -05:00
Description : "Manage all alert rules, contact points, notification policies, silences, etc. in the organization via provisioning API." ,
2022-06-09 02:18:57 -05:00
Group : AlertRolesGroup ,
Permissions : [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingProvisioningRead , // organization scope
} ,
{
Action : accesscontrol . ActionAlertingProvisioningWrite , // organization scope
} ,
2024-03-14 08:58:25 -05:00
{
Action : dashboards . ActionFoldersRead ,
Scope : dashboards . ScopeFoldersAll ,
} ,
2022-06-09 02:18:57 -05:00
} ,
} ,
2022-08-10 04:56:48 -05:00
Grants : [ ] string { string ( org . RoleAdmin ) } ,
2022-06-09 02:18:57 -05:00
}
2023-08-08 11:29:34 -05:00
alertingProvisioningReaderWithSecretsRole = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
Name : accesscontrol . FixedRolePrefix + "alerting.provisioning.secrets:reader" ,
DisplayName : "Read via Provisioning API + Export Secrets" ,
Description : "Read all alert rules, contact points, notification policies, silences, etc. in the organization via provisioning API and use export with decrypted secrets" ,
Group : AlertRolesGroup ,
Permissions : [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingProvisioningReadSecrets , // organization scope
} ,
{
Action : accesscontrol . ActionAlertingProvisioningRead , // organization scope
} ,
} ,
} ,
Grants : [ ] string { string ( org . RoleAdmin ) } ,
}
2024-03-22 17:14:15 -05:00
alertingProvisioningStatus = accesscontrol . RoleRegistration {
Role : accesscontrol . RoleDTO {
Name : accesscontrol . FixedRolePrefix + "alerting.provisioning.provenance:writer" ,
DisplayName : "Set provisioning status" ,
Description : "Set provisioning status for alerting resources. Should be used together with other regular roles (Notifications Writer and/or Rules Writer)" ,
Group : AlertRolesGroup ,
Permissions : [ ] accesscontrol . Permission {
{
Action : accesscontrol . ActionAlertingProvisioningSetStatus , // organization scope
} ,
} ,
} ,
Grants : [ ] string { string ( org . RoleAdmin ) , string ( org . RoleEditor ) } ,
}
2022-03-15 13:30:32 -05:00
)
2022-08-26 02:59:34 -05:00
func DeclareFixedRoles ( service accesscontrol . Service ) error {
return service . DeclareFixedRoles (
2022-06-09 07:29:27 -05:00
rulesReaderRole , rulesWriterRole ,
instancesReaderRole , instancesWriterRole ,
notificationsReaderRole , notificationsWriterRole ,
2024-03-22 17:14:15 -05:00
alertingReaderRole , alertingWriterRole , alertingProvisionerRole , alertingProvisioningReaderWithSecretsRole , alertingProvisioningStatus ,
2022-03-15 13:30:32 -05:00
)
}