Skip to main content
If your PostgreSQL database runs on Google Cloud SQL, aidnn can reach it without allowlisting IP addresses, even when the database has only a private IP. You still add a regular Postgres connector; you only choose a different Connection method.

Choose a connection method

With Cloud SQL Auth Proxy and IAP tunnel, aidnn signs in to Google with a service account key you provide. Google checks the account’s roles before any traffic reaches your database.

1. Prerequisites - Google Cloud admin setup

These steps run in the Google Cloud project that holds the database. The examples use project acme-analytics, region us-central1 and instance acme-pg; substitute your own names. First, enable the APIs the connection uses (the IAP tunnel also needs the last two):

Create a read-only database user

Connect as an admin user (for example in Cloud SQL Studio) and create a user that can only read:
Repeat the last three statements for each schema aidnn should read.

Create a service account for aidnn

Create a dedicated service account and a key for it. You paste the key into aidnn later. If your organization blocks service account keys (the iam.disableServiceAccountKeyCreation policy), ask your organization admin for an exception for this account.
Give the account the roles for your connection method:
  • Cloud SQL Auth Proxy - Cloud SQL Client (roles/cloudsql.client).
  • IAP tunnel - IAP-secured Tunnel User (roles/iap.tunnelResourceAccessor) and Compute Viewer (roles/compute.viewer).
For example, for the Cloud SQL Auth Proxy (for the IAP tunnel, run it once for each of its two roles):

IAP tunnel only - run a proxy VM

With the IAP tunnel, aidnn reaches a small VM in your network through Google IAP, and the VM forwards to the database’s private IP. The VM has no public IP. The database needs a private IP on the same VPC network as the VM.
  • Give the VM its own service account with the Cloud SQL Client role. This is not the aidnn service account, and its key is never shared.
  • Turn on Private Google Access for the VM’s subnet, so the VM can reach Google without a public IP.
  • Allow Google IAP’s address range, 35.235.240.0/20, to reach the VM on port 5432.
The VM runs Google’s Cloud SQL Auth Proxy from a startup script. Write the script to a file, then create the VM with it:
For the IAP tunnel, paste the key of the aidnn service account into aidnn, not the proxy VM’s service account. The VM’s account has no tunnel permission, and the test fails with Required 'compute.instances.get' permission.

2. Add the connector in aidnn

Open Connectors, click Add New Connector and select Postgres, as in the Postgres connector guide. Choose a Connection method, then fill in its fields. Both methods ask for:
  • Database, User, Password - the database and the read-only user from step 1.
  • Service account key (JSON) - the full contents of aidnn-key.json.

Cloud SQL Auth Proxy

  • Instance connection name - the Connection name on the instance’s Overview page, for example acme-analytics:us-central1:acme-pg.
Postgres connector form with the Cloud SQL Auth Proxy method

IAP tunnel

  • IAP project, IAP zone, Proxy VM name - the proxy VM’s project, zone and name, for example acme-analytics, us-central1-a, aidnn-sql-proxy.
  • Proxy VM port - 5432, the port the proxy listens on.
Postgres connector form with the IAP tunnel method
You don’t need to allowlist aidnn’s IPs for these methods. The connection method can’t be changed after the connector is created.

3. Test, create and sync

Click Test Connection. It takes about 20 seconds, and up to a minute the first time, while aidnn opens the connection to Google. Then click Create and sync the schemas you want, as in the Postgres connector guide.

If the test fails

The test shows Google’s own message. The most common ones:
To rotate the key, paste a new key on the connector’s edit page, then delete the old one in Google Cloud.