Enable workload identity federation for GitHub Actions
Databricks OAuth token federation, also known as OpenID Connect (OIDC), allows your automated workloads running outside of Databricks to securely access Databricks without the need for Databricks secrets. See Authenticate access to Databricks using OAuth token federation.
To enable workload identity federation for GitHub Actions:
After you enable workload identity federation, the Databricks SDKs and the Databricks CLI automatically fetch workload identity tokens from GitHub and exchange them for Databricks OAuth tokens.
Create a federation policy
First, create a workload identity federation policy. For instructions, see Configure a service principal federation policy. For GitHub, set the following values for the policy:
- Organization: The name of your Github organization. For example, if your repository URL is
https://github.com/databricks-inc/data-platform
, then the organization isdatabricks-inc
. - Repository: The name of the single repository to allow, such as
data-platform
. - Entity type: The kind of GitHub entity represented in the
sub
(subject) claim of your token. The default is Branch. Databricks recommends using Environment, which you can enable by setting theenvironment
attribute in your GitHub Actions YAML file. See Deploying to a specific environment. - Issuer URL:
https://token.actions.githubusercontent.com
- Subject: A string formed by concatenating values from the GitHub Actions job context.
- Audiences: The repository URL. If omitted, the Databricks account ID is used by default.
- Subject claim: (Optional) The JWT claim that contains the workload identity (
sub
) value from the OIDC token. For GitHub, leave the field assub
, which encodes the repository, branch, tag, pull/merge request, or environment that triggered the workflow.
For example, the following Databricks CLI command creates a federation policy for an organization named my-org
and a Databricks service principal numeric ID of 5581763342009999
:
databricks account service-principal-federation-policy create 5581763342009999 --json '{
"oidc_policy": {
"issuer": "https://token.actions.githubusercontent.com",
"audiences": [
"https://github.com/my-org"
],
"subject": "repo:my-github-org/my-repo:environment:prod"
}
}'
Configure the GitHub Actions YAML file
Next, configure the GitHub Actions YAML file. Set the following environment variables:
DATABRICKS_AUTH_TYPE
:github-oidc
DATABRICKS_HOST
: Your Databricks workspace URLDATABRICKS_CLIENT_ID
: The service principal (application) ID
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
my_script_using_wif:
runs-on: ubuntu-latest
environment: prod
env:
DATABRICKS_AUTH_TYPE: github-oidc
DATABRICKS_HOST: https://my-workspace.cloud.databricks.com/
DATABRICKS_CLIENT_ID: a1b2c3d4-ee42-1eet-1337-f00b44r
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Databricks CLI
uses: databricks/setup-cli@main
- name: Run Databricks CLI commands
run: databricks current-user me