Skip to content

Connect SPSync to Google BigQuery

This guide covers Google BigQuery. SPSync uses one destination kind, bigquery. BigQuery has no connection string: SPSync signs in as a Google principal, and the destination is a dataset in a project you name. Many organisations block service-account key creation (iam.disableServiceAccountKeyCreation), so SPSync can sign in without a key.

  • A Google Cloud project with the BigQuery API enabled and billing switched on.
  • Nothing to install on the machine that runs SPSync. The Google client library is part of SPSync.
  • Rights to create a service account and grant it roles on the project (and, to use impersonation, to grant roles/iam.serviceAccountTokenCreator on that account).
  • A decision on the dataset region. A dataset keeps the region it was created in, so choose it before the first run.

Create the database and a least-privilege user

Section titled “Create the database and a least-privilege user”

In BigQuery the dataset is the whole namespace: dataset_name is the dataset, and every list table, child table and sp_users sits directly in it. SPSync creates the dataset on first use if it does not exist, in the service account’s own project. Datasets in another project are not supported.

The service account needs two roles:

  • BigQuery Data Editor (roles/bigquery.dataEditor) to create and change tables and to insert, update and merge rows.
  • BigQuery Job User (roles/bigquery.jobUser) to run load and query jobs. This role is granted on the project.

Create the account yourself (gcloud iam service-accounts create spsync-loader --project=PROJECT_ID), then let SPSync print the grant commands:

Terminal window
spsync auth bigquery-grants \
--principal spsync-loader@PROJECT_ID.iam.gserviceaccount.com --project PROJECT_ID

It prints Job User on the project and Data Editor on the project. It only prints; you review the commands and run them as a project IAM admin. SPSync never runs them. Use --principal-type user or group if SPSync signs in as a person or a group.

To keep the account away from every other dataset, create the dataset yourself in the region you want and add --dataset DATASET. The output then grants Data Editor on that dataset only (with bq add-iam-policy-binding) and keeps Job User on the project. SPSync then finds the dataset and does not need to create one. The commands come from the Google Cloud documentation and have not been run against a live project here.

If you use the service-account key fallback (see “Authentication SPSync supports today” below), create the key with:

Terminal window
gcloud iam service-accounts keys create spsync-key.json \
--iam-account="spsync-loader@PROJECT_ID.iam.gserviceaccount.com"

If your organisation prefers a custom role to the two predefined ones, SPSync needs these permissions: bigquery.datasets.get, bigquery.datasets.create (only if SPSync creates the dataset), bigquery.tables.create, bigquery.tables.get, bigquery.tables.list, bigquery.tables.getData, bigquery.tables.updateData, bigquery.tables.update, bigquery.tables.delete (only for a table SPSync replaces) and bigquery.jobs.create. That list is derived from the operations SPSync issues and has not been checked against a live project.

Keep spsync-key.json, if you create one, out of source control. It is a long-lived secret.

BigQuery is a Google-hosted API, so there is no database firewall to open. SPSync makes outbound HTTPS calls to Google’s APIs, so the machine that runs it must be allowed to reach bigquery.googleapis.com and oauth2.googleapis.com. If your organisation uses VPC Service Controls around the project, SPSync’s address or network must be inside the perimeter or an access level must allow it. The perimeter check has not been tried here.

Every call to Google’s APIs is over HTTPS, with no setting to change.

SPSync supports four ways to sign in to BigQuery. Choose the first one that your environment allows. No mode, including the service-account key, has been verified against a live Google Cloud project yet. The three key-free modes are labelled preview, not verified live below. They are covered by tests that use Google’s own authentication library and a fake BigQuery client, which prove how SPSync selects and builds the credential, not that Google accepts it in your organisation.

Mode auth.mode What it uses Status
Application Default Credentials gcp_adc The gcloud user (gcloud auth application-default login), the service account attached to a Compute Engine VM or Cloud Run service, or the file GOOGLE_APPLICATION_CREDENTIALS names. Preview, not verified live
Workload identity federation gcp_workload_identity_federation A credential-configuration file ("type": "external_account") that exchanges an OIDC token from GitHub, Azure or another provider for a Google token. Preview, not verified live
Impersonation impersonate_service_account option on either mode above The principal above acts as a named service account, so the loader account never needs a key. Preview, not verified live
Service-account key password (the default) The whole downloaded JSON key file, passed as text. Earlier release, also not verified live; spsync doctor flags it as the fallback

A key-free mode needs the Google Cloud project id (bigquery_project), because there is no key to read it from. For impersonation, the principal needs roles/iam.serviceAccountTokenCreator on the service account it impersonates. For federation, the pool must map the external identity to a principal that holds the two BigQuery roles above (or to the service account, with roles/iam.workloadIdentityUser).

SPSync accepts only a federation file whose type is external_account and in which every URL is HTTPS. That rules out Azure’s plain-HTTP instance-metadata source: on Azure, use a file source that points at the federated token file. An AWS source is refused for the same reason, and so is a file that names an executable credential source, because it would run a command named by the file. The variable named in credential_configuration_path_env must be a plain environment-variable name; a file:, env:, keychain: or keyvault: reference is refused. The service account to impersonate must be an email address. Not supported: user OAuth sign-in as a separate mode (an Application Default Credentials login covers a developer machine).

Google access tokens last one hour. The Google library refreshes them itself, so a load that runs longer keeps working; SPSync does not store a token anywhere.

dataset_name is the BigQuery dataset. bigquery_location is the dataset’s region, for example US, EU or europe-west2. It matters only when SPSync has to create the dataset; an existing dataset keeps its own region. If you leave it out, SPSync uses US.

  • Desktop app: open the Destination screen and choose Google BigQuery. Under Authentication pick Google Application Default Credentials or Google workload identity federation, enter the Google Cloud project id (and, for federation, the name of the environment variable that holds the path of the credential-configuration file, and optionally a service account to impersonate), set Dataset location if the dataset is not in US, and choose Test connection. To use a key instead, pick Service-account key (fallback) and paste the whole contents of the key file into Connection string. The key is write-only: SPSync never shows it again.

  • CLI, key-free: export-config writes the key-based form, so edit the file: remove connection_string_env and add an auth block and the project.

    destination:
    kind: bigquery
    dataset_name: sharepoint_sync
    bigquery_project: my-gcp-project
    bigquery_location: EU
    auth:
    mode: gcp_adc # or gcp_workload_identity_federation
    # impersonate_service_account: spsync-loader@PROJECT_ID.iam.gserviceaccount.com
    # For federation:
    # mode: gcp_workload_identity_federation
    # credential_configuration_path_env: SPSYNC_GCP_WIF_CONFIG
  • CLI, service-account key: the environment variable holds the JSON text of the key file, not a path.

    Terminal window
    export SPSYNC_BQ_SERVICE_ACCOUNT="$(cat spsync-key.json)"
    spsync export-config --output replication.yaml \
    --site-url https://contoso.sharepoint.com/sites/x --list Projects \
    --pipeline-name spsync_dev --prefix dev \
    --destination-kind bigquery --connection-string-env SPSYNC_BQ_SERVICE_ACCOUNT \
    --dataset-name sharepoint_sync --bigquery-location EU \
    --client-id <entra-app-client-id>
  • AI assistant: with the admin MCP server connected, ask for the destination requirements, then let the assistant create the destination with bigquery_location. For a key, you enter it on the secure entry page, never in the chat. For a key-free mode the assistant passes auth_mode, auth_options and bigquery_project; there is nothing to enter, and test_destination shows the principal.

spsync doctor (destination-connectivity) creates a BigQuery client, runs SELECT SESSION_USER() and, when the dataset is named, reads that dataset. A pass proves the credential is valid, the project accepts jobs from it and, if the dataset exists, that it is reachable in the region given. The result names the principal BigQuery sees, for example connected (bigquery) using auth mode gcp_adc as spsync-loader@PROJECT_ID.iam.gserviceaccount.com, so you can confirm the sync runs as the identity you intended. With a service-account key the same line ends with a warning that a long-lived key is in use. The desktop Test connection button runs the same query and shows the principal.

It does not prove the account can create tables or write rows: Data Editor is only used on the first load. SPSync’s own BigQuery verification against a live Google Cloud project is not complete, so run one small list first.

What you see What it means and the fix
403 ... does not have bigquery.jobs.create permission The service account has no BigQuery Job User role on the project. Grant it.
403 ... Access Denied: Dataset or bigquery.tables.create The account has no Data Editor role on the project or the dataset. Grant it.
404 Not found: Dataset ... was not found in location The dataset exists in a different region from bigquery_location. Set the region the dataset really has.
Invalid JWT or invalid_grant The key was deleted or disabled, or the pasted text is not the complete JSON file. Create a new key.
Your default credentials were not found gcp_adc found no credentials. Run gcloud auth application-default login, attach a service account to the host, or set GOOGLE_APPLICATION_CREDENTIALS.
environment variable ... is not set (auth.credential_configuration_path_env) The variable named in the config does not exist where SPSync runs. Set it to the path of the federation file.
must be a workload identity federation configuration The file is a service-account key or a user credential. Create a federation file with gcloud iam workload-identity-pools create-cred-config.
Permission 'iam.serviceAccounts.getAccessToken' denied The principal may not impersonate the service account. Grant it roles/iam.serviceAccountTokenCreator on that account.
Access Not Configured or BigQuery API has not been used Enable the BigQuery API on the project.