ggershinsky commented on code in PR #18220:
URL: https://github.com/apache/iceberg/pull/18220#discussion_r4366548869


##########
core/src/main/java/org/apache/iceberg/encryption/EncryptionUtil.java:
##########
@@ -202,6 +211,51 @@ static ByteBuffer encryptManifestListKeyMetadata(
     return ByteBuffer.wrap(encryptedKeyMetadata);
   }
 
+  /**
+   * Produces a base64-encoded hash of the serialized table metadata.
+   *
+   * <p>Catalogs that keep encryption parameters, such as the table key ID, 
outside of the metadata
+   * file can store this hash next to them, in order to detect tampering with 
a metadata file kept
+   * in a storage vulnerable to modification.
+   *
+   * @param metadata table metadata to hash
+   * @return base64-encoded hash of the metadata
+   */
+  public static String metadataHash(TableMetadata metadata) {
+    return Base64.getEncoder().encodeToString(hashOf(metadata));
+  }
+
+  /**
+   * Verifies that the table metadata loaded from storage matches a hash 
produced by {@link
+   * #metadataHash(TableMetadata)} and kept in a trusted catalog.
+   *
+   * @param metadata table metadata loaded from storage
+   * @param expectedMetadataHash base64-encoded hash retrieved from the catalog
+   */
+  public static void verifyMetadataHash(TableMetadata metadata, String 
expectedMetadataHash) {
+    byte[] currentHashBytes = hashOf(metadata);

Review Comment:
   A good point. I thought this had been handled in Hive, 
https://github.com/apache/iceberg/pull/14685#discussion_r2581852336



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to