Skip to content

fix(bigquery): migrate credential options to WithAuthCredentials* (ServiceAccount) - #492

Merged
kuldeep0020 merged 8 commits into
mainfrom
feat/pro-5712-bigquery-auth-credentials
Jun 10, 2026
Merged

kuldeep0020 merged 8 commits into
mainfrom
feat/pro-5712-bigquery-auth-credentials

Conversation

@kuldeep0020

@kuldeep0020 kuldeep0020 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Migrate the BigQuery client from the deprecated option.WithCredentialsJSON / option.WithCredentialsFile to option.WithAuthCredentialsJSON / option.WithAuthCredentialsFile, passing option.ServiceAccount explicitly.

Linear: PRO-5712.
Decision context: Slack thread — team agreed to standardise on service-account credentials across all BQ-using components.

Changes

  • db.go, driver/driver.go — use the new options with option.ServiceAccount.
  • driver.go — when disable_auth=true, skip credential options (mutually exclusive).
  • Extract optionsFor(config) + add options_test.go covering the four config shapes (disable-auth, JSON-only, file-only, with-endpoint).
  • mappings.go, legacy_mappings.go — gofumpt fixup, unrelated to the migration but required to pass the generated files gate.
  • Bump codecov/codecov-action to v7.0.0.

Validation

go build, go vet, go test, make fmt && git diff --exit-code all clean. Integration test (TestBigqueryDriver) skips without BIGQUERY_TEST_ENVIRONMENT_CREDENTIALS.

Replace the deprecated option.WithCredentialsJSON/WithCredentialsFile
(staticcheck SA1019) with option.WithAuthCredentialsJSON and
option.WithAuthCredentialsFile, which require an option.CredentialsType.

Add CredentialsTypeFromJSON to derive the type from the credential JSON
"type" field, falling back to the Unknown type (which skips credential-type
validation) for missing, unrecognised, or malformed payloads so existing
behaviour is preserved. The file-based path now surfaces a read error
instead of silently falling back.

Ref: PRO-5712
Table-driven tests for CredentialsTypeFromJSON across all mapped credential
types, the two types not exported by option, and the unknown fallbacks
(missing/non-string/malformed). Add a unit test asserting a missing
credential file surfaces a read error at connection open.

Ref: PRO-5712
@kuldeep0020
kuldeep0020 requested a review from atzoum as a code owner May 29, 2026 04:27
@codecov

codecov Bot commented May 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.73%. Comparing base (4c2c400) to head (1c87822).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #492      +/-   ##
==========================================
+ Coverage   84.54%   84.73%   +0.18%     
==========================================
  Files          96       96              
  Lines        4341     4342       +1     
==========================================
+ Hits         3670     3679       +9     
+ Misses        505      501       -4     
+ Partials      166      162       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Drop redundant parens around type-switch operands so 'make fmt' is a
no-op on CI. Surfaced by the gofumpt version bump pulled in via the
generated-files job.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the internal BigQuery driver to stop using deprecated Google API credential options by migrating to option.WithAuthCredentialsJSON / option.WithAuthCredentialsFile, introducing a helper to derive option.CredentialsType from credential JSON to preserve legacy behavior (skip type validation when unknown).

Changes:

  • Added driver.CredentialsTypeFromJSON to infer option.CredentialsType from the credential JSON "type" field with an Unknown fallback.
  • Migrated BigQuery driver and DB initialization to use WithAuthCredentials* options and removed deprecated option usage.
  • Added tests for credential-type derivation and for surfacing credential-file read errors.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sqlconnect/internal/bigquery/mappings.go Minor type-switch cleanup in JSON row mapping.
sqlconnect/internal/bigquery/legacy_mappings.go Minor type-switch cleanup in legacy JSON row mapping.
sqlconnect/internal/bigquery/driver/driver.go Migrates credential options; adds credential file read + auth type derivation.
sqlconnect/internal/bigquery/driver/driver_test.go Updates test connector to use WithAuthCredentialsJSON.
sqlconnect/internal/bigquery/driver/driver_open_test.go Adds coverage for missing credential file error path.
sqlconnect/internal/bigquery/driver/credentials.go Adds CredentialsTypeFromJSON helper.
sqlconnect/internal/bigquery/driver/credentials_test.go Adds unit tests for credential type derivation and fallbacks.
sqlconnect/internal/bigquery/db.go Migrates DB creation to WithAuthCredentialsJSON using derived credential type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 38 to 41
@@ -38,12 +39,15 @@ func (b bigQueryDriver) Open(uri string) (driver.Conn, error) {
opts = append(opts, option.WithoutAuthentication())
}
if config.credentialFile != "" {
kuldeep0020 and others added 3 commits June 9, 2026 11:11
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Address review feedback:

- When 'disable_auth=true', skip 'credential_file' / 'credentials_json'
  options so we (a) don't fail early on missing/unreadable credential
  files when auth is explicitly disabled, and (b) don't pass conflicting
  auth options ('WithoutAuthentication' together with credentials) to
  the BigQuery client.
- Assert 'db.Close()' in the cleanup of the new test for consistency
  with the rest of the package's cleanup hooks.
…ction

Per team agreement (see Slack thread linked in PR description), restrict
credential type to ServiceAccount everywhere instead of inferring it from
the credential JSON. The prod-DB scan across BQ/BQSTREAM/GCF/GoogleProsperousPubSub
showed no legitimate non-ServiceAccount configs; product docs document
service-account-only for every BQ-using destination.

- db.go, driver.go: pass option.ServiceAccount literally to
  WithAuthCredentialsJSON / WithAuthCredentialsFile.
- Drop CredentialsTypeFromJSON helper and its table-test; the option
  argument now communicates intent rather than discovering it.
- Drop the file-side os.ReadFile path: the underlying Google client
  opens the file lazily, so the local read added latency and an extra
  failure surface for no benefit.
- Drop driver_open_test.TestOpenMissingCredentialFile: the 'reading
  credential file' error string no longer exists; rewriting it against
  Google client internals would be brittle.
- Extract optionsFor(config) helper and add options_test.go covering
  the disable_auth=true / credentials_json / credential_file /
  endpoint branches without requiring a real BigQuery client.
@kuldeep0020 kuldeep0020 changed the title fix(bigquery): migrate google credential option to WithAuthCredentials* fix(bigquery): migrate credential options to WithAuthCredentials* (ServiceAccount) Jun 9, 2026
@kuldeep0020
kuldeep0020 requested a review from Copilot June 9, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +12 to +34
func optionTypeNames(opts []option.ClientOption) []string {
names := make([]string, len(opts))
for i, o := range opts {
names[i] = fmt.Sprintf("%T", o)
}
return names
}

func containsCredentials(name string) bool {
return strings.Contains(strings.ToLower(name), "credentials")
}

func containsWithoutAuth(name string) bool {
return strings.Contains(strings.ToLower(name), "withoutauthentication")
}

func containsScopes(name string) bool {
return strings.Contains(strings.ToLower(name), "scopes")
}

func containsEndpoint(name string) bool {
return strings.Contains(strings.ToLower(name), "endpoint")
}

@atzoum atzoum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Please bump codecov-action to 7.0.0 to fix the failing action.
  • Please trim down the description of this pr to only what is required and meaningful

@atzoum

atzoum commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

@kuldeep0020 updating main branch please rebase

v5.5.2 is failing on CI. Pinning to the v7.0.0 release SHA.
…y-auth-credentials

# Conflicts:
#	sqlconnect/internal/bigquery/db.go
@kuldeep0020
kuldeep0020 merged commit 500d383 into main Jun 10, 2026
31 of 33 checks passed
@kuldeep0020
kuldeep0020 deleted the feat/pro-5712-bigquery-auth-credentials branch June 10, 2026 07:57
kuldeep0020 pushed a commit that referenced this pull request Jun 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.26.0](v1.25.2...v1.26.0)
(2026-06-10)


### Features

* **databricks:** bump github.com/databricks/databricks-sql-go from
1.10.0 to 1.12.0
([#502](#502))
([d68b3a6](d68b3a6))
* **deps:** bump github.com/aws/aws-sdk-go-v2/service/sts from 1.41.10
to 1.42.3
([#490](#490))
([4c2c400](4c2c400))
* **redshiftdata:** bump
github.com/aws/aws-sdk-go-v2/service/redshiftdata from 1.38.4 to 1.40.1
([#500](#500))
([be2c9e8](be2c9e8))


### Bug Fixes

* **bigquery:** migrate credential options to WithAuthCredentials*
(ServiceAccount)
([#492](#492))
([500d383](500d383))


### Miscellaneous

* add dependabot cooldown
([#468](#468))
([2b09c56](2b09c56))
* **deps:** bump actions/create-github-app-token from 3.0.0 to 3.2.0
([#493](#493))
([841bf95](841bf95))
* **deps:** bump actions/labeler from 6.0.1 to 6.1.0
([#496](#496))
([069b5a6](069b5a6))
* **deps:** bump codecov/codecov-action from 5.5.2 to 7.0.0
([#494](#494))
([5b522cb](5b522cb))
* **deps:** bump golang.org/x/crypto from 0.51.0 to 0.52.0
([#501](#501))
([6ba33b0](6ba33b0))
* **deps:** bump golangci/golangci-lint-action from 8.0.0 to 9.2.1
([#498](#498))
([2cbb7f5](2cbb7f5))
* **deps:** bump google.golang.org/api from 0.267.0 to 0.280.0
([#503](#503))
([9ffaf40](9ffaf40))
* **deps:** bump step-security/harden-runner from 2.16.0 to 2.19.4
([#499](#499))
([3babb21](3babb21))
* **docs:** bootstrap agent knowledge for sqlconnect-go
([#497](#497))
([fcd11d4](fcd11d4))
* exclude trino from cleanup
([#478](#478))
([4feb215](4feb215))
* **vuln:** scope workflow permissions to least privilege (SEC-167)
([#479](#479))
([c57b20b](c57b20b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.

3 participants