Add EnableOAuthSecretFromPwd connection parameter#1241
Open
gopalldb wants to merge 1 commit intodatabricks:mainfrom
Open
Add EnableOAuthSecretFromPwd connection parameter#1241gopalldb wants to merge 1 commit intodatabricks:mainfrom
gopalldb wants to merge 1 commit intodatabricks:mainfrom
Conversation
When using OAuth Client Credentials (M2M), BI tools like DBeaver expose the full JDBC URL in clear text, which leaks the OAuth2Secret. This commit introduces an opt-in EnableOAuthSecretFromPwd parameter that lets the driver read the OAuth client secret from the PWD/password property instead, leveraging BI tools' built-in password masking. Behavior when EnableOAuthSecretFromPwd=1: - getClientSecret() always reads from PWD/password (pwd takes priority over password, matching getToken() behavior) - OAuth2Secret is ignored even if explicitly set — PWD always wins - If neither PWD nor password is provided, throws a DatabricksDriverException with a clear error message - Covers all flows that call getClientSecret(): M2M Standard, M2M Azure, Refresh Token, and Browser-Based (U2M) Behavior when EnableOAuthSecretFromPwd=0 (default): - No change — getClientSecret() reads from OAuth2Secret as before Files changed: - DatabricksJdbcUrlParams: add ENABLE_OAUTH_SECRET_FROM_PWD enum - IDatabricksConnectionContext: add isOAuthSecretFromPwdEnabled() - DatabricksConnectionContext: implement isOAuthSecretFromPwdEnabled(), update getClientSecret() with PWD fallback and validation - DatabricksDriverPropertyUtil: skip reporting CLIENT_SECRET as missing in CLIENT_CREDENTIALS and TOKEN_PASSTHROUGH flows when the feature is enabled and PWD/password is present - DatabricksConnectionContextTest: 12 unit tests covering all scenarios - M2MAuthIntegrationTests: 3 integration tests (secret from pwd, pwd wins over explicit secret, missing pwd throws error) - OAuthTests: 1 E2E test for M2M with secret from password - IntegrationTestUtil: add getValidM2MConnectionWithSecretFromPwd() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
fb3c4a7 to
019f577
Compare
Collaborator
vikrantpuppala
left a comment
There was a problem hiding this comment.
why not also take the client ID as the user based on this param?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #1132 — OAuth secrets exposed in JDBC URL.
When using OAuth Client Credentials (M2M), BI tools like DBeaver treat the
passwordfield as sensitive (masked, not logged), but display the full JDBC URL in clear text. This exposes theOAuth2Secretparameter. This PR introduces an opt-inEnableOAuthSecretFromPwdconnection parameter that lets the driver read the OAuth client secret fromPWD/passwordinstead.New Connection Parameter
EnableOAuthSecretFromPwd01, read OAuth client secret fromPWD/passwordinstead ofOAuth2SecretBehavior
When
EnableOAuthSecretFromPwd=1:getClientSecret()always reads fromPWD/password(pwdtakes priority overpassword, matchinggetToken()behavior)OAuth2Secretis ignored even if explicitly set —PWDalways wins when the feature is enabledPWDnorpasswordis provided, throwsDatabricksDriverExceptionwith a clear error message:getClientSecret(): M2M Standard, M2M Azure, Refresh Token, and Browser-Based (U2M)When
EnableOAuthSecretFromPwd=0(default):getClientSecret()reads fromOAuth2Secretas before. Fully backward compatible.Usage Example
Files Changed
DatabricksJdbcUrlParams.javaENABLE_OAUTH_SECRET_FROM_PWDenum constantIDatabricksConnectionContext.javaisOAuthSecretFromPwdEnabled()interface methodDatabricksConnectionContext.javaisOAuthSecretFromPwdEnabled(), updategetClientSecret()with PWD reading + validation errorDatabricksDriverPropertyUtil.javaCLIENT_SECRETas missing when feature enabled andPWD/passwordis present (inCLIENT_CREDENTIALSandTOKEN_PASSTHROUGHflows)NEXT_CHANGELOG.mdDatabricksConnectionContextTest.javaM2MAuthIntegrationTests.javaOAuthTests.javaIntegrationTestUtil.javagetValidM2MConnectionWithSecretFromPwd()helperTest Coverage
Unit tests (12 new):
passwordproperty when feature enabledpwdtakes priority overpassword(same asgetToken())OAuth2Secretwhen feature enabledpwdparam wins over explicitOAuth2Secretwhen feature enabledOAuth2Secretas normalOAuth2Secretset but no PWD: throws error=0): normal behaviorAuth_Flow=2)Auth_Flow=0)Integration tests (3 new in M2MAuthIntegrationTests):
E2E test (1 new in OAuthTests):
getValidM2MConnectionWithSecretFromPwd()Test plan
mvn test -Dtest="com.databricks.jdbc.api.impl.DatabricksConnectionContextTest"(96 tests, 0 failures)mvn compile test-compilemvn spotless:apply🤖 Generated with Claude Code