> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bqto.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# First connection

> Sign in to Google Cloud, get the APIs, the firewall rule and the roles that bqto needs, and open a first session to a private Cloud SQL instance.

At the end of this page, a database client on your laptop talks to a private Cloud SQL instance
through bqto.

## Before you start

* bqto is installed. See [Install](https://docs.bqto.dev/install.md).
* The target service has a private IP, through private services access (PSA) or Private Service
  Connect (PSC). bqto refuses a target service that has only a public IP.
* The region and VPC network of the target service have a subnet where a VM can run.

**1. Sign in to Google Cloud**

```sh theme={null}
gcloud auth login
gcloud auth application-default login
```

Both logins must use the same account. bqto checks this.

**2. Enable the APIs**

Enable these APIs in the project of the target service:

```sh theme={null}
gcloud services enable compute.googleapis.com cloudresourcemanager.googleapis.com \
  iap.googleapis.com oslogin.googleapis.com sqladmin.googleapis.com --project PROJECT
```

For AlloyDB, replace `sqladmin.googleapis.com` with `alloydb.googleapis.com`. For Redis, use
`redis.googleapis.com`. For Valkey, use `memorystore.googleapis.com`.

**3. Allow IAP to reach the bastion**

The VPC network of the target service needs a firewall rule or policy that allows ingress on
tcp:22 from `35.235.240.0/20`, the IAP range. bqto checks for this rule, but does not create
it. A network admin can create one:

```sh theme={null}
gcloud compute firewall-rules create allow-iap-ssh \
  --project=NETWORK_PROJECT --network=NETWORK \
  --direction=INGRESS --action=ALLOW --rules=tcp:22 \
  --source-ranges=35.235.240.0/20
```

**4. Get the roles**

Ask an admin for these roles:

| Where | For | Roles |
| - | - | - |
| Service project | Finding the service | The viewer role of the service, such as `roles/cloudsql.viewer` |
| Service project | Creating and deleting the bastion | `roles/compute.instanceAdmin.v1` |
| Service project | SSH through IAP | `roles/iap.tunnelResourceAccessor`, `roles/compute.osLogin` |
| Network project (Shared VPC host, or the same project) | Subnet and firewall checks | `roles/compute.networkViewer` |
| Network project, Shared VPC only | Using the subnet | `roles/compute.networkUser` on the subnet |

If you use `roles/editor` instead of these roles, add `roles/iap.tunnelResourceAccessor` as
well. [Permissions](https://docs.bqto.dev/reference/permissions.md) has every role, a minimal custom role, and the
commands to grant them.

**5. Connect**

```sh theme={null}
bqto connect --project my-project --service cloudsql --instance my-db
```

Replace `my-project` and `my-db` with your project ID and your instance. Without flags, bqto
starts a wizard. The wizard asks for the project, the service, the instance, and the session
duration.

`bqto connect -h` lists every flag. `bqto help` lists the commands.

## What you see

```text theme={null}
$ bqto connect --project my-project --service cloudsql --instance orders-db
checking auth…
resolving endpoint…
checking firewall…
finding zones…
finding subnet…
creating bastion from debian-13-trixie-v20261027…
bastion bqto-410ded5f is in us-east1-b
opening tunnel…
ready: 127.0.0.1:15432 → 10.0.0.5:5432 (instance orders-db), bastion bqto-410ded5f, expires at 00:38 (in 29m)
try: psql "host=127.0.0.1 port=15432 user=postgres"
^C
deleting bastion…
bastion bqto-410ded5f is being deleted (about 2 minutes)
```

Wait for the `ready:` line before you connect. Then use the local port that it prints. The `try:`
line gives a command for the client of the service.

If the default port is taken, bqto says so and uses the next one. So read the number from
`ready:`. If you ask for a port with `-p`, bqto does not move it. If that port is taken, bqto stops
before it creates the bastion.

To end the session, press Ctrl-C. bqto deletes the bastion.

## How long a session lasts

`--duration` sets the lifetime of the VM. The default is `30m`, counted from when the VM starts.
The tunnel takes a minute or two to open, so the time that you can use is a little shorter. The
`ready:` line shows when the session ends. bqto warns you 5 minutes before the end.

The tunnel can drop in these cases:

* The laptop sleeps.
* The network changes.
* IAP closes the session.

If the VM is still running and the session still has time, bqto opens the tunnel again to the same
bastion. bqto stops after five attempts in a row, or as soon as the bastion is gone.

## When something fails

When a check or the tunnel fails, bqto prints the cause and a `Fix:` line.
[Troubleshooting](https://docs.bqto.dev/reference/troubleshooting.md) matches each tunnel error to its fix.

## Next steps

> [card] [Scripts and CI](https://docs.bqto.dev/guides/scripts-and-ci.md)
>
> Run a command through the tunnel, or read the session as JSON.

> [card] [Coding agents](https://docs.bqto.dev/guides/coding-agents.md)
>
> Let Claude Code, Codex, or Cursor open a session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.