Provisioning

You can create, change or remove Custom roles and create or remove built-in role assignments, by adding one or more YAML configuration files in the provisioning/access-control/ directory. Refer to Grafana provisioning to learn more about provisioning.

If you want to manage roles and built-in role assignments by API, refer to the Fine-grained access control HTTP API.

Configuration

The configuration files must be placed in provisioning/access-control/. Grafana performs provisioning during the startup. Refer to the Reload provisioning configurations to understand how you can reload configuration at runtime.

Manage custom roles

You can create, update, and delete custom roles, as well as create and remove built-in role assignments.

Create or update roles

To create or update custom roles, you can add a list of roles in the configuration.

Every role has a version number. For each role you update, you must remember to increment it, otherwise changes won’t be applied.

When you update a role, the existing role inside Grafana is altered to be exactly what is specified in the YAML file, including permissions.

Here is an example YAML file to create a local role with a set of permissions:

  1. # config file version
  2. apiVersion: 1
  3. # Roles to insert into the database, or roles to update in the database
  4. roles:
  5. - name: custom:users:editor
  6. description: 'This role allows users to list, create, or update other users within the organization.'
  7. version: 1
  8. orgId: 1
  9. permissions:
  10. - action: 'users:read'
  11. scope: 'users:*'
  12. - action: 'users:write'
  13. scope: 'users:*'
  14. - action: 'users:create'
  15. scope: 'users:*'

Here is an example YAML file to create a global role with a set of permissions, where the global:true option makes a role global:

  1. # config file version
  2. apiVersion: 1
  3. # Roles to insert into the database, or roles to update in the database
  4. roles:
  5. - name: custom:users:editor
  6. description: 'This role allows users to list, create, or update other users within the organization.'
  7. version: 1
  8. global: true
  9. permissions:
  10. - action: 'users:read'
  11. scope: 'users:*'
  12. - action: 'users:write'
  13. scope: 'users:*'
  14. - action: 'users:create'
  15. scope: 'users:*'

The orgId is lost when the role is set to global.

Delete roles

To delete a role, add a list of roles under the deleteRoles section in the configuration file.

Note: Any role in the deleteRoles section is deleted before any role in the roles section is saved.

Here is an example YAML file to delete a role:

  1. # config file version
  2. apiVersion: 1
  3. # list of roles that should be deleted
  4. deleteRoles:
  5. - name: custom:reports:editor
  6. orgId: 1
  7. force: true

Assign your custom role to specific built-in roles

To assign roles to built-in roles, add said built-in roles to the builtInRoles section of your roles. To remove a specific assignment, remove it from the list.

Note: Assignments are updated if the version of the role is greater or equal to the one stored internally. You don’t need to increment the version number of the role to update its assignments.

For example, the following role is assigned to an organization editor or an organization administrator:

  1. # config file version
  2. apiVersion: 1
  3. # Roles to insert/update in the database
  4. roles:
  5. - name: custom:users:editor
  6. description: 'This role allows users to list/create/update other users in the organization'
  7. version: 1
  8. orgId: 1
  9. permissions:
  10. - action: 'users:read'
  11. scope: 'users:*'
  12. - action: 'users:write'
  13. scope: 'users:*'
  14. - action: 'users:create'
  15. scope: 'users:*'
  16. builtInRoles:
  17. - name: 'Editor'
  18. - name: 'Admin'

Assign your custom role to specific teams

To assign roles to teams, add said teams to the teams section of your roles. To remove a specific assignment, remove it from the list.

Note: Assignments are updated if the version of the role is greater or equal to the one stored internally.
You don’t need to increment the version number of the role to update its assignments.
Assignments to built-in roles will be ignored. Use addDefaultAssignments and removeDefaultAssignments instead.

In order for provisioning to succeed, specified teams must already exist. Additionally, since teams are local to an organization, the organization has to be specified in the assignment.

For example, the following role is assigned to the user editors team and user admins team:

  1. # config file version
  2. apiVersion: 1
  3. # Roles to insert/update in the database
  4. roles:
  5. - name: custom:users:writer
  6. description: 'List/update other users in the organization'
  7. version: 1
  8. global: true
  9. permissions:
  10. - action: 'org.users:read'
  11. scope: 'users:*'
  12. - action: 'org.users:write'
  13. scope: 'users:*'
  14. teams:
  15. - name: 'user editors'
  16. orgId: 1
  17. - name: 'user admins'
  18. orgId: 1

Assign fixed roles to specific teams

To assign a fixed role to teams, add said teams to the teams section of the associated entry. To remove a specific assignment, remove it from the list.

Note: Since fixed roles are global, the Global attribute has to be specified. A fixed role will never be updated through provisioning.

In order for provisioning to succeed, specified teams must already exist. Additionally, since teams are local to an organization, the organization has to be specified in the assignment.

For example, the following fixed role is assigned to the user editors team and user admins team:

  1. # config file version
  2. apiVersion: 1
  3. # Roles to insert/update in the database
  4. roles:
  5. - name: fixed:users:writer
  6. global: true
  7. teams:
  8. - name: 'user editors'
  9. orgId: 1
  10. - name: 'user admins'
  11. orgId: 1

Manage default built-in role assignments

During startup, Grafana creates default built-in role assignments with fixed roles. You can remove and later restore those assignments with provisioning.

Remove default assignment

To remove default built-in role assignments, use the removeDefaultAssignments element in the configuration file. You need to provide the built-in role name and fixed role name.

Here is an example:

  1. # config file version
  2. apiVersion: 1
  3. # list of default built-in role assignments that should be removed
  4. removeDefaultAssignments:
  5. - builtInRole: 'Grafana Admin'
  6. fixedRole: 'fixed:permissions:admin'

Restore default assignment

To restore the default built-in role assignment, use the addDefaultAssignments element in the configuration file. You need to provide the built-in role name and the fixed-role name.

Here is an example:

  1. # config file version
  2. apiVersion: 1
  3. # list of default built-in role assignments that should be added back
  4. addDefaultAssignments:
  5. - builtInRole: 'Admin'
  6. fixedRole: 'fixed:reporting:admin:read'

Full example of a role configuration file

  1. # config file version
  2. apiVersion: 1
  3. # list of default built-in role assignments that should be removed
  4. removeDefaultAssignments:
  5. # <string>, must be one of the Organization roles (`Viewer`, `Editor`, `Admin`) or `Grafana Admin`
  6. - builtInRole: 'Grafana Admin'
  7. # <string>, must be one of the existing fixed roles
  8. fixedRole: 'fixed:permissions:admin'
  9. # list of default built-in role assignments that should be added back
  10. addDefaultAssignments:
  11. # <string>, must be one of the Organization roles (`Viewer`, `Editor`, `Admin`) or `Grafana Admin`
  12. - builtInRole: 'Admin'
  13. # <string>, must be one of the existing fixed roles
  14. fixedRole: 'fixed:reporting:admin:read'
  15. # list of roles that should be deleted
  16. deleteRoles:
  17. # <string> name of the role you want to create. Required if no uid is set
  18. - name: 'custom:reports:editor'
  19. # <string> uid of the role. Required if no name
  20. uid: 'customreportseditor1'
  21. # <int> org id. will default to Grafana's default if not specified
  22. orgId: 1
  23. # <bool> force deletion revoking all grants of the role
  24. force: true
  25. - name: 'custom:global:reports:reader'
  26. uid: 'customglobalreportsreader1'
  27. # <bool> overwrite org id and removes a global role
  28. global: true
  29. force: true
  30. # list of roles to insert/update depending on what is available in the database
  31. roles:
  32. # <string, required> name of the role you want to create. Required
  33. - name: 'custom:users:editor'
  34. # <string> uid of the role. Has to be unique for all orgs.
  35. uid: customuserseditor1
  36. # <string> description of the role, informative purpose only.
  37. description: 'Role for our custom user editors'
  38. # <int> version of the role, Grafana will update the role when increased
  39. version: 2
  40. # <int> org id. will default to Grafana's default if not specified
  41. orgId: 1
  42. # <list> list of the permissions granted by this role
  43. permissions:
  44. # <string, required> action allowed
  45. - action: 'users:read'
  46. #<string> scope it applies to
  47. scope: 'users:*'
  48. - action: 'users:write'
  49. scope: 'users:*'
  50. - action: 'users:create'
  51. scope: 'users:*'
  52. # <list> list of builtIn roles the role should be assigned to
  53. builtInRoles:
  54. # <string, required> name of the builtin role you want to assign the role to
  55. - name: 'Editor'
  56. # <int> org id. will default to the role org id
  57. orgId: 1
  58. - name: 'custom:global:users:reader'
  59. uid: 'customglobalusersreader1'
  60. description: 'Global Role for custom user readers'
  61. version: 1
  62. # <bool> overwrite org id and creates a global role
  63. global: true
  64. permissions:
  65. - action: 'users:read'
  66. scope: 'users:*'
  67. builtInRoles:
  68. - name: 'Viewer'
  69. orgId: 1
  70. - name: 'Editor'
  71. # <bool> overwrite org id and assign role globally
  72. global: true
  73. - name: fixed:users:writer
  74. global: true
  75. # <list> list of teams the role should be assigned to
  76. teams:
  77. - name: 'user editors'
  78. orgId: 1

Supported settings

The following sections detail the supported settings for roles and built-in role assignments.

  • Refer to Permissions for full list of valid permissions.
  • Check Custom roles to understand attributes for roles.
  • The default org ID is used if orgId is not specified in any of the configuration blocks.

Validation rules

A basic set of validation rules are applied to the input yaml files.

Roles

  • name must not be empty
  • name must not have fixed: prefix.

Permissions

  • name must not be empty

Built-in role assignments

  • name must be one of the Organization roles (Viewer, Editor, Admin) or Grafana Admin.
  • When orgId is not specified, it inherits the orgId from role. For global roles the default orgId is used.
  • orgId in the role and in the assignment must be the same for none global roles.

Role deletion

  • Either the role name or uid must be provided