Skip to content

docs(config): supplying a BigQuery service account key from the environment - #339

Merged
lloydtabb merged 3 commits into
mainfrom
bq-service-account-key-json-docs
Aug 15, 2026
Merged

docs(config): supplying a BigQuery service account key from the environment#339
lloydtabb merged 3 commits into
mainfrom
bq-service-account-key-json-docs

Conversation

@lloydtabb

@lloydtabb lloydtabb commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Docs for malloydata/malloy#3039, which adds serviceAccountKeyJson to the BigQuery connection — one secret string holding the whole key file, as JSON or base64, with the encoding detected rather than declared.

Two changes to setup/config.malloynb:

The BigQuery section gains the parameter, an example of pointing it at an environment variable, and the shell commands that produce each encoding (jq -c for JSON, base64 | tr -d '\n' for base64 — GNU base64 wraps at 76 columns, which is awkward in an environment variable even though the decoder tolerates it). It notes that the encoding needs no flag because JSON always starts with { and { is not a base64 character, and that surrounding whitespace is ignored. It also mentions that with no key configured the connection falls back to application default credentials, which is what most local development is actually using.

The section says plainly that serviceAccountKey cannot take an {"env": ...} reference, and quotes the error BigQuery gives when someone tries — The incoming JSON object does not contain a client_email field. That string is the entire symptom, and it names neither the property nor the reason, so it is worth having in a page that search will find.

The Environment Variables section currently opens with "Any property value can be replaced with an environment variable reference," which isn't true of json properties. The postgres and trino sections each already carry a local correction for their own json properties; this adds the general statement in the place where someone forms the expectation, and points to the string-typed property to use instead.

No new pages and no anchor changes; the one new cross-link resolves to the existing #bigquery-google-bigquery heading, checked against the site's own hashForHeading.

…the environment

`serviceAccountKey` is a `json` property, and json properties take their value
literally — an `{"env": "..."}` inside one is never resolved. A server holding
its key in an environment variable therefore cannot use that property, and the
failure arrives as an error from BigQuery about a missing client_email field
rather than anything naming the config.

Document `serviceAccountKeyJson` and `serviceAccountKeyJsonBase64`
(malloydata/malloy#3039), which are `secret` strings and do take references,
with the shell commands that produce each form. Also state the json-property
exception in the Environment Variables section, which until now claimed
without qualification that any property value can be replaced with a
reference.

Signed-off-by: lloyd tabb <lloyd@malloydata.org>
@lloydtabb lloydtabb self-assigned this Aug 13, 2026
Comment thread src/documentation/setup/config.malloynb Outdated
export BIGQUERY_CREDENTIALS_JSON_B64="$(base64 < service-account-key.json | tr -d '\n')"
```

Note that `serviceAccountKey` — the `json`-typed property — **cannot** take an environment variable reference. Like every `json` property, it treats `{"env": "..."}` as literal data, so that object itself becomes the credentials and BigQuery rejects it with `The incoming JSON object does not contain a client_email field`. Use one of the two `secret` properties above instead. If several are set, the order of precedence is `serviceAccountKey`, `serviceAccountKeyJson`, `serviceAccountKeyJsonBase64`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need this note @mtoy-googly-moogly, what do you think? Is it too verbose? The other is useful.

Comment thread src/documentation/setup/config.malloynb Outdated

You can also provide a plain string value directly — this is useful for testing but not recommended for shared or committed config files.

**One exception: `json` properties.** Properties whose type is `json` — `serviceAccountKey`, `ssl`, `session`, `extraCredential`, `extraHeaders` — hold structured data, and they take that data literally. A `{"env": "..."}` written inside one is not resolved; it is passed along to the driver as the object it looks like, which usually surfaces later as a confusing error from the driver rather than as a missing-variable message. Where a secret needs to come from the environment, use the string-typed property meant for it (for BigQuery, [`serviceAccountKeyJson`](#bigquery-google-bigquery)).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtoy-googly-moogly I think to kill this too, but I figured I'd discuss before doing it.

Follows the change in malloydata/malloy#3039 to a single
`serviceAccountKeyJson` that takes JSON or base64 and detects which. Drops the
separate base64 property, and states the true reason base64 is offered:
quoting, not newlines — a downloaded key file carries its newlines as `\n`
escapes, so the JSON is one line with none to mangle.

Signed-off-by: lloyd tabb <lloyd@malloydata.org>
Comment thread src/documentation/setup/config.malloynb Outdated
export BIGQUERY_CREDENTIALS_JSON="$(base64 < service-account-key.json | tr -d '\n')"
```

No flag distinguishes the two — the encoding is detected, since JSON always begins with `{` and `{` is not a base64 character. Surrounding whitespace is ignored, so a trailing newline from `$(cat …)` or a here-doc is harmless.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's lose this paragraph. I don't think anyone cares

Review feedback on #339. The detection rule (JSON starts with `{`, base64
can't) is implementation detail nobody reading this page needs — both
encodings work, which the examples already show. The json-property exception
in the Environment Variables section is dropped too; the note in the BigQuery
section covers the case a reader actually hits, and postgres and trino already
carry their own.

Signed-off-by: lloyd tabb <lloyd@malloydata.org>
@lloydtabb
lloydtabb merged commit 0bc0f1e into main Aug 15, 2026
5 checks passed
@lloydtabb
lloydtabb deleted the bq-service-account-key-json-docs branch August 15, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant