Skip to content

[Server] Authorize the Iceberg REST catalog endpoints - #1813

Merged
yili-db merged 2 commits into
unitycatalog:mainfrom
yili-db:stack/irc_auth_1
Sep 28, 2026
Merged

yili-db merged 2 commits into
unitycatalog:mainfrom
yili-db:stack/irc_auth_1

Conversation

@yili-db

@yili-db yili-db commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


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

Description of changes

  • Gate every Iceberg REST endpoint on shared AuthorizeExpressions policies instead of the metastore-owner placeholder:
    • config -> GET_CATALOG
    • loadNamespace/getNamespace/namespaceExists/listNamespaces -> GET_SCHEMA
    • createNamespace -> CREATE_SCHEMA
    • updateNamespaceProperties -> UPDATE_SCHEMA
    • dropNamespace -> DELETE_SCHEMA
    • loadTable/tableExists/loadView/reportMetrics/listTables/loadCredentials -> GET_TABLE
    • createTable -> CREATE_ICEBERG_TABLE
    • dropTable -> DELETE_TABLE
    • (namespaceExists, updateNamespaceProperties, dropNamespace, and loadCredentials are newer endpoints on the Iceberg surface, authorized here alongside the rest.)
  • Add GET_CATALOG, GET_SCHEMA, CREATE_SCHEMA, CREATE_SCHEMA_WITH_STORAGE_ROOT, UPDATE_SCHEMA, DELETE_SCHEMA, and CREATE_ICEBERG_TABLE to AuthorizeExpressions, and filter listNamespaces/listTables per row with @ResponseAuthorizeFilter.
  • Move existing UC REST inline expressions onto the shared constants (behavior-preserving):
    • CatalogService get/list -> GET_CATALOG (dropping the private LIST_AND_GET_AUTH_EXPRESSION), and the DeltaApiService config expression likewise.
    • SchemaService: getSchema/listSchemas -> GET_SCHEMA, createSchema -> CREATE_SCHEMA_WITH_STORAGE_ROOT, updateSchema -> UPDATE_SCHEMA, deleteSchema -> DELETE_SCHEMA.
  • Return raw TableInfoDAOs from the listIcebergTables page and teach ResultFilter to resolve a TABLE id from either the DAO or a TableInfo, so listTables filters per row without re-loading each table.
  • Scope the credentials loadTable/loadCredentials vend in getLoadCredentialPrivileges by table OWNER/SELECT+MODIFY, dropping the principalId == null short-circuit.
  • Leave updateTable and renameTable on the metastore-owner placeholder; both need the body-derived AuthorizeValueExtractor deferred to the next branch:
    • updateTable: one endpoint covers a plain commit (UPDATE_TABLE) and a staged-create commit (create authorization plus a check that the write location matches a staging table the caller can access), selected by a request-body condition a declarative expression cannot key here.
    • renameTable: the source/destination are structured TableIdentifiers whose full identity spans the URL {catalog} and the body, which a scalar field key cannot compose into a resolvable name.
  • Add SdkIcebergRestCatalogAccessControlTest (a per-user IcebergRestClient plus Iceberg error-assert helpers in TestUtils) exercising every authorized endpoint, with metastore-admin-denied cases on the dropNamespace/updateNamespaceProperties mutations.

@yili-db
yili-db marked this pull request as ready for review August 28, 2026 07:28
@yili-db
yili-db requested review from openinx and tdas as code owners August 28, 2026 07:28
@yili-db

yili-db commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator Author

FYI @iamkiayun
I am adding the authz expressions to IRC endpoints.
Also I am working on adding Integration test with Spark+Iceberg.

@yili-db
yili-db requested a review from timothyw553 August 28, 2026 20:23
@iamkiayun

Copy link
Copy Markdown
Contributor

Thanks for the heads-up, @yili-db. This looks like a useful authorization follow-up to #1696. I’ll keep an eye on the Spark + Iceberg integration coverage, and I’d be happy to help validate the native Iceberg lifecycle if that would be useful.

@yili-db
yili-db force-pushed the stack/irc_auth_1 branch 6 times, most recently from f45e559 to d9577e7 Compare September 24, 2026 18:34

@openinx openinx left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

High level LGTM

  • Replaces the metastore-owner placeholder on the Iceberg REST endpoints with the shared AuthorizeExpressions policies, adds per-row @ResponseAuthorizeFilter on listNamespaces/listTables, and adds an exhaustive access-control test. Well-scoped; the UC REST/Delta moves onto shared constants look behavior-preserving, and leaving updateTable/renameTable on the metastore-owner placeholder fails closed.
  • One question on the getLoadCredentialPrivileges guard removal; the rest are nits.

if (state.dataSourceFormat() != DataSourceFormat.ICEBERG) {
return READ_ONLY;
}
UUID principalId = userRepository.findPrincipalId();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Removing the principalId == null short-circuit changes two things: (1) with auth off (AllowingAuthorizer) this now vends READ_WRITE instead of READ_ONLY — intended per the new doc; (2) with a real JCasbinAuthorizer, a null principalId here would NPE (principal.toString() in authorize/authorizeAll) instead of falling back to READ_ONLY. Is principalId provably non-null once GET_TABLE has passed? If yes, a one-line note/assert would make that explicit; if not, this is a latent NPE.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

With a real JCasbinAuthorizer but a null principalId, it would fail earlier at endpoint authorization stage and never hit here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Adding a comment here.

* the resolved external location) keeps the no-overlap guard running when a path resolves to no
* external location.
*/
public static final String CREATE_ICEBERG_TABLE =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: CREATE_ICEBERG_TABLE is identical to CREATE_TABLE except for the MANAGED/EXTERNAL discriminator (#location == null vs #table_type != 'EXTERNAL'). Consider factoring the shared catalog/schema tier + external-location tail so the two policies can't drift.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CREATE_ICEBERG_TABLE will be removed in the next PR in stack once it's able to extract table_type for IRC.

* fields ({@code id}, {@code name}), since the rows are detached once the page returns.
*/
public record IcebergTablePage(List<String> tableNames, Optional<String> nextPageToken) {}
public record IcebergTablePage(List<TableInfoDAO> tableDaos, Optional<String> nextPageToken) {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: returning detached TableInfoDAOs (safe only for eager id/name, per the doc) leaks a persistence entity into the service and ResultFilter, and is what forces the instanceof TableInfoDAO branch in ResultFilter (L173-176). A minimal projection record (UUID id, String name) would drop both the "eager fields only" caveat and the instanceof. Non-blocking.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In a follow up PR, I can make a minimum interface and have TableInfoDAO implements it.

- Gate every Iceberg REST endpoint on shared `AuthorizeExpressions` policies instead of the metastore-owner placeholder:
  - `config` -> `GET_CATALOG`
  - `loadNamespace`/`getNamespace`/`namespaceExists`/`listNamespaces` -> `GET_SCHEMA`
  - `createNamespace` -> `CREATE_SCHEMA`
  - `updateNamespaceProperties` -> `UPDATE_SCHEMA`
  - `dropNamespace` -> `DELETE_SCHEMA`
  - `loadTable`/`tableExists`/`loadView`/`reportMetrics`/`listTables`/`loadCredentials` -> `GET_TABLE`
  - `createTable` -> `CREATE_ICEBERG_TABLE`
  - `dropTable` -> `DELETE_TABLE`
  - (`namespaceExists`, `updateNamespaceProperties`, `dropNamespace`, and `loadCredentials` are newer endpoints on the Iceberg surface, authorized here alongside the rest.)
- Add `GET_CATALOG`, `GET_SCHEMA`, `CREATE_SCHEMA`, `CREATE_SCHEMA_WITH_STORAGE_ROOT`, `UPDATE_SCHEMA`, `DELETE_SCHEMA`, and `CREATE_ICEBERG_TABLE` to `AuthorizeExpressions`, and filter `listNamespaces`/`listTables` per row with `@ResponseAuthorizeFilter`.
- Move existing UC REST inline expressions onto the shared constants (behavior-preserving):
  - `CatalogService` get/list -> `GET_CATALOG` (dropping the private `LIST_AND_GET_AUTH_EXPRESSION`), and the `DeltaApiService` `config` expression likewise.
  - `SchemaService`: `getSchema`/`listSchemas` -> `GET_SCHEMA`, `createSchema` -> `CREATE_SCHEMA_WITH_STORAGE_ROOT`, `updateSchema` -> `UPDATE_SCHEMA`, `deleteSchema` -> `DELETE_SCHEMA`.
- Return raw `TableInfoDAO`s from the `listIcebergTables` page and teach `ResultFilter` to resolve a `TABLE` id from either the DAO or a `TableInfo`, so `listTables` filters per row without re-loading each table.
- Scope the credentials `loadTable`/`loadCredentials` vend in `getLoadCredentialPrivileges` by table `OWNER`/`SELECT`+`MODIFY`, dropping the `principalId == null` short-circuit.
- Leave `updateTable` and `renameTable` on the metastore-owner placeholder; both need the body-derived `AuthorizeValueExtractor` deferred to the next branch:
  - `updateTable`: one endpoint covers a plain commit (`UPDATE_TABLE`) and a staged-create commit (create authorization plus a check that the write location matches a staging table the caller can access), selected by a request-body condition a declarative expression cannot key here.
  - `renameTable`: the source/destination are structured `TableIdentifier`s whose full identity spans the URL `{catalog}` and the body, which a scalar field key cannot compose into a resolvable name.
- Add `SdkIcebergRestCatalogAccessControlTest` (a per-user `IcebergRestClient` plus Iceberg error-assert helpers in `TestUtils`) exercising every authorized endpoint, with metastore-admin-denied cases on the `dropNamespace`/`updateNamespaceProperties` mutations.

Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>

@openinx openinx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@yili-db
yili-db merged commit da911fa into unitycatalog:main Sep 28, 2026
16 checks passed
moomindani added a commit to moomindani/unitycatalog that referenced this pull request Sep 29, 2026
Resolves the conflicts with unitycatalog#1813, which authorizes the Iceberg listings
by filtering them per schema and per table. Both sides now apply: each
page the repository reads is filtered before its entries are answered,
and the token still comes from the last row read, so a page can hold
fewer than pageSize, or none, while more remain. IcebergTablePage takes
unitycatalog#1813's shape (the DAOs, so the filter can resolve each table by id)
with this branch's maxResults. The parent-namespace branch returns
early, so it calls the filter on an empty list: @ResponseAuthorizeFilter
rejects a response that never ran it.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Noritaka Sekiyama <[email protected]>
moomindani added a commit to moomindani/unitycatalog that referenced this pull request Sep 29, 2026
After the merge with unitycatalog#1813 a paged listing filters each page on its
own, so a page can come back empty while its token leads on. Follow the
token one entry per page as a restricted principal and assert the
result is the unpaged filtered listing. Neither side's tests covered the
two together.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Noritaka Sekiyama <[email protected]>
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.

3 participants