> ## 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.

# Security

> What bqto does with your identity, your network and your data, what it stores on your machine, what the audit logs record, and how to use it on shared machines and in CI.

This page is for the team that decides whether developers are allowed to use bqto. It says what bqto does
with your identity, your network, and your data, and what it does not do. The roles are in
[Permissions](https://docs.bqto.dev/reference/permissions.md).

## Data flows

```text theme={null}
developer's laptop ──HTTPS── Google APIs (Compute, the service's API, IAM, Resource Manager)
developer's laptop ──WSS──── IAP (tunnel.cloudproxy.app) ──tcp:22── bastion ──── the service's private IP
```

* bqto calls the APIs of Google. It sends no telemetry, and no server that Pilef runs is in the
  path. Outside a Google client library, bqto makes these HTTP calls only:
  * `oauth2.googleapis.com/tokeninfo`, to read the email of your own login.
  * GitHub, from `bqto version` and `bqto update` only.
  * Polar, from bqto Pro, to check the license key. See [License key](https://docs.bqto.dev/pro/license-key.md).
* Only `bqto version` and `bqto update` ask for the newest release. The free bqto sends one
  unauthenticated `GET` to `api.github.com/repos/pilef-co/bqto/releases/latest`, with the
  `User-Agent` `bqto` and nothing about you, your version, or your projects. GitHub sees your IP
  address. bqto Pro looks in the releases of `pilef-co/bqto-pro-releases` on GitHub. Nothing runs
  in the background. If you never want bqto to contact GitHub, do not run these two commands.
* `bqto update` checks what it downloads. It installs only an archive whose SHA-256 matches the
  `checksums.txt` of the release. It writes the new binary next to the old one, and then renames
  the new binary over the old one. So a failed update leaves the old binary in place.
  `checksums.txt` comes from the same release. So this check guards against a broken download, but
  not against a compromised release.
* The tunnel is the tunnel of gcloud: `gcloud compute ssh --tunnel-through-iap`. This is an SSH
  session through Identity-Aware Proxy to port 22 of the bastion, with port forwards to the service. From
  your laptop to the bastion, the traffic is inside that SSH session. From the bastion to the
  service, it is plain VPC traffic, encrypted only if the service itself uses TLS.
* Everything that bqto creates stays in your project: the bastion VM and its boot disk. bqto
  creates no service account and no IAM binding.
* bqto creates no firewall rule, but it needs one: an ingress rule for tcp:22 from
  `35.235.240.0/20`. bqto copies the target tags of that rule onto the bastion. So every other rule
  that uses those tags applies to the bastion too. Watch those tags.

### Data flows in bqto Pro

* Cloud Run, Managed Kafka, and Redis or Valkey clusters go through a SOCKS proxy on the bastion
  (`ssh -D`). That proxy reaches anything that the bastion can reach, not only the service. For
  Cloud Run, it uses Private Google Access. With `--web`, a proxy on `127.0.0.1` adds your identity
  token to each request.
* The `--web` proxy asks for the session secret. bqto makes one secret for each session. A
  request with neither the cookie that the link sets nor the `X-Bqto-Token` header gets 403. So
  another account on the machine cannot use the proxy as you. [Cloud Run](https://docs.bqto.dev/services/cloud-run.md#open-the-service-in-a-browser)
  lists the two limits that remain.

## What bqto stores on your machine

| What | Where | What it holds |
| - | - | - |
| Nothing, for the free bqto | | The free bqto keeps no configuration and no credentials |
| Profiles and stacks (bqto Pro) | `config.toml` in the bqto config folder: `~/Library/Application Support/bqto/` on macOS, `~/.config/bqto/` on Linux | Project, service, instance, and settings. No secrets |
| The license key (bqto Pro) | `license.json` in the same folder | The key. Only you can read the file |
| Recent sessions (Mac app) | The preferences of the app | Project, service, instance, and settings. No secrets |

gcloud also keeps files for the tunnel. [Cleanup](https://docs.bqto.dev/reference/cleanup.md) lists them.

## Credentials

| Credential | Where it lives | For how long |
| - | - | - |
| Your gcloud login and Application Default Credentials | Your laptop, where gcloud keeps them | Until you revoke them. bqto only reads them |
| The SSH key for the tunnel | `~/.ssh/google_compute_engine`, created by `gcloud compute ssh --quiet` with no passphrase. gcloud gets a short-lived OS Login certificate for it for each bastion | The key has no expiry. Each certificate is short-lived |
| Cloud Run identity tokens (`--web`, bqto Pro) | In memory, from `gcloud auth print-identity-token` | About an hour, refreshed by the proxy |
| The credentials of the bastion | None: the VM is created with no service account | |
| Database passwords and service tokens | Never seen by bqto: you type them into your own client | |

bqto never needs a service account key. bqto runs as a service account through impersonation or
Workload Identity Federation, with no key. See
[Run as a service account](https://docs.bqto.dev/reference/permissions.md#run-as-a-service-account).

## The bastion

* `e2-micro` by default, Shielded VM (secure boot, vTPM, integrity monitoring), from the public `debian-cloud`
  image, or the image that `--image` names in bqto Pro. The boot disk uses the default encryption
  of Google.
* No external IP and no service account. OS Login is on. If its subnet has Cloud NAT, the
  bastion can still reach the internet. bqto does not check for Cloud NAT.
* It deletes itself when `--duration` ends, even if bqto was killed. Compute Engine enforces the
  deadline, not bqto. The developer picks the duration: 30 minutes by default, and up to 120 days.
  An admin cannot set a limit on it.
* It carries the label `bqto=session` and a random name, `bqto-` plus eight hex characters. Nothing
  on it names the person who created it. The audit logs do.

## What a developer can do

bqto adds no power that a developer did not have. The roles that it needs let them create a VM and
open a tunnel by hand.

* Other addresses in the VPC: a bastion reaches what any VM there reaches. bqto does not limit
  it. To limit it, give bastions their own subnet with egress firewall rules, and grant
  `compute.subnetworks.use` on that subnet only. This setup needs the `--subnet` flag of bqto Pro,
  or a profile that holds it.
* Root on the bastion, a colleague's included: with `roles/compute.osAdminLogin` (bqto warns
  when the session has it), or through `compute.instances.setMetadata` on any `bqto-*` VM. The fix
  is the [minimal custom role](https://docs.bqto.dev/reference/permissions.md#a-minimal-custom-role), which holds no
  `reset`, `stop`, or `start`, together with the organization policy `compute.requireOsLogin`.
* Other ports of the bastion: closed by granting `roles/iap.tunnelResourceAccessor` with the
  condition `destination.port == 22`.
* Other VMs: closed by the IAM condition that limits the role to `bqto-*`.

[Narrowing the grant](https://docs.bqto.dev/reference/permissions.md#narrowing-the-grant) shows each condition.

## The audit trail

| Question | Where the answer is | Cost | Can it be turned off |
| - | - | - | - |
| Who created and deleted the bastion | Admin Activity, `compute.instances.insert` and `delete` | Free | No |
| Who logged in, to which bastion, with or without sudo | Data Access, `oslogin.googleapis.com` `CheckPolicy` | Data Access volume, inside the 50 GiB free tier for normal use | Yes, it is a project setting |
| Whether a session ended cleanly | A `delete` by the person, or `compute.instances.deferredDelete` by `system@google.com` when bqto was not there | Free | No |
| When the tunnel opened | Nowhere: IAP writes nothing for TCP forwarding | | |
| What was typed on the bastion | Nowhere | | |
| What was done in the service | The connection logs of the service, which see the IP of the bastion | For each service | Yes, they are off by default |

Who created a `bqto-*` VM:

```sh theme={null}
gcloud logging read \
  'logName:"cloudaudit.googleapis.com%2Factivity"
   AND protoPayload.methodName="v1.compute.instances.insert"
   AND protoPayload.resourceName:"instances/bqto-"' \
  --project $PROJECT --freshness 7d --limit 20 \
  --format='table(timestamp, protoPayload.authenticationInfo.principalEmail, protoPayload.resourceName.scope(instances))'
```

To ask about one bastion, add its name to `protoPayload.resourceName`. To see who removed it,
change `insert` to `delete`.

Who logged in to one:

```sh theme={null}
gcloud logging read \
  'protoPayload.serviceName="oslogin.googleapis.com"
   AND protoPayload.methodName:"CheckPolicy"' \
  --project $PROJECT --freshness 7d --limit 20 \
  --format='table(timestamp, protoPayload.authenticationInfo.principalEmail, protoPayload.request.instance, protoPayload.request.policy)'
```

The bastions that the deadline deleted, because bqto was not running:

```sh theme={null}
gcloud logging read \
  'protoPayload.methodName="compute.instances.deferredDelete"
   AND protoPayload.resourceName:"instances/bqto-"' \
  --project $PROJECT --freshness 7d --limit 20 \
  --format='table(timestamp, protoPayload.resourceName.scope(instances))'
```

## Shared machines and CI

bqto assumes one person for each machine. Every local port that bqto opens listens on `127.0.0.1`.
That keeps the network out, but not the other accounts and jobs on the same machine.

* The hints of bqto keep tokens out of the command line, where `ps` shows them to every user.
* A port forward and the SOCKS proxy have no login. Anyone on the machine can use them while the
  session is up.
* In bqto Pro, the `--web` proxy asks for the session secret.

In CI, run bqto where no one else shares the machine:

* GitHub-hosted runners are safe. Each job gets its own VM, which is deleted after the job.
* A self-hosted runner is safe when it runs one job for each VM, and the VM is deleted after the job
  (an ephemeral runner).
* A self-hosted runner that runs several jobs or repositories on one machine at the same time is a
  risk. Another job there can use your session, and with it your identity on the service.

The services still check who connects. bqto gets a developer to the port. The database, cache, or
API decides whether they get in.

## Report a vulnerability

Report a vulnerability privately, never in a public issue. Use the private vulnerability reporting
of GitHub. On the **Security** tab of [pilef-co/bqto](https://github.com/pilef-co/bqto), choose
**Report a vulnerability**. Fixes go into the latest release only.


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