Repository navigation
HIVE-29981: compact2 reinforcement - #6884
DanielZhu58 wants to merge 10 commits into
Conversation
1acad66 to
afea1ad
Compare
| throw new MetaException("Cannot determine storage location of " + dbName + "." + tblName | ||
| + "; compaction is not supported for this table or partition"); | ||
| } | ||
| rqst.setRunas(TxnUtils.findUserToRunAs(location, table, conf)); |
There was a problem hiding this comment.
Existing-table cleanup still accepts the caller’s location, so Cleaner may delete a path different from the authorized table.
There was a problem hiding this comment.
Fixed.
For non-privileged callers, a supplied cleanup location must now be inside the authorized table's or partition's location after normalizing. Otherwise it is rejected.
| allowedRoots.add(normalizePath(warehouse, new Path(db.getManagedLocationUri()))); | ||
| } | ||
| allowedRoots.add(normalizePath(warehouse, warehouse.getDatabaseManagedPath(db))); | ||
| boolean allowed = allowedRoots.stream() |
There was a problem hiding this comment.
Database containment isn’t enough. A fake table name can still target another table’s directory right?
There was a problem hiding this comment.
Acknowledged.
Fixed by removing the database-level fallback.
Non-privileged callers can only clean up for an existing table they are authorized on, and the location is constrained to it.
| String catName = parsedDbName[CAT_NAME]; | ||
| String dbName = parsedDbName[DB_NAME]; | ||
| String tblName = rqst.getTablename(); | ||
| rqst.setDbname(dbName); |
There was a problem hiding this comment.
The catalog is removed after authorization, so the queued operation may affect a same-named table in the default catalog. Also, check if you need normalize catName, dbName, and tblName.
There was a problem hiding this comment.
Fixed. The request is now queued with the normalized db and table names from the fetched table.
| authorizeCleanupOfMissingTable(rqst, catName, dbName); | ||
| return; | ||
| } | ||
| firePreEvent(new PreAlterTableEvent(table, table, this)); |
There was a problem hiding this comment.
This authorizes compaction as ADD COLUMNS. Could we use the actual COMPACT operation instead?
There was a problem hiding this comment.
A COMPACT pre-event would also need changes in HiveMetaStoreAuthorizer and the authorization plugins, so it's better as a follow-up.
| } | ||
| @Override | ||
| public CompactionResponse compact2(CompactionRequest rqst) throws TException { | ||
| try { |
There was a problem hiding this comment.
The compact2 is a maintenance API, let's consider:
If a user passes in authorizeProxyPrivilege, then let the request go, otherwise fire the authorization check on the table being requested.
There was a problem hiding this comment.
Acknowedged. Callers with proxy privilege (same rules as authorizeProxyPrivilege) pass through. Everyone else is authorized against the table.
| String tblName = rqst.getTablename(); | ||
| rqst.setDbname(dbName); | ||
|
|
||
| FilterUtils.checkDbAndTableFilters(isServerFilterEnabled, filterHook, catName, dbName, tblName); |
There was a problem hiding this comment.
we don't need to check checkDbAndTableFilters, a PreAlterTableEvent is enough
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
6 open issues
UsingPreAlterTableEvent/PreAlterDatabaseEventto authorize compaction/cleanup is… · New UsingPreAlterTableEvent/PreAlterDatabaseEventto authorize compaction/cleanup is… · New Catching broadExceptionhere will also catchInterruptedExceptionthrown by… · New Catching broadExceptionhere will also catchInterruptedExceptionthrown by… · New TheallowMissingTableboolean introduces a dual-mode code path that’s easy to misuse and harder… · New This test mutates a static global (DummyMetaStoreFilterHookImpl.blockResults). Even with… · New
What changed in this PR
Reinforces metastore server-side authorization for compact2 and submit_for_cleanup, including stricter handling of cleanup requests when the backing table is missing.
Changes:
- Add server-side authorization + run-as derivation for
compact2andsubmit_for_cleanup. - Add validation to restrict cleanup of missing-table locations to be strictly within database roots.
- Extend/adjust metastore server tests to cover new authorization and validation paths.
| File | Description |
|---|---|
| standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHmsServerAuthorization.java | Adds new authorization/validation tests for compact2 and submitForCleanup. |
| standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java | Adjusts test environment setup to avoid filter-hook blocking during compaction enqueue. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/handler/TransactionHandler.java | Implements authorization + location restriction logic for client-initiated compaction/cleanup requests. |
Review effort: Lite
| public boolean submit_for_cleanup(CompactionRequest rqst, long highestWriteId, long txnId) | ||
| throws TException { | ||
| try { | ||
| authorizeAndPrepareCompactionRequest(rqst, true); |
There was a problem hiding this comment.
If the target table/partition has been dropped, is it better to ignore such case? cause we do nothing in Cleaner for this case.
| try { | ||
| authorizeAndPrepareCompactionRequest(rqst); | ||
| } catch (Exception e) { | ||
| rethrowException(e); |
There was a problem hiding this comment.
we don't need to re-throw the exception
There was a problem hiding this comment.
Acknowledged. Removed the try/catch.
| e.getMessage()); | ||
| return false; | ||
| } catch (Exception e) { | ||
| rethrowException(e); |
There was a problem hiding this comment.
we don't need to re-throw the generic exception
| * trusted in embedded mode, when the proxy check is disabled, in test mode, or when the user has host-proxy | ||
| * privileges. | ||
| */ | ||
| protected boolean hasProxyPrivilege() throws TException { |
There was a problem hiding this comment.
This method is similar to authorizeProxyPrivilege, can we reuse this method? upon TException, return false
There was a problem hiding this comment.
Acknowledged. It now calls authorizeProxyPrivilege() and returns false on TException. I also made its error log generic.
| + table.getTableName() + "; compaction is not supported for this table or partition"); | ||
| } | ||
|
|
||
| String requestedLocation = rqst.getProperties() == null ? null : rqst.getProperties().get(META_TABLE_LOCATION); |
There was a problem hiding this comment.
Why do we check the META_TABLE_LOCATION here?
There was a problem hiding this comment.
The Cleaner purges the location property as is, without looking at the table.
Without this check a caller authorized on table A could pass table B's directory and have it purged.
| if (rqst.isSetPartitionname() && rqst.getPartitionname() != null) { | ||
| List<String> partVals = getPartValsFromName(table, rqst.getPartitionname()); | ||
| Partition partition = getMS().getPartition(catName, table.getDbName(), table.getTableName(), partVals); | ||
| location = partition.getSd() == null ? null : partition.getSd().getLocation(); |
There was a problem hiding this comment.
partition.getSd shouldn't be null
There was a problem hiding this comment.
Acknowledge. Removed the null check.
There was a problem hiding this comment.
🟡 Changes recommended
The maintenance APIs permit authorization and request-validation bypasses when notification authentication is disabled or SASL PLAIN callers are evaluated using the HMS service identity.
5 open issues
Prevent notification auth from bypassing maintenance authorization · New Authorize SASL PLAIN clients using the authenticated identity · New Preserve old table state during transactional validation · New Support Iceberg compactions without HMS partition records · New Canonicalize partition names in queued cleanup requests · New
6 resolved since last review
UsingPreAlterTableEvent/PreAlterDatabaseEventto authorize compaction/cleanup is… UsingPreAlterTableEvent/PreAlterDatabaseEventto authorize compaction/cleanup is… This test mutates a static global (DummyMetaStoreFilterHookImpl.blockResults). Even with… TheallowMissingTableboolean introduces a dual-mode code path that’s easy to misuse and harder… Catching broadExceptionhere will also catchInterruptedExceptionthrown by… Catching broadExceptionhere will also catchInterruptedExceptionthrown by…
Review effort: Balanced
|
@DanielZhu58 The 2 failures sound related, could you fix them please? cc @kuczoram @deniskuzZ can you take a look please if have cycles? |
4fcb9a7 to
47a8445
Compare
|





What changes were proposed in this pull request?
Why are the changes needed?
Does this PR introduce any user-facing change?
How was this patch tested?