Repository navigation
fix(bigquery): migrate credential options to WithAuthCredentials* (ServiceAccount) - #492
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
There was a problem hiding this comment.
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.CredentialsTypeFromJSONto inferoption.CredentialsTypefrom 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.
| @@ -38,12 +39,15 @@ func (b bigQueryDriver) Open(uri string) (driver.Conn, error) { | |||
| opts = append(opts, option.WithoutAuthentication()) | |||
| } | |||
| if config.credentialFile != "" { | |||
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.
| 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
left a comment
There was a problem hiding this comment.
- Please bump
codecov-actionto7.0.0to fix the failing action. - Please trim down the description of this pr to only what is required and meaningful
|
@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
🤖 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>
Summary
Migrate the BigQuery client from the deprecated
option.WithCredentialsJSON/option.WithCredentialsFiletooption.WithAuthCredentialsJSON/option.WithAuthCredentialsFile, passingoption.ServiceAccountexplicitly.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 withoption.ServiceAccount.driver.go— whendisable_auth=true, skip credential options (mutually exclusive).optionsFor(config)+ addoptions_test.gocovering 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 thegenerated filesgate.codecov/codecov-actionto v7.0.0.Validation
go build,go vet,go test,make fmt && git diff --exit-codeall clean. Integration test (TestBigqueryDriver) skips withoutBIGQUERY_TEST_ENVIRONMENT_CREDENTIALS.