Skip to content

fix(bigquery): sign in through the shared Google auth - #2305

Merged
cevheri merged 2 commits into
mainfrom
fix/bigquery-shared-google-auth
Nov 15, 2026
Merged

cevheri merged 2 commits into
mainfrom
fix/bigquery-shared-google-auth

Conversation

@cevheri

@cevheri cevheri commented Nov 15, 2026

Copy link
Copy Markdown
Member

BigQuery now signs in through the shared Google auth in src/lib/db/auth/google, the module Firestore already uses, and its own copy of the credential and token code (bigquery/auth.ts) is deleted.
BigQuery keeps only its policy, declared in the new bigquery/credential-policy.ts: the three kinds it accepts, its opt-in BIGQUERY_SERVER_CREDENTIALS, its two server-identity sentences (byte-identical), its scope and its project id rule.
This closes D294.

What changes

  • src/lib/db/providers/sql/bigquery/credential-policy.ts is new: the rules object, resolveBigQueryCredential (the process environment and files read at each connect, as before), and bigQueryTokenSourceDeps(), whose transport factory is createNodeTransport itself.
  • bigquery/index.ts resolves the credential through the policy; its own browser-empty branch is gone, because the shared gate raises the same sentence.
  • bigquery/transport.ts builds its token source with createGoogleTokenSource, none under BIGQUERY_EMULATOR_HOST as before; it sends x-goog-user-project on API lanes, checks closed before asking for a token, cancels a job with the bearer of the lane the job last ran on, and closes the token source in close().
  • tests/unit/db/auth/seam-guard.test.ts: the AUTH6 exception for bigquery/auth.ts is deleted; the list is empty, and the planted proofs plant their own exception.
  • tests/unit/db/bigquery/credentials.test.ts and token-source.test.ts are deleted: their mechanism cases live in tests/unit/db/auth/google/, their BigQuery cases in the new credential-policy.test.ts.
  • Docs: docs/providers/bigquery.md (Files table, section 3.2 keeps the policy and links docs/DB_AUTH.md#google, the logged-path sentence goes, every change below is listed), docs/providers/firestore.md (unpinned mechanism prose of 4.2 and 4.4 becomes a link), docs/DB_AUTH.md (lazy lanes, quota header, blank variables, empty AUTH6 list), docs/SECURITY.md control 3.40 and its id in scripts/security-check.mjs.
  • docs/BACKLOG.md: D294 deleted; D463 (bearer lane pool in BigQuery, Firestore and Snowflake), D464 (BigQuery API lanes without refusesLinkLocal and refusesUpgrade), D465 (isServiceAccountKey keeps CR and LF), D466 (BigQuery error mapping quotes Google's text with no secret forms) filed; REL6 re-measured.
  • bin/lib/launcher-utils.mjs and tests/live/bigquery-evidence.ts follow the move.

User-visible changes

Everything else keeps today's behaviour, including both server-identity sentences, "Google token request failed: " for a reason without a credential form, "The BigQuery connection is closed" for a call after close(), the scope, the emulator path and the agent leg.

# Change Test
1 A credential that does not parse gets the shared sentences instead of BigQuery's three credential-policy.test.ts "1:", integration "a credential that does not parse"
2 Empty strings in a key or authorized-user JSON are refused at parse credential-policy.test.ts "2:", integration "empty client_email"
3 A non-PKCS #8 key is refused at parse, a placeholder key JSON for the emulator included; an unimportable key is an authentication error before any request credential-policy.test.ts "3:"
4 The assertion carries kid from private_key_id credential-policy.test.ts "4:", integration "kid"
5 quota_project_id is checked with BigQuery's project rule and sent as x-goog-user-project on API and cancel requests, so that project needs serviceusage.services.use for the user (bigquery.md 3.3) credential-policy.test.ts "5:", transport.test.ts "5:", integration "quota project"
6 A raw line break inside a pasted JSON, as in a terminal-wrapped key, is removed before parsing credential-policy.test.ts "6:"
7 An ADC file holding a bare token is refused; the file text is trimmed credential-policy.test.ts "7:"
8 Blank GOOGLE_APPLICATION_CREDENTIALS and HOME count as unset credential-policy.test.ts "8:"
9 A gcloud ADC file that exists and cannot be read is refused; only an absent one moves on to the metadata server credential-policy.test.ts "9:"
10 On Windows the ADC file is read under %APPDATA% credential-policy.test.ts "10:"
11 GCE_METADATA_HOST is validated ([::1]:8080 kept, http://x refused) credential-policy.test.ts "11:"
12 expires_in 0 or below is one hour; an empty token is refused; a reason is cut to 300 characters; a null body is refused cleanly transport.test.ts "12:"
13 A long or markup type is not echoed credential-policy.test.ts "13:"
14 The token lane is built on the first refresh with refusesLinkLocal and refusesUpgrade; a pasted token builds none transport.test.ts "14:", integration "token lane"
15 close() closes the token source and aborts a refresh in flight; a later call keeps "The BigQuery connection is closed"; a job cancel uses the bearer and quota project of the job's lane, after close() too. A call waiting on a refresh that close() aborts now fails with "The request was cancelled", or "The Google token source is closed" while an assertion is being signed, where it failed with "The connection was closed, so the request did not complete" transport.test.ts "15:", and the unchanged close and abort tests
16 An unreadable credentials file is no longer logged with its path credential-policy.test.ts "a named file that cannot be read"
17 A token refusal whose reason holds a form of the credential is withheld whole transport.test.ts "17:"

Changes 7 and 9 remove silent fallbacks: a setup that relied on a bare token in an ADC file, or on an unreadable gcloud file falling through to the metadata server, now sees a refusal that names the cause.

The Turbopack warning count of bun run build on this branch is 6, none of them a BigQuery file (REL6 updated).

Test plan

bun tests/run-tests.ts tests/unit/db/bigquery/credential-policy.test.ts
bun tests/run-tests.ts tests/unit/db/bigquery/transport.test.ts
bun tests/run-tests.ts tests/unit/db/bigquery/provider.test.ts
bun tests/run-tests.ts tests/integration/db/bigquery-provider.test.ts
bun tests/run-tests.ts tests/unit/db/auth/seam-guard.test.ts
bun tests/run-tests.ts tests/unit/security-check.test.ts
bun tests/run-tests.ts tests/unit/backlog-structure.test.ts
SEED_CONFIG_PATH= heavy bun tests/run-tests.ts <every test that reads SECURITY.md, BACKLOG.md, DB_AUTH.md, bigquery.md, firestore.md or the launcher> tests/unit/db/auth tests/unit/db/bigquery tests/unit/db/firestore tests/unit/db/s3 tests/unit/db/http tests/unit/lib/governance tests/unit/lib/db/provider-cache-key.test.ts tests/integration/db/bigquery-provider.test.ts tests/integration/db/firestore-provider.test.ts
(cd vscode-extension && npm ci --ignore-scripts) && bun run format && bun run lint && bun run typecheck && bun run knip && bun run security:check && bun run readme:check && bun run channels:showcase:check
SEED_CONFIG_PATH= heavy bun tests/run-tests.ts --coverage tests/unit/db/bigquery tests/integration/db/bigquery-provider.test.ts   # every bigquery/ line covered
bun run build   # 6 Turbopack warnings

The new integration cases and the new transport cases fail on the base branch and pass here.
The full gate set, test:coverage with coverage:check, build:lib, attw, lib:closure and the VS Code build run in CI.

BigQuery now declares its credential policy in credential-policy.ts and
signs in through src/lib/db/auth/google; its own copy, auth.ts, is gone.
The move brings the shared parser, ADC chain and token source to
BigQuery, with 17 listed behaviour changes: shared refusal sentences,
quota project header, lazy guarded token lane, token source closed with
the connection, no logged credential path, and the rest in
docs/providers/bigquery.md. D294 is closed; D463 to D466 are filed.
Review round 1: pin the job cancel's bearer and quota project after
close() and the token deadline signal, list the close-during-refresh
sentence change, document serviceusage.services.use for a quota project
and the emulator's placeholder key, and correct D464, REL6 and control
3.40.
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@cevheri
cevheri merged commit 430c8fd into main Nov 15, 2026
39 checks passed
@cevheri
cevheri deleted the fix/bigquery-shared-google-auth branch November 15, 2026 05:59
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