Manage RBAC roles

Note: Available in Grafana Enterprise and Grafana Cloud Advanced.

This section includes instructions for how to view permissions associated with roles, create custom roles, and update and delete roles.

The following example includes the base64 username:password Basic Authorization. You cannot use authorization tokens in the request.

List permissions associated with roles

Use a GET command to see the actions and scopes associated with a role. For more information about seeing a list of permissions for each role, refer to Get a role.

To see the permissions associated with basic roles, refer to the following basic role UIDs:

Basic roleUID
Viewerbasic_viewer
Editorbasic_editor
Adminbasic_admin
Grafana Adminbasic_grafana_admin

Example request

  1. curl --location --request GET '<grafana_url>/api/access-control/roles/qQui_LCMk' --header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ='

Example response

  1. {
  2. "version": 2,
  3. "uid": "qQui_LCMk",
  4. "name": "fixed:users:writer",
  5. "displayName": "User writer",
  6. "description": "Read and update all attributes and settings for all users in Grafana: update user information, read user information, create or enable or disable a user, make a user a Grafana administrator, sign out a user, update a user’s authentication token, or update quotas for all users.",
  7. "global": true,
  8. "permissions": [
  9. {
  10. "action": "org.users:add",
  11. "scope": "users:*",
  12. "updated": "2021-05-17T20:49:18+02:00",
  13. "created": "2021-05-17T20:49:18+02:00"
  14. },
  15. {
  16. "action": "org.users:read",
  17. "scope": "users:*",
  18. "updated": "2021-05-17T20:49:18+02:00",
  19. "created": "2021-05-17T20:49:18+02:00"
  20. },
  21. {
  22. "action": "org.users:remove",
  23. "scope": "users:*",
  24. "updated": "2021-05-17T20:49:18+02:00",
  25. "created": "2021-05-17T20:49:18+02:00"
  26. },
  27. {
  28. "action": "org.users:write",
  29. "scope": "users:*",
  30. "updated": "2021-05-17T20:49:18+02:00",
  31. "created": "2021-05-17T20:49:18+02:00"
  32. }
  33. ],
  34. "updated": "2021-05-17T20:49:18+02:00",
  35. "created": "2021-05-13T16:24:26+02:00"
  36. }

Refer to the RBAC HTTP API for more details.

Create custom roles

This section shows you how to create a custom RBAC role using Grafana provisioning and the HTTP API.

Create a custom role when basic roles and fixed roles do not meet your permissions requirements.

Before you begin:

  • Plan your RBAC rollout strategy.
  • Determine which permissions you want to add to the custom role. To see a list of actions and scope, refer to RBAC permissions, actions, and scopes.
  • Enable role provisioning.
  • Ensure that you have permissions to create a custom role.
    • By default, the Grafana Admin role has permission to create custom roles.
    • A Grafana Admin can delegate the custom role privilege to another user by creating a custom role with the relevant permissions and adding the permissions:type:delegate scope.

Create custom roles using provisioning

File-based provisioning is one method you can use to create custom roles.

  1. Open the YAML configuration file and locate the roles section.

  2. Refer to the following table to add attributes and values.

AttributeDescription
nameA human-friendly identifier for the role that helps administrators understand the purpose of a role. name is required and cannot be longer than 190 characters. We recommend that you use ASCII characters. Role names must be unique within an organization.
uidA unique identifier associated with the role. The UID enables you to change or delete the role. You can either generate a UID yourself, or let Grafana generate one for you. You cannot use the same UID within the same Grafana instance.
orgIdIdentifies the organization to which the role belongs. The default org ID is used if you do not specify orgId.
globalGlobal roles are not associated with any specific organization, which means that you can reuse them across all organizations. This setting overrides orgId.
displayNameHuman-friendly text that is displayed in the UI. Role display name cannot be longer than 190 ASCII-based characters. For fixed roles, the display name is shown as specified. If you do not set a display name the display name replaces ‘:’ (a colon) with ‘ ‘ (a space).
descriptionHuman-friendly text that describes the permissions a role provides.
groupOrganizes roles in the role picker.
versionA positive integer that defines the current version of the role, which prevents overwriting newer changes.
hiddenHidden roles do not appear in the role picker.
stateState of the role. Defaults to present, but if set to absent the role will be removed.
forceCan be used in addition to state absent, to force the removal of a role and all its assignments.
fromAn optional list of roles from which you want to copy permissions.
permissionsProvides users access to Grafana resources. For a list of permissions, refer to RBAC permissions actions and scopes. If you do not know which permissions to assign, you can create and assign roles without any permissions as a placeholder. Using the from attribute, you can specify additional permissions or permissions to remove by adding a state to your permission list.
  1. Reload the provisioning configuration file.

    For more information about reloading the provisioning configuration at runtime, refer to Reload provisioning configurations.

The following example creates a local role:

  1. # config file version
  2. apiVersion: 2
  3. roles:
  4. - name: custom:users:writer
  5. description: 'List, create, or update other users.'
  6. version: 1
  7. orgId: 1
  8. permissions:
  9. - action: 'users:read'
  10. scope: 'global.users:*'
  11. - action: 'users:write'
  12. scope: 'global.users:*'
  13. - action: 'users:create'

The following example creates a hidden global role. The global: true option creates a global role, and the hidden: true option hides the role from the role picker.

  1. # config file version
  2. apiVersion: 2
  3. roles:
  4. - name: custom:users:writer
  5. description: 'List, create, or update other users.'
  6. version: 1
  7. global: true
  8. hidden: true
  9. permissions:
  10. - action: 'users:read'
  11. scope: 'global.users:*'
  12. - action: 'users:write'
  13. scope: 'global.users:*'
  14. - action: 'users:create'

The following example creates a global role based on other fixed roles. The from option contains the roles from which we want to copy permissions. The permission state: absent option can be used to specify permissions to exclude from the copy.

  1. # config file version
  2. apiVersion: 2
  3. roles:
  4. - name: custom:org.users:writer
  5. description: 'List and remove other users from the organization.'
  6. version: 1
  7. global: true
  8. from:
  9. - name: 'fixed:org.users:reader'
  10. global: true
  11. - name: 'fixed:org.users:writer'
  12. global: true
  13. permissions:
  14. - action: 'org.users:write'
  15. scope: 'users:*'
  16. state: 'absent'
  17. - action: 'org.users:add'
  18. scope: 'users:*'
  19. state: 'absent'

Create custom roles using the HTTP API

The following examples show you how to create a custom role using the Grafana HTTP API. For more information about the HTTP API, refer to Create a new custom role.

Note: You cannot create a custom role with permissions that you do not have. For example, if you only have users:create permissions, then you cannot create a role that includes other permissions.

The following example creates a custom:users:admin role and assigns the users:create action to it.

Example request

  1. curl --location --request POST '<grafana_url>/api/access-control/roles/' \
  2. --header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' \
  3. --header 'Content-Type: application/json' \
  4. --data-raw '{
  5. "version": 1,
  6. "uid": "jZrmlLCkGksdka",
  7. "name": "custom:users:admin",
  8. "displayName": "custom users admin",
  9. "description": "My custom role which gives users permissions to create users",
  10. "global": true,
  11. "permissions": [
  12. {
  13. "action": "users:create"
  14. }
  15. ]
  16. }'

Example response

  1. {
  2. "version": 1,
  3. "uid": "jZrmlLCkGksdka",
  4. "name": "custom:users:admin",
  5. "displayName": "custom users admin",
  6. "description": "My custom role which gives users permissions to create users",
  7. "global": true,
  8. "permissions": [
  9. {
  10. "action": "users:create"
  11. "updated": "2021-05-17T22:07:31.569936+02:00",
  12. "created": "2021-05-17T22:07:31.569935+02:00"
  13. }
  14. ],
  15. "updated": "2021-05-17T22:07:31.564403+02:00",
  16. "created": "2021-05-17T22:07:31.564403+02:00"
  17. }

Refer to the RBAC HTTP API for more details.

Update basic role permissions

If the default basic role definitions do not meet your requirements, you can change their permissions.

Before you begin:

  • Determine the permissions you want to add or remove from a basic role. For more information about the permissions associated with basic roles, refer to RBAC role definitions.

To change permissions from a basic role:

  1. Open the YAML configuration file and locate the roles section.

  2. Refer to the following table to add attributes and values.

    AttributeDescription
    nameThe name of the basic role you want to update. You can specify a uid instead of a role name. The role name or the uid are required.
    orgIdIdentifies the organization to which the role belongs. global can be used instead to specify it’s a global role.
    versionIdentifies the version of the role, which prevents overwriting newer changes.
    fromList of roles from which to copy permissions.
    permissions > stateThe state of the permission. You can set it to absent to ensure it exclusion from the copy list.
  3. Reload the provisioning configuration file.

    For more information about reloading the provisioning configuration at runtime, refer to Reload provisioning configurations.

The following example modifies the Grafana Admin basic role permissions.

  • Permissions to list, grant, and revoke roles to teams are removed.
  • Permission to read and write Grafana folders is added.
  1. # config file version
  2. apiVersion: 2
  3. roles:
  4. - name: 'basic:grafana_admin'
  5. global: true
  6. version: 3
  7. from:
  8. - name: 'basic:grafana_admin'
  9. global: true
  10. permissions:
  11. # Permissions to remove
  12. - action: 'teams.roles:read'
  13. scope: 'teams:*'
  14. state: 'absent'
  15. - action: 'teams.roles:remove'
  16. scope: 'permissions:type:delegate'
  17. state: 'absent'
  18. - action: 'teams.roles:add'
  19. scope: 'permissions:type:delegate'
  20. state: 'absent'
  21. # Permissions to add
  22. - action: 'folders:read'
  23. scope: 'folder:*'
  24. - action: 'folders:write'
  25. scope: 'folder:*'

Note: You can add multiple fixed, basic or custom roles to the from section. Their permissions will be copied and added to the basic role.
Note: Make sure to increment the role version for the changes to be accounted for.

You can also change basic roles’ permissions using the API. Refer to the RBAC HTTP API for more details.

Reset basic roles to their default

This section describes how to reset the basic roles to their default:

  1. Open the YAML configuration file and locate the roles section.

  2. Grant the action: "roles:write", scope: "permissions:type:escalate permission to Grafana Admin. Note that this permission has not been granted to any basic roles by default, because users could acquire more permissions than they previously had through the basic role permissions reset.

    1. apiVersion: 2
    2. roles:
    3. - name: 'basic:grafana_admin'
    4. global: true
    5. version: 3
    6. from:
    7. - name: 'basic:grafana_admin'
    8. global: true
    9. permissions:
    10. # Permission allowing to reset basic roles
    11. - action: 'roles:write'
    12. scope: 'permissions:type:escalate'
  3. As a Grafana Admin, call the API endpoint to reset the basic roles to their default. Refer to the RBAC HTTP API for more details.

Delete a custom role using Grafana provisioning

Delete a custom role when you no longer need it. When you delete a custom role, the custom role is removed from users and teams to which it is assigned.

Before you begin:

  • Identify the role or roles that you want to delete.
  • Ensure that you have access to the YAML configuration file.

To delete a custom role:

  1. Open the YAML configuration file and locate the roles section.

  2. Refer to the following table to add attributes and values.

    AttributeDescription
    nameThe name of the custom role you want to delete. You can specify a uid instead of a role name. The role name or the uid are required.
    orgIdIdentifies the organization to which the role belongs.
    stateThe state of the role set to absent to trigger its removal.
    forceWhen set to true, the roles are removed even if there are existing assignments.
  3. Reload the provisioning configuration file.

    For more information about reloading the provisioning configuration at runtime, refer to Reload provisioning configurations.

The following example deletes a custom role:

  1. # config file version
  2. apiVersion: 2
  3. roles:
  4. - name: 'custom:reports:editor'
  5. orgId: 1
  6. state: 'absent'
  7. force: true

You can also delete a custom role using the API. Refer to the RBAC HTTP API for more details.