Google Cloud

QueryDesk lists the Cloud SQL and AlloyDB instances in your projects and adds them as databases that sign in with IAM. You never create or upload a key, and QueryDesk stores no database password.

QueryDesk acts as a service account you own, through workload identity federation. It signs a short-lived token as your organization, Google exchanges it for a token of that service account, and each database connection signs in with a one-hour token scoped to database login. This works the same on QueryDesk Cloud and on a self-hosted install.

Cloud SQL for PostgreSQL, Cloud SQL for MySQL and AlloyDB are supported. Cloud SQL for SQL Server has no IAM database sign-in, so it can't be added this way. Connecting through the Cloud SQL Auth Proxy or Private Service Connect is not supported.

You must be a super admin. Open Databases, click New database, and choose Google Cloud under Quick connect. Step 1 shows your organization's issuer and subject, and fills them into each command below.

Let Google Cloud trust your organization

Create a workload identity pool and an OIDC provider that trusts your organization's issuer. Run this in the project that will hold the pool:

gcloud iam workload-identity-pools create querydesk --location=global --project=<project>

gcloud iam workload-identity-pools providers create-oidc querydesk \
  --workload-identity-pool=querydesk --location=global --project=<project> \
  --issuer-uri=<issuer> --attribute-mapping=google.subject=assertion.sub

The subject of every token QueryDesk signs for you is querydesk:<organization id>. A token signed for another organization carries its own subject, so it never matches your binding.

Google reads the issuer's keys over the internet. If your QueryDesk runs on a private network Google can't reach, download its keys (JWKS) from the link in step 1 and add --jwk-json-path=jwks.json to the second command instead.

Let QueryDesk act as your service account

Create a service account for QueryDesk if you don't have one, then let the provider's subject act as it:

gcloud iam service-accounts add-iam-policy-binding querydesk@<project>.iam.gserviceaccount.com \
  --role=roles/iam.workloadIdentityUser \
  --member=principal://iam.googleapis.com/projects/<project number>/locations/global/workloadIdentityPools/querydesk/subject/querydesk:<organization id>

Grant the roles

Grant the service account these roles in each project QueryDesk should read. They let it list instances and sign in, and give it no access to data:

  • roles/cloudsql.viewer and roles/cloudsql.instanceUser
  • roles/alloydb.viewer and roles/alloydb.databaseUser
  • roles/serviceusage.serviceUsageConsumer
gcloud projects add-iam-policy-binding <project> \
  --member=serviceAccount:querydesk@<project>.iam.gserviceaccount.com --role=roles/cloudsql.viewer

A project that uses only one of the two products needs only that product's roles. A project where the Cloud SQL Admin API or the AlloyDB API is turned off simply has none of that product's instances, and step 2 says the API is off.

Turn on IAM sign-in and add QueryDesk's user

Each instance needs IAM database sign-in turned on, and an IAM database user for the service account. Step 2 lists any instance missing either, with the command that fixes it. For Cloud SQL:

gcloud sql instances patch <instance> --project=<project> \
  --database-flags=cloudsql.iam_authentication=on

gcloud sql users create querydesk@<project>.iam.gserviceaccount.com \
  --instance=<instance> --project=<project> --type=cloud_iam_service_account

On MySQL the flag is cloudsql_iam_authentication. --database-flags replaces the instance's flags, so list any others it already has. For AlloyDB:

gcloud alloydb instances update <instance> --cluster=<cluster> --region=<region> --project=<project> \
  --database-flags=alloydb.iam_authentication=on

gcloud alloydb users create querydesk@<project>.iam \
  --cluster=<cluster> --region=<region> --project=<project> --type=IAM_BASED

Choose what QueryDesk can do in each database

QueryDesk signs in as one IAM database user, so it can do only what you grant it. Read only is enough for most teams. On PostgreSQL and AlloyDB:

GRANT pg_read_all_data TO "querydesk@<project>.iam";

On MySQL:

GRANT SELECT, SHOW VIEW ON *.* TO 'querydesk'@'%';

To let a team write, add a password credential for a user with more access in the database's settings, with the reviews it should need.

Allow QueryDesk Cloud's address

On QueryDesk Cloud, an instance reached on its public IP must allow 35.224.237.12 in its authorized networks:

gcloud sql instances patch <instance> --project=<project> --authorized-networks=35.224.237.12/32

--authorized-networks replaces the instance's list, so include any networks it already allows. A self-hosted install connects from its own address.

Add instances

  1. Connect. Enter a name for the connection, the service account's email, the workload identity provider's full name (projects/<project number>/locations/global/workloadIdentityPools/querydesk/providers/querydesk) and the projects to read. Click Connect. QueryDesk checks the connection by listing the instances in each project. If Google refuses, the step says which grant is missing.
  2. Choose instances. Each project lists the instances that can be added. Those that can't be added yet, and databases whose instance has left Google Cloud, are listed under Can't be added yet.
  3. Review and add. Name each database, choose the database on the instance, and how QueryDesk reaches it: its public IP, its private IP on a self-hosted install, or a Tunnel. Click Add.

Each database starts with one review required, open only to super admins, with AI access off. Change each in the database's settings. QueryDesk then tests each connection, and a test that fails says what is missing.

A database added from Google Cloud is managed in QueryDesk. Its address, port, encryption, engine and Tunnel come from the instance, and neither its settings page, the API nor the Terraform provider can change them. To move it to another instance, remove it and add the instance again.

Reach private instances through a Tunnel

QueryDesk Cloud can't reach a private IP, so an instance with only a private IP is added through a Tunnel. Choose an existing Tunnel, or a new one for the instance's network.

Instances on one network share one Tunnel, named for the network's project and name, such as halyard-prod/prod-vpc. If a Tunnel of that name already exists, it is used. Once the databases are added, each new or offline Tunnel shows its setup once, for GKE or Cloud Run on that network, and the databases behind it are tested when it comes online.

A self-hosted install can dial a private IP directly when it runs on a network that reaches it, with a Tunnel as the alternative.

What the hourly sync changes

Every hour QueryDesk lists each connection's projects again. For each database added from it:

  • An instance whose IP or server CA changed: the database is pointed at the new address and CA.
  • An instance that no longer has the IP its database uses, such as a public IP turned off: the database keeps its last address, and the Google Cloud steps say which one. Remove the database from its settings, then add the instance again on its new route.
  • An instance no longer in Google Cloud: the database is marked gone and stays, with its query history. Remove it from its settings when you no longer need it.
  • A project QueryDesk can't read: nothing changes, and the Google Cloud steps show the reason.

Removing a connection keeps its databases. Their IAM credentials can no longer sign in, so add a password credential to any you keep querying.

Was this page helpful?