Repository navigation
[CXH-2721] - Add Unity Catalog catalog sync - Databricks Connector - #71
mateoHernandez123 wants to merge 8 commits into
Conversation
e894653 to
019c458
Compare
00adc02 to
5933db6
Compare
FeliLucero1
left a comment
There was a problem hiding this comment.
Did a pass on this one. Main thing is the first comment: Revoke can say "already revoked" while the privilege still exists. The rest are perf and dupe stuff.
Comments tagged (out of scope / non-blocking) are low-confidence or nits I didn't fully verify, so treat them as FYI. Also out of scope: the databricks-connector: error prefix vs baton-databricks: is a convention that predates this PR, not something it introduced.
Heads up: the unreachable-catalog thing below is still the same in #72 / #73.
5933db6 to
6add251
Compare
CXH-2721. Catalogs hang from the metastore, keyed {metastore_id}::{name},
with one entitlement per catalog privilege plus a read-only owner. The
connector reads them through every running in-scope workspace attached to
the metastore, caches the routes in the sync session store, and grants and
revokes privileges with a live read that bypasses the response cache.
The tree is unchanged from 60501e2, which is the state reviewed on #71.
The branch is rebuilt on top of the staging-to-main landing so the PR shows
only the catalog layer instead of the 42 staging commits it used to carry.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
60501e2 to
a343b68
Compare
Superseded — see the current review report for commit
|
Connector PR Review: [CXH-2721] - Add Unity Catalog catalog sync - Databricks ConnectorBlocking Issues: 1 | Suggestions: 2 | Threads Resolved: 0 Review SummaryThis PR adds an opt-in Unity Catalog The pagination, the 401/403/404 handling (no empty-list fallbacks, and the Security IssuesNone found. Correctness Issues
Suggestions
Prompt for AI agentsReviewed commit: |
There was a problem hiding this comment.
Blocking issues found — see the full review report
Dismissing: this review is on a343b68 and both findings have moved since.
The blocking one, GetCatalog addressing a different catalog, is fixed in 2855a2b. GetCatalog now runs the same addressesSecurable guard permissionsUrl runs and rejects an answer whose name is not the one it asked for, and catalogThrough passes the InvalidArgument through instead of degrading it to Unknown. Two tests cover it and both fail without the guard.
The CANCELLING suggestion is declined, with the reasoning in the thread. Dropping CANCELLING from workspaceIsUsable takes the workspace out of scope, which leaves the metastore that routed through it out of the sync, and ConductorOne reads that as a deletion and removes its grants. The status set is deliberate; the comments that described it as dropped were the wrong half and are corrected in #90.
The openapi spec note is tracked as a follow-up.
FeliLucero1
left a comment
There was a problem hiding this comment.
Pass on f8cd1917. CI is green and this looks close: the errMetastoreGone / %w fixes, the GetCatalog guard (I traced ?, #, %2F and ..; all rejected), the system/samples skip and the session-store routes all check out. There's one low inline, and I bumped the CATALOG_DOES_NOT_EXIST thread.
CXH-2721. Catalogs hang from the metastore, keyed {metastore_id}::{name},
with one entitlement per catalog privilege plus a read-only owner. The
connector reads them through every running in-scope workspace attached to
the metastore, caches the routes in the sync session store, and grants and
revokes privileges with a live read that bypasses the response cache.
The tree is unchanged from 60501e2, which is the state reviewed on #71.
The branch is rebuilt on top of the staging-to-main landing so the PR shows
only the catalog layer instead of the 42 staging commits it used to carry.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
GetCatalog joined the raw catalog name into the path and skipped the
addressesSecurable guard that permissionsUrl applies. prepareRequest
unescapes the URL again before sending it, so a name holding "?", "#" or
"%" addressed a different catalog: GetCatalog("sales?x") read "sales" and
returned it.
That answer reached a write. catalogThrough checked only MetastoreID, and
routedEntitlement rebuilds the resource from the returned catalog.Name, so
Grant and Revoke sent their PATCH to the catalog Databricks answered with
rather than the one the entitlement named.
GetCatalog now runs the same guard permissionsUrl runs, and rejects an
answer whose name is not the name it asked for. catalogThrough passes
InvalidArgument through instead of folding it into catalogListingError,
which would have degraded it to Unknown.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The profile workspace was reused whenever it was still attached, but it was picked under the owner the last sync saw, and the owner decides which workspaces read every privilege: with the connector owning the metastore any of them does, otherwise only the ones it is a direct Admin of. After a transfer the recorded workspace can be one the connector no longer reads, while another attached workspace still satisfies the documented rule. Grant and Revoke refused the write with PermissionDenied and told the operator to grant Admin, on a metastore that was reachable. The route is now kept only when it still reads under the live owner, so the saved account round trip survives a transfer that does not move what the connector can read, and otherwise pickReadableWorkspace runs again. Also corrects the GetUncached comment: Cache-Control is part of the cache key, so the no-cache read does not refresh the entry normal reads look up. The behaviour is right and the comment described the opposite. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
f8cd191 to
5cc43e3
Compare
…s used entitlementOnLiveRoute only re-checked that the workspace on the profile still reads every privilege when the owner had changed since the sync that recorded it. The owner is not the only thing that decides this: a connector that does not own the metastore reads through a workspace it is a direct Admin of, and that assignment can be withdrawn with the owner untouched. The route was then kept, and resolveChange answered PermissionDenied, which ConductorOne reports as a failed grant even though another attached workspace could still serve it. Dropping the owner condition re-checks the route on every provisioning call that has one. It costs nothing when the connector owns the metastore, since ownsPrincipal short-circuits before isWorkspaceAdmin, and one ListWorkspaceMembers otherwise. Not reproduced against a tenant: ours has one workspace and its service principal owns the metastore, so the branch never nils the route there. The test covers it instead, and fails on the old condition with workspace = "wsa", want wsb. Verified live that the change is inert where it does run: same route, same owner, no extra call. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
FeliLucero1
left a comment
There was a problem hiding this comment.
Re-checked all the old threads against HEAD. Nice work, almost everything landed. Two of mine (T27 partial list, T36 non-RUNNING bindings) only got docs answers; I left a note in those threads. New stuff inline. One pre-existing thing outside the diff, following the bot's earlier note about GetUncached (Cache-Control is part of the cache key, client.go:111): the bot called it comment-only, but unity_catalog.go:311-316 actually relies on that refresh. So after a Grant/Revoke, a sync within the hour can still read the pre-change page, and TestASyncReadAfterAGrantSeesThePostChangeState passes without the refresh because it never seeds the cache. Fix here or ticket? Also heads up: after #90 lands this conflicts in 5 files (connector/metastore/metastore_helpers/metastore_test/docs).
Rebuilding this branch by squash onto the new base silently reverted #88 (03655ad), which had landed on staging in the meantime and touches the same four files. The reverted text contradicts the code: ListWorkspaces applies --databricks-exclude-workspaces before the audit feed picks a warehouse (audit_event_feed.go:351-353), a statement gets statementWaitTimeout of 30s plus statementPollMaxWait of 5 minutes rather than 5 minutes in total (sql.go:22,31), incremental sync detects removed memberships but not deleted principals, and access-control rule-set changes are not read at all. config_schema.json matches the output of ./connector config. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…s trust The shared Grants path decided by securable type which levels had already been refused by List, so the branch named metastore and catalog in a file that knows about neither. Both levels now carry listProvesTrust, and the branch reads the flag. No behaviour change: the two levels that exist both set it to true, so the check is skipped exactly where it was skipped before. Dropping the branch instead would not have been safe, since the schema, table and volume levels do not prove trust in their own List and rely on Grants running the check; false is the default that keeps that working. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…on note The securableLevel paragraph sat on securableOps, which left securableLevel undocumented, and three doc comments still named the pre-refactor functions syncSecurableGrants, grantSecurable and revokeSecurable. profileKeyMetastoreOwner claimed List writes the owner so Grants does not resolve it again. With listProvesTrust: true the catalog Grants path skips ensureGrantsAreTrustworthy entirely, so the only reader left is the provisioning trust check, which reads it off the resource routedEntitlement rebuilds from the route it just resolved. catalogThrough kept the comparison against the listing it replaced, which is history rather than behavior. In connector.mdx, workspace Admin reads as if any Admin qualifies, while the code accepts only an Admin assigned directly to the service principal, and three new lines said ConductorOne where the rest of the page says C1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ready has Three behaviors the code has and the docs did not state. A workspace that refuses the catalog listing fails the sync naming the metastore and that workspace, rather than removing the catalogs it could not list (catalogListingError). Catalogs sync as children of a metastore, so a selection that enables Catalogs without Metastores syncs nothing and still exits 0, measured against the tenant with --sync-resource-types. The metastore standing warning the section restructure dropped is back, because pickReadableWorkspace still fails that sync. Ownership is matched against the service principal itself, so the docs no longer read as if a catalog owned by a group it belongs to counted. Databricks documents neither that nor whether the permissions endpoint answers a partial list instead of an error, so both now describe the connector, or the visibility rule Databricks does document, rather than asserting vendor behavior. The customer page drops the raw SYSTEM_CATALOG enum and the unmeasured samples claim; the precise rule stays in docs-info, which also records that a catalog is keyed by name because CatalogInfo exposes no immutable id. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
#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>
#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>

Description
Second of four stacked PRs for Unity Catalog (CXH-2721). Adds the
catalogresource: sync, entitlements, grants, and Grant/Revoke of catalog privileges. No new config field, no credential change.What this adds
metastorewas a leaf. Catalogs now hang from it, opt-in, keyed{metastore_id}::{name}, with a read-onlyownerentitlement.Who may read a catalog
The decision the sync hangs on. Databricks shows any other caller only the grants it may see, so a list that cannot be proved complete is unusable — reporting it would make C1 revoke the rest.
flowchart TD q["Can every privilege on this catalog be read?"] --> own{"owns the metastore,<br/>or owns the catalog?"} own -->|yes| ok["trusted — sync it"] own -->|no| grp{"owner is _workspace_admins_<ws>_<id><br/>and the connector is a <b>direct</b> Admin there?"} grp -->|yes| ok grp -->|no| man{"holds MANAGE on the catalog?"} man -->|yes| ok man -->|no| deny["PermissionDenied naming the catalog<br/>and the remedy — C1 removes nothing"] style ok fill:#238636,color:#fff,stroke:#238636 style deny fill:#da3633,color:#fff,stroke:#da3633What the sync does in each case
The rule throughout: nothing is removed on an answer the connector could not prove.
FailedPreconditionPermissionDeniedCATALOG_DOES_NOT_EXISTFailedPreconditionsystem, or typedSYSTEM_CATALOGProvisioning
PATCH .../permissions/catalog/{name}, with an uncached pre-read decidingGrantAlreadyExists/GrantAlreadyRevokedand the echo confirming the write. A catalog no workspace lists is not proof of deletion — an unbound workspace answers the same 404 as a deleted one.flowchart TD start[Grant or Revoke] --> route[rebuild the route] route -->|a workspace serves the catalog| write[PATCH permissions] route -->|every workspace answers CATALOG_DOES_NOT_EXIST| proof{connector owns the metastore?} proof -->|no| unknown[FailedPrecondition: deletion cannot be proved] proof -->|yes| unbound[list with include_unbound=true] unbound -->|catalog is in the listing| exists[FailedPrecondition: it exists, out of reach] unbound -->|catalog is absent| gone[Revoke: GrantAlreadyRevoked / Grant: NotFound]Measured on the Baton account
samplesandsystem; the real catalog is unchanged.GrantAlreadyRevoked; Grant returnsNotFound.Links