| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2022-08-05 15:19:50 +08:00
										 |  |  | 	"fmt" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	ac "github.com/grafana/grafana/pkg/services/accesscontrol" | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | 	contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" | 
					
						
							| 
									
										
										
										
											2022-03-10 00:57:50 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/dashboards" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/datasources" | 
					
						
							| 
									
										
										
										
											2023-10-12 07:30:50 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/libraryelements" | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/org" | 
					
						
							| 
									
										
										
										
											2023-03-27 17:15:37 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginaccesscontrol" | 
					
						
							| 
									
										
										
										
											2022-08-05 15:19:50 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/tsdb/grafanads" | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // API related actions
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	ActionProvisioningReload = "provisioning:reload" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // API related scopes
 | 
					
						
							| 
									
										
										
										
											2021-10-06 19:15:09 +08:00
										 |  |  | var ( | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	ScopeProvisionersAll           = ac.Scope("provisioners", "*") | 
					
						
							|  |  |  | 	ScopeProvisionersDashboards    = ac.Scope("provisioners", "dashboards") | 
					
						
							|  |  |  | 	ScopeProvisionersPlugins       = ac.Scope("provisioners", "plugins") | 
					
						
							|  |  |  | 	ScopeProvisionersDatasources   = ac.Scope("provisioners", "datasources") | 
					
						
							|  |  |  | 	ScopeProvisionersNotifications = ac.Scope("provisioners", "notifications") | 
					
						
							| 
									
										
										
										
											2022-07-15 05:53:13 +08:00
										 |  |  | 	ScopeProvisionersAlertRules    = ac.Scope("provisioners", "alerting") | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // declareFixedRoles declares to the AccessControl service fixed roles and their
 | 
					
						
							|  |  |  | // grants to organization roles ("Viewer", "Editor", "Admin") or "Grafana Admin"
 | 
					
						
							|  |  |  | // that HTTPServer needs
 | 
					
						
							|  |  |  | func (hs *HTTPServer) declareFixedRoles() error { | 
					
						
							| 
									
										
										
										
											2022-07-08 19:24:09 +08:00
										 |  |  | 	// Declare plugins roles
 | 
					
						
							| 
									
										
										
										
											2023-03-27 17:15:37 +08:00
										 |  |  | 	if err := pluginaccesscontrol.DeclareRBACRoles(hs.accesscontrolService, hs.Cfg); err != nil { | 
					
						
							| 
									
										
										
										
											2022-07-08 19:24:09 +08:00
										 |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	provisioningWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 			Name:        "fixed:provisioning:writer", | 
					
						
							|  |  |  | 			DisplayName: "Provisioning writer", | 
					
						
							|  |  |  | 			Description: "Reload provisioning.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Provisioning", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					Action: ActionProvisioningReload, | 
					
						
							|  |  |  | 					Scope:  ScopeProvisionersAll, | 
					
						
							| 
									
										
										
										
											2021-09-01 21:18:17 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 		Grants: []string{ac.RoleGrafanaAdmin}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	datasourcesExplorerRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2022-01-31 23:33:41 +08:00
										 |  |  | 			Name:        "fixed:datasources:explorer", | 
					
						
							|  |  |  | 			DisplayName: "Data source explorer", | 
					
						
							|  |  |  | 			Description: "Enable the Explore feature. Data source permissions still apply; you can only query data sources for which you have query permissions.", | 
					
						
							|  |  |  | 			Group:       "Data sources", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-01-31 23:33:41 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 					Action: ac.ActionDatasourcesExplore, | 
					
						
							| 
									
										
										
										
											2022-01-31 23:33:41 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleEditor)}, | 
					
						
							| 
									
										
										
										
											2022-01-31 23:33:41 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-16 17:54:01 +08:00
										 |  |  | 	if hs.Cfg.ViewersCanEdit { | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		datasourcesExplorerRole.Grants = append(datasourcesExplorerRole.Grants, string(org.RoleViewer)) | 
					
						
							| 
									
										
										
										
											2022-01-31 23:33:41 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	datasourcesReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 			Name:        "fixed:datasources:reader", | 
					
						
							|  |  |  | 			DisplayName: "Data source reader", | 
					
						
							|  |  |  | 			Description: "Read and query all data sources.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Data sources", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-03-16 22:11:03 +08:00
										 |  |  | 					Action: datasources.ActionRead, | 
					
						
							|  |  |  | 					Scope:  datasources.ScopeAll, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-03-16 22:11:03 +08:00
										 |  |  | 					Action: datasources.ActionQuery, | 
					
						
							|  |  |  | 					Scope:  datasources.ScopeAll, | 
					
						
							| 
									
										
										
										
											2021-09-01 21:18:17 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleAdmin)}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 15:19:50 +08:00
										 |  |  | 	builtInDatasourceReader := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:datasources.builtin:reader", | 
					
						
							|  |  |  | 			DisplayName: "Built in data source reader", | 
					
						
							|  |  |  | 			Description: "Read and query Grafana's built in test data sources.", | 
					
						
							|  |  |  | 			Group:       "Data sources", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					Action: datasources.ActionRead, | 
					
						
							|  |  |  | 					Scope:  fmt.Sprintf("%s%s", datasources.ScopePrefix, grafanads.DatasourceUID), | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					Action: datasources.ActionQuery, | 
					
						
							|  |  |  | 					Scope:  fmt.Sprintf("%s%s", datasources.ScopePrefix, grafanads.DatasourceUID), | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			Hidden: true, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleViewer)}, | 
					
						
							| 
									
										
										
										
											2022-08-05 15:19:50 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 19:43:58 +08:00
										 |  |  | 	// when running oss or enterprise without a license all users should be able to query data sources
 | 
					
						
							| 
									
										
										
										
											2022-12-02 20:19:14 +08:00
										 |  |  | 	if !hs.License.FeatureEnabled("dspermissions.enforcement") { | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		datasourcesReaderRole.Grants = []string{string(org.RoleViewer)} | 
					
						
							| 
									
										
										
										
											2022-05-25 19:43:58 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 21:36:41 +08:00
										 |  |  | 	datasourcesCreatorRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:datasources:creator", | 
					
						
							|  |  |  | 			DisplayName: "Data source creator", | 
					
						
							|  |  |  | 			Description: "Create data sources.", | 
					
						
							|  |  |  | 			Group:       "Data sources", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					Action: datasources.ActionCreate, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	datasourcesWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 			Name:        "fixed:datasources:writer", | 
					
						
							|  |  |  | 			DisplayName: "Data source writer", | 
					
						
							|  |  |  | 			Description: "Create, update, delete, read, or query data sources.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Data sources", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: ac.ConcatPermissions(datasourcesReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-03-16 22:11:03 +08:00
										 |  |  | 					Action: datasources.ActionWrite, | 
					
						
							|  |  |  | 					Scope:  datasources.ScopeAll, | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-03-16 22:11:03 +08:00
										 |  |  | 					Action: datasources.ActionCreate, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-03-16 22:11:03 +08:00
										 |  |  | 					Action: datasources.ActionDelete, | 
					
						
							|  |  |  | 					Scope:  datasources.ScopeAll, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 			}), | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleAdmin)}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	datasourcesIdReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 			Name:        "fixed:datasources.id:reader", | 
					
						
							|  |  |  | 			DisplayName: "Data source ID reader", | 
					
						
							|  |  |  | 			Description: "Read the ID of a data source based on its name.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Infrequently used", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2022-03-16 22:11:03 +08:00
										 |  |  | 					Action: datasources.ActionIDRead, | 
					
						
							|  |  |  | 					Scope:  datasources.ScopeAll, | 
					
						
							| 
									
										
										
										
											2021-10-21 21:41:40 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleViewer)}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 21:09:55 +08:00
										 |  |  | 	apikeyReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:apikeys:reader", | 
					
						
							|  |  |  | 			DisplayName: "APIKeys reader", | 
					
						
							|  |  |  | 			Description: "Gives access to read api keys.", | 
					
						
							|  |  |  | 			Group:       "API Keys", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					Action: ac.ActionAPIKeyRead, | 
					
						
							|  |  |  | 					Scope:  ac.ScopeAPIKeysAll, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleAdmin)}, | 
					
						
							| 
									
										
										
										
											2022-04-14 21:09:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 02:01:03 +08:00
										 |  |  | 	apikeyWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:apikeys:writer", | 
					
						
							|  |  |  | 			DisplayName: "APIKeys writer", | 
					
						
							|  |  |  | 			Description: "Gives access to add and delete api keys.", | 
					
						
							|  |  |  | 			Group:       "API Keys", | 
					
						
							| 
									
										
										
										
											2022-04-20 15:45:45 +08:00
										 |  |  | 			Permissions: ac.ConcatPermissions(apikeyReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-05 02:01:03 +08:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					Action: ac.ActionAPIKeyCreate, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					Action: ac.ActionAPIKeyDelete, | 
					
						
							|  |  |  | 					Scope:  ac.ScopeAPIKeysAll, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2022-04-20 15:45:45 +08:00
										 |  |  | 			}), | 
					
						
							| 
									
										
										
										
											2022-03-05 02:01:03 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleAdmin)}, | 
					
						
							| 
									
										
										
										
											2022-03-05 02:01:03 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	orgReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-24 17:08:42 +08:00
										 |  |  | 			Name:        "fixed:organization:reader", | 
					
						
							|  |  |  | 			DisplayName: "Organization reader", | 
					
						
							|  |  |  | 			Description: "Read an organization, such as its ID, name, address, or quotas.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Organizations", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-09-23 04:04:48 +08:00
										 |  |  | 				{Action: ac.ActionOrgsRead}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgsQuotasRead}, | 
					
						
							| 
									
										
										
										
											2021-10-27 17:01:21 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleViewer), ac.RoleGrafanaAdmin}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	orgWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-24 17:08:42 +08:00
										 |  |  | 			Name:        "fixed:organization:writer", | 
					
						
							|  |  |  | 			DisplayName: "Organization writer", | 
					
						
							|  |  |  | 			Description: "Read an organization, its quotas, or its preferences. Update organization properties, or its preferences.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Organizations", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: ac.ConcatPermissions(orgReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-09-23 04:04:48 +08:00
										 |  |  | 				{Action: ac.ActionOrgsPreferencesRead}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgsWrite}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgsPreferencesWrite}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 			}), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleAdmin)}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	orgMaintainerRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2021-11-24 17:08:42 +08:00
										 |  |  | 			Name:        "fixed:organization:maintainer", | 
					
						
							|  |  |  | 			DisplayName: "Organization maintainer", | 
					
						
							|  |  |  | 			Description: "Create, read, write, or delete an organization. Read or write an organization's quotas. Needs to be assigned globally.", | 
					
						
							| 
									
										
										
										
											2021-11-18 17:16:18 +08:00
										 |  |  | 			Group:       "Organizations", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: ac.ConcatPermissions(orgReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-09-23 04:04:48 +08:00
										 |  |  | 				{Action: ac.ActionOrgsCreate}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgsWrite}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgsDelete}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgsQuotasWrite}, | 
					
						
							| 
									
										
										
										
											2021-11-17 22:40:39 +08:00
										 |  |  | 			}), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 		Grants: []string{string(ac.RoleGrafanaAdmin)}, | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 	teamCreatorGrants := []string{string(org.RoleAdmin)} | 
					
						
							| 
									
										
										
										
											2022-01-11 18:58:40 +08:00
										 |  |  | 	if hs.Cfg.EditorsCanAdmin { | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		teamCreatorGrants = append(teamCreatorGrants, string(org.RoleEditor)) | 
					
						
							| 
									
										
										
										
											2022-01-11 18:58:40 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	teamsCreatorRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2022-01-26 22:48:41 +08:00
										 |  |  | 			Name:        "fixed:teams:creator", | 
					
						
							|  |  |  | 			DisplayName: "Team creator", | 
					
						
							| 
									
										
										
										
											2022-07-26 16:43:29 +08:00
										 |  |  | 			Description: "Create teams and read organisation users (required to manage the created teams).", | 
					
						
							| 
									
										
										
										
											2022-01-11 18:58:40 +08:00
										 |  |  | 			Group:       "Teams", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsCreate}, | 
					
						
							|  |  |  | 				{Action: ac.ActionOrgUsersRead, Scope: ac.ScopeUsersAll}, | 
					
						
							| 
									
										
										
										
											2022-01-11 18:58:40 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-01-26 22:48:41 +08:00
										 |  |  | 		Grants: teamCreatorGrants, | 
					
						
							| 
									
										
										
										
											2022-01-11 18:58:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 21:36:41 +08:00
										 |  |  | 	teamsReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:teams:read", | 
					
						
							|  |  |  | 			DisplayName: "Team reader", | 
					
						
							|  |  |  | 			Description: "List all teams.", | 
					
						
							|  |  |  | 			Group:       "Teams", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsRead, Scope: ac.ScopeTeamsAll}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	teamsWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2022-01-27 23:16:44 +08:00
										 |  |  | 			Name:        "fixed:teams:writer", | 
					
						
							|  |  |  | 			DisplayName: "Team writer", | 
					
						
							|  |  |  | 			Description: "Create, read, write, or delete a team as well as controlling team memberships.", | 
					
						
							|  |  |  | 			Group:       "Teams", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsCreate}, | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsDelete, Scope: ac.ScopeTeamsAll}, | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsPermissionsRead, Scope: ac.ScopeTeamsAll}, | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsPermissionsWrite, Scope: ac.ScopeTeamsAll}, | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsRead, Scope: ac.ScopeTeamsAll}, | 
					
						
							|  |  |  | 				{Action: ac.ActionTeamsWrite, Scope: ac.ScopeTeamsAll}, | 
					
						
							| 
									
										
										
										
											2022-01-27 23:16:44 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleAdmin)}, | 
					
						
							| 
									
										
										
										
											2022-01-27 23:16:44 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 	annotationsReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2022-02-12 02:43:29 +08:00
										 |  |  | 			Name:        "fixed:annotations:reader", | 
					
						
							|  |  |  | 			DisplayName: "Annotation reader", | 
					
						
							|  |  |  | 			Description: "Read annotations and tags", | 
					
						
							|  |  |  | 			Group:       "Annotations", | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: ac.ActionAnnotationsRead, Scope: ac.ScopeAnnotationsAll}, | 
					
						
							| 
									
										
										
										
											2022-02-12 02:43:29 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleViewer)}, | 
					
						
							| 
									
										
										
										
											2022-02-12 02:43:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-22 01:28:39 +08:00
										 |  |  | 	dashboardAnnotationsWriterRole := ac.RoleRegistration{ | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 		Role: ac.RoleDTO{ | 
					
						
							| 
									
										
										
										
											2022-03-22 01:28:39 +08:00
										 |  |  | 			Name:        "fixed:annotations.dashboard:writer", | 
					
						
							|  |  |  | 			DisplayName: "Dashboard annotation writer", | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 			Description: "Update annotations associated with dashboards.", | 
					
						
							|  |  |  | 			Group:       "Annotations", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-24 05:39:00 +08:00
										 |  |  | 				{Action: ac.ActionAnnotationsCreate, Scope: ac.ScopeAnnotationsTypeDashboard}, | 
					
						
							| 
									
										
										
										
											2022-03-22 01:28:39 +08:00
										 |  |  | 				{Action: ac.ActionAnnotationsDelete, Scope: ac.ScopeAnnotationsTypeDashboard}, | 
					
						
							|  |  |  | 				{Action: ac.ActionAnnotationsWrite, Scope: ac.ScopeAnnotationsTypeDashboard}, | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleViewer)}, | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	annotationsWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:annotations:writer", | 
					
						
							|  |  |  | 			DisplayName: "Annotation writer", | 
					
						
							|  |  |  | 			Description: "Update all annotations.", | 
					
						
							|  |  |  | 			Group:       "Annotations", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-24 05:39:00 +08:00
										 |  |  | 				{Action: ac.ActionAnnotationsCreate, Scope: ac.ScopeAnnotationsAll}, | 
					
						
							| 
									
										
										
										
											2022-03-22 01:28:39 +08:00
										 |  |  | 				{Action: ac.ActionAnnotationsDelete, Scope: ac.ScopeAnnotationsAll}, | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 				{Action: ac.ActionAnnotationsWrite, Scope: ac.ScopeAnnotationsAll}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 		Grants: []string{string(org.RoleEditor)}, | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 	dashboardsCreatorRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:dashboards:creator", | 
					
						
							|  |  |  | 			DisplayName: "Dashboard creator", | 
					
						
							|  |  |  | 			Description: "Create dashboard in general folder.", | 
					
						
							|  |  |  | 			Group:       "Dashboards", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-30 21:14:26 +08:00
										 |  |  | 				{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							| 
									
										
										
										
											2022-05-04 22:12:09 +08:00
										 |  |  | 				{Action: dashboards.ActionDashboardsCreate, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Editor"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dashboardsReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:dashboards:reader", | 
					
						
							|  |  |  | 			DisplayName: "Dashboard reader", | 
					
						
							|  |  |  | 			Description: "Read all dashboards.", | 
					
						
							|  |  |  | 			Group:       "Dashboards", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-05-04 22:12:09 +08:00
										 |  |  | 				{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeDashboardsAll}, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dashboardsWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:dashboards:writer", | 
					
						
							|  |  |  | 			DisplayName: "Dashboard writer", | 
					
						
							|  |  |  | 			Group:       "Dashboards", | 
					
						
							|  |  |  | 			Description: "Create, read, write or delete all dashboards and their permissions.", | 
					
						
							|  |  |  | 			Permissions: ac.ConcatPermissions(dashboardsReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-05-04 22:12:09 +08:00
										 |  |  | 				{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll}, | 
					
						
							|  |  |  | 				{Action: dashboards.ActionDashboardsDelete, Scope: dashboards.ScopeDashboardsAll}, | 
					
						
							|  |  |  | 				{Action: dashboards.ActionDashboardsCreate, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 				{Action: dashboards.ActionDashboardsPermissionsRead, Scope: dashboards.ScopeDashboardsAll}, | 
					
						
							|  |  |  | 				{Action: dashboards.ActionDashboardsPermissionsWrite, Scope: dashboards.ScopeDashboardsAll}, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 			}), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	foldersCreatorRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:folders:creator", | 
					
						
							|  |  |  | 			DisplayName: "Folder creator", | 
					
						
							|  |  |  | 			Description: "Create folders.", | 
					
						
							|  |  |  | 			Group:       "Folders", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-10 00:57:50 +08:00
										 |  |  | 				{Action: dashboards.ActionFoldersCreate}, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Editor"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	foldersReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:folders:reader", | 
					
						
							|  |  |  | 			DisplayName: "Folder reader", | 
					
						
							|  |  |  | 			Description: "Read all folders and dashboards.", | 
					
						
							|  |  |  | 			Group:       "Folders", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-10 00:57:50 +08:00
										 |  |  | 				{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							| 
									
										
										
										
											2022-05-04 22:12:09 +08:00
										 |  |  | 				{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	foldersWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:folders:writer", | 
					
						
							|  |  |  | 			DisplayName: "Folder writer", | 
					
						
							|  |  |  | 			Description: "Create, read, write or delete all folders and dashboards and their permissions.", | 
					
						
							|  |  |  | 			Group:       "Folders", | 
					
						
							|  |  |  | 			Permissions: ac.ConcatPermissions( | 
					
						
							|  |  |  | 				foldersReaderRole.Role.Permissions, | 
					
						
							|  |  |  | 				[]ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-03-10 00:57:50 +08:00
										 |  |  | 					{Action: dashboards.ActionFoldersCreate}, | 
					
						
							|  |  |  | 					{Action: dashboards.ActionFoldersWrite, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 					{Action: dashboards.ActionFoldersDelete, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							| 
									
										
										
										
											2022-05-04 22:12:09 +08:00
										 |  |  | 					{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 					{Action: dashboards.ActionDashboardsDelete, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 					{Action: dashboards.ActionDashboardsCreate, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 					{Action: dashboards.ActionDashboardsPermissionsRead, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 					{Action: dashboards.ActionDashboardsPermissionsWrite, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 				}), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-12 07:30:50 +08:00
										 |  |  | 	libraryPanelsCreatorRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:library.panels:creator", | 
					
						
							|  |  |  | 			DisplayName: "Library panel creator", | 
					
						
							|  |  |  | 			Description: "Create library panel in general folder.", | 
					
						
							|  |  |  | 			Group:       "Library panels", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsCreate, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Editor"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	libraryPanelsReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:library.panels:reader", | 
					
						
							|  |  |  | 			DisplayName: "Library panel reader", | 
					
						
							|  |  |  | 			Description: "Read all library panels.", | 
					
						
							|  |  |  | 			Group:       "Library panels", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2023-10-26 01:44:55 +08:00
										 |  |  | 				{Action: libraryelements.ActionLibraryPanelsRead, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							| 
									
										
										
										
											2023-10-12 07:30:50 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	libraryPanelsGeneralReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:library.panels:general.reader", | 
					
						
							|  |  |  | 			DisplayName: "Library panel general reader", | 
					
						
							|  |  |  | 			Description: "Read all library panels in general folder.", | 
					
						
							|  |  |  | 			Group:       "Library panels", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Viewer"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	libraryPanelsWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:library.panels:writer", | 
					
						
							|  |  |  | 			DisplayName: "Library panel writer", | 
					
						
							|  |  |  | 			Group:       "Library panels", | 
					
						
							|  |  |  | 			Description: "Create, read, write or delete all library panels and their permissions.", | 
					
						
							|  |  |  | 			Permissions: ac.ConcatPermissions(libraryPanelsReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2023-10-26 01:44:55 +08:00
										 |  |  | 				{Action: libraryelements.ActionLibraryPanelsWrite, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsDelete, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsCreate, Scope: dashboards.ScopeFoldersAll}, | 
					
						
							| 
									
										
										
										
											2023-10-12 07:30:50 +08:00
										 |  |  | 			}), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	libraryPanelsGeneralWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:library.panels:general.writer", | 
					
						
							|  |  |  | 			DisplayName: "Library panel general writer", | 
					
						
							|  |  |  | 			Group:       "Library panels", | 
					
						
							|  |  |  | 			Description: "Create, read, write or delete all library panels and their permissions in the general folder.", | 
					
						
							|  |  |  | 			Permissions: ac.ConcatPermissions(libraryPanelsGeneralReaderRole.Role.Permissions, []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsWrite, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsDelete, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							|  |  |  | 				{Action: libraryelements.ActionLibraryPanelsCreate, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)}, | 
					
						
							|  |  |  | 			}), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Editor"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-05 23:22:39 +08:00
										 |  |  | 	publicDashboardsWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:dashboards.public:writer", | 
					
						
							|  |  |  | 			DisplayName: "Public Dashboard writer", | 
					
						
							|  |  |  | 			Description: "Create, write or disable a public dashboard.", | 
					
						
							|  |  |  | 			Group:       "Dashboards", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							| 
									
										
										
										
											2022-09-08 05:29:01 +08:00
										 |  |  | 				{Action: dashboards.ActionDashboardsPublicWrite, Scope: dashboards.ScopeDashboardsAll}, | 
					
						
							| 
									
										
										
										
											2022-09-05 23:22:39 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-25 04:12:59 +08:00
										 |  |  | 	featuremgmtReaderRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:featuremgmt:reader", | 
					
						
							|  |  |  | 			DisplayName: "Feature Management reader", | 
					
						
							|  |  |  | 			Description: "Read feature toggles", | 
					
						
							|  |  |  | 			Group:       "Feature Management", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: ac.ActionFeatureManagementRead}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-09 23:32:28 +08:00
										 |  |  | 	featuremgmtWriterRole := ac.RoleRegistration{ | 
					
						
							|  |  |  | 		Role: ac.RoleDTO{ | 
					
						
							|  |  |  | 			Name:        "fixed:featuremgmt:writer", | 
					
						
							|  |  |  | 			DisplayName: "Feature Management writer", | 
					
						
							|  |  |  | 			Description: "Write feature toggles", | 
					
						
							|  |  |  | 			Group:       "Feature Management", | 
					
						
							|  |  |  | 			Permissions: []ac.Permission{ | 
					
						
							|  |  |  | 				{Action: ac.ActionFeatureManagementWrite}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Grants: []string{"Admin"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-12 07:30:50 +08:00
										 |  |  | 	roles := []ac.RoleRegistration{provisioningWriterRole, datasourcesReaderRole, builtInDatasourceReader, datasourcesWriterRole, | 
					
						
							| 
									
										
										
										
											2023-10-19 21:36:41 +08:00
										 |  |  | 		datasourcesIdReaderRole, datasourcesCreatorRole, orgReaderRole, orgWriterRole, | 
					
						
							|  |  |  | 		orgMaintainerRole, teamsCreatorRole, teamsWriterRole, teamsReaderRole, datasourcesExplorerRole, | 
					
						
							| 
									
										
										
										
											2022-03-22 01:28:39 +08:00
										 |  |  | 		annotationsReaderRole, dashboardAnnotationsWriterRole, annotationsWriterRole, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 		dashboardsCreatorRole, dashboardsReaderRole, dashboardsWriterRole, | 
					
						
							| 
									
										
										
										
											2022-04-14 21:09:55 +08:00
										 |  |  | 		foldersCreatorRole, foldersReaderRole, foldersWriterRole, apikeyReaderRole, apikeyWriterRole, | 
					
						
							| 
									
										
										
										
											2023-10-26 01:44:55 +08:00
										 |  |  | 		publicDashboardsWriterRole, featuremgmtReaderRole, featuremgmtWriterRole, libraryPanelsCreatorRole, | 
					
						
							|  |  |  | 		libraryPanelsReaderRole, libraryPanelsWriterRole, libraryPanelsGeneralReaderRole, libraryPanelsGeneralWriterRole} | 
					
						
							| 
									
										
										
										
											2023-10-12 07:30:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return hs.accesscontrolService.DeclareFixedRoles(roles...) | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-22 19:50:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | // Metadata helpers
 | 
					
						
							|  |  |  | // getAccessControlMetadata returns the accesscontrol metadata associated with a given resource
 | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | func (hs *HTTPServer) getAccessControlMetadata(c *contextmodel.ReqContext, | 
					
						
							| 
									
										
										
										
											2022-03-24 15:58:10 +08:00
										 |  |  | 	orgID int64, prefix string, resourceID string) ac.Metadata { | 
					
						
							| 
									
										
										
										
											2022-03-22 00:58:18 +08:00
										 |  |  | 	ids := map[string]bool{resourceID: true} | 
					
						
							| 
									
										
										
										
											2023-08-18 18:42:18 +08:00
										 |  |  | 	return hs.getMultiAccessControlMetadata(c, prefix, ids)[resourceID] | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // getMultiAccessControlMetadata returns the accesscontrol metadata associated with a given set of resources
 | 
					
						
							| 
									
										
										
										
											2022-03-24 15:58:10 +08:00
										 |  |  | // Context must contain permissions in the given org (see LoadPermissionsMiddleware or AuthorizeInOrgMiddleware)
 | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | func (hs *HTTPServer) getMultiAccessControlMetadata(c *contextmodel.ReqContext, | 
					
						
							| 
									
										
										
										
											2023-08-18 18:42:18 +08:00
										 |  |  | 	prefix string, resourceIDs map[string]bool) map[string]ac.Metadata { | 
					
						
							| 
									
										
										
										
											2023-05-31 16:58:57 +08:00
										 |  |  | 	if !c.QueryBool("accesscontrol") { | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 		return map[string]ac.Metadata{} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-18 18:42:18 +08:00
										 |  |  | 	if len(c.SignedInUser.GetPermissions()) == 0 { | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | 		return map[string]ac.Metadata{} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-18 18:42:18 +08:00
										 |  |  | 	return ac.GetResourcesMetadata(c.Req.Context(), c.SignedInUser.GetPermissions(), prefix, resourceIDs) | 
					
						
							| 
									
										
										
										
											2022-02-18 18:27:00 +08:00
										 |  |  | } |