Skip to content

Fix Azure OIDC endpoint selection to support both U2M and M2M authentication flows #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New Features and Improvements

### Bug Fixes
- Fix Azure OIDC endpoint selection to support both U2M and M2M authentication flows ([#453](https://github.com/databricks/databricks-sdk-java/pull/454)).

### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ private OpenIDConnectEndpoints fetchDefaultOidcEndpoints() throws IOException {
if (getHost() == null) {
return null;
}
if (isAzure() && getAzureClientId() != null) {

if (isAzure() && shouldUseAzureOidcEndpoints()) {
Copy link
Contributor

@hectorcast-db hectorcast-db May 30, 2025

Choose a reason for hiding this comment

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

Something to check/test, is whether this breaks Databricks OIDC. If I am reading this correct, Databricks OIDC will also try to connect to Azure endpoints.

Copy link
Contributor Author

@samikshya-db samikshya-db May 30, 2025

Choose a reason for hiding this comment

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

Thanks for the review, Hector!

The flows I have tested for this change is :

  1. U2M for azure databricks workspace
  2. M2M with databricks based credentials for Azure workspace
  3. M2M with Azure service principals for Azure workspace

Is there any other testing that you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Adding context from our offline discussion from the past week) : our product does not use this flow and we will need to build the testing infra to be able to test out the suggested flow.

Request request = new Request("GET", getHost() + "/oidc/oauth2/v2.0/authorize");
request.setRedirectionBehavior(false);
Response resp = getHttpClient().execute(request);
Expand Down Expand Up @@ -742,4 +743,13 @@ public DatabricksConfig newWithWorkspaceHost(String host) {
public String getEffectiveOAuthRedirectUrl() {
return redirectUrl != null ? redirectUrl : "http://localhost:8080/callback";
}

/**
* Determines if Azure-specific OIDC endpoints should be used. This is true in two cases: 1. When
* auth type is not specified (this is only in case of external browser auth) 2. When Azure client
* ID is present (service principal auth)
*/
boolean shouldUseAzureOidcEndpoints() {
return Objects.equals(getAuthType(), null) || getAzureClientId() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,35 @@ public void testGetTokenSourceWithOAuth() {
assertFalse(tokenSource instanceof ErrorTokenSource);
assertEquals(tokenSource.getToken().getAccessToken(), "test-token");
}

@Test
public void testShouldUseAzureOidcEndpointsForExternalBrowserAuth() {
DatabricksConfig config =
new DatabricksConfig()
.setHost("https://adb-1234567890.0.azuredatabricks.net/")
.setAuthType(null);
assertTrue(config.shouldUseAzureOidcEndpoints());
}

@Test
public void testShouldUseAzureOidcEndpointsForServicePrincipal() {
DatabricksConfig config =
new DatabricksConfig()
.setHost("https://adb-1234567890.0.azuredatabricks.net/")
.setAzureClientId("test-client-id")
.setAzureClientSecret("test-client-secret")
.setAzureTenantId("test-tenant-id");
assertTrue(config.shouldUseAzureOidcEndpoints());
}

@Test
public void testShouldNotUseAzureOidcEndpointsForAzureM2M() {
DatabricksConfig config =
new DatabricksConfig()
.setHost("https://adb-1234567890.0.azuredatabricks.net/")
.setAuthType("oauth-m2m")
.setClientId("test-client-id")
.setClientSecret("test-client-secret");
assertFalse(config.shouldUseAzureOidcEndpoints());
}
}
Loading