Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
MS Entra service principal authentication uses the credentials of a MS Entra service principal to authenticate. To create and manage service principals for Azure Databricks, see:
Note
Databricks recommends using OAuth machine-to-machine (M2M) authentication in most scenarios. OAuth M2M uses OAuth access tokens that are more robust when authenticating only with Azure Databricks. Only use MS Entra service principal authentication when you must authenticate with Azure Databricks and other Azure resources at the same time.
For more information, see Use Azure managed identities with Azure Databricks.
To configure MS Entra service principal authentication with Azure Databricks, you must set the following associated environment variables, .databrickscfg fields, Terraform fields, or Config fields:
The Azure Databricks host.
For account operations, specify
https://accounts.databricks.azure.cn.For workspace operations, specify the per-workspace URL, for example
https://adb-1234567890123456.7.databricks.azure.cn.If the MS Entra service principal has not already been added to the workspace, then specify the Azure resource ID instead. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource.
For account operations, the Azure Databricks account ID.
The Azure resource ID.
The tenant ID of the MS Entra service principal.
The client ID of the MS Entra service principal.
The client secret of the MS Entra service principal.
To perform MS Entra service principal authentication with Azure Databricks, integrate the following within your code, based on the participating tool or SDK:
To use environment variables for a specific Azure Databricks authentication type with a tool or SDK, see Authorize access to Azure Databricks resources or the tool's or SDK's documentation. See also Environment variables and fields for unified authentication and the Authentication method priority.
For account-level operations, set the following environment variables:
DATABRICKS_HOST, set to the value of your Azure Databricks account console URL,https://accounts.databricks.azure.cn.DATABRICKS_ACCOUNT_IDARM_TENANT_IDARM_CLIENT_IDARM_CLIENT_SECRET
For workspace-level operations, set the following environment variables:
DATABRICKS_HOST, set to the value of your Azure Databricks per-workspace URL, for examplehttps://adb-1234567890123456.7.databricks.azure.cn.ARM_TENANT_IDARM_CLIENT_IDARM_CLIENT_SECRET
For workspace-level operations, if the MS Entra service principal has not already been added to the workspace, then specify
DATABRICKS_AZURE_RESOURCE_IDalong with the Azure resource ID for the Azure Databricks workspace, instead ofHOSTalong with the workspace URL. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource for the Azure Databricks workspace.
Create or identify an Azure Databricks configuration profile with the following fields in your .databrickscfg file. If you create the profile, replace the placeholders with the appropriate values. To use the profile with a tool or SDK, see Authorize access to Azure Databricks resources or the tool's or SDK's documentation. See also Environment variables and fields for unified authentication and the Authentication method priority.
For account-level operations, set the following values in your .databrickscfg file. In this case, the Azure Databricks account console URL is https://accounts.databricks.azure.cn:
[<some-unique-configuration-profile-name>]
host = <account-console-url>
account_id = <account-id>
azure_tenant_id = <azure-service-principal-tenant-id>
azure_client_id = <azure-service-principal-application-id>
azure_client_secret = <azure-service-principal-client-secret>
For workspace-level operations, set the following values in your .databrickscfg file. In this case, the host is the Azure Databricks per-workspace URL, for example https://adb-1234567890123456.7.databricks.azure.cn:
[<some-unique-configuration-profile-name>]
host = <workspace-url>
azure_tenant_id = <azure-service-principal-tenant-id>
azure_client_id = <azure-service-principal-application-id>
azure_client_secret = <azure-service-principal-client-secret>
For workspace-level operations, if the MS Entra service principal has not already been added to the workspace, then specify azure_workspace_resource_id along with the Azure resource ID for the Azure Databricks workspace, instead of host along with the workspace URL. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource for the Azure Databricks workspace.
For the Databricks CLI, do one of the following:
- Set the environment variables as specified on the Environment tab.
- Set the values in your
.databrickscfgfile as specified on the Profile tab.
Environment variables always take precedence over values in your .databrickscfg file.
See also Microsoft Entra ID service principal authentication.
Note
MS Entra service principal authentication is supported on the following Databricks Connect versions:
- For Python, Databricks Connect for Databricks Runtime 13.1 and above.
- For Scala, Databricks Connect for Databricks Runtime 13.3 LTS and above.
For Databricks Connect, you can either:
- Use a config profile: Set workspace-level values in your
.databrickscfgfile as described on the Profile tab. Also set thecluster_idto your workspace instance URL. - Use environment variables: Set the same values as shown on the Environment tab. Also set the
DATABRICKS_CLUSTER_IDto your workspace instance URL.
Values in .databrickscfg take precedence over environment variables.
To initialize Databricks Connect with these settings, see Compute configuration for Databricks Connect.
For the Databricks extension for Visual Studio Code, do the following:
Set the values in your
.databrickscfgfile for Azure Databricks workspace-level operations as specified on the Profile tab.In the Configuration pane of the Databricks extension for Visual Studio Code, click Configure Databricks.
In the Command Palette, for Databricks Host, enter your per-workspace URL, for example
https://adb-1234567890123456.7.databricks.azure.cn, and then pressEnter.In the Command Palette, select your target profile's name in the list for your URL.
For more details, see Set up authorization for the Databricks extension for Visual Studio Code.
For account-level operations, for default authentication:
provider "databricks" {
alias = "accounts"
}
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as HashiCorp Vault. See also Vault Provider). In this case, the Azure Databricks account console URL is https://accounts.databricks.azure.cn:
provider "databricks" {
alias = "accounts"
host = <retrieve-account-console-url>
account_id = <retrieve-account-id>
azure_tenant_id = <retrieve-azure-tenant-id>
azure_client_id = <retrieve-azure-client-id>
azure_client_secret = <retrieve-azure-client-secret>
}
For workspace-level operations, for default authentication:
provider "databricks" {
alias = "workspace"
}
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as HashiCorp Vault. See also Vault Provider). In this case, the host is the Azure Databricks per-workspace URL, for example https://adb-1234567890123456.7.databricks.azure.cn:
provider "databricks" {
alias = "workspace"
host = <retrieve-workspace-url>
azure_tenant_id = <retrieve-azure-tenant-id>
azure_client_id = <retrieve-azure-client-id>
azure_client_secret = <retrieve-azure-client-secret>
}
For workspace-level operations, if the MS Entra service principal has not already been added to the workspace, then specify azure_workspace_resource_id along with the Azure resource ID for the Azure Databricks workspace, instead of host along with the workspace URL. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource for the Azure Databricks workspace.
For more information about authenticating with the Databricks Terraform provider, see Authentication.
For account-level operations, for default authentication:
from databricks.sdk import AccountClient
a = AccountClient()
# ...
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as Azure KeyVault). In this case, the Azure Databricks account console URL is https://accounts.databricks.azure.cn:
from databricks.sdk import AccountClient
a = AccountClient(
host = retrieve_account_console_url(),
account_id = retrieve_account_id(),
azure_tenant_id = retrieve_azure_tenant_id(),
azure_client_id = retrieve_azure_client_id(),
azure_client_secret = retrieve_azure_client_secret()
)
# ...
For workspace-level operations, for default authentication:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
# ...
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as Azure KeyVault). In this case, the host is the Azure Databricks per-workspace URL, for example https://adb-1234567890123456.7.databricks.azure.cn:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient(
host = retrieve_workspace_url(),
azure_tenant_id = retrieve_azure_tenant_id(),
azure_client_id = retrieve_azure_client_id(),
azure_client_secret = retrieve_azure_client_secret()
)
# ...
For workspace-level operations, if the MS Entra service principal has not already been added to the workspace, then specify azure_workspace_resource_id along with the Azure resource ID for the Azure Databricks workspace, instead of host along with the workspace URL. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource for the Azure Databricks workspace.
For more information about authenticating with Databricks tools and SDKs that use Python and that implement Databricks unified authentication, see:
- Set up the Databricks Connect client for Python
- Set up authorization for the Databricks extension for Visual Studio Code
- Authenticate the Databricks SDK for Python with your Azure Databricks account or workspace
For account-level operations, for default authentication:
import com.databricks.sdk.AccountClient;
// ...
AccountClient a = new AccountClient();
// ...
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as Azure KeyVault). In this case, the Azure Databricks account console URL is https://accounts.databricks.azure.cn:
import com.databricks.sdk.AccountClient;
import com.databricks.sdk.core.DatabricksConfig;
// ...
DatabricksConfig cfg = new DatabricksConfig()
.setHost(retrieveAccountConsoleUrl())
.setAccountId(retrieveAccountId())
.setAzureTenantId(retrieveAzureTenantId())
.setAzureClientId(retrieveAzureClientId())
.setAzureClientSecret(retrieveAzureClientSecret())
AccountClient a = new AccountClient(cfg);
// ...
For workspace-level operations, for default authentication:
import com.databricks.sdk.WorkspaceClient;
// ...
WorkspaceClient w = new WorkspaceClient();
// ...
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as Azure KeyVault). In this case, the host is the Azure Databricks per-workspace URL, for example https://adb-1234567890123456.7.databricks.azure.cn:
import com.databricks.sdk.WorkspaceClient;
import com.databricks.sdk.core.DatabricksConfig;
// ...
DatabricksConfig cfg = new DatabricksConfig()
.setHost(retrieveWorkspaceUrl())
.setAzureTenantId(retrieveAzureTenantId())
.setAzureClientId(retrieveAzureClientId())
.setAzureClientSecret(retrieveAzureClientSecret())
WorkspaceClient w = new WorkspaceClient(cfg);
// ...
For workspace-level operations, if the MS Entra service principal has not already been added to the workspace, then specify setAzureWorkspaceResourceId along with the Azure resource ID for the Azure Databricks workspace, instead of setHost along with the workspace URL. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource for the Azure Databricks workspace.
For more information about authenticating with Databricks tools and SDKs that use Java and that implement Databricks unified authentication, see:
- Set up the Databricks Connect client for Scala (the Databricks Connect client for Scala uses the included Databricks SDK for Java for authentication)
- Authenticate the Databricks SDK for Java with your Azure Databricks account or workspace
For account-level operations, for default authentication:
import (
"github.com/databricks/databricks-sdk-go"
)
// ...
a := databricks.Must(databricks.NewAccountClient())
// ...
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as Azure KeyVault). In this case, the Azure Databricks account console URL is https://accounts.databricks.azure.cn:
import (
"github.com/databricks/databricks-sdk-go"
)
// ...
a := databricks.Must(databricks.NewAccountClient(&databricks.Config{
Host: retrieveAccountConsoleUrl(),
AccountId: retrieveAccountId(),
AzureTenantId: retrieveAzureTenantId(),
AzureClientId: retrieveAzureClientId(),
AzureClientSecret: retrieveAzureClientSecret(),
}))
// ...
For workspace-level operations, for default authentication:
import (
"github.com/databricks/databricks-sdk-go"
)
// ...
w := databricks.Must(databricks.NewWorkspaceClient())
// ...
For direct configuration (replace the retrieve placeholders with your own implementation to retrieve the values from the console or some other configuration store, such as Azure KeyVault). In this case, the host is the Azure Databricks per-workspace URL, for example https://adb-1234567890123456.7.databricks.azure.cn:
import (
"github.com/databricks/databricks-sdk-go"
)
// ...
w := databricks.Must(databricks.NewWorkspaceClient(&databricks.Config{
Host: retrieveWorkspaceUrl(),
AzureTenantId: retrieveAzureTenantId(),
AzureClientId: retrieveAzureClientId(),
AzureClientSecret: retrieveAzureClientSecret(),
}))
// ...
For workspace-level operations, if the MS Entra service principal has not already been added to the workspace, then specify AzureWorkspaceResourceId along with the Azure resource ID for the Azure Databricks workspace, instead of Host along with the workspace URL. In this case, the MS Entra service principal must have at least Contributor or Owner permissions on the Azure resource for the Azure Databricks workspace.
For more information about authenticating with Databricks tools and SDKs that use Go and that implement Databricks client unified authentication, see Authenticate the Databricks SDK for Go with your Azure Databricks account or workspace.