Installing Databricks
Install the P0 Databricks integration from the P0 app or with the P0 Terraform provider: the connector, then each Databricks account, workspace, and catalog.
Install the connector first, then each Databricks account, workspace, and catalog that P0 should manage, either from the P0 app or with the P0 Terraform provider. The P0 app shows the Terraform to apply for each component. For what each one is, see How it works.
Before you begin
To install the integration, you need:
An AWS account for the connector, with P0's AWS IAM management installed for it. See Setting up AWS IAM management. The connector must run in a commercial AWS region, not in GovCloud, China, ISO, or European Sovereign Cloud regions.
An AWS admin of that account, to deploy the connector.
A Databricks account admin, or a service principal that is one, to add each account and workspace, and to turn admin requests on or off. See Sign in the Databricks provider. The P0 app has you add all of the Terraform to the configuration that holds the connector, so whoever applies it also needs AWS access to the connector's account.
The ID and URL of each workspace you add. To find them, see Databricks' Workspace instance names, URLs, and IDs.
A Unity Catalog metastore assigned to each workspace you add. P0 can't add a workspace without one.
To add a catalog, a Databricks account admin who is also the catalog's owner, holds
MANAGEon it, or is a metastore admin. Account admins don't getMANAGEon catalogs by default.Terraform 1.4 or later, with version 6.36.0 or later of the
hashicorp/awsprovider version 1.115.0 or later of thedatabricks/databricksprovider, and version 3.x of thekreuzwerker/dockerprovider. P0's RDS security perimeter and Postgres or MySQL connector modules pin the AWS provider to 5.x, so keep the connector's Terraform in a configuration without them.dockerand the AWS CLI wherever you run the connector's Terraform, with the AWS CLI signed in to the connector's AWS account. See The connector image.Databricks accounts and workspaces that are reachable over the public internet. Workspaces that accept only private connections, and workspaces or account consoles that limit access with an IP access list, aren't supported.
P0 grants access only to users who already exist in Databricks. For what each requestor needs, see Before you request.
The connector image
The connector runs P0's image, p0security/p0-connector-databricks on Docker Hub, pinned to a sha-<commit> tag and the digest that tag resolves to. A tag on Docker Hub can be pushed again, so the plan fails if the tag no longer resolves to the pinned digest. Lambda runs images only from Amazon ECR, so the connector's Terraform creates an ECR repository named p0-connector-databricks, with scan on push and immutable tags turned on, and copies the image into it by its digest. Because a tag in the repository can't be overwritten, nobody who can push to it can replace the image the Lambda runs. The copy runs docker and the AWS CLI on the machine that runs Terraform, and Terraform repeats it whenever the image's tag or digest changes. The image's digest in ECR can differ from the one pinned for Docker Hub, because the copy pulls only the image for the Lambda's platform. The Lambda runs the image by its ECR digest. The Lambda writes its logs to a CloudWatch log group, /aws/lambda/p0-connector-databricks, that the Terraform creates with 30-day retention. The Terraform tags the repository, the log group, the connector's IAM role, and its Lambda with ManagedBy = "Terraform" and ManagedFor = "P0".
If you run Terraform somewhere without docker, such as HCP Terraform's remote runs, the apply fails at the terraform_data resource that copies the image, or at the aws_ecr_image data source that reads it back. The error doesn't mention Databricks. Apply the connector's Terraform from a machine that has docker and the AWS CLI.
If that machine can't pull from Docker Hub, mirror the image to a registry it can pull from, keeping its tag and digest. Then point the connector's Terraform at your mirror by changing the image's name in its locals block.
Outbound web identity federation
Before you apply, check whether outbound web identity federation is already on in the account:
If it's on, the output shows "JwtVendingEnabled": true, and IssuerIdentifier holds the account's issuer URL. Import it rather than create it, using the terraform import command in the comments of the connector's Terraform. If the command fails with a FeatureDisabled error, or shows "JwtVendingEnabled": false, it's off, and the connector's Terraform turns it on.
To turn it on yourself instead, run aws iam enable-outbound-web-identity-federation, which prints the issuer URL as IssuerIdentifier, then import it as above.
Both commands need AWS CLI 2.32.0 or later. Older versions, such as 2.15, don't have them. Run aws --version to check yours.
To remove the connector and leave federation on, replace the resource with a removed block before you destroy the rest. Terraform then stops managing the setting without turning it off. The connector's Terraform has this block in its comments, with the resource's name filled in. removed blocks need Terraform 1.7 or later:
Sign in the Databricks provider
The Terraform for each account, workspace, and catalog uses an account-level databricks provider, whose host is your account console URL and which has your account_id. Unless you configure how it signs in, the provider uses whatever Databricks credentials it finds, such as a Databricks CLI login. Each person who plans or applies then needs their own Databricks account admin login. A plan reads the Databricks resources, so it needs the same sign-in as an apply.
Whoever the provider signs in as needs:
The account admin role.
To add a catalog, an assignment to the catalog's workspace, with the
USERpermission or higher. The provider grantsMANAGEon the catalog through the workspace that the grant'sprovider_configblock names, and account admins aren't assigned to workspaces by default.To add a catalog,
MANAGEon it, ownership of it, or metastore admin.
To run Terraform without personal logins, have the provider sign in as a Databricks service principal, using an identity token from an identity provider you already run Terraform with, such as your CI system or a cloud service account. The service principal has no secret to store or rotate, and one federation policy decides which workloads can sign in as it:
Create a service principal in the Databricks account, and give it the
account_adminrole. Don't create an OAuth secret for it. Whoever held the secret could act as an account admin.Add a federation policy to the service principal that trusts your identity provider's tokens. Set its issuer, the subject of the identity that runs Terraform, and its audience, which defaults to your Databricks account ID. See Databricks' Configure a federation policy.
Give it access to each catalog you add. Assign the service principal to the catalog's workspace with the
USERpermission, and have the catalog's owner or a metastore admin grant itMANAGE:Configure the provider to sign in only as the service principal. In the Terraform from the P0 app, the provider is in each account's Terraform, with an
alias. Addauth_typeandclient_idto it:With
auth_type = "env-oidc", the provider never uses a Databricks CLI login, client secret, or token left in the environment.Set
DATABRICKS_OIDC_TOKENbefore each plan or apply, to an identity token from your identity provider with the audience that the federation policy expects. For example, for a Google Cloud service account that the federation policy trusts:Google identity tokens last an hour, so mint a new one for a later plan. In GitHub Actions, set
auth_type = "github-oidc"instead and give the workflow theid-token: writepermission. The provider then requests the token from GitHub itself. See Databricks' Enable workload identity federation for GitHub Actions.
Install from the P0 app
Open p0.app, click Integrations, and under Resources select Databricks. P0 lists the components alphabetically, but install them in this order: Connector, Account, Workspace, then Catalog. When you've applied a component's Terraform, P0 checks that it can reach what the Terraform set up, and if it can't, the error says what to fix.
Install the connector
Select the Connector component, then click Add connector.
In Connector AWS account, select the AWS account the connector runs in. The list shows the AWS accounts where P0's AWS IAM management is installed and that don't have a connector yet. If P0's AWS IAM management isn't installed for any account, P0 asks you to install it first.
In Region, select the AWS region for the connector.
In Allowed email domains, enter a regular expression that matches the email domains of the users P0 may grant access to, such as
example\.com. Then click Next.Add the providers that P0 lists to your Terraform configuration, then add the connector's Terraform. Apply it as an AWS admin of the account, then click Next. P0 checks that it can invoke the connector. If AWS refuses the call or can't find the Lambda yet, P0 tries again for about half a minute before it reports the failure.
Click Finish.
The connector checks the domain after the @ in each requestor's P0 email and in their Databricks username, never in the other emails on their Databricks user. The match ignores case, and the pattern must match the whole domain: example\.com doesn't match mail.example.com. To allow subdomains, use (.+\.)?example\.com. To allow several domains, separate them with |, as in example\.com|example\.org. If your users' Databricks usernames are on another domain, such as Azure UPNs, include that domain too.
The connector's Terraform sets the pattern as the Lambda's DOMAIN_PATTERN environment variable. Keep your copy of that Terraform: P0 shows it only while you add the connector, and you change the pattern and the connector's image in it later. See Change the install later.
Add a Databricks account
Select the Account component, then click Add account.
In Account ID, enter your Databricks account ID. To find it, see Databricks' Locate your account ID.
In Connector, select the connector that reaches this account. If you haven't added the connector yet, P0 asks you to install it first.
In Accounts URL, enter the account console URL for the cloud your account runs on, then click Next:
AWS:
https://accounts.cloud.databricks.comAWS GovCloud:
https://accounts.cloud.databricks.usAzure:
https://accounts.azuredatabricks.netGoogle Cloud:
https://accounts.gcp.databricks.com
Add the Terraform that P0 shows to the Terraform configuration that holds the connector, and apply it as a Databricks account admin with AWS access to the connector's account. It creates P0's service principal in the account and adds a federation policy that lets the connector sign in as that principal with its AWS identity tokens. Then click Next.
In Service principal application ID, enter the value that
terraform output -raw <output-name>prints where you applied the Terraform. P0 shows the command with the output's name, which ends in_application_id.To let your users request account admin in this account, turn on Enable account-admin requests. P0's service principal then needs account admin itself.
Click Finish. If you turned on account-admin requests, P0 shows the Terraform that gives its service principal account admin. Add it to the same configuration, apply it as a Databricks account admin with AWS access to the connector's account, then click Next. P0 checks that it can sign in to the account as the service principal, and, with account-admin requests on, that the service principal is an account admin.
Add a workspace
Select the Workspace component, then click Add workspace.
In Workspace ID, enter the workspace's ID, such as
1234567890123456. When you're signed in to the workspace, it's the number after?o=in your browser's address bar.In Account, select the Databricks account the workspace belongs to. If you haven't added an account yet, P0 asks you to install one first.
In Workspace URL, enter
https://and the workspace's host in lowercase, with nothing after the host, such ashttps://dbc-1234abcd-5678.cloud.databricks.com. Leave out the/?o=and ID that your browser shows after it. Then click Next. The host is on the workspace domain of the cloud your account runs on:AWS:
cloud.databricks.comAWS GovCloud:
cloud.databricks.usAzure:
azuredatabricks.netGoogle Cloud:
gcp.databricks.com
If the URL is on another cloud's workspace domain than the account's, P0 refuses it with
Workspaces in the account at <accounts-url> are served from <domain>. Enter this workspace's URL on that domain.You can't change the URL after this step. To use another URL, remove the workspace and add it again.Add the Terraform that P0 shows to the Terraform configuration that holds the account, and apply it as a Databricks account admin with AWS access to the connector's account. It assigns P0's service principal to the workspace with the
USERpermission. Then click Next. P0 checks that it can reach the workspace at the URL you entered, and that the URL belongs to this workspace ID. If the URL belongs to another workspace, P0 says which one. See If a step fails.In Workspace name, enter a name for the workspace in P0, such as
analytics-prod. Requests show it, and approval rules can match it with theworkspacefilter'snamekey. See Available filters.To let your users request workspace admin on this workspace, turn on Enable workspace-admin requests. P0's service principal then needs to be a workspace admin itself.
Click Finish. If you turned on workspace-admin requests, P0 shows the workspace's Terraform with the
ADMINpermission in place ofUSER. In your Terraform configuration, replace the workspace'sdatabricks_mws_permission_assignmentblock with it. Apply it as a Databricks account admin with AWS access to the connector's account, then click Next. P0 checks that its service principal is a workspace admin.
Add a catalog
Select the Catalog component, then click Add catalog. If you haven't added a workspace yet, P0 asks you to install one first.
In Catalog key, enter the catalog's name in lowercase, then
@and the ID of the workspace that P0 reaches the catalog through, such asmain@1234567890123456. Under the key, P0 lists the workspaces you've added, with their IDs. Once the key names one of them, P0 lists the keys of the catalogs it can already see through that workspace, leaving out catalogs already added through any workspace in the account. A catalog that isn't listed works too: P0 sees a catalog only once its service principal has privileges on it. P0 can't add a catalog whose name contains#,?,%, or\. Contact support@p0.dev if you need P0 to manage one.Click Next. P0 refuses a key whose workspace you haven't added to P0.
Add the Terraform that P0 shows to the Terraform configuration that holds the account. Apply it as a Databricks account admin who is also the catalog's owner, holds
MANAGEon it, or is a metastore admin, with AWS access to the connector's account: every apply of that configuration also refreshes the account's and the connector's resources. It grants P0's service principalMANAGEon the catalog. Then click Next.Click Finish.
Add more catalogs the same way. Each new catalog needs only its own Terraform.
You can add each catalog once per metastore. Catalog names are unique within a metastore, so P0 refuses to add a catalog through a second workspace on the same metastore. It refuses when you click Next after the catalog's key, before you apply any Terraform, even if the catalog you added first isn't finished installing. Requests for that catalog go through the one you added first. To add it through another workspace instead, remove the first one.
If a step fails
When P0 can't check a component, the installer's message starts with what failed, such as P0 can't reach the Databricks connector in AWS account <aws-account-id> (<region>), then says why and what to do. For example, it can end with:
Databricks is busy or unavailable. Try again in a few minutes.AWS doesn't let P0 invoke the p0-connector-databricks Lambda. Check that the connector's Terraform, which lets P0's role invoke the Lambda, is applied, then try again.AWS has no p0-connector-databricks Lambda in the connector's account and region. Check that the connector's Terraform is applied in that region. If it was just applied, give the Lambda a few minutes to deploy, then try again.
When P0 can't reach a workspace you're adding, the message starts with P0's service principal can't reach Databricks workspace <workspace-id> at <workspace-url>, and the reason that follows starts with one of these:
Databricks workspace URL <workspace-url> belongs to workspace <other-workspace-id>, not <workspace-id>.You can't change the URL of a workspace you're adding, so remove the workspace and add it again with its own URL.Databricks workspace <workspace-id> has no Unity Catalog metastore.Assign the workspace a metastore, then try again.Service principal <application-id> can't call Databricks workspace <workspace-id> at <workspace-url>.Check the URL, and that the workspace's Terraform is applied.
When you turn on admin requests and P0 can't find the role, the message starts with P0 can't confirm its service principal is an account admin in Databricks account <account-id> or P0 can't confirm its service principal is an admin of Databricks workspace <workspace-id>. Apply the Terraform that P0 showed when you turned the setting on, as a Databricks account admin with AWS access to the connector's account, then try again.
For other failures, the message includes the explanation that Databricks or AWS gave. When P0 can't load the catalog suggestions, it also asks you to check that the account's and the workspace's Terraform are still applied.
Install with the P0 Terraform provider
Use the P0 Terraform provider's Databricks resources alongside the hashicorp/aws, databricks/databricks, and kreuzwerker/docker providers, at the versions listed in Before you begin. To set up the P0 provider, see Manage integrations as code with the P0 Terraform provider.
To install the connector, a Databricks account, its workspaces, and their catalogs in one configuration, start from Installing Databricks in one configuration in the Terraform registry. Each resource in it refers to the one before it, so you don't copy IDs between them.
Each resource's page in the Terraform registry has a complete example, including the AWS and Databricks resources: p0_databricks_connector, p0_databricks_account, p0_databricks_workspace, and p0_databricks_catalog. Start from those examples, and create the resources in this order:
Stage the connector with
p0_databricks_connector_staged. Setidto the AWS account ID, and setregionanddomain_pattern. In HCL, escape each backslash in the pattern, as in"example\\.com". Addlifecycle { ignore_changes = [domain_pattern] }, as the example does, so that changing the pattern later doesn't replace the connector.Deploy the connector in that AWS account and region:
Turn on outbound web identity federation for the AWS account.
Create an IAM role named
p0-connector-databricksthat Lambda can assume. Allow it to callsts:GetWebIdentityTokenonly for the audiencedatabricks, which the staged resource exposes asfederation_audience, and to write logs only to the Lambda's own CloudWatch log group,/aws/lambda/p0-connector-databricks, which you create.Check that the connector image's tag resolves to the digest in the example, and copy the image by that digest into an ECR repository with immutable tags in that account, and deploy it as a Lambda function named
p0-connector-databricksthat runs as that role, on thex86_64architecture, with a 30-second timeout. Set the Lambda'sDOMAIN_PATTERNenvironment variable todomain_pattern.Let P0's AWS IAM management role invoke the Lambda through a policy on that role (
aws_iam_role_policy), rather than a resource policy on the Lambda.
Then create
p0_databricks_connectorwith the same values andlifecycleblock as the staged resource. P0 checks that it can invoke the connector, and retries for about half a minute while a new IAM policy takes effect. If the first apply is denied access, apply again.Stage each account with
p0_databricks_account_staged. Setidto the Databricks account ID,connectorto the connector'sid, andaccounts_urlto the account console URL.Create the service principal. As a Databricks account admin, create P0's service principal with a federation policy that trusts the connector's role. The policy's issuer is the outbound web identity federation issuer of the connector's AWS account, its subject is the role's ARN, and its audience is
databricks. To let your users request account admin in the account, also give the service principal theaccount_adminrole. Then createp0_databricks_accountwith the same values as the staged resource, plus the service principal'sapplication_id, andis_account_admin_enabled = trueif you gave it the role. The example sets both from one local,enable_account_admin.Add each workspace. Assign the service principal to the workspace with the
USERpermission, or withADMINto let your users request workspace admin there. Then createp0_databricks_workspacewith the workspace ID asid, the Databricks account ID asaccount, the workspace's URL asworkspace_url, a name for the workspace in P0 asworkspace_name, andis_workspace_admin_enabled = trueif you assignedADMIN. The example sets the permission andis_workspace_admin_enabledfrom one local,enable_workspace_admin. A configuration that holds the workspace'sdatabricks_mws_workspacescan pass itsworkspace_id,workspace_url, andworkspace_namestraight through. The workspace ID is the number after?o=in your browser's address bar when you're signed in to the workspace. The workspace URL ishttps://and the workspace's host in lowercase, with nothing after the host. A newworkspace_urlreplaces the workspace in P0.Add each catalog. As a Databricks account admin who is also the catalog's owner, holds
MANAGEon it, or is a metastore admin, grant the service principalMANAGEon the catalog withdatabricks_grant. If the same configuration holds the workspace, add itsp0_databricks_workspaceto the grant'sdepends_on, so that Terraform creates the grant, and the catalog that depends on it, only after the workspace and its service principal assignment. Then createp0_databricks_catalogwith the workspace ID asworkspace_idand the catalog's name, in lowercase, ascatalog_name. P0 identifies the catalog as<catalog_name>@<workspace_id>.
Change the install later
Change the allowed email domains
You can't change Allowed email domains in P0 once you've added the connector. Change the pattern on the connector's Lambda instead:
From the P0 app: change
DOMAIN_PATTERNin your copy of the connector's Terraform, and apply it.With the P0 Terraform provider: change the domain pattern in the
localsblock of your copy of the connector example, and apply it. The example's P0 connector resources ignore later changes todomain_pattern, so the apply changes only the Lambda, and Terraform doesn't replace the connector.
Either way, the connector's page in P0 keeps showing the pattern you entered when you added it, but the connector checks only the pattern set on its Lambda. Don't remove the connector from P0 to change the pattern: while it's removed, P0 can't revoke the access it granted in the connector's Databricks accounts. For what a narrower pattern changes, see Known behavior.
Update the connector
To move the connector to a new image, change the image's tag and digest to the ones in the latest p0_databricks_connector example in the Terraform registry, and apply. Change both together: if the tag doesn't resolve to the digest, the plan fails. Both are in the locals block of your copy of the connector's Terraform, whether you copied it from the P0 app or from the example. Terraform then copies the new image into your ECR repository and redeploys the Lambda. Nothing changes in P0. If you mirror the image, copy the new one to your registry first, keeping its tag and digest.
Turn admin requests on or off
To turn a setting on from the P0 app:
Select the Account or Workspace component, then the account or workspace.
Turn on Enable account-admin requests or Enable workspace-admin requests, then click Update.
Apply the Terraform that P0 shows as a Databricks account admin with AWS access to the connector's account, then click Next. For an account, the Terraform adds the service principal's account admin role. For a workspace, it changes the service principal's assignment to
ADMIN. P0 checks that its service principal holds the role, and keeps the setting off if it doesn't.
To turn a setting off from the P0 app:
Select the Account or Workspace component, then the account or workspace.
Turn off Enable account-admin requests or Enable workspace-admin requests, then click Update.
Wait for P0 to show the Terraform for the change. While an approved admin request there hasn't ended, P0 lists the requests in its place, in a message that starts with
P0 still manages account admin in Databricks account <account-id>orP0 still manages workspace admin on Databricks workspace <workspace-name> (<workspace-id>). Let them end, or revoke them. P0 checks again every few seconds.Click Next before you apply anything. P0 turns the setting off.
Apply the change that P0 showed, as a Databricks account admin with AWS access to the connector's account. For an account, remove the service principal's
databricks_service_principal_roleblock. For a workspace, change thepermissionsof itsdatabricks_mws_permission_assignmentblock from["ADMIN"]to["USER"]. The service principal stays assigned to the workspace, which Unity Catalog privileges need.
With the P0 Terraform provider: change is_account_admin_enabled together with the service principal's account_admin role, or is_workspace_admin_enabled together with the permission of its workspace assignment, and apply. In the examples, enable_account_admin and enable_workspace_admin set both. P0 updates the account or workspace in place. When a setting turns on, P0 checks the role, and if the check fails, the apply fails and the setting stays off.
Before you turn a setting off with the provider, let the approved admin requests there end, or revoke them. While any remain, P0 refuses the change and the apply fails with the same P0 still manages error. Terraform can change the role in that apply before P0 refuses, so if it did, apply your previous configuration again to restore the role.
Last updated