Skip to content

fix(encryption): reject encryption.key-id on pre-v3 tables - #3659

Merged
CTTY merged 14 commits into
apache:mainfrom
xanderbailey:xb/reject-pre-v3-encryption-manager
Nov 11, 2026
Merged

CTTY merged 14 commits into
apache:mainfrom
xanderbailey:xb/reject-pre-v3-encryption-manager

Conversation

@xanderbailey

@xanderbailey xanderbailey commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

What changes are included in this PR?

Encryption is v3-only, so TableMetadataBuilder::build now 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

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 {}: {}",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@xanderbailey

Copy link
Copy Markdown
Contributor Author

@kevinjqliu we discussed this in the python PR and I'm updating rust here to match

@kevinjqliu kevinjqliu 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.

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

Copy link
Copy Markdown
Contributor

btw i played around with the solution, heres something that seems acceptable. main...kevinjqliu:iceberg-rust:kevinjqliu-pr-3659-review

lmk what you think!

kevinjqliu and others added 11 commits November 9, 2026 16:39
…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]>
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]>
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]>
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]>
@mbutrovich

mbutrovich commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

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 FileScanTasks and might use a custom encryption solution for pre-v3 tables, right?

@xanderbailey

Copy link
Copy Markdown
Contributor Author

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

@xanderbailey

Copy link
Copy Markdown
Contributor Author

From Claude, not verified by my:

Right, no impact. Comet builds FileScanTasks straight from the JVM-planned protobuf and reads them with ArrowReader. It never constructs TableMetadata natively, and this check only runs in TableMetadataBuilder::build. Deserializing existing metadata doesn't go through the builder either, and the reader decrypts from key_metadata whatever the format version. (A custom non-standard key_metadata format on pre-v3 wouldn't decode in iceberg-rust's reader today anyway, so this PR doesn't change that.)

@mbutrovich

Copy link
Copy Markdown
Collaborator

That was my interpretation at a quick glance as well. Thanks for the sanity check!

@CTTY CTTY left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@CTTY
CTTY added this pull request to the merge queue Nov 11, 2026
Merged via the queue into apache:main with commit ebf2d6e Nov 11, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commits to v1/v2 tables with encryption.key-id write plaintext files

4 participants