Fine-grained access control API

The API can be used to create, update, get and list roles, and create or remove built-in role assignments. To use the API, you would need to enable fine-grained access control.

The API does not currently work with an API Token. So in order to use these API endpoints you will have to use .

Returns an indicator to check if fine-grained access control is enabled or not.

Example request

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "enabled": true
  5. }

Status codes

CodeDescription
200Returned a flag indicating if the fine-grained access control is enabled or no.
403Access denied
404Not found, an indication that fine-grained access control is not available at all.
500Unexpected error. Refer to body and/or server logs for more details.

Get all roles

GET /api/access-control/roles

Gets all existing roles. The response contains all global and organization local roles, for the organization which user is signed in.

Refer to the for more information.

Required permissions

ActionScope
roles:listroles:*

Example request

  1. GET /api/access-control/roles
  2. Accept: application/json
  3. Content-Type: application/json

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. [
  4. {
  5. "version": 3,
  6. "uid": "XvHQJq57z",
  7. "name": "fixed:reports:reader",
  8. "displayName": "Report reader",
  9. "description": "Read all reports and shared report settings.",
  10. "group": "Reports",
  11. "updated": "2021-11-19T10:48:00+01:00",
  12. "created": "2021-11-19T10:48:00+01:00",
  13. "global": false
  14. },
  15. {
  16. "version": 4,
  17. "uid": "6dNwJq57z",
  18. "name": "fixed:reports:writer",
  19. "displayName": "Report writer",
  20. "description": "Create, read, update, or delete all reports and shared report settings.",
  21. "group": "Reports",
  22. "updated": "2021-11-19T10:48:00+01:00",
  23. "created": "2021-11-19T10:48:00+01:00",
  24. "global": false
  25. },
  26. ]

Status codes

CodeDescription
200Global and organization local roles are returned.
403Access denied
500Unexpected error. Refer to body and/or server logs for more details.

Get a role

GET /api/access-control/roles/:uid

Get a role for the given UID.

Required permissions

ActionScope
roles:readroles:*

Example request

  1. GET /api/access-control/roles/PYnDO3rMk
  2. Accept: application/json
  3. Content-Type: application/json

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "uid": "6dNwJq57z",
  5. "name": "fixed:reports:writer",
  6. "displayName": "Report writer",
  7. "description": "Create, read, update, or delete all reports and shared report settings.",
  8. "group": "Reports",
  9. "permissions": [
  10. {
  11. "action": "reports:delete",
  12. "scope": "reports:*",
  13. "updated": "2021-11-19T10:48:00+01:00",
  14. "created": "2021-11-19T10:48:00+01:00"
  15. },
  16. {
  17. "action": "reports:read",
  18. "scope": "reports:*",
  19. "updated": "2021-11-19T10:48:00+01:00",
  20. "created": "2021-11-19T10:48:00+01:00"
  21. },
  22. {
  23. "action": "reports:send",
  24. "scope": "reports:*",
  25. "updated": "2021-11-19T10:48:00+01:00",
  26. "created": "2021-11-19T10:48:00+01:00"
  27. },
  28. {
  29. "action": "reports.admin:create",
  30. "scope": "",
  31. "updated": "2021-11-19T10:48:00+01:00",
  32. "created": "2021-11-19T10:48:00+01:00"
  33. },
  34. {
  35. "action": "reports.admin:write",
  36. "scope": "reports:*",
  37. "updated": "2021-11-19T10:48:00+01:00",
  38. "created": "2021-11-19T10:48:00+01:00"
  39. },
  40. {
  41. "action": "reports.settings:read",
  42. "scope": "",
  43. "updated": "2021-11-19T10:48:00+01:00",
  44. "created": "2021-11-19T10:48:00+01:00"
  45. },
  46. {
  47. "action": "reports.settings:write",
  48. "scope": "",
  49. "updated": "2021-11-19T10:48:00+01:00",
  50. "created": "2021-11-19T10:48:00+01:00"
  51. }
  52. ],
  53. "updated": "2021-11-19T10:48:00+01:00",
  54. "created": "2021-11-19T10:48:00+01:00",
  55. "global": false
  56. }

Status codes

CodeDescription
200Role is returned.
403Access denied.
500Unexpected error. Refer to body and/or server logs for more details.

Create a new custom role

POST /api/access-control/roles

Creates a new custom role and maps given permissions to that role. Note that roles with the same prefix as Fixed Roles can’t be created.

Required permissions

permission:delegate scope ensures that users can only create custom roles with the same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to create a custom role which allows to do that. This is done to prevent escalation of privileges.

ActionScope
roles:writepermissions:delegate

Example request

  1. POST /api/access-control/roles
  2. Accept: application/json
  3. Content-Type: application/json
  4. {
  5. "version": 1,
  6. "uid": "jZrmlLCGka",
  7. "name": "custom:delete:roles",
  8. "group":"My Group",
  9. "displayName": "My Custom Role",
  10. "global": false,
  11. "permissions": [
  12. {
  13. "action": "roles:delete",
  14. "scope": "permissions:delegate"
  15. }
  16. ]
  17. }

JSON body schema

Field NameDate TypeRequiredDescription
uidstringNoUID of the role. If not present, the UID will be automatically created for you and returned in response. Refer to the Custom roles for more information.
globalbooleanNoA flag indicating if the role is global or not. If set to false, the default org ID of the authenticated user will be used from the request. Refer to the for more information.
versionnumberNoVersion of the role. If not present, version 0 will be assigned to the role and returned in the response. Refer to the Custom roles for more information.
namestringYesName of the role. Refer to for more information.
descriptionstringNoDescription of the role.
displayNamestringNoDisplay name of the role, visible in the UI.
groupstringNoThe group name the role belongs to.
permissionsPermissionNoIf not present, the role will be created without any permissions.

Permission

Field NameData TypeRequiredDescription
actionstringYesRefer to Permissions for full list of available actions.
scopestringNoIf not present, no scope will be mapped to the permission. Refer to for full list of available scopes.

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "version": 2,
  5. "uid": "jZrmlLCGka",
  6. "name": "custom:delete:create:roles",
  7. "description": "My custom role which gives users permissions to delete and create roles",
  8. "group":"My Group",
  9. "displayName": "My Custom Role",
  10. "global": false,
  11. "permissions": [
  12. {
  13. "action": "roles:delete",
  14. "scope": "permissions:delegate",
  15. "updated": "2021-05-13T23:19:46+02:00",
  16. "created": "2021-05-13T23:19:46+02:00"
  17. }
  18. ],
  19. "updated": "2021-05-13T23:20:51.416518+02:00",
  20. "created": "2021-05-13T23:19:46+02:00"
  21. }

Status codes

CodeDescription
200Role is updated.
400Bad request (invalid json, missing content-type, missing or invalid fields, etc.).
403Access denied
500Unexpected error. Refer to body and/or server logs for more details.

PUT /api/access-control/roles/:uid

Required permissions

permission:delegate scope ensures that users can only update custom roles with the same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to update a custom role which allows to do that. This is done to prevent escalation of privileges.

ActionScope
roles:writepermissions:delegate

Example request

  1. PUT /api/access-control/roles/jZrmlLCGka
  2. Accept: application/json
  3. Content-Type: application/json
  4. {
  5. "version": 3,
  6. "name": "custom:delete:write:roles",
  7. "description": "My custom role which gives users permissions to delete and write roles",
  8. "group":"My Group",
  9. "displayName": "My Custom Role",
  10. "global": false,
  11. "permissions": [
  12. {
  13. "action": "roles:delete",
  14. "scope": "permissions:delegate"
  15. },
  16. {
  17. "action": "roles:write",
  18. "scope": "permissions:delegate"
  19. }
  20. ]
  21. }

JSON body schema

Field NameData TypeRequiredDescription
versionnumberYesVersion of the role. Must be incremented for update to work.
namestringYesName of the role.
descriptionstringNoDescription of the role.
displayNamestringNoDisplay name of the role, visible in the UI.
groupstringNoThe group name the role belongs to.
permissionsList of PermissionsNoThe full list of permissions the role should have after the update.

Permission

Example response

Status codes

CodeDescription
200Role is updated.
400Bad request (invalid json, missing content-type, missing or invalid fields, etc.).
403Access denied
404Role was not found to update.
500Unexpected error. Refer to body and/or server logs for more details.

Delete a custom role

DELETE /api/access-control/roles/:uid?force=false

Delete a role with the given UID, and it’s permissions. If the role is assigned to a built-in role, the deletion operation will fail, unless force query param is set to true, and in that case all assignments will also be deleted.

Required permissions

permission:delegate scope ensures that users can only delete a custom role with the same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to delete a custom role which allows to do that.

ActionScope
roles:deletepermissions:delegate

Example request

  1. DELETE /api/access-control/roles/jZrmlLCGka?force=true&global=false
  2. Accept: application/json

Query parameters

ParamTypeRequiredDescription
forcebooleanNoWhen set to true, the role will be deleted with all it’s assignments.

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "message": "Role deleted"
  5. }

Status codes

CodeDescription
200Role is deleted.
400Bad request (invalid json, missing content-type, missing or invalid fields, etc.).
403Access denied
500Unexpected error. Refer to body and/or server logs for more details.

List roles assigned to a user

GET /api/access-control/users/:userId/roles

Lists the roles that have been directly assigned to a given user. The list does not include built-in roles (Viewer, Editor, Admin or Grafana Admin), and it does not include roles that have been inherited from a team.

Required permissions

ActionScope
users.roles:listusers:id:<user ID>

Example request

  1. Accept: application/json

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. [
  4. {
  5. "version": 4,
  6. "uid": "6dNwJq57z",
  7. "name": "fixed:reports:writer",
  8. "displayName": "Report writer",
  9. "description": "Create, read, update, or delete all reports and shared report settings.",
  10. "group": "Reports",
  11. "updated": "2021-11-19T10:48:00+01:00",
  12. "created": "2021-11-19T10:48:00+01:00",
  13. "global": false
  14. }
  15. ]

Status codes

CodeDescription
200Set of assigned roles is returned.
403Access denied.
500Unexpected error. Refer to body and/or server logs for more details.

List permissions assigned to a user

GET /api/access-control/users/:userId/permissions

Lists the permissions that a given user has.

Required permissions

ActionScope
users.permissions:listusers:id:<user ID>

Example request

  1. GET /api/access-control/users/1/permissions
  2. Accept: application/json

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. [
  4. {
  5. "action": "ldap.status:read",
  6. "scope": ""
  7. },
  8. {
  9. "action": "ldap.user:read",
  10. "scope": ""
  11. }
  12. ]

Status codes

CodeDescription
200Set of assigned permissions is returned.
403Access denied.
500Unexpected error. Refer to body and/or server logs for more details.

POST /api/access-control/users/:userId/roles

Assign a role to a specific user.

For bulk updates consider Set user role assignments.

Required permissions

permission:delegate scope ensures that users can only assign roles which have same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to assign a role which will allow to do that. This is done to prevent escalation of privileges.

ActionScope
users.roles:addpermissions:delegate

Example request

  1. Accept: application/json
  2. Content-Type: application/json
  3. {
  4. "global": false,
  5. "roleUid": "XvHQJq57z"
  6. }

JSON body schema

Field NameData TypeRequiredDescription
roleUidstringYesUID of the role.
globalbooleanNoA flag indicating if the assignment is global or not. If set to false, the default org ID of the authenticated user will be used from the request to create organization local assignment.

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "message": "Role added to the user."
  5. }

Status codes

CodeDescription
200Role is assigned to a user.
403Access denied.
404Role not found.
500Unexpected error. Refer to body and/or server logs for more details.

DELETE /api/access-control/users/:userId/roles/:roleUID

For bulk updates consider .

Required permissions

permission:delegate scope ensures that users can only unassign roles which have same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to unassign a role which will allow to do that. This is done to prevent escalation of privileges.

Query parameters

ParamTypeRequiredDescription
globalbooleanNoA flag indicating if the assignment is global or not. If set to false, the default org ID of the authenticated user will be used from the request to remove assignment.

Example request

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "message": "Role removed from user."
  5. }

Status codes

CodeDescription
200Role is unassigned.
403Access denied.
500Unexpected error. Refer to body and/or server logs for more details.

Set user role assignments

PUT /api/access-control/users/:userId/roles

Update the user’s role assignments to match the provided set of UIDs. This will remove any assigned roles that aren’t in the request and add roles that are in the set but are not already assigned to the user.

If you want to add or remove a single role, consider using Add a user role assignment or instead.

Required permissions

permission:delegate scope ensures that users can only assign or unassign roles which have same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to assign or unassign a role which will allow to do that. This is done to prevent escalation of privileges.

ActionScope
users.roles:addpermissions:delegate
users.roles:removepermissions:delegate

Example request

  1. PUT /api/access-control/users/1/roles
  2. Accept: application/json
  3. Content-Type: application/json
  4. {
  5. "global": false,
  6. "roleUids": [
  7. "ZiHQJq5nk",
  8. "GzNQ1357k"
  9. ]
  10. }

JSON body schema

Field NameDate TypeRequiredDescription
globalbooleanNoA flag indicating if the assignment is global or not. If set to false, the default org ID of the authenticated user will be used from the request.
roleUidslistYesList of role UIDs.

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "message": "User roles have been updated."
  5. }

Status codes

CodeDescription
200Roles have been assigned.
403Access denied.
404Role not found.
500Unexpected error. Refer to body and/or server logs for more details.

API set allows to create or remove built-in role assignments and list current assignments.

Get all built-in role assignments

GET /api/access-control/builtin-roles

Gets all built-in role assignments.

Required permissions

ActionScope
roles.builtin:listroles:*

Example request

  1. GET /api/access-control/builtin-roles
  2. Accept: application/json
  3. Content-Type: application/json

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "Admin": [
  5. {
  6. "version": 1,
  7. "uid": "qQui_LCMk",
  8. "name": "fixed:users:org:edit",
  9. "description": "",
  10. "global": false,
  11. "updated": "2021-05-13T16:24:26+02:00",
  12. "created": "2021-05-13T16:24:26+02:00"
  13. },
  14. {
  15. "version": 1,
  16. "uid": "PeXmlYjMk",
  17. "name": "fixed:users:org:read",
  18. "description": "",
  19. "global": false,
  20. "updated": "2021-05-13T16:24:26+02:00",
  21. "created": "2021-05-13T16:24:26+02:00"
  22. }
  23. ],
  24. "Grafana Admin": [
  25. {
  26. "version": 1,
  27. "uid": "qQui_LCMk",
  28. "name": "fixed:users:org:edit",
  29. "description": "",
  30. "global": false,
  31. "updated": "2021-05-13T16:24:26+02:00",
  32. "created": "2021-05-13T16:24:26+02:00"
  33. }
  34. ]
  35. }

Status codes

CodeDescription
200Built-in role assignments are returned.
403Access denied
500Unexpected error. Refer to body and/or server logs for more details.

Create a built-in role assignment

POST /api/access-control/builtin-roles

Creates a new built-in role assignment.

Required permissions

permission:delegate scope ensures that users can only create built-in role assignments with the roles which have same, or a subset of permissions which the user has. For example, if a user does not have required permissions for creating users, they won’t be able to create a built-in role assignment which will allow to do that. This is done to prevent escalation of privileges.

ActionScope
roles.builtin:addpermissions:delegate

Example request

  1. POST /api/access-control/builtin-roles
  2. Accept: application/json
  3. Content-Type: application/json
  4. {
  5. "roleUid": "LPMGN99Mk",
  6. "builtinRole": "Grafana Admin",
  7. "global": false
  8. }

JSON body schema

Field NameDate TypeRequiredDescription
roleUidstringYesUID of the role.
builtinRolebooleanYesCan be one of Viewer, Editor, Admin or Grafana Admin.
globalbooleanNoA flag indicating if the assignment is global or not. If set to false, the default org ID of the authenticated user will be used from the request to create organization local assignment. Refer to the Built-in role assignments for more information.

Example response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. {
  4. "message": "Built-in role grant added"
  5. }

Status codes

CodeDescription
200Role was assigned to built-in role.
400Bad request (invalid json, missing content-type, missing or invalid fields, etc.).
403Access denied
404Role not found
500Unexpected error. Refer to body and/or server logs for more details.

DELETE /api/access-control/builtin-roles/:builtinRole/roles/:roleUID

Deletes a built-in role assignment (for one of Viewer, Editor, Admin, or Grafana Admin) to the role with the provided UID.

Required permissions

ActionScope
roles.builtin:removepermissions:delegate

Example request

  1. DELETE /api/access-control/builtin-roles/Grafana%20Admin/roles/LPMGN99Mk?global=false

Query parameters

Example response

Status codes

CodeDescription
200Role was unassigned from built-in role.
400Bad request (invalid json, missing content-type, missing or invalid fields, etc.).
403Access denied
404Role not found.
500Unexpected error. Refer to body and/or server logs for more details.