Set up a Google Cloud service account for Data Studio

You can set up a Google Cloud service account so that Data Studio can access your BigQuery data without relying on individual user credentials. Delegating access to a service account can help you meet security requirements and keep data sources working even if the person who created the data source leaves your organization.

This document is intended for Google Cloud administrators who want to set up a service account for Data Studio. To use an existing service account in a data source, see Data credentials.

Key concepts

When you set up a service account for Data Studio, it's helpful to understand the following concepts:

  • Service account: An identity that acts as a non-human user to access the BigQuery data. You create and manage the service account.
  • Data Studio service agent: A special type of service account that Google Cloud creates and manages. The service agent lets Data Studio access resources on your behalf.
  • How the service agent and service account work together: Data Studio uses the service agent to impersonate your service account. Your service account has the permissions to read the BigQuery data.

For more information, see Service accounts overview.

Benefits of using a service account with Data Studio

Using a service account instead of an individual user's credentials provides these benefits:

  • Business continuity: Data sources that use service account credentials won't break if the creator leaves your company.
  • VPC Service Controls support: Automated features such as scheduled emails, alerts, and scheduled data extracts work with data sources that are behind a VPC Service Controls perimeter. For more information, see Notes and limits.
  • Device policy support: Service account credentials support access to data that is located behind VPC Service Controls perimeters that use device policies.
  • Ingress and egress rules: You can create ingress and egress rules to allow the service account access to and from the resources and clients that are protected by service perimeters.
  • Organizational policy compliance: If your organization's Google Workspace policies restrict Owner's credentials to prevent broad data sharing, service accounts provide an alternative that administrators control. You can delegate access without exposing individual human credentials or over-granting permissions.
  • Granular access control: You can grant the service account access to only specific BigQuery datasets or tables, which supports the principle of least privilege. You can then control which Data Studio users can impersonate or use that service account.

Required roles

The following sections show the roles that are required to configure a service account for Data Studio.

For administrators

To get the Data Studio service agent email address, you must be a Google Workspace or Cloud Identity user.

To get the permissions that you need to configure a service account for Data Studio, ask your administrator to grant you the following IAM roles:

For more information about granting roles, see Manage access to projects, folders, and organizations.

These predefined roles contain the permissions required to configure a service account for Data Studio. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to configure a service account for Data Studio:

  • Set up a service account: iam.serviceAccounts.create on your project
  • Configure access to a BigQuery dataset or table:
    • bigquery.datasets.setIamPolicy on the dataset
    • bigquery.tables.setIamPolicy on the table

You might also be able to get these permissions with custom roles or other predefined roles.

For the service account

To ensure that the service account has the necessary permissions to access BigQuery data for Data Studio, ask your administrator to grant the following IAM roles to the service account:

  • BigQuery Data Viewer (roles/bigquery.dataViewer) on the specific tables or datasets that the service account needs to read
  • BigQuery Job User (roles/bigquery.jobUser) on the billing project (the Google Cloud project that runs and pays for query jobs)

For more information about granting roles, see Manage access to projects, folders, and organizations.

These predefined roles contain the permissions required to access BigQuery data for Data Studio. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to access BigQuery data for Data Studio:

  • bigquery.tables.getData on the specific tables or datasets that the service account needs to read
  • bigquery.jobs.create on the billing project

Your administrator might also be able to give the service account these permissions with custom roles or other predefined roles.

Setup instructions

To set up a service account that provides access to BigQuery data, complete the following steps:

  1. Get the Data Studio service agent: Copy the service agent email address to use in a later step.
  2. Create a service account for Data Studio: Create the non-human user identity that accesses the data.
  3. Allow the Data Studio service agent to access your service account: Grant the service agent the required role on the service account.
  4. Grant user roles: Grant your users the required role so that they can create data sources that use service account credentials.
  5. Enable the service account to access your BigQuery data: Grant the service account the required role to access a BigQuery dataset or table.

You need to perform the instructions in this document only once unless you want to create different service accounts for different teams or groups of users. To create multiple service accounts, repeat these instructions for each additional service account.

Step 1: Get the Data Studio service agent

To allow the service account to access your data, you need the email address of the Data Studio service agent for your organization. You can get the email address from a help page in Data Studio:

  1. Go to the Data Studio service agent help page.
  2. Copy the service agent email address that is shown on that page and save it for use in step 3.

The service agent email address uses the following format, where ORG_ID is your Google Cloud organization ID:

service-org-ORG_ID@gcp-sa-datastudio.iam.gserviceaccount.com

Step 2: Create a service account for Data Studio

To create the service account, you can use either the Google Cloud console or the Cloud Shell command line.

Console

  1. In the Google Cloud console, go to the Create service account page.

    Go to Create service account

  2. Select a project.
  3. Enter a service account name to display in the Google Cloud console.

    The Google Cloud console generates a service account ID that's based on this name. Edit the ID now if necessary. You can't change the ID later.

  4. Optional: Enter a description for the service account.
  5. Copy the service account email address and save it for use in Step 5.
  6. Click Create and continue.
  7. In Permissions, grant the service account the BigQuery Job User IAM role (roles/bigquery.jobUser)—or a custom role that includes the bigquery.jobs.create permission—on the billing project where Data Studio runs query jobs.

    If your billing project is different from the project in which you're creating the service account, skip this step and grant the BigQuery Job User role to the service account on the billing project's IAM page instead.

  8. Click Continue.
  9. In the Service account users role field, add the users who can use this service account to provide credentials for their data sources. If you're not ready to add users now, you can add them later. For more information, see Grant user roles.
  10. Click Done to save the service account and return to the service accounts list page for your project.

gcloud

Follow the general steps that are listed under Cloud Shell in Creating and managing service accounts.

  1. Open the Cloud Shell.
  2. Select a project, if necessary.
  3. To create the service account, run the gcloud iam service-accounts create command. You can use whatever account name, description, and display name that you choose.

Example:

gcloud iam service-accounts create data-studio-service-account \
--description="Use for Data Studio access to BigQuery" \
--display-name="DS_BQ"

Copy the service account email address and save it for use in Step 5.

  1. To allow the service account to run BigQuery query jobs, give the service account the bigquery.jobs.create permission on your billing project by granting the BigQuery Job User IAM role (roles/bigquery.jobUser).

    To grant this role, run the gcloud projects add-iam-policy-binding command. In the following example, replace BILLING_PROJECT_ID with the ID of the billing project where Data Studio runs query jobs, and replace PROJECT_ID with the ID of the project in which you created the service account.

Example: Grant the BigQuery Job User role

gcloud projects add-iam-policy-binding BILLING_PROJECT_ID \
--member="serviceAccount:data-studio-service-account@PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/bigquery.jobUser"

For more information, see Creating and Managing Service Accounts.

Step 3: Allow the Data Studio service agent to access your service account

To allow the Data Studio service agent to access data by using the service account, grant the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) to the service agent.

Console

  1. Return to the Google Cloud console service accounts list.
  2. In the list, select the Data Studio service account that you created.
  3. Click Principals with access.
  4. Click person_add Grant access.
  5. In the Add principals section, paste the Data Studio service agent email address that you copied in Step 1 into the New principals field.
  6. Select a role that gives the service agent the iam.serviceAccounts.getAccessToken permission. For example, you can use the Service Account Token Creator role, or any custom role that grants this permission.
  7. Click Save.

gcloud

Run the gcloud iam service-accounts add-iam-policy-binding command. In the following example, replace ORG_ID with your organization's ID.

Example:

gcloud iam service-accounts add-iam-policy-binding data-studio-service-account@PROJECT_ID.iam.gserviceaccount.com \
--member="serviceAccount:service-org-ORG_ID@gcp-sa-datastudio.iam.gserviceaccount.com" \
--role="roles/iam.serviceAccountTokenCreator"

Step 4: Grant user roles

Data Studio users who create or edit data sources must be granted a role that includes the iam.serviceAccounts.actAs permission, such as the Service Account User role (roles/iam.serviceAccountUser). You can grant this role on the project or on an individual service account. To limit access, grant the role on the service account only. For instructions, see Managing service account impersonation.

Don't grant the Service Account Token Creator role to Data Studio users. Only the service agent needs this role.

Console

  1. Go to the Google Cloud console service accounts list.
  2. In the list, select your Data Studio service account.
  3. Click Principals with access.
  4. Click person_add Grant access.
  5. In the Add principals section, enter the email addresses of your users in the New principals field.
  6. Select the Service Account User role.
  7. Optional: To allow users to browse projects and datasets in menus (rather than entering them manually), also select the BigQuery Metadata Viewer role.
  8. Click Save.

gcloud

To grant the Service Account User role, run the gcloud iam service-accounts add-iam-policy-binding command. In the following examples, replace PROJECT_ID with your project ID, and replace USER_EMAIL with the user's email address. To add multiple users, repeat the command for each user.

Example:

gcloud iam service-accounts add-iam-policy-binding data-studio-service-account@PROJECT_ID.iam.gserviceaccount.com \
--member="user:USER_EMAIL" \
--role="roles/iam.serviceAccountUser"

Optional: To allow users to browse projects and datasets in menus (rather than entering them manually), also grant the BigQuery Metadata Viewer role.

Example:

gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:USER_EMAIL" \
--role="roles/bigquery.metadataViewer"

Step 5: Enable the service account to access your BigQuery data

To allow Data Studio to read your data, grant the BigQuery Data Viewer role (roles/bigquery.dataViewer) to the service account on the specific tables or datasets that it needs to read. Don't grant the BigQuery Data Viewer role at the project level, because that grants access to all tables and datasets in the project.

Console

To grant access to a table:

  1. Copy the Data Studio service account email address (see Step 2: Create a service account for Data Studio).
  2. Go to BigQuery, and then select a project.
  3. Click dataset Datasets, and then select a dataset.
  4. Select a table.
  5. In the toolbar, click the person_add Share menu, and then click Share.
  6. In the Share permissions panel, click person_add Add principal.
  7. In the New principals field, paste the Data Studio service account email address.
  8. Select the BigQuery Data Viewer role.
  9. Click Save.

To grant access to a dataset:

  1. Copy the Data Studio service account email address (see Step 2: Create a service account for Data Studio).
  2. Go to BigQuery, and then select a project.
  3. Click dataset Datasets, and then select a dataset.
  4. Click more_vert Actions chevron_forward Share chevron_forward Manage permissions.
  5. In the Share permissions panel, click person_add Add principal.
  6. In the New principals field, paste the Data Studio service account email address.
  7. Select the BigQuery Data Viewer role.
  8. Click Save.

gcloud

Use the Google Cloud console instructions to grant access to data. To grant access to data by using the bq command-line tool, see Grant access to a dataset in the BigQuery documentation.

Provide the Data Studio service account to your Data Studio users

Data Studio users need to know which service account to use when they create data sources. Because you can't view the list of available service accounts from within Data Studio, share the service account email address through your organization's documentation, internal website, or email.

Keep the following points in mind when sharing service account details:

  • You don't need to manage service account keys manually, and users don't need to download service account keys from the Google Cloud console or upload them to Data Studio.
  • The limit of 10 service account keys per service account doesn't apply to Data Studio.
  • Knowing the service agent name alone doesn't allow a user to access data. The service agent must be added to a service account, and end users must have permission to act as that service account.

Create a data source that uses service account credentials

To create data sources that use service account credentials, Data Studio users can follow the same steps as for other data credential types:

  1. Create or edit a BigQuery data source.
  2. In the toolbar, click Data Credentials.
  3. Select Service Account Credentials.
  4. Enter your Service account email address in the box.
  5. Click Update.

Edit a data source that uses service account credentials

When someone edits a data source that uses service account credentials, Data Studio checks whether they have permission to use the service account. If they don't, the data source switches to use that person's credentials instead.

See who is using the service account to access data

You can check the audit logs for service accounts in the Google Cloud console. To receive audit logs for service accounts, you must enable IAM audit logs for Data Access activity.

Service account example scenario

Suppose you want to make sure that Data Studio users in your company have access only to the data for their country's subsidiary. To do this, create a service account for each country, and give only the Data Studio users in each country permission to act as that country's service account.

Example setup

In this example, you'll create three service accounts: one for the UK, one for France, and one for Germany. You'll then assign as principals your service agent and any users whom you want to be able to create data sources that use the service account. You'll also assign the proper roles to each.

UK service account

service-account-1@example-org-uk-example-project.iam.gserviceaccount.com

UK principals

Principals Roles
service-org-ORG_ID@gcp-sa-datastudio.iam.gserviceaccount.com

This is the service agent.

Service Account Token Creator
User 1 Service Account User
User 2 Service Account User

France service account

service-account-1@example-org-fr-example-project.iam.gserviceaccount.com

France principals

Principals Roles
service-org-ORG_ID@gcp-sa-datastudio.iam.gserviceaccount.com

This is the service agent.

Service Account Token Creator
User 3 Service Account User
User 4 Service Account User

Germany service account

service-account-1@example-org-de-example-project.iam.gserviceaccount.com

Germany principals

Principals Roles
service-org-ORG_ID@gcp-sa-datastudio.iam.gserviceaccount.com

This is the service agent.

Service Account Token Creator
User 5 Service Account User
User 6 Service Account User

Knowing a service account email address doesn't grant access to data or to the account itself. Even if User 5 knows that service-account-1@example-org-fr-example-project.iam.gserviceaccount.com exists, they can't use it without being granted the Service Account User role (roles/iam.serviceAccountUser). Both the user and the service agent must have the appropriate roles configured for the service account to access resources.

Troubleshoot service account errors

This section explains the errors that Data Studio data source creators and report viewers might see when they try to use a service account. In most cases, these errors have the same root cause: incorrect or incomplete setup of the service account.

Missing service agent role

Messages

  • Data Studio's service agent is missing the iam.serviceAccounts.getAccessToken permission for this service.
  • The service agent used by this data source's service account is missing the Service Account Token Creator role.

Cause

The service agent hasn't been granted the Service Account Token Creator role (or another role that includes the iam.serviceAccounts.getAccessToken permission).

Solution

Grant the Service Account Token Creator role to the service agent.

No access to the data

Message

This service account can't access the underlying dataset.

Causes

  • The service account hasn't been granted access to the underlying table or dataset.
  • The billing project is connected to a project that the service account doesn't have access to.
  • The service account doesn't have the BigQuery Job User role (roles/bigquery.jobUser) on the billing project.

Solution

  • Grant the BigQuery Data Viewer role (roles/bigquery.dataViewer) to the service account on the specific tables or datasets that it needs to read.
  • Grant the BigQuery Job User role (roles/bigquery.jobUser) to the service account on the billing project in which the query runs.

Missing user role

Message

You don't have permission to use this service account.

Cause

The user hasn't been added as a principal to the service account with the Service Account User role.

Solution

Grant the Service Account User role to the user on the service account.

Service agent not available for the account

Messages

  • Service agents cannot be generated for this account — try again with a Google Workspace or Cloud Identity managed account.
  • Service agent credentials are available only for Google Workspace or Cloud Identity managed organizations. Use a different account to use this feature.

Cause

The user is trying to use a standard (consumer user) Google Account to access data that's controlled by a service account.

Solution

Use a Google Workspace or Cloud Identity account to access the data.

Can't use service agent in credentials dialog

Message

Data Studio service agents can't be used to directly connect to data. Use a service account instead.

Solution

Service agents and service accounts are different. Enter a service account in the credentials dialog. You can find the list of available service accounts using either the Google Cloud console or the Cloud Shell:

Console

  1. Go to the Service accounts page.
  2. Select a project, if necessary.
  3. In the Service accounts for project page, locate the service account that Data Studio will use to access your BigQuery data.
  4. Copy the email address for that account.

gcloud

  1. Open the Cloud Shell.
  2. Select a project, if necessary.
  3. To list the service accounts to which you have access, run the gcloud iam service-accounts list command.

Example:

gcloud iam service-accounts list

Notes and limits of service account credentials

  • Service account credentials are available only for BigQuery data sources. IAM limits apply to service accounts.
  • It might take a few minutes for changes to service account permissions to be reflected in Data Studio.
  • Because Data Studio runs on Google-managed infrastructure with dynamic IP addresses and project allocations, you can't configure VPC Service Controls perimeters by using static IP allowlists or project rules. To permit Data Studio access through a VPC Service Controls perimeter, you must add a service account as a principal in your access levels or ingress and egress rules.