Skip to content

HIVE-30004: Restrict Iceberg REST catalog table registration and drop-purge to authorized/contained locations - #6812

Open
henrib wants to merge 1 commit into
apache:masterfrom
henrib:HIVE-30004
Open

henrib wants to merge 1 commit into
apache:masterfrom
henrib:HIVE-30004

Conversation

@henrib

@henrib henrib commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reject REGISTER_TABLE requests whose metadata location or embedded table location is not authorized or contained within the namespace.
  • Authorize DROP_TABLE purge against the table's location, and fence purge deletions to the table's own location as defense in depth.

Test plan

  • mvn -pl standalone-metastore/metastore-rest-catalog,iceberg/iceberg-catalog -am test — 885 tests in metastore-rest-catalog (0 failures/errors, 45 skipped Docker-dependent), 142 tests in iceberg-catalog (0 failures/errors, 16 skipped)

🤖 Generated with Claude Code

…-purge to authorized/contained locations

Reject REGISTER_TABLE requests whose metadata location or embedded
table location is not authorized or contained within the namespace.
Authorize DROP_TABLE purge against the table's location, and fence
purge deletions to the table's own location as defense in depth.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 22, 2026 18:18

Copilot AI left a comment

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.

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

Review effort: Lite
Findings: 5 Medium severity

Open (5)
What changed in this PR

This PR tightens authorization around Iceberg REST catalog table registration and drop-table purge operations by validating locations (metadata/table) and adding a defense-in-depth deletion fence so purge cannot remove files outside the table location.

Changes:

  • Add REGISTER_TABLE validation to authorize the metadata location and the embedded table location (or enforce namespace containment when no authorizer exists).
  • Add DROP_TABLE purge authorization against the table’s location in the REST adapter.
  • Fence purge deletions in HiveCatalog.dropTable(..., purge=true) to the table’s own location via a FileIO wrapper.
File Description
standalone-metastore/​metastore-rest-catalog/​src/​main/​java/​org/​apache/​iceberg/​rest/​IcebergAuthorizer.java Adds register-table + drop-purge authorization/containment logic and URI normalization helpers.
standalone-metastore/​metastore-rest-catalog/​src/​main/​java/​org/​apache/​iceberg/​rest/​HMSCatalogAdapter.java Wires new authorization checks into REST endpoints for register-table and drop-table purge.
iceberg/​iceberg-catalog/​src/​main/​java/​org/​apache/​iceberg/​hive/​HiveCatalog.java Wraps purge deletion with a scoped FileIO and exposes catalog FileIO via a new accessor.
iceberg/​iceberg-catalog/​src/​main/​java/​org/​apache/​iceberg/​hive/​ScopedDeleteFileIO.java Introduces a FileIO decorator to skip deletions outside the table’s location.
standalone-metastore/​metastore-rest-catalog/​src/​test/​java/​org/​apache/​iceberg/​rest/​*.java Adds unit/integration tests covering authorization decisions and purge fencing behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return name;
}

public FileIO io() {
Comment on lines +61 to +65
public void deleteFile(String path) {
if (!isContained(location, normalize(path))) {
LOG.warn("Skipping delete outside table location {}: {}", location, path);
return;
}
Comment on lines +84 to +90
private static boolean isContained(String root, String candidate) {
return candidate.equals(root) || candidate.startsWith(root.endsWith("/") ? root : root + "/");
}

private static String normalize(String location) {
return new Path(location).toUri().normalize().toString();
}
Comment on lines +330 to 332
FileIO io = ((HiveCatalog) catalog).io();
icebergAuthorizer.validateRegisterTable(catalogName, namespace, namespaceMetadata, request, io);
return castResponse(LoadTableResponse.class, CatalogHandlers.registerTable(catalog, namespace, request));
Comment on lines +288 to +296
private static String writeMetadataFile(String directory, String tableLocation) throws IOException {
var metadataLocation = directory + "/v1.metadata.json";
Files.deleteIfExists(java.nio.file.Path.of(metadataLocation));
var io = new HadoopFileIO(new Configuration(false));
var metadata = TableMetadata.newTableMetadata(new Schema(), PartitionSpec.unpartitioned(), tableLocation,
Collections.emptyMap());
TableMetadataParser.write(metadata, io.newOutputFile(metadataLocation));
return metadataLocation;
}
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants