markhoerth opened a new pull request, #14595:
URL: https://github.com/apache/gravitino/pull/14595
### What changes were proposed in this pull request?
Four commits, readable one at a time:
1. **Service account connection** (`iceberg-common`, `iceberg-rest-server`,
`catalog-lakehouse-iceberg`). New catalog properties: `rest-backend-auth-type`
(`user-token` by default, or `service-account`), `rest-backend-token`,
`rest-backend-credential`, `rest-backend-oauth2-server-uri` and
`rest-backend-scope`.
- In service-account mode,
`IcebergCatalogUtil.applyRestBackendAuthProperties` passes exactly one of the
token or the client credential to Iceberg's OAuth2 auth manager, instead of
installing `UserPrincipalForwardingAuthManager`.
- Token and credential are hidden catalog properties.
- The Gravitino API catalog and the Iceberg REST server both build the
backend through this code, so both connect as the service account.
- `IcebergCatalogWrapper.remoteCatalogAuthorizesUsers()` replaces
`isRESTCatalog()` in
`IcebergMetadataAuthorizationMethodInterceptor.shouldSkipAuthorization`. A
service-account catalog is therefore always authorized locally, whatever
`disable-rest-authz` is set to.
- `IcebergCatalogWrapperManager` refuses to serve a service-account
catalog when authorization is disabled.
2. **Gravitino-issued storage credentials** (`iceberg-rest-server`). New
property `rest-backend-credential-vending` (`remote` by default, or
`gravitino`). A service-account catalog always uses `gravitino`, because the
remote vends credentials for the service account rather than for the caller. In
`gravitino` mode, `FederatedCatalogWrapper`:
- never sends `X-Iceberg-Access-Delegation` to the remote;
- drops remote `storage-credentials` and credential keys from load and
scan responses;
- issues credentials through
`CatalogWrapperForREST.injectCredentialConfig` and `injectScanCredentials` for
load, create, register, credential refresh and scan planning.
Privilege follows `IcebergTableOperationExecutor.getCredentialPrivilege`:
READ unless the caller holds MODIFY_TABLE. Create and register get WRITE, as
for local catalogs.
3. **Grants follow the table, not the name** (`api`, `core`,
`catalog-lakehouse-iceberg`, `iceberg-rest-server`). New reserved table
property `Table.PROPERTY_TABLE_UUID` (`table-uuid`), which the Iceberg catalog
reports from table metadata. It is honored only in catalogs that declare it
reserved.
- `TableOperationDispatcher` records it on import and create, keeps it on
alter and rename, and backfills it on registrations made before this change.
- When a load finds a different identifier under the same name, it
deletes the stale registration (with its grants, tags, owner and statistics)
under the schema write lock and imports the new table.
- On the Iceberg REST server, `IcebergTableHookDispatcher` makes the same
check for load, credentials and scan planning. On a mismatch it replaces the
registration, authorizes the caller again against the new registration, and
reloads, so neither access nor credential scope follows the old table.
- A rename keeps the UUID.
4. **Purges go to the remote** (`iceberg-common`, `iceberg-rest-server`).
`IcebergCatalogWrapper.purgeTable` forwards a purge on a REST catalog backend
to the remote with `purgeRequested`, on both the Iceberg REST and Gravitino API
paths. Before, it dropped the remote entry and then deleted the files from
Gravitino, and an `X-Gravitino-Async-Purge` request queued a local cleanup job
to do the same. A REST catalog backend never takes the async path now.
### Why are the changes needed?
To federate remote Iceberg REST catalogs that cannot authorize Gravitino's
users, with Gravitino as the single place access is granted, without handing
clients the remote catalog's broad storage keys, without grants leaking to a
table recreated under an old name, and without Gravitino deleting files the
remote catalog owns.
Fix: #14594
### Does this PR introduce _any_ user-facing change?
- New Iceberg catalog / Iceberg REST service properties:
`rest-backend-auth-type`, `rest-backend-token`, `rest-backend-credential`,
`rest-backend-oauth2-server-uri`, `rest-backend-scope`,
`rest-backend-credential-vending`. Defaults keep today's behavior.
- New reserved Iceberg table property `table-uuid`, reported on load and
rejected on create and alter.
- Docs: `iceberg-rest-service.md` (REST backend section) and
`lakehouse-iceberg-catalog.md`.
### How was this patch tested?
Unit tests:
- `TestIcebergCatalogUtil`: auth modes, the exactly-one-credential check, an
invalid mode.
- `TestIcebergMetadataAuthorizationMethodInterceptor`: a service-account
catalog is not skipped.
- `TestCatalogWrapperForREST`: gravitino mode, and service-account mode with
default vending, send no delegation header, drop remote credentials and return
provider-issued credentials.
- `TestIcebergTableHookDispatcher`: a replaced registration is reconciled; a
registration without a UUID is left alone.
- `TestIcebergCatalogWrapper`: a purge on a REST catalog is forwarded with
`purgeRequested` and loads nothing locally.
- `TestIcebergAsyncPurge`: an async purge request on a REST catalog is
forwarded inline and queues no job.
- `TestTableOperationDispatcher`: the registration survives a reload, a
replaced table gets a new registration, a missing UUID is backfilled, plus
`isReplacedExternally` cases.
End to end, against a live Cloudflare R2 Data Catalog federated with a
service account connection and an R2 temporary-credential provider: a user
granted SELECT_TABLE on one table received a credential that could list that
table's location and nothing else, and could not write; a user with write
privileges could write only inside the table's location; creating a table
without CREATE_TABLE and loading as a non-member both returned 403.
### Known limitations, left for follow-up
- **Multi-node edge case.** The stale-registration check reads the table
entity through the entity cache. In a multi-node deployment, a node with a
stale cache entry could, in a narrow window, drop a registration another node
has just replaced. Deleting conditioned on the entity version would close it.
- **Token fetch per call.** With an OAuth2 client credential (not a static
token), each remote call through `callRemoteCatalog` fetches a fresh token. A
per-wrapper auth session cache would remove that.
- **Copied properties now rejected.** `table-uuid` is reserved, so flows
that copy a loaded table's properties into a create, such as `CREATE TABLE
LIKE`, must drop it. `sort-order` already behaves this way.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Eu6fb6yGcAF4XcGDTmKE56
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]