Skip to content

refactor(db): move the Google credential and token code to src/lib/db/auth/google - #2299

Merged
cevheri merged 2 commits into
mainfrom
refactor/db-auth-google
Nov 15, 2026
Merged

cevheri merged 2 commits into
mainfrom
refactor/db-auth-google

Conversation

@cevheri

@cevheri cevheri commented Nov 15, 2026

Copy link
Copy Markdown
Member

Moves Firestore's Google credential and token code out of the provider directory into a new shared layer, src/lib/db/auth, so the next Google provider signs in through one implementation instead of a copy.
Firestore keeps every sentence, request, lane option and error it had; its existing tests are the oracle and pass with only import and pin edits.

What changes

  • src/lib/db/auth/google/credentials.ts and token-source.ts are the two Firestore files, moved with git mv and made provider-neutral.
    Policy now comes in as a rules object: the accepted kinds (a kind the parser knows and the rules omit is refused as unsupported), the quota-project rule and a server-identity gate.
    resolveGoogleCredential is the one entry to the ADC chain: its reader is no longer exported, so the chain is reachable only through the gate.
    The token source accepts any credential it is given, so a provider passes it only what resolveGoogleCredential returned.
    The token source takes one transport factory and builds its lane options itself, through one strategy per credential kind in a typed table.
  • src/lib/db/auth/server-identity-gate.ts: managed exactly true, then the provider's *_SERVER_CREDENTIALS opt-in exactly "true", in one place.
  • src/lib/db/auth/lanes.ts: the transport options of every credential-endpoint lane (one socket, TLS against the host, no 101, link-local refused unless it is the metadata lane), imported only inside the layer.
  • Firestore declares its three kinds and its gate in credential-policy.ts, passes its seams' createTransport straight through, and builds its secret forms with googleCredentialSecrets.
    GOOGLE_TOKEN_URL and the two ADC variable names leave Firestore's constants.ts; FIRESTORE_ENV_NAMES is the same six names in the same order.
  • tests/unit/db/auth/seam-guard.test.ts holds the layer's lines (AUTH1 to AUTH6: imports, ambient effects, engine names, module state, import direction, one copy of each mechanism), each proven with a planted violation.
    BigQuery's own copy is the one listed AUTH6 exception, with its count.
  • tests/unit/lib/governance/preflight.test.ts now finds every *_SERVER_CREDENTIALS literal under src/ and checks that the governance preflight refuses it when set to "true".
  • docs/DB_AUTH.md is new; ARCHITECTURE.md, ADDING_A_PROVIDER.md, docs/providers/firestore.md and the launcher comment point at it.

BigQuery is not touched.

User-visible change

  • A Google token or metadata refusal whose reason quotes a form of the configured credential (the token, a key, a key id, a client secret, a refresh token, or their base64 or URL-encoded forms) now shows the fixed withheld sentence in place of the reason.
    Any other reason is unchanged and still cut at 300 characters.
    The error table in docs/providers/firestore.md says so.

Test plan

bun tests/run-tests.ts tests/unit/db/auth/seam-guard.test.ts
bun tests/run-tests.ts tests/unit/db/auth/server-identity-gate.test.ts
bun tests/run-tests.ts tests/unit/db/auth/lanes.test.ts
bun tests/run-tests.ts tests/unit/db/auth/google/credentials.test.ts
bun tests/run-tests.ts tests/unit/db/auth/google/token-source.test.ts
bun tests/run-tests.ts tests/unit/db/firestore/credential-policy.test.ts
bun tests/run-tests.ts tests/unit/lib/governance/preflight.test.ts
SEED_CONFIG_PATH= heavy bun tests/run-tests.ts tests/unit/db/auth tests/unit/db/firestore tests/integration/db/firestore-provider.test.ts tests/unit/lib/no-engine-branches.test.ts
(cd vscode-extension && npm ci --ignore-scripts) && bun run format && bun run lint && bun run typecheck && bun run knip && bun run chart:check && bun run channels:showcase:check && bun run readme:check && bun run security:check && bun run test && bun run build
bun run test:coverage && bun run coverage:check
bun run build:lib && bun run attw && bun run lib:closure
cd vscode-extension && npm run build

Review the moves with git diff -M30% origin/main... so the two source files show as renames.

…/auth/google

Firestore's Google credential parsing, ADC chain, grants and token cache move
out of the provider directory into a shared layer, src/lib/db/auth, which a
second Google provider can sign in through without a copy. Firestore declares
its accepted kinds and its server-identity gate as rules and keeps every
sentence and request it had.

The layer starts with the server-identity gate, the credential-endpoint lane
options, a seam guard (AUTH1 to AUTH6) and docs/DB_AUTH.md. A governance test
now finds every *_SERVER_CREDENTIALS opt-in under src/ and checks that the
preflight refuses it.

One hardening: a token or metadata refusal reason that holds a form of the
credential is withheld whole instead of quoted.
…/auth/google

Review round 1: pin the token URL literal and the 300-character cut of a refusal reason exactly, document the withheld reason in the Firestore error table, word the gate by the managed flag instead of server-written, and narrow the only-way claim to the ADC chain.
@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 d3fe797 into main Nov 15, 2026
29 checks passed
@cevheri
cevheri deleted the refactor/db-auth-google 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