Google authentication
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 begin
Before you configure authentication, ensure you have the following:
- A Google Cloud Platform project with the Monitoring API enabled.
- Permissions to create service accounts or configure GCE instance settings in your GCP project.
- Access to the Grafana data source configuration page.
Supported authentication methods
The Google Cloud Monitoring data source supports the following authentication methods:
Use a Google service account key file
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.
Create a GCP service account and key file
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.
Upload the key file to Grafana
- In Grafana, navigate to the Google Cloud Monitoring data source configuration page.
- Under Authentication type, select Google JWT File.
- Upload the JSON key file using one of the available methods (drag and drop, browse, or paste).
- Click Save & test to verify the connection.
Grant access to multiple projects
You can configure a single service account to access multiple GCP projects:
- Create a service account and key file following the steps above.
- Note the service account email address (for example,
grafana-monitoring@my-project.iam.gserviceaccount.com). - In each additional project you want to access:
- Navigate to IAM & Admin > IAM.
- Click Grant access.
- Enter the service account email address.
- Assign the Monitoring Viewer role.
- Click Save.
- Use the original key file in Grafana. The service account can now access all configured projects.
Use GCE Default Service Account
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.
Prerequisites for GCE authentication
Before using this method, ensure the following:
- Grafana is running on a GCE virtual machine.
- The VM has a service account assigned with the Monitoring Viewer role.
- The VM has the Cloud Monitoring API scope enabled.
Configure the GCE instance
- In the GCP Console, navigate to Compute Engine > VM instances.
- Stop the VM if it’s running (you can’t change scopes on a running VM).
- Click the VM name, then click Edit.
- Under Service account, select a service account with the Monitoring Viewer role.
- Under Access scopes, select Set access for each API and enable the Cloud Monitoring API (read-only).
- Click Save and restart the VM.
Configure the data source
- In Grafana, navigate to the Google Cloud Monitoring data source configuration page.
- Under Authentication type, select GCE Default Service Account.
- Click Save & test to verify the connection.
For more information about GCE service accounts, refer to the Google documentation on service accounts for instances.
Configure service account impersonation
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:
- Accessing resources across multiple projects with a single configuration.
- Following the principle of least privilege by separating authentication from authorization.
- Auditing and tracking which service account accessed specific resources.
Prerequisites for impersonation
The service account used by Grafana (the “caller”) must have the following:
- The
iam.serviceAccounts.getAccessTokenpermission on the target service account. - This permission is included in the Service Account Token Creator role (
roles/iam.serviceAccountTokenCreator).
The service account being impersonated (the “target”) must have:
- The Monitoring Viewer role on the projects you want to access.
Configure impersonation
- In the GCP Console, grant the caller service account the Service Account Token Creator role on the target service account.
- Grant the target service account the Monitoring Viewer role on the relevant projects.
- In Grafana, navigate to the Google Cloud Monitoring data source configuration page.
- Configure authentication using either Google JWT File or GCE Default Service Account.
- Enable Service Account Impersonation.
- Enter the email address of the target service account.
- Click Save & test to verify the connection.
For more information, refer to the Google documentation on service account impersonation.



