2021-08-04 07:44:37 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-08-05 02:19:50 -05:00
|
|
|
"fmt"
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
2023-01-27 01:50:36 -06:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2022-03-09 10:57:50 -06:00
|
|
|
"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"
|
2023-03-27 04:15:37 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginaccesscontrol"
|
2022-08-05 02:19:50 -05:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/grafanads"
|
2021-08-04 07:44:37 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// API related actions
|
|
|
|
const (
|
|
|
|
ActionProvisioningReload = "provisioning:reload"
|
|
|
|
)
|
|
|
|
|
|
|
|
// API related scopes
|
2021-10-06 06:15:09 -05:00
|
|
|
var (
|
2022-02-18 04:27:00 -06: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-14 16:53:13 -05:00
|
|
|
ScopeProvisionersAlertRules = ac.Scope("provisioners", "alerting")
|
2021-08-04 07:44:37 -05: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 06:24:09 -05:00
|
|
|
// Declare plugins roles
|
2023-03-27 04:15:37 -05:00
|
|
|
if err := pluginaccesscontrol.DeclareRBACRoles(hs.accesscontrolService, hs.Cfg); err != nil {
|
2022-07-08 06:24:09 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
provisioningWriterRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-17 08:40:39 -06:00
|
|
|
Name: "fixed:provisioning:writer",
|
|
|
|
DisplayName: "Provisioning writer",
|
|
|
|
Description: "Reload provisioning.",
|
2021-11-18 03:16:18 -06:00
|
|
|
Group: "Provisioning",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
2021-11-17 08:40:39 -06:00
|
|
|
{
|
|
|
|
Action: ActionProvisioningReload,
|
|
|
|
Scope: ScopeProvisionersAll,
|
2021-09-01 08:18:17 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-18 04:27:00 -06:00
|
|
|
Grants: []string{ac.RoleGrafanaAdmin},
|
2021-11-17 08:40:39 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
datasourcesExplorerRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2022-01-31 09:33:41 -06: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 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
2022-01-31 09:33:41 -06:00
|
|
|
{
|
2022-02-18 04:27:00 -06:00
|
|
|
Action: ac.ActionDatasourcesExplore,
|
2022-01-31 09:33:41 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleEditor)},
|
2022-01-31 09:33:41 -06:00
|
|
|
}
|
|
|
|
|
2023-03-16 04:54:01 -05:00
|
|
|
if hs.Cfg.ViewersCanEdit {
|
2022-08-10 04:56:48 -05:00
|
|
|
datasourcesExplorerRole.Grants = append(datasourcesExplorerRole.Grants, string(org.RoleViewer))
|
2022-01-31 09:33:41 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
datasourcesReaderRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-17 08:40:39 -06:00
|
|
|
Name: "fixed:datasources:reader",
|
|
|
|
DisplayName: "Data source reader",
|
|
|
|
Description: "Read and query all data sources.",
|
2021-11-18 03:16:18 -06:00
|
|
|
Group: "Data sources",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
2021-11-17 08:40:39 -06:00
|
|
|
{
|
2022-03-16 09:11:03 -05:00
|
|
|
Action: datasources.ActionRead,
|
|
|
|
Scope: datasources.ScopeAll,
|
2021-11-17 08:40:39 -06:00
|
|
|
},
|
|
|
|
{
|
2022-03-16 09:11:03 -05:00
|
|
|
Action: datasources.ActionQuery,
|
|
|
|
Scope: datasources.ScopeAll,
|
2021-09-01 08:18:17 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleAdmin)},
|
2021-11-17 08:40:39 -06:00
|
|
|
}
|
|
|
|
|
2022-08-05 02:19:50 -05: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 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleViewer)},
|
2022-08-05 02:19:50 -05:00
|
|
|
}
|
|
|
|
|
2022-05-25 06:43:58 -05:00
|
|
|
// when running oss or enterprise without a license all users should be able to query data sources
|
2022-12-02 06:19:14 -06:00
|
|
|
if !hs.License.FeatureEnabled("dspermissions.enforcement") {
|
2022-08-10 04:56:48 -05:00
|
|
|
datasourcesReaderRole.Grants = []string{string(org.RoleViewer)}
|
2022-05-25 06:43:58 -05:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
datasourcesWriterRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-17 08:40:39 -06:00
|
|
|
Name: "fixed:datasources:writer",
|
|
|
|
DisplayName: "Data source writer",
|
|
|
|
Description: "Create, update, delete, read, or query data sources.",
|
2021-11-18 03:16:18 -06:00
|
|
|
Group: "Data sources",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: ac.ConcatPermissions(datasourcesReaderRole.Role.Permissions, []ac.Permission{
|
2021-11-17 08:40:39 -06:00
|
|
|
{
|
2022-03-16 09:11:03 -05:00
|
|
|
Action: datasources.ActionWrite,
|
|
|
|
Scope: datasources.ScopeAll,
|
2021-08-04 07:44:37 -05:00
|
|
|
},
|
2021-11-17 08:40:39 -06:00
|
|
|
{
|
2022-03-16 09:11:03 -05:00
|
|
|
Action: datasources.ActionCreate,
|
2021-11-17 08:40:39 -06:00
|
|
|
},
|
|
|
|
{
|
2022-03-16 09:11:03 -05:00
|
|
|
Action: datasources.ActionDelete,
|
|
|
|
Scope: datasources.ScopeAll,
|
2021-11-17 08:40:39 -06:00
|
|
|
},
|
|
|
|
}),
|
2021-08-04 07:44:37 -05:00
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleAdmin)},
|
2021-11-17 08:40:39 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
datasourcesIdReaderRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-17 08:40:39 -06: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 03:16:18 -06:00
|
|
|
Group: "Infrequently used",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
2021-11-17 08:40:39 -06:00
|
|
|
{
|
2022-03-16 09:11:03 -05:00
|
|
|
Action: datasources.ActionIDRead,
|
|
|
|
Scope: datasources.ScopeAll,
|
2021-10-21 08:41:40 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleViewer)},
|
2021-11-17 08:40:39 -06:00
|
|
|
}
|
|
|
|
|
2022-04-14 08:09:55 -05: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 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleAdmin)},
|
2022-04-14 08:09:55 -05:00
|
|
|
}
|
|
|
|
|
2022-03-04 12:01:03 -06: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 02:45:45 -05:00
|
|
|
Permissions: ac.ConcatPermissions(apikeyReaderRole.Role.Permissions, []ac.Permission{
|
2022-03-04 12:01:03 -06:00
|
|
|
{
|
|
|
|
Action: ac.ActionAPIKeyCreate,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: ac.ActionAPIKeyDelete,
|
|
|
|
Scope: ac.ScopeAPIKeysAll,
|
|
|
|
},
|
2022-04-20 02:45:45 -05:00
|
|
|
}),
|
2022-03-04 12:01:03 -06:00
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleAdmin)},
|
2022-03-04 12:01:03 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
orgReaderRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-24 03:08:42 -06:00
|
|
|
Name: "fixed:organization:reader",
|
|
|
|
DisplayName: "Organization reader",
|
|
|
|
Description: "Read an organization, such as its ID, name, address, or quotas.",
|
2021-11-18 03:16:18 -06:00
|
|
|
Group: "Organizations",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
2022-09-22 15:04:48 -05:00
|
|
|
{Action: ac.ActionOrgsRead},
|
|
|
|
{Action: ac.ActionOrgsQuotasRead},
|
2021-10-27 04:01:21 -05:00
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleViewer), ac.RoleGrafanaAdmin},
|
2021-11-17 08:40:39 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
orgWriterRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-24 03:08:42 -06: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 03:16:18 -06:00
|
|
|
Group: "Organizations",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: ac.ConcatPermissions(orgReaderRole.Role.Permissions, []ac.Permission{
|
2022-09-22 15:04:48 -05:00
|
|
|
{Action: ac.ActionOrgsPreferencesRead},
|
|
|
|
{Action: ac.ActionOrgsWrite},
|
|
|
|
{Action: ac.ActionOrgsPreferencesWrite},
|
2021-11-17 08:40:39 -06:00
|
|
|
}),
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleAdmin)},
|
2021-11-17 08:40:39 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
orgMaintainerRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2021-11-24 03:08:42 -06: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 03:16:18 -06:00
|
|
|
Group: "Organizations",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: ac.ConcatPermissions(orgReaderRole.Role.Permissions, []ac.Permission{
|
2022-09-22 15:04:48 -05:00
|
|
|
{Action: ac.ActionOrgsCreate},
|
|
|
|
{Action: ac.ActionOrgsWrite},
|
|
|
|
{Action: ac.ActionOrgsDelete},
|
|
|
|
{Action: ac.ActionOrgsQuotasWrite},
|
2021-11-17 08:40:39 -06:00
|
|
|
}),
|
|
|
|
},
|
2022-02-18 04:27:00 -06:00
|
|
|
Grants: []string{string(ac.RoleGrafanaAdmin)},
|
2021-08-04 07:44:37 -05:00
|
|
|
}
|
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
teamCreatorGrants := []string{string(org.RoleAdmin)}
|
2022-01-11 04:58:40 -06:00
|
|
|
if hs.Cfg.EditorsCanAdmin {
|
2022-08-10 04:56:48 -05:00
|
|
|
teamCreatorGrants = append(teamCreatorGrants, string(org.RoleEditor))
|
2022-01-11 04:58:40 -06:00
|
|
|
}
|
2022-02-18 04:27:00 -06:00
|
|
|
teamsCreatorRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2022-01-26 08:48:41 -06:00
|
|
|
Name: "fixed:teams:creator",
|
|
|
|
DisplayName: "Team creator",
|
2022-07-26 03:43:29 -05:00
|
|
|
Description: "Create teams and read organisation users (required to manage the created teams).",
|
2022-01-11 04:58:40 -06:00
|
|
|
Group: "Teams",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
|
|
|
{Action: ac.ActionTeamsCreate},
|
|
|
|
{Action: ac.ActionOrgUsersRead, Scope: ac.ScopeUsersAll},
|
2022-01-11 04:58:40 -06:00
|
|
|
},
|
|
|
|
},
|
2022-01-26 08:48:41 -06:00
|
|
|
Grants: teamCreatorGrants,
|
2022-01-11 04:58:40 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
teamsWriterRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2022-01-27 09:16:44 -06: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 04:27:00 -06: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 09:16:44 -06:00
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleAdmin)},
|
2022-01-27 09:16:44 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
annotationsReaderRole := ac.RoleRegistration{
|
|
|
|
Role: ac.RoleDTO{
|
2022-02-11 12:43:29 -06:00
|
|
|
Name: "fixed:annotations:reader",
|
|
|
|
DisplayName: "Annotation reader",
|
|
|
|
Description: "Read annotations and tags",
|
|
|
|
Group: "Annotations",
|
2022-02-18 04:27:00 -06:00
|
|
|
Permissions: []ac.Permission{
|
|
|
|
{Action: ac.ActionAnnotationsRead, Scope: ac.ScopeAnnotationsAll},
|
2022-02-11 12:43:29 -06:00
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleViewer)},
|
2022-02-11 12:43:29 -06:00
|
|
|
}
|
|
|
|
|
2022-03-21 12:28:39 -05:00
|
|
|
dashboardAnnotationsWriterRole := ac.RoleRegistration{
|
2022-03-18 11:33:21 -05:00
|
|
|
Role: ac.RoleDTO{
|
2022-03-21 12:28:39 -05:00
|
|
|
Name: "fixed:annotations.dashboard:writer",
|
|
|
|
DisplayName: "Dashboard annotation writer",
|
2022-03-18 11:33:21 -05:00
|
|
|
Description: "Update annotations associated with dashboards.",
|
|
|
|
Group: "Annotations",
|
|
|
|
Permissions: []ac.Permission{
|
2022-03-23 16:39:00 -05:00
|
|
|
{Action: ac.ActionAnnotationsCreate, Scope: ac.ScopeAnnotationsTypeDashboard},
|
2022-03-21 12:28:39 -05:00
|
|
|
{Action: ac.ActionAnnotationsDelete, Scope: ac.ScopeAnnotationsTypeDashboard},
|
|
|
|
{Action: ac.ActionAnnotationsWrite, Scope: ac.ScopeAnnotationsTypeDashboard},
|
2022-03-18 11:33:21 -05:00
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleViewer)},
|
2022-03-18 11:33:21 -05: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-23 16:39:00 -05:00
|
|
|
{Action: ac.ActionAnnotationsCreate, Scope: ac.ScopeAnnotationsAll},
|
2022-03-21 12:28:39 -05:00
|
|
|
{Action: ac.ActionAnnotationsDelete, Scope: ac.ScopeAnnotationsAll},
|
2022-03-18 11:33:21 -05:00
|
|
|
{Action: ac.ActionAnnotationsWrite, Scope: ac.ScopeAnnotationsAll},
|
|
|
|
},
|
|
|
|
},
|
2022-08-10 04:56:48 -05:00
|
|
|
Grants: []string{string(org.RoleEditor)},
|
2022-03-18 11:33:21 -05:00
|
|
|
}
|
|
|
|
|
2022-03-03 08:05:47 -06: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 08:14:26 -05:00
|
|
|
{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)},
|
2022-05-04 09:12:09 -05:00
|
|
|
{Action: dashboards.ActionDashboardsCreate, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(ac.GeneralFolderUID)},
|
2022-03-03 08:05:47 -06: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 09:12:09 -05:00
|
|
|
{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeDashboardsAll},
|
2022-03-03 08:05:47 -06: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 09:12:09 -05: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 08:05:47 -06: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-09 10:57:50 -06:00
|
|
|
{Action: dashboards.ActionFoldersCreate},
|
2022-03-03 08:05:47 -06: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-09 10:57:50 -06:00
|
|
|
{Action: dashboards.ActionFoldersRead, Scope: dashboards.ScopeFoldersAll},
|
2022-05-04 09:12:09 -05:00
|
|
|
{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeFoldersAll},
|
2022-03-03 08:05:47 -06: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-09 10:57:50 -06:00
|
|
|
{Action: dashboards.ActionFoldersCreate},
|
|
|
|
{Action: dashboards.ActionFoldersWrite, Scope: dashboards.ScopeFoldersAll},
|
|
|
|
{Action: dashboards.ActionFoldersDelete, Scope: dashboards.ScopeFoldersAll},
|
2022-05-04 09:12:09 -05: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 08:05:47 -06:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
Grants: []string{"Admin"},
|
|
|
|
}
|
|
|
|
|
2022-09-05 10:22:39 -05: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-07 16:29:01 -05:00
|
|
|
{Action: dashboards.ActionDashboardsPublicWrite, Scope: dashboards.ScopeDashboardsAll},
|
2022-09-05 10:22:39 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Grants: []string{"Admin"},
|
|
|
|
}
|
|
|
|
|
2023-07-24 15:12:59 -05: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 10:32:28 -05: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"},
|
|
|
|
}
|
|
|
|
|
2022-08-26 02:59:34 -05:00
|
|
|
return hs.accesscontrolService.DeclareFixedRoles(
|
2022-08-05 02:19:50 -05:00
|
|
|
provisioningWriterRole, datasourcesReaderRole, builtInDatasourceReader, datasourcesWriterRole,
|
2022-05-25 06:43:58 -05:00
|
|
|
datasourcesIdReaderRole, orgReaderRole, orgWriterRole,
|
2022-03-18 11:33:21 -05:00
|
|
|
orgMaintainerRole, teamsCreatorRole, teamsWriterRole, datasourcesExplorerRole,
|
2022-03-21 12:28:39 -05:00
|
|
|
annotationsReaderRole, dashboardAnnotationsWriterRole, annotationsWriterRole,
|
2022-03-03 08:05:47 -06:00
|
|
|
dashboardsCreatorRole, dashboardsReaderRole, dashboardsWriterRole,
|
2022-04-14 08:09:55 -05:00
|
|
|
foldersCreatorRole, foldersReaderRole, foldersWriterRole, apikeyReaderRole, apikeyWriterRole,
|
2023-08-09 10:32:28 -05:00
|
|
|
publicDashboardsWriterRole, featuremgmtReaderRole, featuremgmtWriterRole,
|
2021-11-17 08:40:39 -06:00
|
|
|
)
|
2021-08-04 07:44:37 -05:00
|
|
|
}
|
2021-09-22 06:50:21 -05:00
|
|
|
|
2022-02-18 04:27:00 -06:00
|
|
|
// Metadata helpers
|
|
|
|
// getAccessControlMetadata returns the accesscontrol metadata associated with a given resource
|
2023-01-27 01:50:36 -06:00
|
|
|
func (hs *HTTPServer) getAccessControlMetadata(c *contextmodel.ReqContext,
|
2022-03-24 02:58:10 -05:00
|
|
|
orgID int64, prefix string, resourceID string) ac.Metadata {
|
2022-03-21 11:58:18 -05:00
|
|
|
ids := map[string]bool{resourceID: true}
|
2023-08-18 05:42:18 -05:00
|
|
|
return hs.getMultiAccessControlMetadata(c, prefix, ids)[resourceID]
|
2022-02-18 04:27:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// getMultiAccessControlMetadata returns the accesscontrol metadata associated with a given set of resources
|
2022-03-24 02:58:10 -05:00
|
|
|
// Context must contain permissions in the given org (see LoadPermissionsMiddleware or AuthorizeInOrgMiddleware)
|
2023-01-27 01:50:36 -06:00
|
|
|
func (hs *HTTPServer) getMultiAccessControlMetadata(c *contextmodel.ReqContext,
|
2023-08-18 05:42:18 -05:00
|
|
|
prefix string, resourceIDs map[string]bool) map[string]ac.Metadata {
|
2023-05-31 03:58:57 -05:00
|
|
|
if !c.QueryBool("accesscontrol") {
|
2022-02-18 04:27:00 -06:00
|
|
|
return map[string]ac.Metadata{}
|
|
|
|
}
|
|
|
|
|
2023-08-18 05:42:18 -05:00
|
|
|
if len(c.SignedInUser.GetPermissions()) == 0 {
|
2022-02-18 04:27:00 -06:00
|
|
|
return map[string]ac.Metadata{}
|
|
|
|
}
|
|
|
|
|
2023-08-18 05:42:18 -05:00
|
|
|
return ac.GetResourcesMetadata(c.Req.Context(), c.SignedInUser.GetPermissions(), prefix, resourceIDs)
|
2022-02-18 04:27:00 -06:00
|
|
|
}
|