grafana/docs/sources/developers/http_api/datasource_permissions.md

343 lines
8.9 KiB
Markdown
Raw Normal View History

---
aliases:
- ../../http_api/datasource_permissions/
- ../../http_api/datasourcepermissions/
canonical: /docs/grafana/latest/developers/http_api/datasource_permissions/
description: Data Source Permissions API
keywords:
- grafana
- http
- documentation
- api
- datasource
- permission
- permissions
- acl
- enterprise
Explicitly set all front matter labels in the source files (#71548) * Set every page to have defaults of 'Enterprise' and 'Open source' labels Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set administration/enterprise-licensing pages to have 'Enterprise' labels Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set administration/recorded-queries pages to have labels cloud,enterprise * Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set administration/stats-and-license pages to have labels cloud,enterprise * Set alerting pages to have labels cloud,enterprise,oss * Set breaking-changes pages to have labels cloud,enterprise,oss * Set dashboards pages to have labels cloud,enterprise,oss * Set datasources pages to have labels cloud,enterprise,oss * Set explore pages to have labels cloud,enterprise,oss * Set fundamentals pages to have labels cloud,enterprise,oss * Set introduction/grafana-cloud pages to have labels cloud Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Fix introduction pages products Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set panels-visualizations pages to have labels cloud,enterprise,oss * Set release-notes pages to have labels cloud,enterprise,oss * Set search pages to have labels cloud,enterprise,oss * Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss * Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise * Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise * Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise * Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Set troubleshooting pages to have labels cloud,enterprise,oss * Set whatsnew pages to have labels cloud,enterprise,oss * Apply updated labels from review Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com> Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --------- Signed-off-by: Jack Baldry <jack.baldry@grafana.com> Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com> Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
labels:
products:
- enterprise
- oss
title: Datasource Permissions HTTP API
---
2018-10-31 02:02:12 +08:00
2019-09-20 06:22:38 +08:00
# Data Source Permissions API
2018-10-31 02:02:12 +08:00
> The Data Source Permissions is only available in Grafana Enterprise. Read more about [Grafana Enterprise](/docs/grafana/latest/introduction/grafana-enterprise/).
2018-10-31 02:02:12 +08:00
> If you are running Grafana Enterprise, for some endpoints you'll need to have specific permissions. Refer to [Role-based access control permissions](/docs/grafana/latest/administration/roles-and-permissions/access-control/custom-role-actions-scopes/) for more information.
This API can be used to list, add and remove permissions for a data source.
2018-10-31 02:02:12 +08:00
Permissions can be set for a user, team, service account or a basic role (Admin, Editor, Viewer).
2018-10-31 02:02:12 +08:00
## Get permissions for a data source
2018-10-31 02:02:12 +08:00
`GET /api/access-control/datasources/:uid`
2018-10-31 02:02:12 +08:00
Gets all existing permissions for the data source with the given `uid`.
2018-10-31 02:02:12 +08:00
2022-05-21 03:48:52 +08:00
**Required permissions**
See note in the [introduction](#data-source-permissions-api) for an explanation.
| Action | Scope |
| ---------------------------- | ------------------------------------------------------------------------------------------ |
| datasources.permissions:read | datasources:\*<br>datasources:uid:\*<br>datasources:uid:my_datasource (single data source) |
### Examples
**Example request:**
2018-10-31 02:02:12 +08:00
```http
GET /api/access-control/datasources/my_datasource HTTP/1.1
2018-10-31 02:02:12 +08:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
**Example response:**
2018-10-31 02:02:12 +08:00
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 551
2018-10-31 02:02:12 +08:00
[
{
"id": 1,
"roleName": "fixed:datasources:reader",
"isManaged": false,
"isInherited": false,
"isServiceAccount": false,
"userId": 1,
"userLogin": "admin_user",
"userAvatarUrl": "/avatar/admin_user",
"actions": [
"datasources:read",
"datasources:query",
"datasources:read",
"datasources:query",
"datasources:write",
"datasources:delete"
],
"permission": "Edit"
},
{
"id": 2,
"roleName": "managed:teams:1:permissions",
"isManaged": true,
"isInherited": false,
"isServiceAccount": false,
"team": "A team",
"teamId": 1,
"teamAvatarUrl": "/avatar/523d70c8551046f441727d690431858c",
"actions": [
"datasources:read",
"datasources:query"
],
"permission": "Query"
},
{
"id": 3,
"roleName": "basic:admin",
"isManaged": false,
"isInherited": false,
"isServiceAccount": false,
"builtInRole": "Admin",
"actions": [
"datasources:query",
"datasources:read",
"datasources:write",
"datasources:delete"
],
"permission": "Edit"
},
]
2018-10-31 02:02:12 +08:00
```
Status codes:
2018-10-31 02:02:12 +08:00
- **200** - Ok
- **401** - Unauthorized
- **403** - Access denied
- **500** - Internal error
2018-10-31 02:02:12 +08:00
## Add or revoke access to a data source for a user
2018-10-31 02:02:12 +08:00
`POST /api/access-control/datasources/:uid/users/:id`
2018-10-31 02:02:12 +08:00
Sets user permission for the data source with the given `uid`.
To add a permission, set the `permission` field to either `Query`, `Edit`, or `Admin`.
To remove a permission, set the `permission` field to an empty string.
2018-10-31 02:02:12 +08:00
2022-05-21 03:48:52 +08:00
**Required permissions**
See note in the [introduction](#data-source-permissions-api) for an explanation.
| Action | Scope |
| ----------------------------- | ------------------------------------------------------------------------------------------ |
| datasources.permissions:write | datasources:\*<br>datasources:uid:\*<br>datasources:uid:my_datasource (single data source) |
### Examples
**Example request:**
2018-10-31 02:02:12 +08:00
```http
POST /api/access-control/datasources/my_datasource/users/1
2018-10-31 02:02:12 +08:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"permission": "Query",
}
2018-10-31 02:02:12 +08:00
```
**Example response:**
2018-10-31 02:02:12 +08:00
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35
{"message": "Permission updated"}
2018-10-31 02:02:12 +08:00
```
**Example request:**
2018-10-31 02:02:12 +08:00
```http
POST /api/access-control/datasources/my_datasource/users/1
2018-10-31 02:02:12 +08:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"permission": "",
}
2018-10-31 02:02:12 +08:00
```
**Example response:**
2018-10-31 02:02:12 +08:00
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35
2018-10-31 02:02:12 +08:00
{"message": "Permission removed"}
2018-10-31 02:02:12 +08:00
```
Status codes:
2018-10-31 02:02:12 +08:00
- **200** - Ok
- **400** - Permission cannot be added, see response body for details
2018-10-31 02:02:12 +08:00
- **401** - Unauthorized
- **403** - Access denied
## Add or revoke access to a data source for a team
2018-10-31 02:02:12 +08:00
`POST /api/access-control/datasources/:uid/teams/:id`
2018-10-31 02:02:12 +08:00
Sets team permission for the data source with the given `uid`.
To add a permission, set the `permission` field to either `Query`, `Edit`, or `Admin`.
To remove a permission, set the `permission` field to an empty string.
2018-10-31 02:02:12 +08:00
2022-05-21 03:48:52 +08:00
**Required permissions**
See note in the [introduction](#data-source-permissions-api) for an explanation.
| Action | Scope |
| ----------------------------- | ------------------------------------------------------------------------------------------ |
| datasources.permissions:write | datasources:\*<br>datasources:uid:\*<br>datasources:uid:my_datasource (single data source) |
### Examples
**Example request:**
2018-10-31 02:02:12 +08:00
```http
POST /api/access-control/datasources/my_datasource/teams/1
2018-10-31 02:02:12 +08:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"permission": "Edit",
2018-10-31 02:02:12 +08:00
}
```
**Example response:**
2018-10-31 02:02:12 +08:00
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35
{"message": "Permission updated"}
2018-10-31 02:02:12 +08:00
```
**Example request:**
2018-10-31 02:02:12 +08:00
```http
POST /api/access-control/datasources/my_datasource/teams/1
2018-10-31 02:02:12 +08:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"permission": "",
2018-10-31 02:02:12 +08:00
}
```
**Example response:**
2018-10-31 02:02:12 +08:00
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35
{"message": "Permission removed"}
2018-10-31 02:02:12 +08:00
```
Status codes:
2018-10-31 02:02:12 +08:00
- **200** - Ok
- **400** - Permission cannot be added, see response body for details
- **401** - Unauthorized
- **403** - Access denied
## Add or revoke access to a data source for a basic role
2018-10-31 02:02:12 +08:00
`POST /api/access-control/datasources/:uid/builtInRoles/:builtinRoleName`
2018-10-31 02:02:12 +08:00
Sets permission for the data source with the given `uid` to all users who have the specified basic role.
You can set permissions for the following basic roles: `Admin`, `Editor`, `Viewer`.
To add a permission, set the `permission` field to either `Query`, `Edit`, or `Admin`.
To remove a permission, set the `permission` field to an empty string.
2018-10-31 02:02:12 +08:00
2022-05-21 03:48:52 +08:00
**Required permissions**
See note in the [introduction](#data-source-permissions-api) for an explanation.
| Action | Scope |
| ----------------------------- | ------------------------------------------------------------------------------------------ |
| datasources.permissions:write | datasources:\*<br>datasources:uid:\*<br>datasources:uid:my_datasource (single data source) |
### Examples
**Example request:**
2018-10-31 02:02:12 +08:00
```http
POST /api/access-control/datasources/my_datasource/builtInRoles/Admin
2018-10-31 02:02:12 +08:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"permission": "Edit",
}
2018-10-31 02:02:12 +08:00
```
**Example response:**
2018-10-31 02:02:12 +08:00
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35
{"message": "Permission updated"}
```
**Example request:**
```http
POST /api/access-control/datasources/my_datasource/builtInRoles/Viewer
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"permission": "",
}
```
**Example response:**
```http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35
{"message": "Permission removed"}
2018-10-31 02:02:12 +08:00
```
Status codes:
2018-10-31 02:02:12 +08:00
- **200** - Ok
- **400** - Permission cannot be added, see response body for details
2018-10-31 02:02:12 +08:00
- **401** - Unauthorized
- **403** - Access denied