Skip to content

[CXH-2722] - Add Unity Catalog schema sync - Databricks Connector - #72

Open
mateoHernandez123 wants to merge 14 commits into
mateoHernandez123/unity-catalog-catalog-syncfrom
mateoHernandez123/unity-catalog-schema-sync
Open

mateoHernandez123 wants to merge 14 commits into
mateoHernandez123/unity-catalog-catalog-syncfrom
mateoHernandez123/unity-catalog-schema-sync

Conversation

@mateoHernandez123

@mateoHernandez123 mateoHernandez123 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Bug fix
  • New feature

Third of four stacked PRs for Unity Catalog (CXH-2722). Adds the schema resource: sync, entitlements, grants, and Grant/Revoke of schema privileges. No new config field, no credential change.

Merge #71 first. This PR branches from it, so GitHub moves the base to staging when #71 lands.

What this adds

catalog was a leaf. Schemas now hang from it, opt-in, keyed {metastore_id}::{catalog}.{schema}, with a read-only owner entitlement. The privilege set is the catalog set without BROWSE, CREATE_SCHEMA and USE_CATALOG.

flowchart TD
  account[account] --> other["user, group, service principal, role, workspace"]
  account --> metastore[metastore]
  metastore --> catalog[catalog]
  catalog --> schema[schema]
  style schema fill:#1f6feb,color:#fff,stroke:#1f6feb
Loading

A principal can hold USE_SCHEMA and hold nothing on the tables under it, which is why the schema is its own resource.

Who may list the schemas, and who may read their privileges

Two different rights, and the one the sync hangs on. Databricks answers a caller that may not see everything with HTTP 200 and a short list at both levels, so each needs its own proof — and they do not accept the same privileges.

flowchart TD
  q["What may the service principal do on this catalog?"] --> own{"owns the metastore<br/>or the catalog?"}
  own -->|yes| both["lists every schema<br/>and reads every privilege"]
  own -->|no| grp{"owner is _workspace_admins_&lt;ws&gt;_&lt;id&gt;<br/>and a <b>direct</b> Admin there?"}
  grp -->|yes| both
  grp -->|no| man{"holds MANAGE on the<br/>schema or the catalog?"}
  man -->|yes| both
  man -->|no| use{"holds USE_SCHEMA or<br/>ALL_PRIVILEGES on the catalog?"}
  use -->|yes| listonly["lists every schema;<br/>Grants refuses with PermissionDenied"]
  use -->|no| deny["PermissionDenied naming the catalog<br/>and the remedy — C1 removes nothing"]
  style both fill:#238636,color:#fff,stroke:#238636
  style listonly fill:#9e6a03,color:#fff,stroke:#9e6a03
  style deny fill:#da3633,color:#fff,stroke:#da3633
Loading

Databricks leaves MANAGE out of ALL_PRIVILEGES, so the amber branch is a real setup: the operator grants USE_SCHEMA, the schemas sync, and the grants fail. The setup docs now say what each one needs.

What the sync does in each case

The rule throughout: nothing is removed on an answer the connector could not prove.

Situation Connector Effect in C1
A workspace lists the catalog and proves the listing complete emits its schemas synced
The first workspace cannot prove it walks to the next one in scope synced through the one that can
No workspace can prove it PermissionDenied nothing removed
A workspace refuses the catalog read (401, 403) walks on nothing removed
Every workspace answers the catalog is gone, none refusing emits no schemas removed with the parent
A bare 404 on the schemas listing FailedPrecondition nothing removed
404 carrying CATALOG_DOES_NOT_EXIST on that listing NotFound removed by the catalog syncer
A schema's privilege list is not provably complete PermissionDenied nothing removed
information_schema always skipped never synced

Provisioning

PATCH .../permissions/schema/{catalog}.{schema}, with an uncached pre-read deciding GrantAlreadyExists / GrantAlreadyRevoked and the echo confirming the write. owner is read-only and answers InvalidArgument.

Every write first rebuilds the schema from live reads, because the three owners the trust check turns on — metastore, catalog, schema — ride on the profile the last sync wrote, where they can be hours old.

flowchart TD
  start[Grant or Revoke] --> live["live read: metastore owner,<br/>catalog, schema"]
  live -->|recorded workspace still in scope and serving| trust[trust check on the schema]
  live -->|otherwise| walk[first running in-scope workspace that serves the catalog]
  walk --> trust
  live -->|names the schema or its catalog gone| gone{Grant or Revoke?}
  walk -->|no workspace serves the catalog| unproven[FailedPrecondition: deletion cannot be proved]
  gone -->|Grant| nf[NotFound]
  gone -->|Revoke| already[GrantAlreadyRevoked]
  trust --> read[uncached permissions pre-read]
  read --> patch[PATCH permissions, echo confirms]
Loading

Measured on the Baton account

  • A sync of account, user, group, service principal, metastore, catalog and schema exits 0 and emits the same counts twice: 1 schema (default), 28 entitlements on it, 10 grants reaching users, a group and a service principal. information_schema is not emitted.
  • Grant, Grant, Revoke, Revoke on one privilege: written, GrantAlreadyExists, removed, GrantAlreadyRevoked. The schema goes 6 → 7 → 6 grants around it.
  • The privilege is visible to Grants between the write and the revoke.
  • Schemas are children of a catalog: enabling Schemas without Catalogs syncs nothing and still exits 0.

Links

@linear-code

linear-code Bot commented Oct 9, 2026

Copy link
Copy Markdown

CXH-2722

@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-catalog-sync branch from d90274a to aabdb53 Compare October 9, 2026 13:20
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-schema-sync branch from 920df46 to f9142b4 Compare October 9, 2026 13:20
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-catalog-sync branch from aabdb53 to b12726a Compare October 9, 2026 14:27
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-schema-sync branch from f9142b4 to 29274ee Compare October 9, 2026 14:27
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-catalog-sync branch from b12726a to b2ecaf2 Compare October 9, 2026 16:46
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-schema-sync branch from 29274ee to e74210e Compare October 9, 2026 16:46
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-catalog-sync branch from b2ecaf2 to 00adc02 Compare October 9, 2026 16:54
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-schema-sync branch from e74210e to 7deff05 Compare October 9, 2026 16:54
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-catalog-sync branch from 00adc02 to 5933db6 Compare October 9, 2026 18:16
@mateoHernandez123
mateoHernandez123 force-pushed the mateoHernandez123/unity-catalog-schema-sync branch from 7deff05 to 1253d7e Compare October 9, 2026 18:17

@FeliLucero1 FeliLucero1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a pass on this one. The main things are the two mediums: Revoke on a dropped schema fails instead of returning already-revoked, and List swallows a 404 into an empty page. The rest is perf/docs/nits.

Stuff tagged (out of scope) is inherited from #71 or is stack-wide, so FYI, not blocking for this PR. Also checked the schema privilege set against the Databricks docs and it matches exactly (27, minus BROWSE / CREATE_SCHEMA / USE_CATALOG) 👍

Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved

@FeliLucero1 FeliLucero1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image Image Image

mateoHernandez123 and others added 3 commits November 16, 2026 10:45
#71 moved on after this branch was cut: the trust check each securable
level runs now travels with the level through listProvesTrust, the
metastore route is re-checked on every use, and the README and the
connector doc gained the catalog failure modes. Schema sync keeps its own
trust read, because a schema listing proves nothing about the privileges
on it.

Conflicts resolved by keeping both sides: the renamed doc comments and
the level flag from #71, the trust-read classification and the
schema-aware wording from this branch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The trust check that ends schema List reads the connector's own privileges
on the catalog, and that read names the catalog missing only when it is
gone: a workspace the catalog is not bound to refuses with 403, which
deniesTrust already catches. Returning that sentinel raw failed the whole
sync with codes.Unknown and no prefix whenever a catalog was dropped
between the listing that found it and this read.

List now walks on, and reports no schemas for a catalog every workspace
proved gone with none refusing, which is what the catalog syncer removes
in the same sync. A refusal anywhere in the walk still leaves the picture
unproven, so nothing is emptied on it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The setup section told the operator what makes the schema listing
complete and stopped there, so a service principal given only USE_SCHEMA
follows it, sees its schemas synced, and then fails on their grants:
ALL_PRIVILEGES and USE_SCHEMA list every schema, and neither reads the
privileges on one, because Databricks leaves MANAGE out of
ALL_PRIVILEGES. The connector doc, the README and the limitations now
state both requirements, as the catalog sections already do.

The README gains the schema layer it was missing in provisioning and
permissions, and the limitations gain the schema key, the skipped
information_schema and the opt-in rule. The information_schema reason is
the one the code states: Databricks creates it read-only and its
privileges cannot be granted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mateoHernandez123 and others added 4 commits November 16, 2026 11:27
#71 kept moving after this branch was cut, and its review rounds left the
schema layer behind on four counts.

**Writes were decided from sync-time owners.** Grant and Revoke read the
metastore owner, the catalog owner and the schema owner off the profile the
last sync wrote, and those three are exactly what the trust check
short-circuits on. An ownership transfer away from the connector therefore
left a write being decided from a privilege list Databricks had already
started truncating, and Revoke could report a grant removed that is still
held. Both now rebuild the entitlement's schema the way the catalog does: the
metastore owner from a live listing, the catalog from the recorded workspace
when this sync still admits it and otherwise from the first running in-scope
workspace that serves it, and the schema itself from a new
GET /schemas/{full_name}. Both paths bypass the HTTP cache, because a
remembered page would decide the write with the access of an earlier one. A
catalog no workspace serves is still not proof of deletion, so that case
refuses with FailedPrecondition; only a vendor code naming the schema or its
catalog is an absence, answering NotFound on Grant and GrantAlreadyRevoked on
Revoke.

**The recorded workspace was reused without asking whether this sync still
admits it.** The write now goes through profileRoute, which answers the
allowlist and the exclude set off the profile, as the catalog does.

**A live sighting did not supersede an earlier gone answer.** The walk in
pushRoute could empty a catalog that a later workspace had just listed. The
reads run in order and a catalog cannot be absent before it is present, so a
workspace that serves it now clears the flag. A metastore proved gone also
stops returning its bare sentinel, which reaches C1 as Unknown and is retried;
the metastore syncer removes the parent in the same sync.

**The sync session never reached the shared path.** Schema List and Grants now
carry it, so the workspace-Admin check behind the trust rule is read once per
workspace per sync instead of once per schema. The listing also gained the
repeated-page-token guard the catalog listing has.

Measured on the Baton account: grant, repeat, revoke, repeat on
test_workspace.default leaves 7 grants then 6 with the annotations in that
order, and the privilege is visible to Grants in between. A full sync of
account, user, group, service principal, metastore, catalog and schema exits 0
with no errors, twice, emitting the same 29 catalog and 10 schema grants.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
connector.mdx prose uses C1 for the product, which luisina asked for on #71,
and the Go comments on staging follow the same convention. The schema layer
was written against the older wording and tipped the balance back: it added
eight "ConductorOne" to code comments. The lines #71 owns are left as they
are.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The test file was 931 lines built around a fake Databricks, and what it proved
was that the code does what it was written to do. The tenant run is what
answers whether the layer works, and QA runs the connector against a tenant
before production. Nothing else references the fake or its helpers, so the
package builds and tests clean without it. It stays on disk, excluded per
clone, for local iteration.

The comments had grown into paragraphs restating the code around them. Each
one is now the doc above its function, or a single line where a Databricks
behaviour decides the branch and is invisible from it: a 403 for an unbound
workspace, a leaf-named error code, the order the reads run in.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A comment naming the field it sits on, or restating the format the function
parses, costs a line and tells the reader nothing the next line does not. The
ones left are the ones carrying a reason: a Databricks behaviour, or why a
value is written down at all.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mateoHernandez123
mateoHernandez123 marked this pull request as ready for review November 16, 2026 14:44
mateoHernandez123 added a commit that referenced this pull request Nov 17, 2026
…landed

#72 kept moving after this branch was cut, and its review rounds left the table
and volume layer behind on the same counts, one level deeper.

**Writes were decided from sync-time owners.** Grant and Revoke read the
metastore owner, the catalog owner, the schema owner and the securable's own
owner off the profile the last sync wrote, and those four are exactly what the
trust check short-circuits on. An ownership transfer away from the connector
therefore left a write being decided from a privilege list Databricks had
already started truncating, and Revoke could report a grant removed that is
still held. Both now rebuild the entitlement's table or volume the way the
schema does: the metastore owner from a live listing, the catalog from the
recorded workspace when this sync still admits it and otherwise from the first
running in-scope workspace that serves it, the schema from GET
/schemas/{full_name}, and the securable itself from a new GET
/tables/{full_name} or from GET /volumes/{full_name}. The whole path bypasses
the HTTP cache, because a remembered page would decide the write with the
access of an earlier one. A table also reads table_type live, so the write is
no longer checked against the variant the last sync happened to record.

**A live sighting did not supersede an earlier gone answer.** The walk in
pushSchemaChildRoute could empty a schema's children on a gone answer a later
workspace had already contradicted. The reads run in order and a catalog cannot
be absent before it is present, so a workspace that serves it now clears the
flag. A metastore the account no longer lists also stops returning its bare
sentinel; the metastore syncer removes the parent in the same sync.

**The sync session never reached the shared path.** The children listing and
the table and volume Grants now carry it, so the workspace-Admin check behind
the trust rule is read once per workspace per sync instead of once per
securable. The listing also gained the repeated-page-token guard the schema
listing has.

**A refused schema read stopped the walk.** Only the catalog read continued to
the next workspace, so a 401, 403 or 404 on the schema failed the sync even
where another in-scope workspace serves it. Both reads now walk on, and a
refusal left standing is still an error rather than an empty listing: emptying
one is reserved for a parent every workspace named as gone with none refusing.

GetTable and GetVolume check the name Databricks answers with, as GetCatalog and
GetSchema do, because the owner they report decides whether a privilege list is
complete. GetSchema now refuses an answer naming no schema at all for that same
reason, which is what the client test on this branch already asserted.

Not re-measured against the tenant yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mateoHernandez123 added a commit that referenced this pull request Nov 17, 2026
The file was 293 lines built on the fake Databricks account the schema tests
carried, and #72 dropped that fake with them. What it proved was that the code
does what it was written to do. The tenant run is what answers whether the layer
works, and QA runs the connector against a tenant before production.

Nothing tracked references the fake or its helpers any more, so the package
builds and tests clean without this file, which is the view CI gets. It stays
excluded per clone, next to the schema tests, for local iteration.

The client tests in pkg/databricks/unity_catalog_test.go stay: they assert the
query set a listing sends and the name a single read is allowed to answer with,
which is a contract rather than a restatement of the caller.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@FeliLucero1 FeliLucero1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another pass with the updated deep review. The live re-route on schema Grant/Revoke (GetSchema + catalogThrough) closes the stale-profile thing I raised 👍, and the SDK bump to v0.42.5 doesn't let any raw 404 through.

Main ask is the tests (see schema.go:178). The rest are lows/nits. Also, README (:8, :84-85, :92-99, :117-119) and docs-info.md (:9, :17, :26, :46, :50, :59) still only talk about metastores and catalogs. Worth adding schemas there too, the tree and the permissions paragraph are the only parts updated.

Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/securable_helpers.go Resolved
Comment thread docs/connector.mdx Resolved
mateoHernandez123 and others added 2 commits November 17, 2026 15:11
Five call sites asked the same question in two halves: the shared sentinel a
trust read raises, and the per-level one naming a securable or its parent. A
sixth would have had to remember both. isSecurableGoneSentinel now answers for
all three, so Grant, Revoke and the grants sync read as one condition.

The two sites that compare against errSecurableGone alone stay as they are:
catalog.go and schema.go translate it into their own per-level sentinel, so
widening them would lose the distinction they exist to make.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The warning made the exclusion conditional on a privilege list that cannot be
proven complete. The catalog sync skips a catalog named system, and any catalog
Databricks types SYSTEM_CATALOG, before it reads any privilege at all, so the
condition never applied. The page itself, the README and docs-info already said
it was unconditional.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mateoHernandez123 added a commit that referenced this pull request Nov 17, 2026
The warning made the exclusion conditional on a privilege list that cannot be
proven complete. The catalog sync skips a catalog named system, and any catalog
Databricks types SYSTEM_CATALOG, before it reads any privilege at all, so the
condition never applied. The page itself, the README and docs-info already said
it was unconditional. Same wording #72 landed, so the restack carries one text.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/schema.go Resolved
Comment thread pkg/connector/resource_types.go Resolved
Comment thread docs/docs-info.md Resolved
Comment thread docs/connector.mdx Resolved
Comment thread docs/connector.mdx Resolved
Comment thread README.md Resolved
mateoHernandez123 and others added 3 commits November 18, 2026 13:00
…yncer

The schema syncer had its own copy of the walk that finds the workspace a
catalog is routed through, and the copies had drifted: the schema walk
ignored a gone answer, so revoking a grant on a schema whose catalog was
deleted failed with FailedPrecondition instead of returning
GrantAlreadyRevoked, and C1 kept retrying a revoke it could never land.

workspaceForCatalog now takes an acceptance predicate and reports a third
outcome, errCatalogNotAccepted, so the schema listing's completeness check
rides the shared walk instead of repeating it. liveCatalogRoute ends in
confirmCatalogGone, the route read from the profile is profileCatalogRoute,
and the entitlement rebuild is entitlementOnResource, which also checks the
type assertion the catalog path left bare.

Sharing the walk fixes a second divergence: a workspace that answers with a
catalog of another metastore left the schema walk able to conclude "gone"
off another workspace's 404, which would drop the catalog's schemas from
the sync and delete their grants. It now leaves the question open and
refuses.

Grant and Revoke return the write's annotations alone, as catalog.go does,
so C1 reads the PATCH's rate-limit budget instead of an earlier read's.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reading a schema's grants needs MANAGE or ownership, but the type declared
only USE_CATALOG and USE_SCHEMA, so ./baton-databricks capabilities told
the admin to grant a privilege set the sync then fails on.

baton_capabilities.json is regenerated with the command the
capabilities_and_config workflow runs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The schema sections explained Databricks mechanics where the admin needs a
privilege to grant. They now lead with the grant, name the Metastore Admin
and the workspace id the way the catalog sections above them do, and drop
the sentences that repeat the system-catalog note.

docs-info.md no longer claims SchemaInfo exposes no immutable id: it does
expose schema_id, but no endpoint accepts it, which is the reason the
resource is keyed by name.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mateoHernandez123 added a commit that referenced this pull request Nov 18, 2026
…landed

and volume layer behind on the same counts, one level deeper.

**Writes were decided from sync-time owners.** Grant and Revoke read the
metastore owner, the catalog owner, the schema owner and the securable's own
owner off the profile the last sync wrote, and those four are exactly what the
trust check short-circuits on. An ownership transfer away from the connector
therefore left a write being decided from a privilege list Databricks had
already started truncating, and Revoke could report a grant removed that is
still held. Both now rebuild the entitlement's table or volume the way the
schema does: the metastore owner from a live listing, the catalog from the
recorded workspace when this sync still admits it and otherwise from the first
running in-scope workspace that serves it, the schema from GET
/schemas/{full_name}, and the securable itself from a new GET
/tables/{full_name} or from GET /volumes/{full_name}. The whole path bypasses
the HTTP cache, because a remembered page would decide the write with the
access of an earlier one. A table also reads table_type live, so the write is
no longer checked against the variant the last sync happened to record.

**A live sighting did not supersede an earlier gone answer.** The walk in
pushSchemaChildRoute could empty a schema's children on a gone answer a later
workspace had already contradicted. The reads run in order and a catalog cannot
be absent before it is present, so a workspace that serves it now clears the
flag. A metastore the account no longer lists also stops returning its bare
sentinel; the metastore syncer removes the parent in the same sync.

**The sync session never reached the shared path.** The children listing and
the table and volume Grants now carry it, so the workspace-Admin check behind
the trust rule is read once per workspace per sync instead of once per
securable. The listing also gained the repeated-page-token guard the schema
listing has.

**A refused schema read stopped the walk.** Only the catalog read continued to
the next workspace, so a 401, 403 or 404 on the schema failed the sync even
where another in-scope workspace serves it. Both reads now walk on, and a
refusal left standing is still an error rather than an empty listing: emptying
one is reserved for a parent every workspace named as gone with none refusing.

GetTable and GetVolume check the name Databricks answers with, as GetCatalog and
GetSchema do, because the owner they report decides whether a privilege list is
complete. GetSchema now refuses an answer naming no schema at all for that same
reason, which is what the client test on this branch already asserted.

Not re-measured against the tenant yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mateoHernandez123 added a commit that referenced this pull request Nov 18, 2026
The file was 293 lines built on the fake Databricks account the schema tests
carried, and #72 dropped that fake with them. What it proved was that the code
does what it was written to do. The tenant run is what answers whether the layer
works, and QA runs the connector against a tenant before production.

Nothing tracked references the fake or its helpers any more, so the package
builds and tests clean without this file, which is the view CI gets. It stays
excluded per clone, next to the schema tests, for local iteration.

The client tests in pkg/databricks/unity_catalog_test.go stay: they assert the
query set a listing sends and the name a single read is allowed to answer with,
which is a contract rather than a restatement of the caller.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants