Repository navigation
fix(encryption): reject encryption.key-id on pre-v3 tables - #3659
Conversation
EncryptionManager::from_table_metadata returned Ok(None) for v1/v2 tables before reading encryption.key-id, so commits to such tables silently wrote plaintext manifest lists and manifests. Return DataInvalid instead, matching iceberg-python.
|
|
||
| if metadata.format_version() < FormatVersion::V3 { | ||
| return Err(invalid_data!( | ||
| "Invalid properties for {}: {}", |
There was a problem hiding this comment.
This matches iceberg-python's EncryptionManager.from_table_metadata exactly, and uses the same wording as Java's EncryptionUtil.checkCompatibility (Java prints the property set, so it reads Invalid properties for v2: [encryption.key-id]).
|
@kevinjqliu we discussed this in the python PR and I'm updating rust here to match |
kevinjqliu
left a comment
There was a problem hiding this comment.
i think the fix should be deeper in the core code and not in crates/iceberg/src/encryption/manager.rs.
we would want to guard encryption.key-id on pre-v3 tables as invalid metadata. so perhaps in the table metadata validate code.
WYDT?
Reject encryption.key-id and encryption.data-key-length when creating a table or setting properties below v3, before anything is persisted. Pre-v3 tables that already carry them still load, so they can be repaired by removing the properties or upgrading to v3, and snapshot production on them fails before any manifest is written. Co-authored-by: Copilot App <[email protected]>
|
btw i played around with the solution, heres something that seems acceptable. main...kevinjqliu:iceberg-rust:kevinjqliu-pr-3659-review lmk what you think! |
…eation Match Java, which runs EncryptionUtil.checkCompatibility only when creating new table metadata: check in TableMetadataBuilder::new and leave property updates, loading, and snapshot writes unchanged. Co-authored-by: Copilot App <[email protected]>
Only TableMetadataBuilder::new uses it, so check inline like the reserved-property check instead of adding a TableProperties method. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Test v1, v2, and v3 with each encryption property and both together in TableMetadataBuilder, where the check lives, instead of through the memory catalog. Co-authored-by: Copilot App <[email protected]>
Check in TableMetadataBuilder::set_properties so both table creation and property updates reject encryption.key-id and encryption.data-key-length below v3, as iceberg-python does. Only the properties being set are checked, so existing pre-v3 tables that already carry them can still be loaded and updated. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Run check_properties_format_compatibility in TableMetadataBuilder::build against the final properties and format version, so every metadata mutation is checked rather than only set_properties. A pre-v3 table that already has encryption properties must remove them or upgrade to v3 in its next commit; loading it is unaffected. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
v1 and v2 metadata do not serialize encryption-keys, so a key added below v3 was silently dropped on write. Check it in check_format_compatibility so every metadata build rejects it. Co-authored-by: Copilot App <[email protected]>
Merge the property and encryption-key tests into one table-driven test, and keep only the unrelated-update and removal cases for pre-v3 tables that already have encryption.key-id. Co-authored-by: Copilot App <[email protected]>
|
I took a quick look, and I think the answer is no, but just in case: this doesn't affect solutions like Comet that ship across |
|
Very nice @kevinjqliu , I've taken what you had whole-sale actually and touched up the tests. This is a better place for it to live and I think it matches python and java clients better. @mbutrovich let me set claude off, I'm actually not too sure of how comet works for these scans |
|
From Claude, not verified by my:
|
|
That was my interpretation at a quick glance as well. Thanks for the sanity check! |
Which issue does this PR close?
What changes are included in this PR?
Encryption is v3-only, so
TableMetadataBuilder::buildnow rejects encryption properties and keys on v1/v2 metadata, matching Java.Are these changes tested?
Yes, unit tests.
AI Disclosure
Written with Claude Code.
🤖 Generated with Claude Code