BigQuery
BInbox queries BigQuery through its REST API. It asks Google for a token with the read-only scope
(bigquery.readonly), so a connection can list, describe and query and can never write, whatever roles the service
account holds.
BigQuery bills by the data a query scans, so the connection’s cost guards include a limit on the data billed per query, which starts at 10 GB.
What BInbox reads, and what it costs
Section titled “What BInbox reads, and what it costs”BigQuery bills a query for every column it reads, across every row of the table, and a LIMIT does not lower the bill.
- A table’s first rows, which the setup step reads, cost nothing, because BInbox reads them through BigQuery’s table data API and runs no query.
- A view’s rows need a query. BInbox first asks BigQuery what reading the whole view would cost, which is free. When that cost is under the connection’s limit, BInbox reads the view’s first rows.
- A large view is read by its recent days. When the cost is over the limit, BInbox looks for a date column of the view whose filter lowers the cost, which is the column the view’s table is partitioned by. BInbox reads the last 31 days by that column. It reads 7 days or 1 day where 31 would pass the limit, and a year or 5 years where the last 31 days hold no rows. The Data view says which days and which column BInbox read. A view with no such column is refused at this step.
- The Dashboard’s figures are queries that read only the columns the setup uses, added up in BigQuery, across the table’s whole history. A large table can therefore pass the connection’s limit here even when the setup step opened.
- Columns to read turns off the columns the report does not need. BigQuery then bills only for the columns turned on, and Pick a table shows the price of reading them, against the connection’s limit, before anything runs (Pick a table). For a wide view, this is the first thing to try.
- Rows to read bounds both the setup step and the figures. On Pick a table, choose the last 12, 24 or 36 months, or a first day, by the date column the table is partitioned by (Pick a table). The setup step and every figure then read only those days, and BigQuery bills only for them.
For a large table, give BInbox a smaller one to read. That can be a view with only the columns your reports use, or a table that a scheduled query in BigQuery writes each night with those columns and the years you report on. A view that keeps fewer rows lowers the bill only when the table is partitioned or clustered on the column the view filters by. A view of a partitioned table should select the partition’s date column, so the setup step can read the view’s recent days.
What you will paste into BInbox
Section titled “What you will paste into BInbox”On New connection, choose BigQuery.
| Field | What to enter |
|---|---|
| Project | The Google Cloud project id that queries run in and are billed to, such as my-company-data. |
| Dataset | Optional. The dataset a table name without one is read from. |
| Location | Optional. A location such as US, EU or europe-west2. |
| How BInbox signs in | Choose A service account’s user name and password or key file (the key file path below) or BInbox’s own identity, trusted by the warehouse (no secret kept) (the managed identity path). |
| Service account key (JSON) | The key file Google gave you. Choose it with Choose file, and BInbox fills Project from the file when that field is blank. Paste instead takes the file’s text. |
| Workload identity provider | Managed identity only. The provider’s full name, //iam.googleapis.com/projects/…/providers/…. |
| Service account to act as | Managed identity only, optional. A service account’s email address. |
Path 1: a service account’s key file
Section titled “Path 1: a service account’s key file”With the command line
Section titled “With the command line”PROJECT=<project id>gcloud iam service-accounts create binbox-reader --project=$PROJECT --display-name="BInbox reader"SA=binbox-reader@$PROJECT.iam.gserviceaccount.com
# Read the tables, and run queries billed to the projectgcloud projects add-iam-policy-binding $PROJECT --member=serviceAccount:$SA --role=roles/bigquery.dataViewergcloud projects add-iam-policy-binding $PROJECT --member=serviceAccount:$SA --role=roles/bigquery.jobUser
# The key file; choose it in BInboxgcloud iam service-accounts keys create binbox-key.json --iam-account=$SATo read one dataset only, give BigQuery Data Viewer on that dataset instead of the project:
bq add-iam-policy-binding --member=serviceAccount:$SA --role=roles/bigquery.dataViewer $PROJECT:<dataset>BInbox then needs Dataset filled in, since it can read no other dataset. Keep BigQuery Job User on the project.
In the console
Section titled “In the console”- Open IAM and Admin, Service Accounts, in the project. Choose Create service account, name it
binbox-reader, and choose Create and continue. - Under Grant this service account access to project, add the roles BigQuery Data Viewer and BigQuery Job User. Choose Done.
- Open the new service account, then the Keys tab. Choose Add key, Create new key, JSON, Create. The browser downloads the key file.
- In BInbox, choose the downloaded file under Service account key (JSON). Then delete the downloaded file.
If your organization blocks key creation (the policy iam.disableServiceAccountKeyCreation), use the managed
identity path or ask the administrator for an exception.
Path 2: a managed identity
Section titled “Path 2: a managed identity”Choose this only when BInbox tells you the issuer and subject to trust. Until BInbox gives each account its own token, its identity is shared by every account (see Connect a warehouse), so use Path 1.
The warehouse trusts BInbox’s identity through a workload identity pool. BInbox presents its token to Google’s security token service with the provider’s full name as the audience, and then acts as the service account you name.
PROJECT=<project id>gcloud iam workload-identity-pools create binbox --project=$PROJECT --location=globalPROJECT_NUMBER=$(gcloud projects describe $PROJECT --format='value(projectNumber)')PROVIDER=//iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/binbox/providers/binboxgcloud iam workload-identity-pools providers create-oidc binbox --project=$PROJECT --location=global \ --workload-identity-pool=binbox --issuer-uri=<issuer> --allowed-audiences=$PROVIDER \ --attribute-mapping=google.subject=assertion.subgcloud iam service-accounts add-iam-policy-binding $SA \ --member="principal://iam.googleapis.com/projects/$PROJECT_NUMBER/locations/global/workloadIdentityPools/binbox/subject/<subject>" \ --role=roles/iam.workloadIdentityUserecho $PROVIDERMake the service account and give it the two roles as in Path 1, but create no key. Paste $PROVIDER into Workload
identity provider, and the service account’s email into Service account to act as.
Least permissions
Section titled “Least permissions”| Role | On | Why BInbox needs it |
|---|---|---|
BigQuery Data Viewer (roles/bigquery.dataViewer) |
The project, or the one dataset | To list datasets and tables and read them. |
BigQuery Job User (roles/bigquery.jobUser) |
The project | To run queries, which are jobs in the project. |
Do not give BigQuery Data Editor, BigQuery Admin or an Owner or Editor role.
Check: the test-connection report
Section titled “Check: the test-connection report”Choose Test connection in BInbox. The first four permissions must be Granted, and the last two are optional.
| Permission | Granted when |
|---|---|
| Sign in | Google accepts the key, or the identity exchange, and gives a token. |
| List the datasets | The service account may list datasets in the project. |
| Read the tables in a dataset | It may list the tables of the connection’s dataset, or of the first dataset in the project. |
| Run a query | A dry run of SELECT 1 is accepted. A dry run reads nothing and costs nothing. |
| Estimate a query’s cost before it runs (optional) | The dry run reports the bytes it would process. |
| Refuse a write, so SQL an author writes can run (optional) | BigQuery refuses a delete of no rows from the first table of the dataset, DELETE FROM <table> WHERE FALSE, because BInbox’s token has the read-only scope. The delete is run, not dry run, since BigQuery accepts a dry run of a delete under that scope. It deletes nothing even where it is allowed, and it is billed at most 10 MB. Without this, authors still pick tables, but cannot write a dataset’s SQL. |
If Run a query is refused, the service account lacks BigQuery Job User. If Read the tables in a dataset says the project has no dataset, the project is empty or Dataset names one that does not exist.
Add it in BInbox
Section titled “Add it in BInbox”An owner or admin opens the Data tab at app.binbox.ai, chooses Connect, then New connection, fills in the fields above, and chooses Test and save. Connections describes the screen.
Then an author sets up a dataset from one of the connection’s tables or views, as Pick a table describes.