Repository navigation
[Server] Authorize the Iceberg REST updateTable and renameTable - #1921
Conversation
481320c to
066840e
Compare
## 🥞 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]>
066840e to
4a20c89
Compare
| @AuthorizeResourceKey( | ||
| value = EXTERNAL_LOCATION, | ||
| extractor = IcebergCommitLocationExtractor.class) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is indeed a bug. Fixed here. Will prepare a follow up PR for the KeyMapper hardening.
| // 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)); |
There was a problem hiding this comment.
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:
set-locationunder a registered external location, where the caller lacksCREATE_EXTERNAL_TABLEon it.set-locationunder 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(); |
There was a problem hiding this comment.
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.
|
@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) { |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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]>
Signed-off-by: Yi Li <[email protected]>
fcec075 to
feadf8a
Compare
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]>
) **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]>
🥞 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.
AuthorizeValueExtractorinterface, plus@AuthorizeKey/@AuthorizeKeyssupport, to extract an authorization value from the deserialized request body.AuthorizeKeyLocatorresolves those values andUnityAccessDecorator/KeyMapperfeed them into the SpEL context before the handler runs.updateTable:UPDATE_ICEBERG_TABLEbranches on#staged_create: a staged create is authorized asCREATE_TABLE, a regular commit asUPDATE_TABLE.CREATE_ICEBERG_TABLEintoCREATE_TABLE, so a staged create reuses the create policy.IcebergStagedCreateExtractorsupplies#staged_create.IcebergCommitTableTypeExtractorsupplies#table_type.IcebergCommitLocationExtractorsupplies the staged-create#external_location.renameTable:IcebergRenameSourceSchemaExtractorsupplies the source schema.StagingTableRepository.requireOwnedStagingTableverifies the caller owns the staging table before a managed commit, closing a confused-deputy gap.PR Checklist
docsis updatedDescription of changes