Skip to main content
bqto acts as you. It uses your gcloud login and your Application Default Credentials, never a service account of its own. This page lists what your account needs. Two projects matter:
  • Service project: where the instance lives. bqto creates the bastion here.
  • Network project: the project that owns the VPC network. It is the same project, unless you use Shared VPC. With Shared VPC, it is the host project.

Roles

Roles for bqto Pro

These roles are for bqto Pro features.

roles/editor is not enough

roles/editor does not include iap.tunnelInstances.accessViaIAP, so the tunnel fails. Add roles/iap.tunnelResourceAccessor. bqto checks this before it creates the bastion, and prints the command to grant it. If the project does not exist or you cannot see it, bqto stops and suggests gcloud projects list.

APIs

bqto calls the following APIs, so you must enable them in the service project: If one of them is disabled, bqto prints the gcloud services enable command as its Fix: line. Also enable iap.googleapis.com and oslogin.googleapis.com. gcloud uses IAP for the tunnel, and the OS Login API for the short-lived SSH certificate. If one of them is disabled and gcloud needs it, the tunnel fails. bqto then shows the line of gcloud under last stderr:.
Replace sqladmin.googleapis.com with the API of your service.

Which project Google checks APIs and quota in

Google checks that an API is enabled, and counts its quota, in a quota project. As gcloud does by default, bqto uses the project of each call:
  • The lookup of the service, the IAP check, and the bastion use the service project. This is also true for the calls on a Shared VPC host project.
  • In a bqto Pro stack, each service uses its own project for its lookup. The IAP check and the bastion use the project of the first profile.
  • The project list of the wizard uses your gcloud project (gcloud config get project).
That project needs the Compute Engine API, the Cloud Resource Manager API, and the API of the service. You need roles/serviceusage.serviceUsageConsumer on it. Owner and Editor include it. If that project refuses a call, bqto sends the call again with the quota project of your ADC login (set by gcloud auth application-default login). The project can refuse a call because you lack that role, or because the API is disabled there. The second call works if that project has the API and you have the role on it. If both projects refuse the call, the error names the project of the call and the fix. This second call does not happen in two cases:
  • GOOGLE_CLOUD_QUOTA_PROJECT is set: every call uses that project. It always wins.
  • ADC is a service account (a key, impersonation, or the metadata server): the default of the Google client libraries applies, which is the quota project in the ADC file if it has one.

How to grant them

Set the project, and who gets the roles: a developer or a service account.
Service project. Use the viewer role of your service:
--condition=None makes the grant unconditional. gcloud asks for this flag when the project has a conditional grant. Network project, which is the same project unless you use Shared VPC:
Shared VPC only, on the subnet where bqto places the bastion:
bqto Pro, Cloud Run, only for a service that requires authentication:
bqto Pro, only with --image, when the image lives in a project of your own. The default Debian image is public and needs nothing.
The quota project. It is the service project, unless bqto falls back to your ADC quota project or you set GOOGLE_CLOUD_QUOTA_PROJECT:
Organization, optional. Without it, the wizard still lists your projects, but shows folder numbers instead of names.

Run as a service account

bqto checks that ADC and gcloud use the same account. To run as a service account without a key, impersonate it in both. You need roles/iam.serviceAccountTokenCreator on it:
  • A new grant of that role can take a few minutes to apply. Until then, bqto says that your account cannot impersonate the service account.
  • The gcloud config line applies to every gcloud command, not only bqto. To go back to your own account, run gcloud config unset auth/impersonate_service_account.
  • With a key file instead, run gcloud auth activate-service-account --key-file=KEY_FILE, and point GOOGLE_APPLICATION_CREDENTIALS at the same file.
  • Workload Identity Federation, as a GitHub Actions workflow gets it, works the same way as impersonation.
For Cloud Run, bqto Pro makes the identity token as that service account, for the URL of the service, in --web and in the try: line. The account needs roles/run.invoker on the service.

A minimal custom role

roles/compute.instanceAdmin.v1 is broad. It can manage every VM in the project, and it gives sudo on all of them through OS Login. This custom role for the service project holds only what bqto uses. Save it as bqto-role.yaml, and keep the lines of the services that you connect to.
Without Shared VPC, this role alone replaces the service project and network project roles in the table, IAP and OS Login included. A project-level custom role can only be granted in its own project. With Shared VPC, keep the predefined roles in the network project. Bastions set enable-oslogin-certificates=TRUE. So gcloud compute ssh asks the OS Login API for a short-lived certificate, instead of adding a key to your OS Login profile. roles/compute.osLogin and this custom role already hold the permission that this call checks. The bastion has no service account, so you also do not need roles/iam.serviceAccountUser.

Narrowing the grant

Only bastions

An IAM condition can limit roles/compute.instanceAdmin.v1, or the custom role, to VMs and disks whose names start with bqto-. List every zone of the region, and cover both instances and disks, because the boot disk takes the name of the VM. Save the condition as bqto-condition.yaml, with your project ID in place of P:
Then grant the role with it:
  • A condition allows at most 12 logical operators. This one has 9, and a region with four zones needs 11.
  • With predefined roles, put the same condition on roles/compute.osLogin too, so that the account can log in only to bastions.
  • The account cannot create or log in to a VM with another name. IAP cannot filter by VM name, so a tunnel to such a VM still opens.

Only SSH through IAP

IAP conditions cannot match VM names, but they can match the port. Grant roles/iap.tunnelResourceAccessor with the condition destination.port == 22. A tunnel to any other port of the bastion then fails with 4033: 'not authorized'. Google cannot check a conditional grant in advance. So bqto warns that the permission is possibly missing, and goes on.

No root through metadata

Creating a VM with metadata needs compute.instances.setMetadata. With it, anyone can set enable-oslogin=FALSE and an SSH key on a bastion, and the guest agent gives that key sudo. They can also set a startup-script that runs as root when the VM boots again. The organization policy compute.requireOsLogin makes OS Login apply, whatever the instance metadata says. The startup script needs a reboot. So also leave out compute.instances.reset, stop, and start, as the minimal custom role does. This comes from Google’s documentation and was not tested live.

Only for a while

Privileged Access Manager can grant the role for the length of a session. It works with predefined and custom roles, but not with Owner or Editor.