Skip to content

fix(bigquery-jdbc): allow OAuthPvtKey without OAuthServiceAcctEmail for JSON service account keys - #15061

Open
logachev wants to merge 2 commits into
mainfrom
kirl/fix-inline-json-key-without-email
Open

logachev wants to merge 2 commits into
mainfrom
kirl/fix-inline-json-key-without-email

Conversation

@logachev

Copy link
Copy Markdown
Contributor

When using Service Account authentication (OAuthType=0) with an inline JSON key (or JSON key file path) in OAuthPvtKey, BigQueryJdbcOAuthUtility.parseOAuthProperties gated OAuthPvtKey on serviceAccountEmail != null. If OAuthServiceAcctEmail was omitted or passed as an empty string via Properties (which appendPropertiesToURL drops), OAuthPvtKey was silently ignored and getGoogleServiceAccountCredentials threw 'No valid credentials provided.', even though JSON keys contain client_email.

  • Accept non-blank OAuthPvtKey in parseOAuthProperties without requiring OAuthServiceAcctEmail, falling back to OAuthPvtKeyPath when OAuthPvtKey is null or blank.
  • Reject missing or blank OAuthServiceAcctEmail for non-JSON keys (PKCS#8 or P12) with an explicit error message.
  • Use explicit UTF-8 encoding in isJson and OAuthPvtKey byte conversion.
  • Add unit tests covering OAuthPvtKey with omitted/empty/whitespace OAuthServiceAcctEmail across URL, Properties, and DataSource paths.

…or JSON service account keys

When using Service Account authentication (OAuthType=0) with an inline JSON key (or JSON key file path) in OAuthPvtKey, BigQueryJdbcOAuthUtility.parseOAuthProperties gated OAuthPvtKey on serviceAccountEmail != null. If OAuthServiceAcctEmail was omitted or passed as an empty string via Properties (which appendPropertiesToURL drops), OAuthPvtKey was silently ignored and getGoogleServiceAccountCredentials threw 'No valid credentials provided.', even though JSON keys contain client_email.

- Accept non-blank OAuthPvtKey in parseOAuthProperties without requiring OAuthServiceAcctEmail, falling back to OAuthPvtKeyPath when OAuthPvtKey is null or blank.
- Reject missing or blank OAuthServiceAcctEmail for non-JSON keys (PKCS#8 or P12) with an explicit error message.
- Use explicit UTF-8 encoding in isJson and OAuthPvtKey byte conversion.
- Add unit tests covering OAuthPvtKey with omitted/empty/whitespace OAuthServiceAcctEmail across URL, Properties, and DataSource paths.
@logachev
logachev requested review from a team as code owners November 17, 2026 21:13

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the Google Service Account authentication logic in the BigQuery JDBC driver. Specifically, it removes the requirement for OAuthServiceAcctEmail when using JSON-based service account keys, while ensuring it remains mandatory for PKCS#8 and P12 private keys. It also introduces strict UTF-8 encoding handling for JSON parsing and private key bytes, adds robust null and empty checks, and includes comprehensive unit tests to validate these authentication scenarios. I have no feedback to provide as there are no review comments.

…key-without-email

# Conflicts:
#	java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDriverTest.java

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.

1 participant