Skip to content

[Server] Authorize the Iceberg REST updateTable and renameTable - #1921

Merged
yili-db merged 3 commits into
unitycatalog:mainfrom
yili-db:stack/irc_auth_2
Sep 29, 2026
Merged

yili-db merged 3 commits into
unitycatalog:mainfrom
yili-db:stack/irc_auth_2

Conversation

@yili-db

@yili-db yili-db commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


Extend the authorization decorator to derive authorization inputs from the request body, and use it to authorize the two Iceberg REST commit endpoints that were previously unauthorized.

  • Add a body-derived value mechanism to the decorator:
    • AuthorizeValueExtractor interface, plus @AuthorizeKey/@AuthorizeKeys support, to extract an authorization value from the deserialized request body.
    • AuthorizeKeyLocator resolves those values and UnityAccessDecorator/KeyMapper feed them into the SpEL context before the handler runs.
  • Authorize updateTable:
    • UPDATE_ICEBERG_TABLE branches on #staged_create: a staged create is authorized as CREATE_TABLE, a regular commit as UPDATE_TABLE.
    • Fold CREATE_ICEBERG_TABLE into CREATE_TABLE, so a staged create reuses the create policy.
    • New extractors supply the SpEL inputs:
      • IcebergStagedCreateExtractor supplies #staged_create.
      • IcebergCommitTableTypeExtractor supplies #table_type.
      • IcebergCommitLocationExtractor supplies the staged-create #external_location.
    • Reject a commit that sets the table location more than once with a 400, so the authorized location is unambiguously the one Iceberg applies; a regular commit resolves no location.
  • Authorize renameTable:
    • IcebergRenameSourceSchemaExtractor supplies the source schema.
    • Reject a rename without a source with a 400.
  • Harden managed staging-table commits:
    • StagingTableRepository.requireOwnedStagingTable verifies the caller owns the staging table before a managed commit, closing a confused-deputy gap.

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

@yili-db
yili-db marked this pull request as ready for review September 24, 2026 21:28
@yili-db
yili-db force-pushed the stack/irc_auth_2 branch 2 times, most recently from 481320c to 066840e Compare September 25, 2026 00:35
yili-db added a commit that referenced this pull request Sep 28, 2026
## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/1813/files) to
review incremental changes.
-
[**stack/irc_auth_1**](#1813)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/1813/files)]
← _this PR_
-
[stack/irc_auth_2](#1921)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/1921/files/67897a5a191e754d88663f3962143deb29187926..066840e6a66dd427b32ece9c2ec19925f48e8ebd)]

---------
**PR Checklist**

- [x] 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.
- [x] 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 `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]>

@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.

Left comments.

Comment on lines +598 to +600
@AuthorizeResourceKey(
value = EXTERNAL_LOCATION,
extractor = IcebergCommitLocationExtractor.class)

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.

This binds EXTERNAL_LOCATION on every updateTable, not only on a staged create, and it lets a regular commit be authorized against a table the caller picks.

When the commit carries a set-location under a table the caller controls, KeyMapper resolves that path with getMapResourceIdsForPath and putAlls the owning table's CATALOG/SCHEMA/TABLE ids over the ids resolved from the URL. The UPDATE_TABLE branch of UPDATE_ICEBERG_TABLE has no #no_overlap_with_data_securable guard, so it is evaluated against the caller's own table and passes.

I reproduced it locally. regular-1 has no privilege anywhere in the victim's catalog, but owns its own catalog, schema, and external table. A plain set-properties commit to the victim table is denied with 403 as expected, but this one gets past authorization:

new UpdateTableRequest(
    List.of(new UpdateRequirement.AssertTableUUID(UUID.randomUUID().toString())),
    List.of(
        new MetadataUpdate.SetProperties(Map.of("k", "v")),
        new MetadataUpdate.SetLocation(ownTableLocation + "/x")));

The response is 409 Requirement failed: UUID does not match: expected <victim's table uuid> != ..., so the handler read the victim's metadata and returned it to the caller. Without the requirement, the 400 response prints the victim's persisted storage location. The only thing that stops the write today is MetadataService.validateTableMetadataLocation.

Could we resolve the location only for a staged create, e.g. have IcebergCommitLocationExtractor return null unless IcebergStagedCreateExtractor.isStagedCreate(request)? Please also add this case as a 403 regression test in SdkIcebergRestCatalogAccessControlTest. The root cause, KeyMapper letting path-derived ids overwrite explicitly keyed ones, is worth hardening in a separate PR.

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.

This is indeed a bug. Fixed here. Will prepare a follow up PR for the KeyMapper hardening.

Comment on lines +219 to +223
// External commit: a non-marker location takes the external branch. An unregistered path
// leaves #external_location null, so regular-1 (schema USE_SCHEMA + CREATE_TABLE) passes.
TableMetadata stagedExternal =
stageCreate(r1, SCHEMA, "uc_external_ok", tmpLocation("uc_external_ok"));
r1.updateTable(CAT, SCHEMA, "uc_external_ok", commitCreate(stagedExternal));

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.

Could we add deny coverage for the external staged-create commit? A create commit can register an EXTERNAL table without any staging row, and its set-location doesn't have to match what was staged, so the commit-time #external_location / #no_overlap_with_data_securable check is the real guard on this path. Only the allow case (an unregistered path) is covered today. Two cases that should both be denied:

  1. set-location under a registered external location, where the caller lacks CREATE_EXTERNAL_TABLE on it.
  2. set-location under an existing table's location (overlaps a data securable).

@Override
public Object extract(Object body) {
RenameTableRequest request = (RenameTableRequest) body;
return request.source() == null ? null : request.source().namespace().toString();

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.

Returning null here doesn't leave the key unresolved as the Javadoc says. authorizePayload still puts the null SCHEMA (and the null TABLE from source.name) into resourceKeys, and KeyMapper's containsKey checks then look up <catalog>.null.null.

Verified with auth enabled: POST /v1/catalogs/{catalog}/tables/rename with body {} returns 404 NoSuchNamespaceException: Schema not found: <catalog>.null, while IcebergRestCatalogTest asserts 400 for the same body with auth off. Please fail fast with a 400 when source is missing, fix the Javadoc, and add an auth-enabled {} case.

@yili-db
yili-db requested a review from openinx September 28, 2026 08:18
@yili-db

yili-db commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

@openinx PTAL. Thanks!

}

/** The location of the request's last {@code set-location} update, or null when there is none. */
static String lastSetLocation(UpdateTableRequest request) {

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.

[AI-assisted]

can we test multiple set-location updates and verify the last one is authorized? thats the location the commit actually applies.

if extraction ever selects a different update than Iceberg applies, authorization checks one location while metadata is written to another.

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.

I thought about this and decided to go one step further: enforce that at most one location can be set in one updateTable request.
The risk here is about authorizing one location, while the endpoint handler reads another. And they are handled by different code: this extractor v.s. Iceberg MetadataUpdate.applyTo.
Although the IRC spec allows more than one set-location in one request, it is never useful and no client does that. Enforcing that only one set-location is set makes it simpler and safer and easier.

- Add a body-derived authorization-key mechanism for values a field lookup cannot express:
  - `AuthorizeValueExtractor`, set via `extractor` on `@AuthorizeKey` / `@AuthorizeResourceKey`, computes the value from the bound request body.
  - `skipWhen` on `@AuthorizeResourceKey` drops a resource key on request shapes it does not apply to.
- Authorize `updateTable` via `UPDATE_ICEBERG_TABLE` (`#staged_create ? CREATE_TABLE : UPDATE_TABLE`), sharing `IcebergStagedCreateExtractor.isStagedCreate` with the handler dispatch.
- Authorize `renameTable` via `RENAME_TABLE` (drop the source, create in the destination schema).
- Fold `CREATE_ICEBERG_TABLE` into `CREATE_TABLE`; `#table_type` now comes from the Iceberg `*TableTypeExtractor`.
- Add `StagingTableRepository.requireOwnedStagingTable` pre-check so a managed staged create verifies staging-table ownership before writing metadata (confused-deputy guard).
- Add extractor unit tests and Iceberg REST access-control tests.

Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
@yili-db
yili-db merged commit 758cda4 into unitycatalog:main Sep 29, 2026
16 checks passed
moomindani added a commit to moomindani/unitycatalog that referenced this pull request Sep 30, 2026
Resolves an import-only conflict with unitycatalog#1921 in
SdkIcebergRestCatalogAccessControlTest: keep both sides' imports.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Noritaka Sekiyama <[email protected]>
yili-db added a commit that referenced this pull request Nov 3, 2026
)

**PR Checklist**

- [x] 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.
- [x] 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**

Follow-up to [the
comment](#1921 (comment))
on Iceberg REST authorization work: a keyed resource id must win over
one derived from a caller-supplied location path.

- `KeyMapper` merges the ids resolved from an `EXTERNAL_LOCATION` path
with `putIfAbsent` instead of `putAll`:
- the caller controls the body's location, so its owning-entity ids may
add a key the request did not resolve, but never replace an explicitly
keyed `CATALOG`/`SCHEMA`/`TABLE`, which names the resource the request
acts on.
- Defense in depth, not the sole guard: the create policies still reject
a mismatched location via `#no_overlap_with_data_securable` (external)
and the staging-ownership check (managed).

Signed-off-by: Yi Li <[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