Authorize a service principal to access Git folders
A service principal is a non-human identity used to authenticate automated workflows in Databricks. This page explains how to authorize a service principal to use Git credentials for Git folder operations.
Add Git credentials using the Databricks UI
To link Git credentials to a service principal:
- As a workspace admin, log in to the Databricks workspace.
- Click your username in the top bar and select Settings.
- Click the Identity and access tab.
- Next to Service principals, click Manage.
- Select the service principal that you want to update with Git credentials.
- Click the Git integration tab.
- Click Add Git credential.
- Choose the Git provider from the dropdown menu and fill out the required fields.
- Click Save or Link, depending on which provider you chose.
The service principal now uses the linked Git credentials when accessing your Databricks workspace Git folder resources as part of your automation.
Add Git credentials using the Databricks CLI
Configure service principal Git access using the Databricks CLI for automation workflows.
Before you begin, verify that you have:
- The Databricks CLI installed and configured.
- A personal access token from your Git provider. See Configure Git credentials & connect a remote repo to Databricks.
To provide authorized access to your Git folders for service principals using the Databricks CLI:
-
Create a service principal in your workspace:
Bashdatabricks service-principals create --display-name "Git Automation Service Principal"Note the
applicationIdandidvalues from the output. You'll need them in the next steps. -
Generate an OAuth secret for the service principal:
Bashdatabricks service-principal-secrets-proxy create <service-principal-id>Replace
<service-principal-id>with the 15-digitidvalue from the previous step.Copy the
secretvalue from the output. -
Add Git provider credentials for the service principal.
Configure the Databricks CLI to authenticate as the service principal using OAuth:
Bashexport DATABRICKS_HOST=<workspace-url>
export DATABRICKS_CLIENT_ID=<application-id>
export DATABRICKS_CLIENT_SECRET=<oauth-secret>Replace:
<workspace-url>with your workspace URL<application-id>with the application ID from step 1<oauth-secret>with the OAuth secret from step 2
Then add the Git credentials:
Bashdatabricks git-credentials create <git-provider> \
--personal-access-token <git-pat> \
--git-email <git-email>Replace:
<git-provider>with your provider, such asgitHuborgitLab<git-pat>with your Git provider personal access token<git-email>with your Git email address
Some Git providers require
--git-usernameor--git-emailto properly authenticate. GitHub, for example, requires at least one of these parameters.
The service principal can now access Git folders using the linked credentials.
Retrieve service principals programmatically
Retrieve service principals for your workspace using the Databricks SDK, REST APIs, or CLI.
To use the Databricks SDK from a notebook:
- Install the Databricks SDK:
%pip install databricks-sdk --upgrade - Import
ApiClientfromdatabricks.sdk.core. - Call the service principals API.
For code examples, see the Databricks SDK for Python documentation.
You can also use curl, the Databricks CLI, or Terraform to work with service principals programmatically.