Skip to content

Commit d7f8950

Browse files
authored
Exception on encryption key altering (apache#14723)
* initial commit * illegal args exception
1 parent 4c0ad42 commit d7f8950

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,14 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
321321
}
322322

323323
if (removedProps.contains(TableProperties.ENCRYPTION_TABLE_KEY)) {
324-
throw new RuntimeException("Cannot remove key in encrypted table");
324+
throw new IllegalArgumentException("Cannot remove key in encrypted table");
325+
}
326+
327+
if (base != null
328+
&& !Objects.equals(
329+
base.properties().get(TableProperties.ENCRYPTION_TABLE_KEY),
330+
metadata.properties().get(TableProperties.ENCRYPTION_TABLE_KEY))) {
331+
throw new IllegalArgumentException("Cannot modify key in encrypted table");
325332
}
326333

327334
HMSTablePropertyHelper.updateHmsTableForIcebergTable(

spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestTableEncryption.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ public void testKeyDelete() {
169169
.hasMessageContaining("Cannot remove key in encrypted table");
170170
}
171171

172+
@TestTemplate
173+
public void testKeyAlter() {
174+
assertThatThrownBy(
175+
() -> sql("ALTER TABLE %s SET TBLPROPERTIES ('encryption.key-id'='abcd')", tableName))
176+
.hasMessageContaining("Cannot modify key in encrypted table");
177+
}
178+
172179
@TestTemplate
173180
public void testDirectDataFileRead() {
174181
List<Object[]> dataFileTable =

0 commit comments

Comments
 (0)