For the complete documentation index, see llms.txt. This page is also available as Markdown.

Databricks

Install the Databricks (AI) integration and its MCP servers so agents behind the P0 AI Gateway can request temporary access to Unity Catalog data in your Databricks accounts.

The Databricks (AI) integration lets agents behind the P0 Runtime Access for AI request temporary access to data in your Databricks accounts: one catalog, schema, table, view, or volume in one workspace, queried on one SQL warehouse. For each approved request, P0 creates a Databricks service principal named p0-agent-<request ID> and grants it only what the request asks for. The gateway calls Databricks' Genie and Databricks SQL MCP servers as that principal. When the grant ends, P0 hands everything the agent created to an owner principal you choose, then deletes the agent's principal.

Only agents can use this integration. People request Databricks access through the Databricks integration, which is separate.

The Databricks (AI) integration is in beta. Functionality and configuration may change.

Setup has four parts, in this order:

  1. Install the connector, a Lambda function in your AWS account.

  2. Install each Databricks account, which creates P0's service principal there.

  3. Add the Databricks MCP servers to your gateway, one of each for every workspace agents use.

  4. Write the policies that decide which agents get which access.

Prerequisites

  • A registered Gateway component, with the gateway deployed in your environment. The gateway must be able to reach your Databricks workspaces over HTTPS.

  • A Databricks account on AWS, with at least one running workspace. Databricks accounts on Azure and Google Cloud aren't supported.

  • An AWS account for the connector, with P0's AWS IAM management installed for it. See Setting up AWS IAM management. P0 invokes the connector through that integration's role. The connector must run in a commercial AWS region, not in GovCloud or China.

  • An AWS admin of that account, to deploy the connector. Its Terraform turns on outbound web identity federation for the whole AWS account. See Outbound web identity federation on the Databricks page, which applies to this connector too.

  • A Databricks account admin, to apply the account's Terraform. P0 has you add it to the configuration that holds the connector, so whoever applies it also needs AWS access to the connector's account.

  • An admin group on every metastore in the account. The account's Terraform adds P0's service principal to each one, which makes it metastore admin. A metastore that P0's service principal owns directly also passes. A metastore whose admin is a user, or that has no admin, fails P0's install check.

  • An owner principal, to own what agents create once their access ends: a group, a user, or a service principal in the account.

  • Terraform 1.4 or later, with version 6.36.0 or later of the hashicorp/aws provider, version 1.115.0 or later of the databricks/databricks provider, and version 3.x of the kreuzwerker/docker provider. 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.

  • docker and the AWS CLI wherever you run the connector's Terraform, with the AWS CLI signed in to the connector's AWS account. The Terraform copies P0's connector image into Amazon ECR with them.

  • Databricks workspaces and an account console 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.

  • For the SQL tools, the Unity Gateway beta turned on in the account. See Turn on the SQL tools.

What P0 holds

P0 manages each Databricks account through one service principal of its own, p0-databricks-ai, which the account's Terraform creates. It holds these roles:

Role
Why P0 needs it
Where

Account admin

To create and delete each grant's service principal and its federation policy, assign it to the workspace, and find the account's workspaces

The account

Metastore admin

To grant Unity Catalog privileges on any catalog, and to hand what an agent created to the owner principal when its access ends.

Every metastore in the account, as a member of its admin group

Workspace admin

To let each agent's principal use the SQL warehouse its request names

Each workspace an agent lists or requests, and the account's lowest-ID running workspace when you save the account, where P0 checks for the Unity Gateway beta

P0 never removes its own workspace admin assignments.

P0 never:

  • Gives an agent's principal an admin role, MANAGE, ALL_PRIVILEGES, or CREATE_SCHEMA.

  • Stores a Databricks secret. The connector signs in to Databricks with short-lived identity tokens that AWS issues to its role, and Databricks accepts them only for P0's service principal, whose federation policy trusts that role.

When P0 assigns an agent's principal to its workspace, Databricks adds the principal to that workspace's users group, so it also inherits the group's default entitlements.

Install the connector

  1. Navigate to Integrations on p0.app, select Databricks (AI), and choose the Connector component.

  2. Add a connector, choose the AWS account it runs in, and choose its region. P0 lists only AWS accounts where its AWS IAM management is installed.

  3. P0 generates a Terraform configuration in two parts: the providers it needs, and the connector itself. Copy both into your Terraform project, apply them as an AWS admin of the account, then click Next.

    The configuration creates, in the connector's AWS account and region:

    • A Lambda function, p0-connector-databricks-ai, and its IAM role, which can request AWS identity tokens only for the audience databricks.

    • An ECR repository, p0-connector-databricks-ai, with immutable tags and scan on push, and a copy of P0's connector image in it.

    • A CloudWatch log group, /aws/lambda/p0-connector-databricks-ai, with 30-day retention.

    • Permission for P0's AWS IAM management role to invoke the connector.

    • Outbound web identity federation for the AWS account. If it's already on, import it as the comments in the Terraform say.

  4. P0 checks that it can invoke the connector. A new Lambda can take a few seconds to deploy. If the check fails, wait a minute and click Next again.

  5. Review the summary and click Finish.

One connector can reach several Databricks accounts.

Install a Databricks account

  1. On the Databricks (AI) integration, choose the Account component and add an account. Enter its Databricks account ID, a UUID. To find it, see Databricks' Locate your account ID.

  2. Choose the connector that reaches the account, and enter the account's console URL, https://accounts.cloud.databricks.com. Click Next.

  3. P0 generates the account's Terraform. Add it to the configuration that holds the connector. It creates:

    • P0's service principal, p0-databricks-ai, with the account admin role.

    • A federation policy that lets the connector's role sign in as that principal.

    • A membership of each metastore admin group you list.

    • An output that holds the principal's application ID.

  4. Set the Terraform variable whose name ends in _metastore_admin_groups to the display name of each metastore's admin group. Apply the configuration as a Databricks account admin with AWS access to the connector's account, then click Next.

  5. Fill in the account details, then click Next:

    • Service principal application ID: the value that the terraform output -raw command P0 shows prints.

    • Owner principal: who owns what an agent created once its access ends. Enter a group's display name, a user's userName, or a service principal's application ID.

  6. P0 checks the account, in this order, and stops at the first check that fails, with a message that says what to change:

    • P0 can sign in to Databricks as its service principal.

    • The principal is an account admin.

    • The principal is metastore admin of every metastore in the account.

    • The owner principal names exactly one group, user, or service principal.

    Then P0 checks whether the Unity Gateway beta is on. It makes itself workspace admin of the running workspace with the lowest ID, and asks that workspace's Databricks SQL MCP server. If the beta is off, the install still finishes, and the account shows a warning. See Turn on the SQL tools. If the account has no running workspace, the install fails. Create a workspace, or wait for one to be running, then open the account in P0 and click Update.

    On the first save, P0 can fail with a message that Databricks hasn't seen its new workspace admin assignment yet. Wait a few minutes, then save the account again, or apply again. If the beta warning then shows although the beta is on, save the account again.

  7. Review the summary and click Finish. The account now appears with the state Installed.

P0 repeats the four checks every hour, so it notices if its service principal loses a role.

Install with Terraform

Instead of the installer, you can install the connector and each account with the P0 Terraform provider (see Manage integrations as code with the P0 Terraform provider). Create the resources in this order:

  1. Stage the connector with p0_databricks_ai_connector_staged. Set id to the AWS account the connector runs in, and region to its region.

  2. Deploy the connector in that account and region, and let P0's AWS IAM management role invoke it.

  3. Install the connector with p0_databricks_ai_connector, with the same id and region. P0 checks that it can invoke the connector.

  4. Stage each account with p0_databricks_ai_account_staged. Set id to the Databricks account ID, connector to the connector's id, and accounts_url to the account's console URL.

  5. Create P0's service principal in the account, with its federation policy, the account admin role, and a membership of each metastore admin group.

  6. Install the account with p0_databricks_ai_account. Set the staged account's id, connector, and accounts_url, the principal's application_id, and an owner_principal. P0 runs the checks in Install a Databricks account.

Step 1 alone is this one resource, from the provider's p0_databricks_ai_connector_staged example:

The provider's example for p0_databricks_ai_connector does steps 1 to 3 in one configuration. Set account_id and region in its locals:

Step 4 alone is this one resource, from the provider's p0_databricks_ai_account_staged example:

The provider's example for p0_databricks_ai_account does steps 4 to 6 for one account in one configuration. Set the values in its locals:

Turn on the SQL tools

Databricks' SQL MCP server needs the Unity Gateway beta. An account admin turns it on for the whole account, from the Previews page of the account console. See Databricks' Databricks SQL MCP server.

P0 checks for the beta only when you save the account. If it was off, the account in P0 shows this warning:

Databricks SQL tools need the Unity Gateway beta. Turn it on in the account console's Previews page, then click Update on this account in P0.

Once you turn the beta on, save the account again in P0 so that P0 sees it. This applies to accounts installed with Terraform too: Terraform doesn't show the warning, and an apply with no changes doesn't save the account. To save it again, open the account on the Databricks (AI) integration in P0, and click Update.

Add the Databricks MCP servers

There are two servers:

  • Databricks Genie: Databricks' Genie tools, which answer questions about data in natural language. You can add it once at least one account is installed.

  • Databricks SQL: Databricks' SQL tools, which run SQL statements. You can add it once an installed account has the Unity Gateway beta on.

Each server you add covers one workspace. Add a Databricks Genie server and a Databricks SQL server for every workspace agents use.

To add each one:

  1. Follow the shared steps in Add an MCP server to name the server and choose its gateway. On the configuration screen, set the following fields, then click Finish:

    • Credential source: choose Token exchange (RFC 8693).

    • Definition: choose P0, then select Databricks Genie or Databricks SQL.

    • Instance: the workspace's deployment name, the part of its URL before .cloud.databricks.com. For the workspace at https://dbc-a1b2c3d4-e5f6.cloud.databricks.com, enter dbc-a1b2c3d4-e5f6. It takes lowercase letters, digits, and hyphens.

  2. The server now appears with the state Installed.

You can't change a server's instance after you add it. To cover another workspace, add another server. Agents see the instance in the server's name, such as Databricks SQL (dbc-a1b2c3d4-e5f6).

How agents request access

An agent requests access with a server's access tool. It names a workspace by its numeric ID, a pro or serverless SQL warehouse in it, a catalog, and a level. To narrow the request, it also names a schema, and then a table or a volume. P0 grants the level on the deepest object named. A table can also be a view or a materialized view. The equivalent CLI request is:

The level is read or write:

Granted on

read grants

write also grants

A catalog

USE_CATALOG, USE_SCHEMA, SELECT, READ_VOLUME, EXECUTE

MODIFY, WRITE_VOLUME, CREATE_TABLE, CREATE_VOLUME, CREATE_FUNCTION, CREATE_MATERIALIZED_VIEW

A schema

USE_SCHEMA, SELECT, READ_VOLUME, EXECUTE

MODIFY, WRITE_VOLUME, CREATE_TABLE, CREATE_VOLUME, CREATE_FUNCTION, CREATE_MATERIALIZED_VIEW

A table, view, or materialized view

SELECT

MODIFY

A volume

READ_VOLUME

WRITE_VOLUME

P0 also grants USE_CATALOG and USE_SCHEMA on the object's parents, and CAN USE on the warehouse.

Agents call Databricks' MCP servers through the EXECUTE privilege that account users hold on the system.ai schema by default. Keep that default in place. What an agent can reach is controlled by its warehouse and Unity Catalog grants.

A grant works only in the gateway session that requested it, and only on the server whose access tool requested it. To use both the Genie and the SQL tools, the agent requests access through each server.

P0 refuses a request that came through any server other than an installed Databricks Genie or Databricks SQL server, with this message:

This request didn't come through an installed Databricks Genie or Databricks SQL server. Request again through one of them.

A server grants access only in the workspace its instance names. P0 refuses a request for any other workspace, with this message:

This Databricks server covers only the workspace at https://dbc-a1b2c3d4-e5f6.cloud.databricks.com, and workspace 1234567890123456 is at https://dbc-f6e5d4c3-b2a1.cloud.databricks.com. Request access to workspace 1234567890123456 through the Databricks Genie or Databricks SQL server added for https://dbc-f6e5d4c3-b2a1.cloud.databricks.com.

Once a request is approved, access usually works within 30 to 60 seconds, and can take up to two minutes.

When the grant ends, P0 makes the owner principal the owner of every table, view, materialized view, volume, and function the agent's principal owns, then deletes the principal. Before that, P0 deactivates the principal, so the agent gets no new Databricks token, and removes its grants. A token the agent already holds keeps working for up to about 15 minutes after the revoke, with its grants already removed.

See Requesting access for how agents submit and use requests.

Write policies for Databricks

Match Databricks requests in an agentic access policy (see Agentic access policies) with service: databricks-ai and accessType: data. These filters narrow them:

Filter
Key
What it matches
Example

account

id

The Databricks account ID

01234567-89ab-cdef-0123-456789abcdef

workspace

id

The workspace ID

1234567890123456

workspace

name

The workspace's name in Databricks

analytics-prod

catalog

name

The catalog

main

schema

name

The schema, empty for a request on a whole catalog

sales

securable

name

The full name of the object the level is granted on

main.sales.orders

securable

type

That object's type: catalog, schema, table, or volume. A view or materialized view is a table.

table

privilege

name

Each privilege the level grants on the object, as in the table above. The USE_CATALOG and USE_SCHEMA on its parents aren't included.

SELECT

Policies are the only limit on what agents can request. Every catalog a workspace can use can be requested, except Databricks' own system and __databricks_internal catalogs, so write a policy for each kind of access you allow.

Match workspaces on id: a workspace admin can rename a workspace. Privilege names are in uppercase, and catalog, schema, and securable names are in lowercase.

Anchor your patterns

Patterns are case-sensitive regular expressions, and they match anywhere in a value. In a pattern, . matches any character, so ^main.sales$ also matches a schema named main_sales. Write \. to match only a dot, as the examples below do.

Start each pattern with ^, and end it with $ or \.. A pattern without anchors matches more than it looks like it does. sales also matches presales, and ^main\.sales also matches main.sales_archive.

  • ^main\.sales\. matches every table, view, and volume in the main.sales schema, but not the schema itself.

  • ^main\.sales(\.|$) also matches the main.sales schema.

  • ^main\.sales\.orders$ matches one table.

Examples

In a rule that allows access, a keep filter on privilege must match every privilege the request's level grants. So a rule whose privilege pattern lists only read's privileges never matches a write request.

This policy auto-approves read access to the main.sales schema and everything in it, for one agent, in one workspace:

Add this policy to send every other request on main.sales from any agent, write included, to your Security Reviewers. A read request from reporting-agent matches both policies, and the first approves it.

Make the SQL tools read-only

Databricks' SQL MCP server allows reads and writes. To make it read-only for every agent, whatever level they hold, set disallow_writes to true in the built-in system.ai.dbsql_policy policy. See Databricks' Databricks SQL MCP server.

Leftover principals

An agent's service principal, named p0-agent-<request ID>, can stay in your account in two cases:

  • A revoke failed. P0 deactivates the principal before it removes any grant, so the principal stays deactivated.

  • A request failed after P0 created its principal. The principal is active, but bare: it has no federation policy.

Before you delete one in the account console:

  1. Hand anything the principal owns to your owner principal.

  2. Have a metastore admin revoke every privilege the principal holds. If its workspace was deleted, do this from another workspace on the same metastore.

Delete one only once its request has ended or shows an error in P0. A revoke for a workspace that was deleted can't finish, so its request stays errored in P0.

Remove the integration

  1. Remove the Databricks MCP servers from your gateway.

  2. End or revoke every active grant, so that P0 deletes each agent's service principal. Then delete any leftover principals, as in Leftover principals.

  3. Delete each account and the connector from the Databricks (AI) integration in P0.

  4. Destroy the Terraform configuration with terraform destroy. This deletes P0's service principal, so P0 can no longer sign in to the account. To keep outbound web identity federation on in the AWS account, replace its resource with the removed block in the Terraform's comments before you destroy.

Next steps

Last updated