Repository navigation
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 <[email protected]> Signed-off-by: Gopal Lal <[email protected]>
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 Closes #1132. When using OAuth Client Credentials (M2M), BI tools like DBeaver mask the `password` field (not logged, hidden in the UI) but display the full JDBC URL in clear text — which exposes the `OAuth2Secret` embedded in the URL. This PR lets the driver read the OAuth **client secret** from the JDBC `password`/`PWD` property and the OAuth **client id** from the JDBC `user`/`UID` property, so users can pass them through `DriverManager.getConnection(url, user, password)` and let the BI tool mask the secret. ```java String url = "jdbc:databricks://host:443/default;AuthMech=11;Auth_Flow=1;httpPath=/sql/..."; // client id via user, secret via password — masked by the BI tool Connection conn = DriverManager.getConnection(url, "my-client-id", "my-oauth-secret"); ``` ### Behavior - Applies only in OAuth mode (`AuthMech=11`), across all OAuth flows that consume the client secret (M2M standard/Azure, refresh token, browser). - **Explicit params win:** if `OAuth2ClientId`/`OAuth2Secret` are set in the URL, they take precedence. The `user`/`password` values are used only as a fallback, so existing URLs behave identically. - `user`/`UID` value of `"token"` (the PAT sentinel) is ignored as a client id. - UID validation is relaxed in OAuth mode so a non-`"token"` UID may carry the client id. In PAT mode the `UID` must still be `"token"` or omitted (unchanged). - The missing-properties advisor (`getPropertyInfo`) no longer reports `OAuth2ClientId`/`OAuth2Secret` as missing when `user`/`password` supply them. ### Addresses prior review feedback This supersedes the stale PR #1241 and resolves both of its unaddressed review comments: - *"why is this gated?"* — the behavior is **ungated** (no feature flag), instead of the opt-in `EnableOAuthSecretFromPwd` flag. - *"why not also take the client ID as the user?"* — the client id is now read from the JDBC username. ## Changes | File | Change | |------|--------| | `DatabricksConnectionContext.java` | `getClientSecret()`/`getNullableClientId()` fall back to `password`/`user` in OAuth mode | | `DatabricksJdbcUrlParams.java` | Add `USER("user", ...)` param (the `user` arg from the 3-arg `getConnection` was previously unread) | | `ValidationUtil.java` | Allow non-`token` UID in OAuth mode | | `DatabricksDriverPropertyUtil.java` | Don't flag `OAuth2ClientId`/`OAuth2Secret` missing when `user`/`password` present | ## Test plan - [x] `mvn test -Plocal` (full unit suite): **3425 tests, 0 failures** - [x] 10 new unit tests in `DatabricksConnectionContextTest` (secret/id fallback, precedence, `token` sentinel, PAT-mode isolation) - [x] 4 new unit tests in `ValidationUtilTest` (OAuth vs PAT UID validation) - [x] 2 new unit tests in `DatabricksDriverPropertyUtilTest` (missing-property behavior) - [x] `mvn spotless:apply` - [ ] 2 new WireMock M2M integration tests in `M2MAuthIntegrationTests` (validate in CI — the OAuth token exchange requires the real M2M endpoint/creds available only in CI; recorded mappings copied from the existing `testSuccessfulM2MConnection` scenario) Co-authored-by: Isaac --------- Signed-off-by: Vikrant Puppala <[email protected]>
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