Skip to content

feat(go): add options for a caller's access token and an impersonation subject - #374

Open
geoHeil wants to merge 3 commits into
adbc-drivers:mainfrom
geoHeil:feat/caller-credentials
Open

geoHeil wants to merge 3 commits into
adbc-drivers:mainfrom
geoHeil:feat/caller-credentials

Conversation

@geoHeil

@geoHeil geoHeil commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What's Changed

Allow applications to supply an OAuth 2.0 access token through bigquery.auth_type=access_token and bigquery.auth.access_token. The driver uses the token without refreshing it.

Add bigquery.impersonate.subject for domain-wide delegation through the existing ADC-backed impersonation path. A subject requires a target principal.

Closes #333.

Generated-by: OpenAI Codex

…n subject

A client that signs in a user can get a Google credential for that user
at query time. The driver could not take two kinds of it.

Add the auth type access_token with the option bigquery.auth.access_token.
The driver sends the OAuth 2.0 access token as it is, and never refreshes
it. An empty token is refused. Every other auth type ignores the token, so
the driver refuses a token that the auth type does not select, and a token
that is set together with an impersonation option, because impersonation
replaces the base credential.

Add the option bigquery.impersonate.subject. The driver copies it into
impersonate.CredentialsConfig.Subject, which enables domain-wide
delegation without a service account key. A subject without a target
principal is refused, as any impersonation option is.

Both options can be read with GetOption. They have no URI parameter.

Closes adbc-drivers#333

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Automated review generated by GPT-6.1 Sol.

Adds caller-provided access tokens and an impersonation subject. One credential-propagation issue is noted inline.

  • [P0] Shorten the description to the motivation and significant design decisions; remove the test inventory, mutation-testing report, and command results. Complete the required validation before submission and add the required Assisted-by: trailer.

Comment thread go/connection.go
}
}
c.Logger.Debug("Using a static OAuth access token")
authOptions = append(authOptions, option.WithTokenSource(oauth2.StaticTokenSource(&oauth2.Token{AccessToken: c.accessToken})))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Preserve the caller’s identity for Storage Write ingestion. With auth_type=access_token and bulk_ingest.method=storage_write, the separately constructed write client receives no token and falls back to ADC. Token-only deployments therefore fail, while deployments with ADC write as the host identity instead of the caller. Although the underlying omission predates this PR, the new auth mode exposes it too. Pass the selected credential to the write client, or reject this combination before ingestion.

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.

Are you fine with my last commit to address this?

Reject the unsupported combination before table or stream requests can
fall back to ADC. Document load ingestion as the supported alternative
and cover connection and statement options through both execution paths.

Assisted-by: OpenAI Codex (GPT-6)
Comment thread go/docs/bigquery.md Outdated
`bigquery.auth.access_token`
: **Type:** string. **Default:** (empty)

If using `access_token` authentication, this is the OAuth 2.0 access token. The driver sends it as it is and does not refresh it, so it must stay valid for the life of the connection. An empty token is an error. A token set under any other `bigquery.auth_type` is an error, because that auth type would ignore it. A token set together with an impersonation option is also an error, because impersonation would replace it. Storage Write ingestion (`bigquery.bulk_ingest.method=storage_write`) is refused before ingestion because its separate client does not use this token; use the default `load` method instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
If using `access_token` authentication, this is the OAuth 2.0 access token. The driver sends it as it is and does not refresh it, so it must stay valid for the life of the connection. An empty token is an error. A token set under any other `bigquery.auth_type` is an error, because that auth type would ignore it. A token set together with an impersonation option is also an error, because impersonation would replace it. Storage Write ingestion (`bigquery.bulk_ingest.method=storage_write`) is refused before ingestion because its separate client does not use this token; use the default `load` method instead.
If using `access_token` authentication, this is the OAuth 2.0 access token. The driver does not refresh it, so it must stay valid for the life of the connection. Not compatible with impersonation or Storage Write.

Comment thread go/connection.go Outdated

authOptions := []option.ClientOption{}

// Every other arm ignores the token, which would drop it silently.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Every other arm ignores the token, which would drop it silently.

Comment thread go/connection.go Outdated
Comment on lines +937 to +938
// newImpersonatedTokenSource is a variable so that a test can observe the impersonation config.
var newImpersonatedTokenSource = impersonate.CredentialsTokenSource

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I really dislike tests that rely on globals like this. This is a -1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@geoHeil

geoHeil commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback.

This branch has not been deployed

No deployments
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.

Go driver: add options for a bare access token and for an impersonation subject

2 participants