Skip to main content
pilef-co/bqto-action connects a job to a private Google Cloud database or service through bqto. It needs no service account key, no VPN, and no runner inside the VPC network. The action carries the free bqto binary for Linux, so the job installs nothing.

Run a migration

This job runs a migration against a private Cloud SQL instance:
Replace my-project, my-db, the service account, and ./migrate up with your own. Setup creates the provider, the service account, and the variables that the job uses. The run command runs with bash:
  • It gets the local address in BQTO_HOST and BQTO_PORT, and PGHOST and PGPORT for Cloud SQL and AlloyDB.
  • The step fails when the command fails.
  • bqto deletes the bastion VM when the command ends.
The database login is separate from bqto. Pass a password from your secrets, as above, or an IAM token.

Use the session in later steps

Without run, the step ends when the session is ready. Later steps of the same job can use the session:
Later steps get BQTO_HOST and BQTO_PORT, and PGHOST and PGPORT for Cloud SQL and AlloyDB. The step also sets its outputs. At the end of the job, the action stops bqto, which deletes the bastion VM. The session listens on 127.0.0.1 of the runner:
  • Steps of the same job can reach it. Another job must run the action itself.
  • services: containers and uses: docker:// steps cannot reach it.
  • In a job with container:, the session runs inside that container. The image needs gcloud 550.0.0 or later.

Requirements

  • A Linux runner, amd64 or arm64, that supports node24 actions.
  • gcloud 550.0.0 or later. GitHub-hosted Ubuntu runners have it. On other runners, google-github-actions/setup-gcloud installs it.
  • google-github-actions/auth with service_account, then google-github-actions/setup-gcloud, before this action. Workload Identity Federation without a service account does not work with bqto.
  • The APIs, the firewall rule for IAP, and the roles that bqto needs in your project. See First connection.

Setup

Someone who can grant IAM roles in the project does this once. The provider below gives a token only to the production environment of .github/workflows/deploy.yml, run from main of your repository. Change the condition to match your own workflow.
The script reads REPO back from GitHub, because the condition compares names case-sensitively. After you rename the repository, update the condition and the binding.

Roles

Give the service account the minimal custom role of bqto. Limit it to VMs and disks named bqto-* with the condition in Narrowing the grant. Save the role as bqto-role.yaml and the condition as bqto-condition.yaml. Then run:
With Shared VPC, also grant the network project roles from Permissions. Do not give the account roles/editor.

Repository settings

  • Environments: create production, with required reviewers and deployments limited to main. Put DB_PASSWORD in its secrets.
  • Secrets and variables, Actions, Variables: set WIF_PROVIDER to projects/NUMBER/locations/global/workloadIdentityPools/github-deploy/providers/github.

Inputs

All inputs are optional. Set instance, or with bqto Pro, profile or stack. The action always passes --no-input. When runner debug logging is on, it also passes --debug.

Outputs

The action sets outputs only without run. They describe the first service of the session. sessions has one entry for each service. To read one field of sessions, use an expression such as fromJSON(steps.db.outputs.sessions)[0].tls.

bqto Pro

This section needs bqto Pro.
With edition: pro, the action runs the bqto Pro build that it carries. Save the key of a bqto Pro seat as a repository or organization secret, and pass it in license-key:
  • In CI, the key of a seat works in every job and repository of your organization. It does not take one of the computers of the seat.
  • The action hides the key in the log. The command in run and later steps do not get the key in their environment.
  • Without a key, or if bqto Pro cannot use the key, the job runs as the free bqto. A Pro feature then shows the reason.
What the action does differently with bqto Pro:
  • Cloud Run, Managed Kafka, and Memorystore clusters go through a SOCKS5 proxy. With run, the command gets ALL_PROXY and HTTPS_PROXY. Without run, later steps get BQTO_PROXY, and the proxy output is socks5.
  • Profiles and stacks come from the config file in your repository, which holds no secrets. To use several services, leave out run and use the session in later steps.
  • With run, the action refuses --web, because bqto prints the secret of the web proxy. Without run, the action masks web_token in the log.

Security

  • The job needs no service account key. It signs in with Workload Identity Federation.
  • bqto deletes the bastion VM when the command ends, when the job ends, and when someone cancels the job. If the runner kills bqto first, Compute Engine deletes the VM when duration runs out. Keep duration as short as the job allows.
  • Every port that bqto opens listens on 127.0.0.1. On a self-hosted runner that runs several jobs on one machine, another job can use your session. Use runners that run one job for each VM.
Pin the action to a full commit SHA, as you do for other actions that get credentials:
Each release has a v1.x.y tag. The v1 tag moves to the newest v1.x.y release. A change that can break a working workflow gets v2.