> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/integrations/resource-integrations/databricks.md).

# Databricks

Grant just-in-time Unity Catalog privileges, workspace admin, and account admin in your Databricks accounts with P0, and see what P0 can and can't do there.

{% hint style="info" %}
The Databricks integration is in beta. Functionality and configuration may change.
{% endhint %}

Use the Databricks integration to grant temporary Unity Catalog privileges, workspace admin, and account admin in your Databricks accounts. P0 grants access directly to the requestor's existing Databricks user, never by adding them to a group, and removes it when the access expires or is revoked.

To give AI agents temporary access to Databricks data, see [Databricks MCP servers](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/databricks.md).

P0 makes these changes through a P0 connector ([P0 connectors](https://docs.p0.dev/readme/connectors.md)), a Lambda function that you deploy in your AWS account, even when your Databricks accounts run on Azure or Google Cloud.

To learn more, see:

* [Installing Databricks](https://docs.p0.dev/integrations/resource-integrations/databricks/installation.md)
* [Requesting Databricks access](https://docs.p0.dev/integrations/resource-integrations/databricks/requesting-access.md)
* [Databricks use cases](https://docs.p0.dev/integrations/resource-integrations/databricks/use-cases.md)

## How it works

You install four components in order. Each one needs the one before it:

1. **Connector**: the Lambda function in your AWS account. Each AWS account can hold one connector, and one connector can reach several Databricks accounts.
2. **Account**: a Databricks account, which P0 manages through a service principal there. The service principal holds account admin only if you turn on **Enable account-admin requests** for the account.
3. **Workspace**: a workspace in an added account. Its Terraform assigns the service principal to the workspace as a workspace user, or as a workspace admin if you turn on **Enable workspace-admin requests** for the workspace.
4. **Catalog**: a Unity Catalog catalog in an added workspace, on which the service principal holds `MANAGE`.

Add each workspace and catalog that P0 should grant privileges in, and each workspace where your users should be able to request workspace admin. Your users can request Unity Catalog privileges only in the catalogs you add, workspace admin only on the workspaces you add with workspace-admin requests turned on, and account admin only in the accounts you add with account-admin requests turned on.

## What P0 can and can't do

The Terraform for each component gives P0's service principal only what P0 needs to grant each kind of access:

| To grant                 | P0's service principal holds                                                   | Where                                                                     |
| ------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| Unity Catalog privileges | `MANAGE` on the catalog, and a workspace assignment with the `USER` permission | Each catalog and workspace you add                                        |
| Workspace admin          | Workspace admin, an assignment with the `ADMIN` permission in place of `USER`  | Each workspace you add with **Enable workspace-admin requests** turned on |
| Account admin            | Account admin                                                                  | Each account you add with **Enable account-admin requests** turned on     |

P0 uses these only to grant and revoke the privileges and roles described in these pages, and to read what it needs for request options, install checks, and access checks: each workspace's metastore, the catalogs, schemas, tables, volumes, and functions in it, and the grants users already hold. For `admin` requests, it also reads users and the roles they already hold. The connector accepts no other operations.

P0 never:

* Grants `MANAGE`, `ALL_PRIVILEGES`, or `EXTERNAL_USE_SCHEMA`, or changes who owns an object.
* Grants anything to a service principal, including its own.
* Creates or deletes Databricks users, or changes group membership.
* Grants to a user whose P0 email or Databricks username is outside the connector's **Allowed email domains**. That setting is the `DOMAIN_PATTERN` environment variable on the connector's Lambda in your AWS account, and P0 can't change it.

The connector holds no Databricks secret. It signs in to Databricks with short-lived identity tokens that AWS issues to its role. The role can request these tokens only for the audience `databricks`, and the connector sends them only to Databricks. Databricks accepts them only for a service principal whose federation policy trusts that role.

Anyone who can invoke the connector, modify it, or use its role can act with whatever you've given P0's service principal: `MANAGE` on each catalog you add, its assignment to each workspace you add, workspace admin on each workspace where you turned on workspace-admin requests, and account admin in each account where you turned on account-admin requests. The connector doesn't check who invokes it. In its AWS account, any principal whose IAM policies allow `lambda:InvokeFunction` on it, including through a wildcard, can call it the way P0 does. That account also has P0's AWS IAM management, so AWS access that P0 grants there can reach the connector too. To limit who can act through the connector:

* Deploy it in a dedicated AWS account.
* Restrict `lambda:InvokeFunction` on it, for example with a service control policy or a permissions boundary.
* Limit the AWS access that P0 grants in its account, for example with an access policy for that account, as in [Configuring access policies](https://docs.p0.dev/policy-studio/policy-studio/configure-your-first-access-policy.md#different-rules-by-aws-account).
* Alert on Databricks admin role assignments that don't come from a P0 request.

## Access policies

In access policies, Databricks is the service `databricks`, and its access types are `privilege`, for Unity Catalog privileges, and `admin`, for workspace admin and account admin. See [Configuring access policies](https://docs.p0.dev/policy-studio/policy-studio/configure-your-first-access-policy.md#resource).

### Available filters

A rule can filter on these properties of a request:

| Filter      | Key    | What it matches                                                                                                        | Example                                |
| ----------- | ------ | ---------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| `account`   | `id`   | The ID of the Databricks account the access is in                                                                      | `01234567-89ab-cdef-0123-456789abcdef` |
| `workspace` | `id`   | The ID of the workspace a `workspace-admin` request is for, or that P0 reaches a `privilege` request's catalog through | `1234567890123456`                     |
| `workspace` | `name` | The name you give that workspace in P0                                                                                 | `analytics-prod`                       |
| `catalog`   | `name` | The catalog a `privilege` request is in                                                                                | `main`                                 |
| `schema`    | `name` | The schema a `privilege` request is on, or that holds the table, volume, or function it's on                           | `sales`                                |
| `securable` | `name` | The full name of the object a `privilege` request is on                                                                | `main.sales.orders`                    |
| `securable` | `type` | That object's type: `catalog`, `schema`, `table`, `volume`, or `function`                                              | `table`                                |
| `privilege` | `name` | Each privilege a `privilege` request names. The `USE_CATALOG` and `USE_SCHEMA` that P0 adds aren't included.           | `SELECT`                               |
| `adminRole` | `name` | The role an `admin` request asks for: `workspace-admin` or `account-admin`                                             | `account-admin`                        |

Privilege names are in uppercase, as in `USE_CATALOG`, and `schema` and `securable` names are in lowercase, whatever the requestor typed. Patterns are unanchored, case-sensitive regular expressions. Use `^` and `$` to match a whole name.

A request leaves empty the properties it doesn't have, such as `catalog` on an `admin` request, `workspace` on an `account-admin` request, and `schema` on a request for a whole catalog. An empty property never matches a pattern, so a `keep` filter on it never lets the rule match, and a `remove` filter on it never stops the rule from matching. For example, a rule with a `keep` filter on `catalog` never matches an `admin` request, and a rule with a `remove` filter on `schema` still matches a request for a whole catalog, which covers every schema in it.

### Example access policy

These policies send requests for `SELECT` or `BROWSE` in the `main` catalog to your Security Reviewers, including the `USE_CATALOG` and `USE_SCHEMA` that a request on the whole catalog names, and deny account admin:

```yaml
- requestor:
    type: any
  resource:
    type: integration
    service: databricks
    accessType: privilege
    filters:
      catalog:
        effect: keep
        key: name
        pattern: ^main$
      privilege:
        effect: keep
        key: name
        pattern: ^(SELECT|BROWSE|USE_CATALOG|USE_SCHEMA)$
  approval:
    - type: p0
- requestor:
    type: any
  resource:
    type: integration
    service: databricks
    accessType: admin
    filters:
      adminRole:
        effect: keep
        key: name
        pattern: ^account-admin$
  approval:
    - type: deny
```

## Known behavior

* **Revoking admin removes the role only.** Anything the user created or changed while they held it, such as personal access tokens, stays in place.
* **Objects a user creates stay theirs.** A user owns the objects they create with a `CREATE_*` privilege, such as tables, schemas, volumes, and functions, and still owns them after P0 revokes the privilege. P0 never changes who owns an object. Send requests for `CREATE_*` privileges through a stricter access policy. See [#access-policies](#access-policies "mention").
* **Revoking admin never raises access.** It only lowers the user back to what they had before the grant. A workspace user stays a workspace user, and a user who had no assignment of their own goes back to having none. If someone has already demoted or removed the user, P0 leaves them as they are.
* **P0 never removes access a user already had.** It fails a request for a privilege the user already holds directly on the object, or for an admin role they already hold, unless one of their open P0 requests granted it. When P0 adds the `USE_CATALOG` or `USE_SCHEMA` needed to reach an object, it skips one the user already holds and leaves it in place when the access ends.
* **One open request per object.** A user can have one open request at a time for each catalog, schema, table, volume, or function, and one for an admin role on each workspace or account. Requests on different objects can overlap, and a `USE_CATALOG` or `USE_SCHEMA` they share stays until the last of them ends.
* **P0 also removes a matching grant made by someone else.** If someone gives the user the same privilege or role while P0's access is live, revoking P0's access removes it too. Grant it again after P0's access ends if the user should keep it.
* **Access that's already gone.** If someone removes the access by hand, or drops the object, while P0's access is live, P0 counts it as revoked and the revoke succeeds.
* **Workspace admin on a deleted workspace.** If a workspace is deleted while P0's workspace admin access on it is live, P0 can't reach the workspace to revoke the access, and the revoke fails with an error such as `P0 can't reach Databricks workspace <workspace-id> at <workspace-url> to revoke workspace admin. If the workspace was deleted, the user's admin role went with it.` There's nothing left to remove in Databricks.
* **Renaming an object leaves its grants in place.** P0 finds each object by name when it revokes. If someone renames a catalog, schema, or object while P0's access on or inside it is live, P0 counts the access as revoked, as it does for a dropped object, but the user keeps those privileges on the renamed object. Revoke them in Databricks.
* **Revokes use what P0 recorded at grant.** P0 revokes from the Databricks user it recorded when it granted the access, through the account and workspace it granted in. The revoke still works after the user's email changes, or after they're removed from the workspace.
* **Revoking privileges needs the workspace they were granted through.** If P0's service principal loses its assignment to that workspace while the access is live, P0 can't revoke the privileges until you assign the principal to the workspace again. If the workspace is deleted, the revoke fails with an error that names the user and each privilege still to remove, because Unity Catalog grants outlive the workspace. Either way, the privileges keep working from the metastore's other workspaces until they're revoked. To end them sooner, revoke them in Databricks, from another workspace on the same metastore.
* **Removing an account blocks its revokes.** If you remove a Databricks account from P0, or the connector that reaches it, while access granted in that account is live, P0 can't revoke that access until you add it back. For a removed account, revokes fail with `Databricks account <account-id> is not installed in P0. Access granted in it can't be changed or revoked until it is installed again.`
* **Narrowing the allowed domains stops new grants.** If you narrow the connector's **Allowed email domains**, P0 grants nothing more to users outside it, but still revokes the access it already granted them. A pattern that's unset or invalid stops every grant, and revokes still go through. To change the pattern, see [Installing Databricks](https://docs.p0.dev/integrations/resource-integrations/databricks/installation.md#change-the-install-later).
* **Turning admin requests off stops new ones.** Once you turn off **Enable account-admin requests** for an account, or **Enable workspace-admin requests** for a workspace, your users can't request that role there, and a request approved afterwards fails when P0 goes to grant it. P0 needs its own admin role to revoke the admin access it already granted there, so it refuses to turn a setting off while any of that access may still be live. See [Installing Databricks](https://docs.p0.dev/integrations/resource-integrations/databricks/installation.md#turn-admin-requests-on-or-off).
* **Lost `MANAGE` on a catalog.** If P0's service principal loses `MANAGE` on a catalog, grants and revokes there fail with an error about your organization's Databricks installation that says `P0's service principal can't manage privileges on catalog <catalog>`. Apply the catalog's Terraform again to restore it.
* **Lost admin role.** If P0's service principal loses account admin in an account, or workspace admin on a workspace, grants and revokes of that role there fail with an error about your organization's Databricks installation. It starts with `P0's service principal isn't an account admin in Databricks account <account-id>` or `P0's service principal isn't an admin of Databricks workspace <workspace-id>`, and says to turn on the matching setting in P0 and apply the Terraform that P0 shows. If the setting is already on, apply the account's or the workspace's Terraform again.
* **Azure roles.** On Azure Databricks, a user with the Azure Contributor or Owner role over a workspace can make themselves its workspace admin by signing in, outside P0. See Microsoft's [Permissions required to log in as a workspace admin](https://learn.microsoft.com/en-us/azure/databricks/admin/admin-concepts#permissions-required-to-log-in-as-a-workspace-admin).
