Provisioning

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

    The configuration files must be placed in provisioning/access-control/. Grafana performs provisioning during the startup. Refer to the 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.

    To create or update custom roles, you can add a list of 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 accounted for.

    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 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. version: 1
    7. global: true
    8. permissions:
    9. - action: 'users:read'
    10. scope: 'users:*'
    11. - action: 'users:write'
    12. scope: 'users:*'
    13. - action: 'users:create'
    14. 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.

    Here is an example YAML file to delete a role:

    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.

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

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

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

    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:

    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

    • Refer to Permissions for full list of valid permissions.
    • Check 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.
    • 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.

    Role deletion

    • Either the role name or must be provided