jerryshao commented on code in PR #13384:
URL: https://github.com/apache/gravitino/pull/13384#discussion_r4534995548


##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -478,11 +479,33 @@ public LoadTableResponse updateTable(
   }
 
   public LoadTableResponse updateTable(IcebergTableChange icebergTableChange) {
+    getMetadataCache().invalidate(icebergTableChange.getTableIdentifier());

Review Comment:
   The cache is invalidated before the transaction commits, so a concurrent 
loadTable can re-cache the old metadata between invalidate and commit, and the 
later loadTable may serve it. Invalidate after commitTransaction (ideally in a 
finally block so a failed commit also drops the entry).



##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java:
##########
@@ -478,11 +479,33 @@ public LoadTableResponse updateTable(
   }
 
   public LoadTableResponse updateTable(IcebergTableChange icebergTableChange) {
+    getMetadataCache().invalidate(icebergTableChange.getTableIdentifier());
     Transaction transaction = icebergTableChange.getTransaction();
     transaction.commitTransaction();
     return loadTable(icebergTableChange.getTableIdentifier());
   }
 
+  /**
+   * Builds an {@link IcebergTableChange} and commits it within a single 
proxied call. When this
+   * wrapper is behind the {@link KerberosAwareIcebergCatalogProxy}, the 
entire operation, including
+   * the metadata.json read triggered by {@code loadTable()} inside the 
builder, runs under the
+   * impersonated user's UGI context.
+   *
+   * <p>The catalog passed to the builder is the same underlying instance 
returned by {@link
+   * #getCatalog()}; it is not itself proxied. The builder must execute inside 
this wrapper method
+   * so that table loading and transaction construction remain within the 
proxy's Kerberos boundary.
+   * Moving the builder call outside this method would bypass impersonation 
even when using the same
+   * catalog.
+   *
+   * @param builder a function that uses the underlying catalog to build an 
{@link
+   *     IcebergTableChange}
+   * @return the response after committing the table change
+   */
+  public LoadTableResponse buildAndUpdateTable(Function<Catalog, 
IcebergTableChange> builder) {
+    IcebergTableChange change = builder.apply(getCatalog());

Review Comment:
   Nothing stops a caller from building changes with getCatalog() outside this 
method and calling updateTable directly, which silently reintroduces the 
non-impersonated read. Consider noting this in the updateTable javadoc or 
restricting its visibility.



##########
catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/IcebergBackend.java:
##########
@@ -115,13 +116,14 @@ private void reload() {
         IcebergCatalogUtil.withGcsServiceAccountCredentials(new 
IcebergConfig(conf));
     try {
       IcebergCatalogWrapper rawWrapper = new 
IcebergCatalogWrapper(icebergConfig);
+      // Initialize the catalog here so configuration errors are reported 
during reload.
+      Catalog catalog = rawWrapper.getCatalog();

Review Comment:
   Calling getCatalog() eagerly on the raw wrapper before the Kerberos check 
means catalog initialization now happens outside the proxy. Was the previous 
behavior the same, and is that initialization safe without impersonation?



-- 
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]

Reply via email to