Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,61 @@ jobs:
run: |
./baton-databricks --invoke-action=enable_user \
--invoke-action-args="$(jq -nc --arg id "${TEST_ACTION_USER_ID}" '{user_id: $id}')"
# Runs the incremental sync event feed against the local test server (test-server/), so it
# needs no Databricks account or secrets and also runs on pull requests from forks.
test-server:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build connector and test server
run: |
go build -o baton-databricks ./cmd/baton-databricks
go build -o /tmp/databricks-test-server ./test-server
- name: Start test server
run: |
/tmp/databricks-test-server --ca-out /tmp/test-server-ca.pem > test-server.log 2>&1 &
for i in $(seq 1 30); do
if curl -sf --cacert /tmp/test-server-ca.pem https://localhost:8765/health > /dev/null; then
echo "test server is up"; exit 0
fi
sleep 1
done
echo "test server did not come up in time"; cat test-server.log; exit 1
- name: Run incremental sync against the test server
env:
SSL_CERT_FILE: /tmp/test-server-ca.pem
run: |
./baton-databricks \
--hostname localhost:8765 --account-hostname localhost:8765 \
--account-id test-account \
--databricks-client-id test-client --databricks-client-secret test-secret \
--sql-warehouse-id wh-serverless \
--event-feed true --event-feed-id databricks_audit_log \
--event-feed-start-at "$(date -u -d '2 days ago' +%Y-%m-%dT%H:%M:%SZ)" \
> events.jsonl
- name: Compare events with the expected output
run: |
normalize() { jq -c -S 'del(.occurredAt)' "$1" | sort; }
diff <(normalize test-server/testdata/expected-events.jsonl) <(normalize events.jsonl)
- name: Check the cold-start timeout message
env:
SSL_CERT_FILE: /tmp/test-server-ca.pem
run: |
if ./baton-databricks \
--hostname localhost:8765 --account-hostname localhost:8765 \
--account-id test-account \
--databricks-client-id test-client --databricks-client-secret test-secret \
--sql-warehouse-id wh-broken \
--event-feed true --event-feed-id databricks_audit_log \
--event-feed-start-at "$(date -u -d '2 days ago' +%Y-%m-%dT%H:%M:%SZ)" 2> err.log; then
echo "expected the event feed to fail with a broken warehouse"; exit 1
fi
grep -q "has not started" err.log
- name: Show test server log on failure
if: failure()
run: cat test-server.log
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# Dependency directories (remove the comment below to include it)
# vendor/
dist/

# CA certificate written by the local test server (test-server/)
test-server-ca.pem
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,87 @@ To instead exclude specific workspaces from the sync, pass them to the
list. Each entry can be a workspace name, deployment name, or numeric workspace
ID. Excluded workspaces and their roles are skipped entirely.

## Incremental sync

By default, `baton-databricks` does a full resync of every resource on every run.
You can opt into an additional, cheap pathway that polls a Databricks audit log
between full syncs to pick up access changes early. Full syncs still run as the
correctness backstop. Incremental sync picks up added and removed group
memberships, but deleted users, groups and service principals are only caught
by the next full sync.

Role assignments that Databricks stores in access-control rule sets (group roles
such as `roles/group.manager`, service principal roles, and the account
`marketplace.admin` role) are also only caught by the next full sync: the
connector does not read the audit events Databricks writes for rule-set
changes. A `roles/group.manager` change, for example, is logged as
`updateRuleSet` under the `accountsAccessControl` audit service, which the
connector does not query.

**Incremental sync is enabled by setting `--sql-warehouse-id` (or
`BATON_SQL_WAREHOUSE_ID`) and disabled by leaving it unset or empty.** There is
no separate on/off flag. The incremental-sync setup (warehouse found,
`system.access.audit` queryable, at least one workspace in sync scope) is not
checked at startup, so a misconfiguration never blocks full syncs or
provisioning. Instead, each event-feed poll fails with an error naming the
problem until it is fixed.

Incremental sync requires a reachable Account API to resolve audit events back
to synced resources, same as the rest of the connector. Audit events are only
resolved for workspaces in sync scope, so `--workspaces` and
`--databricks-exclude-workspaces` apply to incremental sync the same way they
apply to full syncs.

### Requirements

Incremental sync works only when all of the following are true:

- **Unity Catalog.** The SQL warehouse is in a workspace enabled for Unity
Catalog, and the metastore is on Unity Catalog Privilege Model Version 1.0
([system tables
requirements](https://docs.databricks.com/aws/en/admin/system-tables/)).
- **System tables.** The connector queries the `system.access.audit` system
table, which Databricks currently offers as a Public Preview.
- **A SQL warehouse, preferably serverless.** Pass its ID with
`--sql-warehouse-id`. Any warehouse works, including the **Starter
Warehouse** Databricks creates in each workspace, so you don't need to create
one.
- **Grants for the service principal** the connector authenticates as, on top of
the Account admin role it already needs:
- `USE CATALOG` on the `system` catalog
- `USE SCHEMA` and `SELECT` on the `system.access` schema
- `CAN USE` on the SQL warehouse

For example, run as a metastore admin, replacing `<application-id>` with the
service principal's application (client) ID:

```sql
GRANT USE CATALOG ON CATALOG system TO `<application-id>`;
GRANT USE SCHEMA, SELECT ON SCHEMA system.access TO `<application-id>`;
```

**We recommend a serverless SQL warehouse.** It starts in seconds, while a pro
or classic warehouse can take several minutes. Each statement gets up to 30
seconds on the initial request, including warehouse startup, then up to 5 more
minutes of polling. A statement still unfinished after that is cancelled, so a
poll can take close to 6 minutes before it fails with a `DeadlineExceeded`
error and is retried on the next poll. Serverless SQL warehouses require the
Premium plan or above.

**Incremental sync covers one cloud region.** `system.access.audit` holds
workspace-level events only for workspaces in the same cloud region as the
workspace that queries it; account-level events are global ([system tables
reference](https://docs.databricks.com/aws/en/admin/system-tables/)). The
connector finds the warehouse's workspace automatically by checking each
workspace the service principal can access, except those excluded with
`--databricks-exclude-workspaces`; the `--workspaces` allowlist does not limit
this search. It receives
incremental updates only for workspaces in that region. Workspaces in other
regions are still covered by full syncs.

Audit log entries are delivered with a delay, so the connector reads them about
four hours after they happen.

## Group provisioning

Account groups are provisioned through the OAuth client ID and secret flow.
Expand Down Expand Up @@ -175,6 +256,7 @@ Flags:
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
--skip-entitlements-and-grants This must be set to skip syncing of entitlements and grants ($BATON_SKIP_ENTITLEMENTS_AND_GRANTS)
--skip-full-sync This must be set to skip a full sync ($BATON_SKIP_FULL_SYNC)
--sql-warehouse-id string Setting this enables incremental sync; leaving it empty disables it. ID of the Databricks SQL warehouse used to query the system.access.audit log between full syncs, so access changes show up before the next full sync (deleted users, groups and service principals are still only caught by full syncs). The warehouse can be in any workspace not excluded by databricks-exclude-workspaces, in the same cloud region as the workspaces to update incrementally; Databricks only exposes workspace-level audit events for that region. The connector discovers the warehouse's workspace automatically. ($BATON_SQL_WAREHOUSE_ID)
--storage-engine string The storage engine to use when opening the sync c1z file: sqlite or pebble. Defaults to pebble when unset. ($BATON_STORAGE_ENGINE)
--sync-resource-types strings The resource type IDs to sync ($BATON_SYNC_RESOURCE_TYPES)
--sync-resources strings The resource IDs to sync ($BATON_SYNC_RESOURCES)
Expand Down
11 changes: 10 additions & 1 deletion baton_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_PROVISION"
],
"permissions": {}
Expand All @@ -22,6 +23,7 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_PROVISION"
],
"permissions": {}
Expand All @@ -36,6 +38,7 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_PROVISION"
],
"permissions": {}
Expand All @@ -50,6 +53,7 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_PROVISION"
],
"permissions": {}
Expand All @@ -69,6 +73,7 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_ACCOUNT_PROVISIONING",
"CAPABILITY_RESOURCE_DELETE"
],
Expand All @@ -84,6 +89,7 @@
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_PROVISION"
],
"permissions": {}
Expand All @@ -94,7 +100,10 @@
"CAPABILITY_SYNC",
"CAPABILITY_ACCOUNT_PROVISIONING",
"CAPABILITY_RESOURCE_DELETE",
"CAPABILITY_ACTIONS"
"CAPABILITY_ACTIONS",
"CAPABILITY_TARGETED_SYNC",
"CAPABILITY_EVENT_FEED_V2",
"CAPABILITY_SERVICE_MODE_TARGETED_SYNC"
],
"credentialDetails": {
"capabilityAccountProvisioning": {
Expand Down
6 changes: 6 additions & 0 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@
"displayName": "Exclude Workspaces",
"description": "Workspaces to exclude from sync, identified by workspace name, deployment name, or numeric workspace ID. Mutually exclusive with workspaces.",
"stringSliceField": {}
},
{
"name": "sql-warehouse-id",
"displayName": "SQL Warehouse ID",
"description": "Setting this enables incremental sync; leaving it empty disables it. ID of the Databricks SQL warehouse used to query the system.access.audit log between full syncs, so access changes show up before the next full sync (deleted users, groups and service principals are still only caught by full syncs). The warehouse can be in any workspace not excluded by databricks-exclude-workspaces, in the same cloud region as the workspaces to update incrementally; Databricks only exposes workspace-level audit events for that region. The connector discovers the warehouse's workspace automatically.",
"stringField": {}
}
],
"constraints": [
Expand Down
77 changes: 72 additions & 5 deletions docs/connector.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,85 @@ These actions act on the account-level user, so disabling a user blocks them in

The connector authenticates with **OAuth** — an account-level service principal's client ID and secret. This is the only authentication method the connector supports.

### Optional: faster updates between syncs

By default, the Databricks connector picks up access changes on its regular sync schedule. You can optionally turn on incremental sync, which checks Databricks' activity log between full syncs so that changes like new group members, new service principals, and admin role changes on service principals show up in C1 sooner. Full syncs still run as usual and remain the source of truth. Removed group memberships are picked up incrementally too, but deleted users, groups, and service principals are only reflected after the next full sync.

Role assignments that Databricks stores in access-control rule sets are also only reflected after the next full sync. These are group roles such as group manager, service principal roles, and the account `marketplace.admin` role.

Incremental sync is turned on by providing the ID of a Databricks SQL warehouse (the **SQL Warehouse ID** setting, `BATON_SQL_WAREHOUSE_ID`) and turned off by leaving it empty — there is no separate on/off switch. Ask your connector operator or C1 support contact to enable it for you.

#### Incremental sync requirements

Your Databricks account must meet all of the following:

- **Unity Catalog.** The SQL warehouse must be in a workspace enabled for Unity Catalog, and the metastore must be on Unity Catalog Privilege Model Version 1.0. Databricks enables most workspaces created after November 2023 for Unity Catalog automatically.
- **System tables.** The connector reads Databricks' audit log system table, `system.access.audit`. Databricks currently offers this table as a Public Preview.
- **A SQL warehouse, preferably serverless.** You don't need to create a new one: Databricks creates a **Starter Warehouse** in each workspace automatically, and any SQL warehouse works. See the recommendation below about the warehouse type.
- **Permissions for the connector's service principal**, in addition to the **Account admin** role it already needs:
- `USE CATALOG` on the `system` catalog
- `USE SCHEMA` and `SELECT` on the `system.access` schema
- **Can use** on the SQL warehouse

<Note>
**We recommend a serverless SQL warehouse.** It starts in seconds, while a pro or classic warehouse can take several minutes to start. The connector waits up to about 6 minutes for the warehouse to start and each query to finish, so a slower start can delay updates until the next one. Serverless SQL warehouses require the Premium plan or above.
</Note>

<Warning>
**Incremental sync covers one cloud region.** Databricks keeps workspace activity in the audit log of the region where each workspace is deployed. The connector only receives incremental updates for workspaces in the same region as the SQL warehouse. Workspaces in other regions are still updated by full syncs.
</Warning>

#### Set up incremental sync

<Warning>
A Databricks user with the **Account admin** role, and the **Metastore admin** role or the right to grant access to the `system` catalog, must perform this task.
</Warning>

<Steps>
<Step>
Choose a SQL warehouse in a Unity Catalog-enabled workspace, in the same region as the workspaces you want to update incrementally. In that workspace, go to **SQL Warehouses**, open the warehouse, and copy its ID. Check its type: if it isn't **Serverless**, switch it to serverless if your plan allows it (see the recommendation above).
</Step>
<Step>
On the **SQL Warehouses** page, click the kebab menu (three-dot icon) next to the warehouse, click **Permissions**, and give the connector's service principal the **Can use** permission.
</Step>
<Step>
In the same workspace, run the following in the SQL editor, replacing `<application-id>` with the service principal's application (client) ID:

```sql
GRANT USE CATALOG ON CATALOG system TO `<application-id>`;
GRANT USE SCHEMA, SELECT ON SCHEMA system.access TO `<application-id>`;
```
</Step>
<Step>
Enter the warehouse ID in the connector's **SQL Warehouse ID** setting (`BATON_SQL_WAREHOUSE_ID`).
</Step>
</Steps>

The SQL warehouse can live in any workspace in that region that is not listed in **Exclude Workspaces**, including a workspace outside **Workspaces** — the connector finds it automatically. **Workspaces** and **Exclude Workspaces** also limit which workspaces incremental sync updates, as they do for full syncs. Changes reach C1 roughly four hours after they happen: Databricks delivers audit log entries with a delay, so the connector waits before reading them.

<Note>
The incremental sync setup isn't checked when the connector starts, so a problem with it never blocks full syncs or provisioning. If something is missing, such as a permission or a warehouse that can't be found, every incremental update fails and the connector logs an error that names the cause until you fix it.
</Note>

## Gather Databricks credentials

Configuring the connector requires you to pass in credentials generated in Databricks. Gather these credentials before you move on.

<Warning>
A user with the **Account admin** role in each Databricks workspace you want to sync must perform this task.
A user with the **Account admin** role in your Databricks account must perform this task. Account admin is an account-level role, managed in the Databricks account console.
</Warning>

### Look up your Databricks account ID

<Steps>
<Step>
Ensure that your Databricks user account has the **Account admin** role and is assigned to each Databricks workspace you want to sync to C1.
Log in to the Databricks account console with a user that has the **Account admin** role.
</Step>
<Step>
In the Databricks account console, open the menu that appears next to your username in the upper right corner.
</Step>
<Step>
Carefully and copy and save account ID.
Carefully copy and save the account ID.
</Step>
</Steps>

Expand All @@ -81,6 +141,9 @@ The Databricks connector authenticates with OAuth, which syncs info from all Dat
<Step>
Carefully copy and save the OAuth client ID and secret.
</Step>
<Step>
Give the service principal the **Account admin** role: in the account console, go to **User management** > **Service principals**, click the service principal, and on the **Roles** tab select **Account admin**. Databricks requires this role for any service principal that calls account-level APIs, and the connector fails validation without it.
</Step>
</Steps>

**Done.** Here's the set of credentials you'll need when setting up the connector:
Expand Down Expand Up @@ -214,7 +277,7 @@ stringData:
BATON_CLIENT_ID: <C1 client ID>
BATON_CLIENT_SECRET: <C1 client secret>

# Databricks account ID (required for both credential options below)
# Databricks account ID (required)
BATON_ACCOUNT_ID: <Databricks account ID>

# Databricks credentials: OAuth
Expand All @@ -229,7 +292,11 @@ stringData:
# Optional: exclude specific workspaces from the sync
# (workspace name, deployment name, or numeric ID).
# Mutually exclusive with BATON_WORKSPACES — set one or the other, never both.
BATON_DATABRICKS_EXCLUDE_WORKSPACES: <workspace-a,workspace-b>
# BATON_DATABRICKS_EXCLUDE_WORKSPACES: <workspace-a,workspace-b>

# Optional: setting this enables incremental sync; leave it unset to disable it.
# ID of the SQL warehouse used to query the system.access.audit log between full syncs.
# BATON_SQL_WAREHOUSE_ID: <SQL warehouse ID>

# Optional: include if you want C1 to provision access using this connector
BATON_PROVISIONING: true
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.27.4
require (
github.com/conductorone/baton-sdk v0.46.0
github.com/ennyjfrick/ruleguard-logfatal v0.0.2
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/quasilyte/go-ruleguard/dsl v0.3.23
github.com/stretchr/testify v1.12.1
Expand Down Expand Up @@ -66,7 +67,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.33.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jellydator/ttlcache/v3 v3.4.1 // indirect
Expand Down
Loading
Loading