Audit a Grafana instance
Auditing allows you to track important changes to your Grafana instance. By default, audit logs are logged to file but the auditing feature also supports sending logs directly to Loki.
NOTE: To enable sending Grafana Cloud audit logs to your Grafana Cloud Logs instance, please file a support ticket. Note that standard ingest and retention rates apply for ingesting these audit logs.
Only API requests or UI actions that trigger an API request generate an audit log.
NOTE: Available in Grafana Enterprise version 7.3 and later, and Grafana Cloud.
Audit logs
Audit logs are JSON objects representing user actions like:
-
Modifications to resources such as dashboards and data sources.
-
A user failing to log in.
Format
Audit logs contain the following fields. The fields followed by * are always available, the others depend on the type of action logged.
Field name | Type | Description |
---|---|---|
|
string |
The date and time the request was made, in coordinated universal time (UTC) using the RFC3339 format. |
|
object |
Information about the user that made the request. Either one of the |
|
number |
ID of the Grafana user that made the request. |
|
number |
Current organization of the user that made the request. |
|
string |
Current role of the user that made the request. |
|
string |
Name of the Grafana user that made the request. |
|
number |
ID of the user authentication token. |
|
number |
ID of the Grafana API key used to make the request. |
|
boolean |
If an anonymous user made the request, |
|
string |
The request action. For example, |
|
object |
Information about the HTTP request. |
|
object |
Request’s path parameters. |
|
object |
Request’s query parameters. |
|
string |
Request’s body. Filled with |
|
object |
Information about the HTTP response. |
|
string |
If the request action was successful, |
|
number |
HTTP status of the request. |
|
string |
HTTP error message. |
|
string |
Response body. Filled with |
|
array |
Information about the resources that the request action affected. This field can be null for non-resource actions such as |
|
number |
ID of the resource. |
|
string |
The type of the resource that was logged: |
|
string |
Request URI. |
|
string |
IP address that the request was made from. |
|
string |
Agent through which the request was made. |
|
string |
Current version of Grafana when this log is created. |
|
object |
Additional information that can be provided about the request. |
The additionalData
field can contain the following information: | Field name | Action | Description | | ———- | —— | ———– | | loginUsername
| login
| Login used in the Grafana authentication form. | | extUserInfo
| login
| User information provided by the external system that was used to log in. | | authTokenCount
| login
| Number of active authentication tokens for the user that logged in. | | terminationReason
| logout
| The reason why the user logged out, such as a manual logout or a token expiring. | | billing_role
| billing-information
| The billing role associated with the billing information being sent. |
Recorded actions
The audit logs include records about the following categories of actions. Each action is distinguished by the action
and resources[...].type
fields in the JSON record.
For example, creating an API key produces an audit log like this:
{
"action": "create",
"resources": [
{
"id": 1,
"type": "api-key"
}
],
"timestamp": "2021-11-12T22:12:36.144795692Z",
"user": {
"userId": 1,
"orgId": 1,
"orgRole": "Admin",
"username": "admin",
"isAnonymous": false,
"authTokenId": 1
},
"request": {
"body": "{\"name\":\"example\",\"role\":\"Viewer\",\"secondsToLive\":null}"
},
"result": {
"statusType": "success",
"statusCode": 200,
"responseBody": "{\"id\":1,\"name\":\"example\"}"
},
"resources": [
{
"id": 1,
"type": "api-key"
}
],
"requestUri": "/api/auth/keys",
"ipAddress": "127.0.0.1:54652",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0",
"grafanaVersion": "8.3.0-pre"
}
Some actions can only be distinguished by their requestUri
fields. For those actions, the relevant pattern of the requestUri
field is given.
Note that almost all these recorded actions are actions that correspond to API requests or UI actions that trigger an API request. Therefore, the action {"action": "email", "resources": [{"type": "report"}]}
corresponds to the action when the user requests a report’s preview to be sent through email, and not the scheduled ones.
Sessions
Action | Distinguishing fields |
---|---|
Log in |
|
Log out ** |
|
Force logout for user |
|
Remove user authentication token |
|
Create API key |
|
Delete API key |
|
-
Where
AUTH-MODULE
is the name of the authentication module:grafana
,saml
,ldap
, etc.-
Includes manual log out, token expired/revoked, and SAML Single Logout.
-
Service accounts
Action | Distinguishing fields |
---|---|
Create service account |
|
Update service account |
|
Delete service account |
|
Create service account token |
|
Delete service account token |
|
Hide API keys |
|
Migrate API keys |
|
Migrate API key |
|
Access control
Action | Distinguishing fields |
---|---|
Create role |
|
Update role |
|
Delete role |
|
Assign built-in role |
|
Remove built-in role |
|
Grant team role |
|
Set team roles |
|
Revoke team role |
|
Grant user role |
|
Set user roles |
|
Revoke user role |
|
Set user permissions on folder |
|
Set team permissions on folder |
|
Set basic role permissions on folder |
|
Set user permissions on dashboard |
|
Set team permissions on dashboard |
|
Set basic role permissions on dashboard |
|
Set user permissions on team |
|
Set user permissions on service account |
|
Set user permissions on datasource |
|
Set team permissions on datasource |
|
Set basic role permissions on datasource |
|
User management
Action | Distinguishing fields |
---|---|
Create user |
|
Update user |
|
Delete user |
|
Disable user |
|
Enable user |
|
Update password |
|
Send password reset email |
|
Reset password |
|
Update permissions |
|
Send signup email |
|
Click signup link |
|
Reload LDAP configuration |
|
Get user in LDAP |
|
Sync user with LDAP |
|
Team and organization management
Action | Distinguishing fields |
---|---|
Add team |
|
Update team |
|
Delete team |
|
Add external group for team |
|
Remove external group for team |
|
Add user to team |
|
Update team member permissions |
|
Remove user from team |
|
Create organization |
|
Update organization |
|
Delete organization |
|
Add user to organization |
|
Change user role in organization |
|
Remove user from organization |
|
Invite external user to organization |
|
Revoke invitation |
|
-
Where
TEAM-ID
is the ID of the affected team, andGROUP-ID
(if present) is the ID of the external group.
Folder and dashboard management
Action | Distinguishing fields |
---|---|
Create folder |
|
Update folder |
|
Update folder permissions |
|
Delete folder |
|
Create/update dashboard |
|
Import dashboard |
|
Update dashboard permissions |
|
Restore old dashboard version |
|
Delete dashboard |
|
Library elements management
Action | Distinguishing fields |
---|---|
Create library element |
|
Update library element |
|
Delete library element |
|
Data sources management
Action | Distinguishing fields |
---|---|
Create datasource |
|
Update datasource |
|
Delete datasource |
|
Enable permissions for datasource |
|
Disable permissions for datasource |
|
Grant datasource permission to role, team, or user |
|
Remove datasource permission |
|
Enable caching for datasource |
|
Disable caching for datasource |
|
Update datasource caching configuration |
|
-
resources
may also contain a third item with"type":
set to"user"
or"team"
.
Alerts and notification channels management
Action | Distinguishing fields |
---|---|
Save alert manager configuration |
|
Reset alert manager configuration |
|
Create silence |
|
Delete silence |
|
Create alert |
|
Create or update rule group |
|
Delete rule group |
|
Delete namespace |
|
Test Grafana managed receivers |
|
Create or update the NGalert configuration of the user’s organization |
|
Delete the NGalert configuration of the user’s organization |
|
Where the following:
-
RECIPIENT
isgrafana
for requests handled by Grafana or the data source UID for requests forwarded to a data source. -
NAMESPACE
is the string identifier for the rules namespace. -
GROUP-NAME
is the string identifier for the rules group. -
SILENCE-ID
is the ID of the affected silence.
The following legacy alerting actions are still supported:
Action | Distinguishing fields |
---|---|
Test alert rule |
|
Pause alert |
|
Pause all alerts |
|
Test alert notification channel |
|
Create alert notification channel |
|
Update alert notification channel |
|
Delete alert notification channel |
|
Reporting
Action | Distinguishing fields |
---|---|
Create report |
|
Update report |
|
Delete report |
|
Send report by email |
|
Update reporting settings |
|
Annotations, playlists and snapshots management
Action | Distinguishing fields |
---|---|
Create annotation |
|
Create Graphite annotation |
|
Update annotation |
|
Patch annotation |
|
Delete annotation |
|
Delete all annotations from panel |
|
Create playlist |
|
Update playlist |
|
Delete playlist |
|
Create a snapshot |
|
Delete a snapshot |
|
Delete a snapshot by delete key |
|
Provisioning
Action | Distinguishing fields |
---|---|
Reload provisioned dashboards |
|
Reload provisioned datasources |
|
Reload provisioned plugins |
|
Reload provisioned notifications |
|
Reload provisioned alerts |
|
Reload provisioned access control |
|
Plugins management
Action | Distinguishing fields |
---|---|
Install plugin |
|
Uninstall plugin |
|
Miscellaneous
Action | Distinguishing fields |
---|---|
Set licensing token |
|
Save billing information |
|
Generic actions
In addition to the actions listed above, any HTTP request (POST
, PATCH
, PUT
, and DELETE
) against the API is recorded with one of the following generic actions.
Furthermore, you can also record GET
requests. See below how to configure it.
Action | Distinguishing fields |
---|---|
POST request |
|
PATCH request |
|
PUT request |
|
DELETE request |
|
GET request |
|
Configuration
NOTE: The auditing feature is disabled by default.
Audit logs can be saved into files, sent to a Loki instance or sent to the Grafana default logger. By default, only the file exporter is enabled. You can choose which exporter to use in the configuration file.
Options are file
, loki
, and logger
. Use spaces to separate multiple modes, such as file loki
.
By default, when a user creates or updates a dashboard, its content will not appear in the logs as it can significantly increase the size of your logs. If this is important information for you and you can handle the amount of data generated, then you can enable this option in the configuration.
[auditing]
# Enable the auditing feature
enabled = false
# List of enabled loggers
loggers = file
# Keep dashboard content in the logs (request or response fields); this can significantly increase the size of your logs.
log_dashboard_content = false
# Keep requests and responses body; this can significantly increase the size of your logs.
verbose = false
# Write an audit log for every status code.
# By default it only logs the following ones: 2XX, 3XX, 401, 403 and 500.
log_all_status_codes = false
# Maximum response body (in bytes) to be audited; 500KiB by default.
# May help reducing the memory footprint caused by auditing.
max_response_size_bytes = 512000
Each exporter has its own configuration fields.
File exporter
Audit logs are saved into files. You can configure the folder to use to save these files. Logs are rotated when the file size is exceeded and at the start of a new day.
[auditing.logs.file]
# Path to logs folder
path = data/log
# Maximum log files to keep
max_files = 5
# Max size in megabytes per log file
max_file_size_mb = 256
Loki exporter
Audit logs are sent to a Loki service, through HTTP or gRPC.
NOTE: The HTTP option for the Loki exporter is available only in Grafana Enterprise version 7.4 and later.
[auditing.logs.loki]
# Set the communication protocol to use with Loki (can be grpc or http)
type = grpc
# Set the address for writing logs to Loki
url = localhost:9095
# Defaults to true. If true, it establishes a secure connection to Loki
tls = true
# Set the tenant ID for Loki communication, which is disabled by default.
# The tenant ID is required to interact with Loki running in multi-tenant mode.
tenant_id =
If you have multiple Grafana instances sending logs to the same Loki service or if you are using Loki for non-audit logs, audit logs come with additional labels to help identifying them:
-
host - OS hostname on which the Grafana instance is running.
-
grafana_instance - Application URL.
-
kind -
auditing
When basic authentication is needed to ingest logs in your Loki instance, you can specify credentials in the URL field. For example:
# Set the communication protocol to use with Loki (can be grpc or http)
type = http
# Set the address for writing logs to Loki
url = user:password@localhost:3000
Console exporter
Audit logs are sent to the Grafana default logger. The audit logs use the auditing.console
logger and are logged on debug
-level, learn how to enable debug logging in the log configuration section of the documentation. Accessing the audit logs in this way is not recommended for production use.