Skip to content

[Server][OpenSharing 4/6] Serve OpenSharing's share API from Unity Catalog - #2146

Open
littlegrasscao wants to merge 6 commits into
unitycatalog:mainfrom
littlegrasscao:sharing/provider-shares
Open

littlegrasscao wants to merge 6 commits into
unitycatalog:mainfrom
littlegrasscao:sharing/provider-shares

Conversation

@littlegrasscao

@littlegrasscao littlegrasscao commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Each PR builds on the one before it. Until the earlier PRs merge, a later PR's "Files changed" tab also shows their changes, so use these links to review one PR's own change:

  • Own change: that PR's own commits, inside the PR, so you can comment. The link is updated after each push.
  • Branch compare: the same diff between the fork's branches. It never goes stale, but it is read-only.
# PR Own change Branch compare
1 #2145 Unity Catalog connector and dependencies Files changed main...sharing/connector
2 #2151 OpenSharing's tables in UC's schema steps Files changed sharing/connector...sharing/schema
3 #2152 Authorization for shares and recipients Files changed sharing/schema...sharing/auth
4 #2146 Share API ← this PR Files changed sharing/auth...sharing/provider-shares
5 #2147 Recipient API and share grants Files changed sharing/provider-shares...sharing/provider-recipients
6 #1825 Sharing protocol and recipient activation Files changed sharing/provider-recipients...opensharing-embedded

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated: docs/server/opensharing.md is a new page, linked from mkdocs.yml, and etc/conf/server.properties lists the new settings.

Description of changes

Part 4 of 6 of embedded OpenSharing, which lets one Unity Catalog server share the Delta tables it governs with Delta Sharing recipients.

The six PRs, each building on the one before:

  1. [Server][OpenSharing 1/6] Add the Unity Catalog connector for OpenSharing #2145: the Unity Catalog connector for OpenSharing and its dependencies
  2. [Server][OpenSharing 2/6] Add OpenSharing's tables as schema steps #2151: OpenSharing's tables as schema steps
  3. [Server][OpenSharing 3/6] Authorize shares and recipients #2152: authorization for shares and recipients (the SHARE securable, the CREATE SHARE and USE SHARE privileges, OPA input, grant validation, the key mapper's share lookup and ResultFilter)
  4. [Server][OpenSharing 4/6] Serve OpenSharing's share API from Unity Catalog #2146: the share API (this PR)
  5. [Server][OpenSharing 5/6] Serve OpenSharing's recipient API and share grants from Unity Catalog #2147: the recipient API and share grants
  6. [Server][OpenSharing 6/6] Serve the Delta Sharing protocol and recipient activation from Unity Catalog #1825: the sharing protocol and recipient activation

With server.opensharing.enabled=true, this PR serves OpenSharing's provider API for shares at /api/2.1/unity-catalog/opensharing/provider, behind UC's own authentication and authorization. It creates, lists, gets, updates (adding and removing tables, or transferring ownership) and deletes shares. Request and response bodies use OpenSharing's wire format.

Startup

  • OpenSharing is a regular dependency of server (opensharing-server-core 0.1.1, added in [Server][OpenSharing 1/6] Add the Unity Catalog connector for OpenSharing #2145). UnityCatalogServer builds it through OpenSharingLifecycle.start only when the flag is on.
  • server.authorization=enable is required, since UC users own the shares. Without it, the server doesn't start, and the error names the setting.
  • server.opensharing.public-url is required: it's the address recipients reach this server at. If it's missing or blank, the server doesn't start, and the error names the setting.
  • The provider API is registered in ArmeriaServerBuilder as a new OPENSHARING protocol, with OpenSharing's JSON mapper for request and response bodies.
  • OpenSharingExceptionHandler renders every failure on these routes as OpenSharing's {errorCode, message} body:
    • UC's UNAUTHENTICATED and PERMISSION_DENIED rejections become OpenSharing's equivalents.
    • A malformed or unverifiable token gets a 401, not a 500.
  • A missing share is OpenSharing's own 404 (RESOURCE_DOES_NOT_EXIST). The key mapper lets OpenSharing's not-found error through to that handler.
  • With the flag off, nothing is registered, and no OpenSharing table is read or written.
  • OpenSharing's tables (prefix os_) are part of UC's schema ([Server][OpenSharing 2/6] Add OpenSharing's tables as schema steps #2151), and use UC's session factory and connection pool.
  • New page docs/server/opensharing.md, added to mkdocs.yml. The new settings are in etc/conf/server.properties, commented out like the file's other optional settings.

Authorization

UC authorizes each provider method by its @AuthorizeExpression. The connector's authorize only checks that the caller is an enabled UC user.

Method Expression
POST /shares CREATE SHARE or OWNER on the metastore
GET /shares/{share} OWNER or USE SHARE on the metastore, or OWNER of the share
GET /shares as get, per item
PATCH /shares/{share} OWNER of the share, or OWNER on the metastore when the request sets ownerId
DELETE /shares/{share} OWNER of the share
  • Ownership transfer. The metastore OWNER can transfer a share by sending ownerId with no other change in the request. UC then moves its OWNER record from the old owner to the new one. OpenSharing rejects:
    • a transfer that carries other changes (400);
    • a transfer by a share owner who isn't the metastore OWNER (403).
  • Admin flag. OpenSharingProviderService builds OpenSharing's UserContext from the caller UC authenticated. Its admin flag is true when the caller is OWNER of the metastore, which is what lets OpenSharing accept a transfer.
  • Owner records. UC's authorizer records the creator as OWNER of a new share, and removes the records when the share is deleted.
  • Listings are filtered per item with @ResponseAuthorizeFilter.
    • The service pages through every share with OpenSharing's listAll.
    • As in UC's own listings, a page is filtered after it is read. So a caller without USE SHARE can get short or empty pages with more to follow.
  • Tables. Adding a table to a share needs the access the connector checks ([Server][OpenSharing 1/6] Add the Unity Catalog connector for OpenSharing #2145): USE CATALOG, USE SCHEMA and SELECT, or ownership.

Tests

  • OpenSharingEmbeddedTest drives the API over HTTP on a server with authorization on.
    • providerApiRequiresUnityCatalogPrivileges:
      • No token, or a malformed one, gets a 401 with OpenSharing's UNAUTHENTICATED body.
      • Creating a share needs CREATE SHARE, and adding a table needs USE CATALOG, USE SCHEMA and SELECT.
      • USE SHARE lets a user list and read other users' shares, but not change or delete them.
      • Denials come from UC.
    • unityCatalogRecordsShareOwners:
      • The owner and the metastore owner can read a share by any case of its name.
      • An unknown name gets OpenSharing's 404.
      • Only the owner can change the share.
      • A share deleted and created again under the same name belongs only to its new creator.
    • adminTransfersASharesOwnership:
      • A share owner can't transfer it (403), and a transfer with other changes is a 400.
      • The metastore owner's transfer succeeds, and UC's owner record moves: the new owner can change the share, and the old one can't.
    • listingsAreFilteredPerItemAfterPaging: with one share per page, a user who owns one of three shares gets two empty pages, then their share.
  • OpenSharingLifecycleTest: the server doesn't start without server.authorization=enable, or without server.opensharing.public-url.
  • OpenSharingDisabledTest: with the flag off, the provider path is answered like any unrouted path, and the server keeps serving catalogs and permissions after all os_* tables are dropped.

I ran server/testOnly io.unitycatalog.server.service.sharing.* on JDK 17 and H2, with OpenSharing 0.1.1: 21 tests, all pass. CI runs the full server suite on H2, PostgreSQL and MySQL.

Known gaps

  • Owner records aren't in the share's database transaction. The share is written in a Hibernate transaction, but UC's authorizer writes its records through its own autocommit connection. Create, delete and transfer write the owner record before the share's transaction commits.
    • If recording fails, the share isn't created, deleted or transferred.
    • If the commit fails after the record is written, the two disagree:
      • a created share leaves an unused owner record;
      • a deleted share stays without its owner record, so nobody can change or delete it, and only users with USE SHARE can read it;
      • a failed transfer leaves UC's OWNER record with the new owner, while OpenSharing still has the old one.
  • Deleted owners. When the owner of a share is deleted, nobody can change or delete the share.
  • Shares only. Recipients, share grants and the sharing protocol come in [Server][OpenSharing 5/6] Serve OpenSharing's recipient API and share grants from Unity Catalog #2147 and [Server][OpenSharing 6/6] Serve the Delta Sharing protocol and recipient activation from Unity Catalog #1825.

Compatibility

This pull request and its description were written by Isaac.

@littlegrasscao
littlegrasscao force-pushed the sharing/provider-shares branch from 3c34540 to 8c978a6 Compare November 17, 2026 22:13
Sun Cao and others added 6 commits November 17, 2026 22:15
The connector is how embedded OpenSharing reads Unity Catalog: it
resolves a table only for a user UC lets read its data, and vends that
table's read-only credentials with UC's credential vendor, refusing any
other operation instead of downgrading it. Nothing serves OpenSharing
yet.

opensharing-server-core is an ordinary dependency of the server module,
like Iceberg, and the connector lives in the server's service/sharing
package, so every packaging path that collects the server's classpath
carries it. Its Hadoop modules stay on hadoopVersion, Delta Kernel's
defaults stay on the server's Delta version, and the published
unitycatalog-client and unitycatalog-hadoop that delta-storage brings in
are excluded.

hadoop-client-runtime registers its relocated Woodstox for StAX, which
breaks Jackson's XML mapper (S3Mock, the Azure SDK), so the server sets
the StAX factory system properties to Woodstox's own. The shaded server
that the Spark connector tests use leaves out the modules that only
OpenSharing adds, by module name.

Signed-off-by: Sun Cao <[email protected]>

Consume OpenSharing 0.1.1

Bump opensharing-server-core to 0.1.1. OpenSharing now matches the AWS
SDK and Delta Kernel versions this server uses, so those pins are gone.
It builds against a newer Hadoop, so the server keeps overriding the
Hadoop modules to hadoopVersion. Its core excludes the published Unity
Catalog jars from delta-storage itself, so the exclusion here is gone.
The connector reports whether the caller owns the metastore in the
user context's admin flag, which lets them transfer the ownership of
any share or recipient.

Co-authored-by: Isaac <[email protected]>
Keep OpenSharing's Delta and Hadoop versions in the POM and initialize Woodstox for builder-started servers.

Signed-off-by: Sun Cao <[email protected]>

Co-authored-by: Isaac <[email protected]>
OpenSharing reads the admin flag only to let a caller transfer the ownership
of a share or recipient. UC checks that with the AuthorizeExpression on the
provider endpoints, and OpenSharingProviderService sets the flag on the
context it passes in, so the connector's authorize has nothing to decide.

Signed-off-by: Sun Cao <[email protected]>
Co-authored-by: Isaac <[email protected]>
OpenSharing's six tables (os_shares, os_share_properties, os_shared_data_objects, os_recipients, os_share_permissions and os_recipient_tokens) are Unity Catalog schema steps, V4 through V11, for H2, PostgreSQL and MySQL: one statement per step, the tables in foreign-key order, then the owner_id indexes. They are created whether or not embedded OpenSharing is enabled, and the steps build the schema Hibernate builds from OpenSharing's entities, which UC's own session factory now maps. Each step ships its H2 effect file; the PostgreSQL and MySQL ones follow from a run with Docker.

HibernateTransactions runs OpenSharing's store work in sessions of that factory, and joins a transaction the thread already has, so a caller can make several OpenSharing calls and its own steps one unit of work. The schema migrator and the schema snapshot treat os_* tables as Unity Catalog's own, so the steps' index names are not blamed on another application and the snapshots see the tables the steps create.

Signed-off-by: Sun Cao <[email protected]>

Match OpenSharing 0.1.1's schema

OpenSharing 0.1.1 stores ids as the database's native uuid (binary(16) on MySQL), its enums as plain varchar through converters, and names its foreign keys. The steps build the same columns, types and names its V1 does on each dialect, and the owner_id indexes its entities declare.

Co-authored-by: Isaac <[email protected]>
Shares and recipients become securable types, with CREATE SHARE, USE
SHARE, CREATE RECIPIENT and USE RECIPIENT as privileges on the
metastore. UC grants nothing on a share or recipient itself, so
validation of grants, the authorization hierarchy and the OPA input
treat them as roots, and the permissions API refuses them.

The key mapper resolves a share or recipient by name from OpenSharing's
tables, and answers a missing one with the NOT_FOUND that UC gives for
any missing object, not OpenSharing's own exception. It reads those
tables only when asked for such a key, which only OpenSharing's provider
API, once enabled, produces. The result filter reads the ids of
OpenSharing's share and recipient responses.

Signed-off-by: Sun Cao <[email protected]>

Read OpenSharing 0.1.1's UUID ids

OpenSharing 0.1.1 keys its entities by UUID, so the OPA input and the
key mapper look them up directly instead of by their string form, and
the JSON still carries the string form.

Co-authored-by: Isaac <[email protected]>
With server.opensharing.enabled=true, the server serves OpenSharing's
provider API for shares at /api/2.1/unity-catalog/opensharing/provider,
behind UC's authentication and authorization. It is registered as the
OPENSHARING protocol of ArmeriaServerBuilder next to Iceberg and Delta,
with OpenSharing's JSON mapper and error dialect. UC records each
share's owner in its authorizer, in the same transaction as the share
itself. A share that does not exist is OpenSharing's 404 on these
routes. With the flag off, none of this is registered and none of
OpenSharing's tables is read or written.

A sharing docs page describes the provider API, its privileges, how
shared tables are read, and the database tables.

Signed-off-by: Sun Cao <[email protected]>

Consume OpenSharing 0.1.1 and support admin ownership transfers

The provider service answers with OpenSharing's JSON, so its methods
carry ProducesJson: without it Armeria found no response converter and
answered 500. The caller's context now says whether they own the
metastore, and PATCH /shares/{share} takes a catalog admin transferring
the ownership to the body's ownerId, on its own, with UC's owner record
moving to the new owner in the same transaction.

Co-authored-by: Isaac <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant