Repository navigation
feat: add RegisterTable overwrite support (cherry-pick of #3719) - #4506
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for overwrite=true on the Iceberg REST register table flow for internal (Polaris-managed) catalogs, including new RBAC operation semantics, documentation, and test coverage for overwrite behaviors.
Changes:
- Implement
registerTable(..., overwrite=true)behavior in the internalIcebergCatalogand route REST requests throughIcebergCatalogHandler. - Introduce
REGISTER_TABLE_OVERWRITEauthorization operation mapped toTABLE_FULL_METADATA. - Add/extend unit + integration tests and update federation/user documentation plus
CHANGELOG.md.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| site/content/in-dev/unreleased/federation/iceberg-rest-federation.md | Documents that overwrite registration is internal-only and rejected for federated catalogs. |
| runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogTest.java | Adds catalog-level overwrite behavior tests (update existing, create when missing, reject when overwrite=false). |
| runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogHandlerAuthzTest.java | Adds authz tests for overwrite=true privilege requirements. |
| runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java | Adds overwrite routing/authorization and rejects overwrite for federated catalogs. |
| runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java | Implements overwrite-aware registerTable behavior for internal catalogs. |
| polaris-core/src/main/java/org/apache/polaris/core/auth/RbacOperationSemantics.java | Registers RBAC semantics for the new REGISTER_TABLE_OVERWRITE operation. |
| polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizableOperation.java | Adds the new authorizable operation enum value. |
| integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisRestCatalogIntegrationBase.java | Adds REST integration coverage for overwrite=true register behavior. |
| CHANGELOG.md | Adds changelog entries describing overwrite support and authorization mapping. |
| authorizeCreateTableLikeUnderNamespaceOperationOrThrow( | ||
| PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE, identifier); |
There was a problem hiding this comment.
I think this is a very valid concern.
I will do the suggested changes, let me know what you think.
There was a problem hiding this comment.
I believe the same problem exists for normal "create" vs. "update" table. I think we do not have to alter RBAC in this PR (as long as locations are validated), but it's worth a follow-up discussion.
There was a problem hiding this comment.
By "alter" I mean existing call paths. The Copilot suggestion above SGTM.
There was a problem hiding this comment.
OK but should I alter the RBAC logic for the register-table-overwrite operation, or are you suggesting to keep the current logic then revisit all the impacted logics later?
There was a problem hiding this comment.
Yes, I think REGISTER_TABLE_OVERWRITE should be applied to the table (entity) and REGISTER_TABLE to the namespace -- in this PR 🙂
What I meant for the follow-up discussion is extending "create" / "register" checks to cover the entity too. I believe OPA is capable of that.
@sungwy : FYI.
There was a problem hiding this comment.
@dimas-b OK I implemented your suggestion, PTAL.
| register(CREATE_TABLE_STAGED, TABLE_CREATE); | ||
| register(CREATE_TABLE_STAGED_WITH_WRITE_DELEGATION, EnumSet.of(TABLE_CREATE, TABLE_WRITE_DATA)); | ||
| register(REGISTER_TABLE, TABLE_CREATE); | ||
| register(REGISTER_TABLE_OVERWRITE, TABLE_FULL_METADATA); | ||
| register(LOAD_TABLE, TABLE_READ_PROPERTIES); |
95f678b to
401a92d
Compare
dimas-b
left a comment
There was a problem hiding this comment.
Sorry for coming late to this review parting and expanding scope... but WDYT?
| throw new NoSuchTableException("Table does not exist: %s", identifier); | ||
| } | ||
|
|
||
| validateLocationForTableLike(identifier, metadataFileLocation, resolvedPath); |
There was a problem hiding this comment.
Should do this in registerNewTable() too?
| resolvedEntityView.getPassthroughResolvedPath( | ||
| ResolvedPathKey.ofTableLike(identifier), PolarisEntitySubType.ANY_SUBTYPE); | ||
| if (resolvedPath == null || resolvedPath.getRawLeafEntity() == null) { | ||
| throw new NoSuchTableException("Table does not exist: %s", identifier); |
There was a problem hiding this comment.
Should we do this check on line 330 instead?
There was a problem hiding this comment.
On line 330 we call tableExists already. Here, we need the resolved path instance. It should normally never be null (since we know already that the table exists), but I think the original author introduced this check in case the entity is dropped between the check on line 330 and this line.
There was a problem hiding this comment.
Yeah, exactly. The double load looks odd in this context. However, I do not feel strongly about this.
| Set.of(PolarisStorageActions.READ, PolarisStorageActions.LIST)); | ||
|
|
||
| TableMetadata metadata = TableMetadataParser.read(fileIO, metadataFileLocation); | ||
| validateMetadataFileInTableDir(identifier, metadata); |
There was a problem hiding this comment.
Should we check this in registerNewTable() too?
| RBAC_SEMANTICS_BY_OPERATION.put( | ||
| PolarisAuthorizableOperation.REGISTER_TABLE, | ||
| new RangerPolarisOperationSemantics(toSet(TABLE_CREATE), null, ResolvedPathRooting.ROOT)); | ||
| RBAC_SEMANTICS_BY_OPERATION.put( |
There was a problem hiding this comment.
FYI this PR now has ramifications into the Ranger authorizer. I did the best I could. There is no simple way to map a super-privilege like TABLE_FULL_METADATA into Ranger logic. And oddly enough, some test files already mentioned a privilege named "table-metadata-full".
There was a problem hiding this comment.
@adutra do you see this being a spec mapping issue? if so, I feel we should list out the mapping (your effort) in our docs, to set up a good contract.
There was a problem hiding this comment.
This change looks reasonable to me. Any known reasons to delay merging it?
If Ranger integration is affected we can fix-forward on main.
| IcebergTableLikeEntity updatedEntity = | ||
| new IcebergTableLikeEntity.Builder(existingEntity) | ||
| .setInternalProperties(storedProperties) | ||
| .setMetadataLocation(metadataFileLocation) |
There was a problem hiding this comment.
The overwrite path updates metadata-location and internal properties but doesn't call .setBaseLocation(metadata.location()) . So if the new metadata points at a different table location, the entity's stored base drifts. The normal commit path (line ~1612) does update it. Overlap checks and credential-vending scope depend on this being current.
There was a problem hiding this comment.
Good catch, probably an oversight. cc @sririshindra
There was a problem hiding this comment.
.setBaseLocation(metadata.location()) does not look correct to me. The base location is normally the parent of both "data" and "metadata" sub-directories... right?
There was a problem hiding this comment.
If metadata.location() is outside the old base location, that will (should?) fail the location checks, right?
There was a problem hiding this comment.
.setBaseLocation(metadata.location())does not look correct to me. The base location is normally the parent of both "data" and "metadata" sub-directories... right?
AFAIK metadata.location() returns the table base location. The metadata file location is returned by metadata.metadataFileLocation().
| RBAC_SEMANTICS_BY_OPERATION.put( | ||
| PolarisAuthorizableOperation.REGISTER_TABLE, | ||
| new RangerPolarisOperationSemantics(toSet(TABLE_CREATE), null, ResolvedPathRooting.ROOT)); | ||
| RBAC_SEMANTICS_BY_OPERATION.put( |
There was a problem hiding this comment.
@adutra do you see this being a spec mapping issue? if so, I feel we should list out the mapping (your effort) in our docs, to set up a good contract.
442a1c8 to
da28087
Compare
| } | ||
|
|
||
| String locationDir = metadataFileLocation.substring(0, lastSlashIndex); | ||
| if (tableExists) { |
There was a problem hiding this comment.
FYI, we had a test explicitly testing that if overwrite is true but the table doesn't exist, the register operation should behave as if overwrite is false.
977213c to
c4176f6
Compare
646da8c to
2707936
Compare
| // For non-Polaris/federated catalogs, reject overwrite until this is | ||
| // supported by a common catalog contract. | ||
| CatalogEntity catalogEntity = getResolvedCatalogEntity(); | ||
| if (catalogEntity.isExternal()) { |
There was a problem hiding this comment.
FYI this logic didn't exist in the original PR, but one test fails without it, so I added it.
This is because the test baseCatalog instanceof IcebergCatalog is NOT a reliable test to know if a catalog is external: indeed, a static facade external catalog would pass that test.
flyingImer
left a comment
There was a problem hiding this comment.
Overall LGTM, just minor callouts see inlines
| String.format("Failed to fetch resolved parent for TableIdentifier '%s'", identifier)); | ||
| } | ||
|
|
||
| validateLocationForTableLike(identifier, metadataFileLocation, resolvedParent); |
There was a problem hiding this comment.
This validation is new for the normal register path too, not only for overwrite=true. I think the hardening makes sense, but it can reject register calls that previously succeeded when the metadata file was outside the resolved storage scope/table location. I believe we should mention that behavior change in the changelog and PR description?
There was a problem hiding this comment.
IMHO this doesn't deserve a changelog.
| resolutionManifest.resolveAll(); | ||
|
|
||
| PolarisResolvedPathWrapper tableTarget = | ||
| resolutionManifest.getResolvedPath( |
There was a problem hiding this comment.
FYI, my claude pointed out a ux nit:
if this identifier is occupied by a view, this falls through to the namespace REGISTER_TABLE path and the later create path reports the conflict. That is probably fine authz-wise, but the error may be less clear than "a view already exists at this identifier"
The ux callout makes sense to me, but I haven't dived too deep into how to remediate it
There was a problem hiding this comment.
Fair enough, I introduced a view conflict detection logic, PTAL.
apache#4506) --------- Co-authored-by: Rishi <[email protected]>
apache#4506) --------- Co-authored-by: Rishi <[email protected]>
This is a cherry-pick of #3719.
Although the logic has been reviewed and confirmed, the patch didn't apply cleanly; therefore, a brief follow-up review is recommended.UPDATE
Reviews by Copilot uncovered a few serious issues, notably with the Ranger authorizer. Therefore the PR is now significantly different from #3719. A full review is advised.
Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)