Files
grafana/docs/sources/developers/http_api/datasource_permissions.md
Jack Baldry ebb54aea8d Fix website build errors both for Grafana and content mounted in Grafana Cloud (#64794)
* Fix reference to Grafana CLI

- Make relref for relative permalink
- Use relative path for unambiguous resolution

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Fix alerting relref anchor format

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Avoid ambiguous relref lookups by forcing relative resolution

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Remove reference to non-existent shared page

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Fix links broken in Grafana Cloud using absolute relrefs

By resolving the relref absolutely, it refers to the same location
regardless of mounted directory.

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Remove trailing slash for bundle independent resolution

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Fix typo

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* For now, avoid Hugo checking cross repository /docs/grafana-cloud link

The path is unlikely to change in the short term and this makes CI
completely green for now.

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* No need to specify path for in page anchors

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>

* Fix prose

Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>

---------

Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
2023-03-15 17:06:31 +00:00

8.2 KiB

aliases canonical description keywords title
../../http_api/datasource_permissions/
../../http_api/datasourcepermissions/
/docs/grafana/latest/developers/http_api/datasource_permissions/ Data Source Permissions API
grafana
http
documentation
api
datasource
permission
permissions
acl
enterprise
Datasource Permissions HTTP API

Data Source Permissions API

The Data Source Permissions is only available in Grafana Enterprise. Read more about [Grafana Enterprise]({{< relref "/docs/grafana/latest/introduction/grafana-enterprise" >}}).

If you are running Grafana Enterprise, for some endpoints you'll need to have specific permissions. Refer to [Role-based access control permissions]({{< relref "/docs/grafana/latest/administration/roles-and-permissions/access-control/custom-role-actions-scopes" >}}) for more information.

This API can be used to enable, disable, list, add and remove permissions for a data source.

Permissions can be set for a user or a team. Permissions cannot be set for Admins - they always have access to everything.

The permission levels for the permission field:

  • 1 = Query

Enable permissions for a data source

POST /api/datasources/:id/enable-permissions

Enables permissions for the data source with the given id. No one except Org Admins will be able to query the data source until permissions have been added which permit certain users or teams to query the data source.

Required permissions

See note in the [introduction]({{< ref "#data-source-permissions-api" >}}) for an explanation.

Action Scope
datasources.permissions:write datasources:*
datasources🆔*
datasources🆔1 (single data source)

Examples

Example request:

POST /api/datasources/1/enable-permissions
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{}

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35

{"message":"Datasource permissions enabled"}

Status codes:

  • 200 - Ok
  • 400 - Permissions cannot be enabled, see response body for details
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Disable permissions for a data source

POST /api/datasources/:id/disable-permissions

Disables permissions for the data source with the given id. All existing permissions will be removed and anyone will be able to query the data source.

Required permissions

See note in the [introduction]({{< ref "#data-source-permissions-api" >}}) for an explanation.

Action Scope
datasources.permissions:write datasources:*
datasources🆔*
datasources🆔1 (single data source)

Examples

Example request:

POST /api/datasources/1/disable-permissions
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{}

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35

{"message":"Datasource permissions disabled"}

Status codes:

  • 200 - Ok
  • 400 - Permissions cannot be disabled, see response body for details
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Get permissions for a data source

GET /api/datasources/:id/permissions

Gets all existing permissions for the data source with the given id.

Required permissions

See note in the [introduction]({{< ref "#data-source-permissions-api" >}}) for an explanation.

Action Scope
datasources.permissions:read datasources:*
datasources🆔*
datasources🆔1 (single data source)

Examples

Example request:

GET /api/datasources/1/permissions HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 551

{
  "datasourceId": 1,
  "enabled": true,
  "permissions":
  [
    {
      "id": 1,
      "datasourceId": 1,
      "userId": 1,
      "userLogin": "user",
      "userEmail": "user@test.com",
      "userAvatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56",
      "permission": 1,
      "permissionName": "Query",
      "created": "2017-06-20T02:00:00+02:00",
      "updated": "2017-06-20T02:00:00+02:00",
    },
    {
      "id": 2,
      "datasourceId": 1,
      "teamId": 1,
      "team": "A Team",
      "teamAvatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56",
      "permission": 1,
      "permissionName": "Query",
      "created": "2017-06-20T02:00:00+02:00",
      "updated": "2017-06-20T02:00:00+02:00",
    }
  ]
}

Status codes:

  • 200 - Ok
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Add permission for a data source

POST /api/datasources/:id/permissions

Adds a user permission for the data source with the given id.

Required permissions

See note in the [introduction]({{< ref "#data-source-permissions-api" >}}) for an explanation.

Action Scope
datasources.permissions:write datasources:*
datasources🆔*
datasources🆔1 (single data source)

Examples

Example request:

POST /api/datasources/1/permissions
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{
  "userId": 1,
  "permission": 1
}

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35

{"message":"Datasource permission added"}

Adds a team permission for the data source with the given id.

Example request:

POST /api/datasources/1/permissions
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{
  "teamId": 1,
  "permission": 1
}

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35

{"message":"Datasource permission added"}

Status codes:

  • 200 - Ok
  • 400 - Permission cannot be added, see response body for details
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Remove permission for a data source

DELETE /api/datasources/:id/permissions/:permissionId

Removes the permission with the given permissionId for the data source with the given id.

Required permissions

See note in the [introduction]({{< ref "#data-source-permissions-api" >}}) for an explanation.

Action Scope
datasources.permissions:write datasources:*
datasources🆔*
datasources🆔1 (single data source)

Examples

Example request:

DELETE /api/datasources/1/permissions/2
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example response:

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 35

{"message":"Datasource permission removed"}

Status codes:

  • 200 - Ok
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found or permission not found