Add EnableOAuthSecretFromPwd connection parameter#1241
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
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?
| "Comma-separated list of query prefixes (like INSERT,UPDATE,DELETE) that should return result sets instead of row counts", | ||
| ""); | ||
| ""), | ||
| ENABLE_OAUTH_SECRET_FROM_PWD( |
There was a problem hiding this comment.
why is this gated though, can we add this to telemetry if you still feel it should be gated (in order to monitor and deprecate this later)
|
This PR has been marked as Stale because it has been open for 30 days with no activity. If you would like the PR to remain open, please remove the stale label or comment on the PR. |
|
This PR was closed because it has been inactive for 7 days since being marked as stale. |
|
This PR has been marked as Stale because it has been open for 30 days with no activity. If you would like the PR to remain open, please remove the stale label or comment on the PR. |
|
This PR was closed because it has been inactive for 7 days since being marked as stale. |
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