docs/sources/administration/service-accounts/_index.md
Service accounts allow you to run automated workloads in Grafana, such as dashboard provisioning, configuration, or report generation using the Grafana API.
Note the following:
Use service accounts and tokens to perform operations on automated or triggered tasks such as:
The added benefits of service accounts to API keys include:
Service accounts only work in the organization they are created for. If you have the same task that is needed for multiple organizations, create service accounts in each organization.
Service accounts can't be used for instance-wide operations, such as global user management and organization management. These tasks require a user with Grafana server administrator permissions.
A service account token is a generated random string that acts as an alternative to a password when authenticating with the Grafana HTTP API. Use service access tokens the same way as API Keys, for example to access Grafana HTTP API programmatically. Service account access tokens inherit permissions from the service account.
When you create a service account, you can associate one or more access tokens with it. Create multiple tokens for the same service account if:
Use a service account to run automated workloads in Grafana, like dashboard provisioning, configuration, or report generation.
{{< admonition type="note" >}} To create service accounts via the API refer to Create a service account in the HTTP API. {{< /admonition >}}
In order to create a service account, a user must have:
fixed:roles:reader and fixed:serviceaccounts:creatorThe user who creates a service account can read, update and delete the service account that they created, as well as the permissions associated with that service account.
Ensure you have permission to create and edit service accounts. By default, the organization administrator role is required to create and edit service accounts. For more information about user permissions, refer to About users and permissions.
A service account token is a generated random string that acts as an alternative to a password when authenticating with Grafana’s HTTP API. For more information about service accounts, refer to About service accounts in Grafana.
You can create a service account token using the Grafana UI or via the API. For more information about creating a service account token via the API, refer to Create service account tokens using the HTTP API.
Ensure you have permission to create and edit service accounts. By default, the organization administrator role is required to create and edit service accounts. For more information about user permissions, refer to About users and permissions.
By default, service account tokens don't have an expiration date. However, you can use token_expiration_day_limit to limit the expiration date of the token in days.
You can assign organization roles (Viewer, Editor, Admin) to a Grafana service account to control access for the associated service account tokens. To assign organization roles you can use the Grafana UI or the API. For more information about assigning a role to a service account via the API, refer to Update service account using the HTTP API.
In Grafana Enterprise, you can also assign RBAC roles to grant very specific permissions to applications that interact with Grafana.
{{< admonition type="note" >}}
Since Grafana 10.2.0, the None basic role is available for organization users or service accounts. This role has no permissions by default, and you can grant permissions with RBAC.
{{< /admonition >}}
Ensure you have permission to update service accounts roles. By default, the organization administrator role is required to update service accounts permissions. For more information about user permissions, refer to About users and permissions.
To control what and who can do with the service account you can assign permissions directly to users and teams. You can assign permissions using the Grafana UI.
Make sure that you have the following permissions:
You can assign on of the following permissions to a specific user or a team:
Learn which RBAC permissions are attached to a service account token to diagnose permissions-related issues with token authorization.
If you haven't added a token to a service account, do so before proceeding. Refer to Add a token to a service account to see how.
To list your token's permissions, use the /api/access-control/user/permissions endpoint.
Run the following command with the token whose permissions you want to check:
curl -H "Authorization: Bearer glsa_iNValIdinValiDinvalidinvalidinva_5b582697" -X GET '<grafana_url>/api/access-control/user/permissions' | jq
The output lists the token's permissions:
{{< admonition type="note" >}} The following command output is shortened to show only the relevant content. {{< /admonition >}}
{
"dashboards:read": ["dashboards:uid:70KrY6IVz"],
"dashboards:write": ["dashboards:uid:70KrY6IVz"],
"datasources.id:read": ["datasources:*"],
"datasources:read": ["datasources:*"],
"datasources:explore": [""],
"datasources:query": ["datasources:uid:grafana"],
"datasources:read": ["datasources:uid:grafana"],
"orgs:read": [""]
}
To list which dashboards a token can view, filter the /api/access-control/user/permissions endpoint's response for the dashboards:read permission key:
curl -H "Authorization: Bearer glsa_iNValIdinValiDinvalidinvalidinva_5b582697" -X GET '<grafana_url>/api/access-control/user/permissions' | jq '."dashboards:read"'
The output lists the dashboards a token can view and the folders a token can view dashboards from,
by their unique identifiers (uid):
[
"dashboards:uid:70KrY6IVz",
"dashboards:uid:d61be733D",
"folders:uid:dBS87Axw2",
],