docs/sources/datasources/google-cloud-monitoring/google-authentication/index.md
This document explains how to configure authentication between Grafana and Google Cloud Platform (GCP). You must configure authentication before you can use the Google Cloud Monitoring data source to query metrics and SLOs.
All requests to Google APIs are performed on the server-side by the Grafana backend.
Before you configure authentication, ensure you have the following:
The Google Cloud Monitoring data source supports the following authentication methods:
| Method | Use case |
|---|---|
| Google JWT File | Use when Grafana runs outside of GCP, or when you need explicit control over credentials. |
| GCE Default Service Account | Use when Grafana runs on a Google Compute Engine VM with a configured service account. |
| Forward OAuth Identity | Use when you sign in to Grafana with Google and want each query to run as the signed-in user. |
| Service Account Impersonation | Use when you need Grafana to act as a different service account than the one it authenticates with. |
Use this method when Grafana runs outside of Google Cloud Platform, or when you need explicit control over which credentials are used.
Each Grafana data source connects to one GCP project by default. To visualize data from multiple GCP projects, create one data source per project, or use service account impersonation.
To create a service account and download its key file:
Navigate to the APIs and Services Credentials page in the GCP Console.
Click the Create credentials dropdown and select Service account.
In Service account name, enter a name for the account.
Click Create and continue.
In the Grant this service account access to project section, select the Monitoring Viewer role from the Role dropdown.
Click Continue, then click Done.
In the service accounts list, click the service account you created.
Go to the Keys tab and click Add key > Create new key.
Select JSON and click Create.
A JSON key file downloads to your computer.
Store the key file securely. It grants access to your Google Cloud data.
You can configure a single service account to access multiple GCP projects:
[email protected]).When Grafana runs on a Google Compute Engine (GCE) virtual machine, it can automatically retrieve credentials from the GCE metadata server. This method doesn't require you to create or manage key files.
Before using this method, ensure the following:
For more information about GCE service accounts, refer to the Google documentation on service accounts for instances.
Use this method when your Grafana instance authenticates users with Google OAuth and you want each query to run as the signed-in user instead of as a shared service account. This enables per-user access control: a viewer who lacks Cloud Monitoring permissions on a project sees no data from that project, even when the dashboard's data source is shared.
Grafana forwards the user's existing Google OAuth access token as the bearer token on outgoing Cloud Monitoring API requests. No service account key is stored on the server.
Before using this method, ensure the following:
https://www.googleapis.com/auth/monitoring.read scope on top of the default openid email profile scopes. Without this scope, the user's token is rejected by the Cloud Monitoring API with a 403 response.roles/monitoring.viewer) on the target GCP project.Add the Cloud Monitoring read scope to your Google authentication configuration in grafana.ini or custom.ini:
[auth.google]
scopes = openid email profile https://www.googleapis.com/auth/monitoring.read
If you configure Google authentication through the Grafana SSO settings UI, add the same scope value to the Scopes field.
After you change the scopes, existing user sessions still hold tokens issued under the old scope set. Each affected user must sign out, revoke the existing grant at https://myaccount.google.com/permissions, and sign in again to consent to the new scope. Otherwise, queries continue to fail with 403.
{{< admonition type="note" >}} Service account impersonation isn't compatible with Forward OAuth Identity. The data source authenticates as the signed-in user, so there's no service account to impersonate. {{< /admonition >}}
Service account impersonation allows Grafana to authenticate as one service account but act as a different service account when making API requests. This is useful for:
The service account used by Grafana (the "caller") must have the following:
iam.serviceAccounts.getAccessToken permission on the target service account.roles/iam.serviceAccountTokenCreator).The service account being impersonated (the "target") must have:
For more information, refer to the Google documentation on service account impersonation.