From d8b10d120b5fc231f90a0e8b8eaaf55b0f43602a Mon Sep 17 00:00:00 2001 From: shangxinli Date: Thu, 8 Oct 2026 21:09:17 +0900 Subject: [PATCH 1/9] feat: add EncryptionManager and StandardEncryptionManager - EncryptionManager (core): per-table interface to generate key metadata, open AES GCM Stream files for reading and writing, and encrypt and decrypt manifest list key metadata. - EncryptionManagerRegistry (core): creates the manager of an encrypted table from the trusted table key ID, the table's encryption-keys and the catalog's KMS client. The bundle registers the implementation, so the core library has no crypto dependency. - StandardEncryptionManager (bundle): Java's envelope encryption. Key encryption keys are wrapped by the table master key in the KMS, timestamped, used for 730 days and then rotated; manifest list key metadata is encrypted by a KEK with the KEK timestamp as AAD. Unwrapped KEKs are cached for one hour. Thread-safe. - encryption::RegisterAll() / IsEncryptionAvailable() in the bundle; a no-op when built with ICEBERG_ENCRYPTION=OFF. Adds the Java-written encrypted table fixture under test/resources/encryption/table. Tests decrypt the manifest list key metadata of every Java snapshot and check that its file length is the stored size of the manifest list. --- src/iceberg/CMakeLists.txt | 10 +- src/iceberg/encryption/encryption_manager.cc | 72 +++++ src/iceberg/encryption/encryption_manager.h | 120 ++++++++ src/iceberg/encryption/encryption_register.cc | 36 +++ src/iceberg/encryption/encryption_register.h | 36 +++ .../encryption/standard_encryption_manager.cc | 268 ++++++++++++++++++ .../encryption/standard_encryption_manager.h | 113 ++++++++ src/iceberg/test/CMakeLists.txt | 6 +- ...b-c6f6-4ce2-a242-a0745cf50318-00001.puffin | Bin 0 -> 463 bytes .../encryption/table/data/data-0.parquet | Bin 0 -> 1791 bytes .../encryption/table/data/data-1.parquet | Bin 0 -> 1793 bytes .../encryption/table/data/data-2.avro | Bin 0 -> 445 bytes ...2964d7-9cf9-4547-a01b-29e4eef4bc25-m0.avro | Bin 0 -> 7889 bytes ...1c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro | Bin 0 -> 7886 bytes ...f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro | Bin 0 -> 7844 bytes ...977369-b04a-4cf3-a491-6090bc1572fc-m0.avro | Bin 0 -> 7909 bytes ...-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro | Bin 0 -> 4940 bytes ...-95f19655-198b-4c2a-a7e5-e3cf75d5ab54.avro | Bin 0 -> 5045 bytes ...-d1977369-b04a-4cf3-a491-6090bc1572fc.avro | Bin 0 -> 5145 bytes ...-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro | Bin 0 -> 4825 bytes .../table/metadata/v1.metadata.json | 1 + .../table/metadata/v2.metadata.json | 1 + .../table/metadata/v3.metadata.json | 1 + .../table/metadata/v4.metadata.json | 1 + .../table/metadata/v5.metadata.json | 1 + .../table/metadata/version-hint.text | 1 + .../test/standard_encryption_manager_test.cc | 224 +++++++++++++++ 27 files changed, 889 insertions(+), 2 deletions(-) create mode 100644 src/iceberg/encryption/encryption_manager.cc create mode 100644 src/iceberg/encryption/encryption_manager.h create mode 100644 src/iceberg/encryption/encryption_register.cc create mode 100644 src/iceberg/encryption/encryption_register.h create mode 100644 src/iceberg/encryption/standard_encryption_manager.cc create mode 100644 src/iceberg/encryption/standard_encryption_manager.h create mode 100644 src/iceberg/test/resources/encryption/table/data/00001-1-86fba0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin create mode 100644 src/iceberg/test/resources/encryption/table/data/data-0.parquet create mode 100644 src/iceberg/test/resources/encryption/table/data/data-1.parquet create mode 100644 src/iceberg/test/resources/encryption/table/data/data-2.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/462964d7-9cf9-4547-a01b-29e4eef4bc25-m0.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/d1977369-b04a-4cf3-a491-6090bc1572fc-m0.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/snap-5112456484007752895-1-95f19655-198b-4c2a-a7e5-e3cf75d5ab54.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/snap-5555854819025587960-1-d1977369-b04a-4cf3-a491-6090bc1572fc.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro create mode 100644 src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json create mode 100644 src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json create mode 100644 src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json create mode 100644 src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json create mode 100644 src/iceberg/test/resources/encryption/table/metadata/v5.metadata.json create mode 100644 src/iceberg/test/resources/encryption/table/metadata/version-hint.text create mode 100644 src/iceberg/test/standard_encryption_manager_test.cc diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt index 71c7a40186..1321a82a9a 100644 --- a/src/iceberg/CMakeLists.txt +++ b/src/iceberg/CMakeLists.txt @@ -33,6 +33,7 @@ set(ICEBERG_SOURCES deletes/position_delete_index.cc deletes/position_delete_range_consumer.cc deletes/roaring_position_bitmap.cc + encryption/encryption_manager.cc encryption/key_management_client.cc encryption/standard_key_metadata.cc expression/aggregate.cc @@ -337,6 +338,7 @@ if(ICEBERG_BUILD_BUNDLE) avro/avro_register.cc avro/avro_schema_util.cc avro/avro_stream_internal.cc + encryption/encryption_register.cc parquet/parquet_bloom_row_group_filter.cc parquet/parquet_data_util.cc parquet/parquet_dictionary_row_group_filter.cc @@ -354,7 +356,8 @@ if(ICEBERG_BUILD_BUNDLE) ICEBERG_BUNDLE_SOURCES encryption/aes_gcm.cc encryption/aes_gcm_stream.cc - encryption/in_memory_kms.cc) + encryption/in_memory_kms.cc + encryption/standard_encryption_manager.cc) endif() # Libraries to link with exported libiceberg_bundle.{so,a}. @@ -429,6 +432,11 @@ if(ICEBERG_BUILD_BUNDLE) foreach(target iceberg_bundle_static iceberg_bundle_shared) if(TARGET ${target}) + if(ICEBERG_ENCRYPTION) + target_compile_definitions(${target} PRIVATE ICEBERG_ENCRYPTION_ENABLED=1) + else() + target_compile_definitions(${target} PRIVATE ICEBERG_ENCRYPTION_ENABLED=0) + endif() if(ICEBERG_S3) target_compile_definitions(${target} PUBLIC "$") diff --git a/src/iceberg/encryption/encryption_manager.cc b/src/iceberg/encryption/encryption_manager.cc new file mode 100644 index 0000000000..a49d86d1fc --- /dev/null +++ b/src/iceberg/encryption/encryption_manager.cc @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/encryption_manager.h" + +#include + +#include "iceberg/util/macros.h" + +namespace iceberg { + +namespace { + +struct RegistryState { + std::mutex mutex; + EncryptionManagerRegistry::Factory factory; +}; + +RegistryState& State() { + static RegistryState state; + return state; +} + +} // namespace + +void EncryptionManagerRegistry::Register(Factory factory) { + auto& state = State(); + std::lock_guard lock(state.mutex); + state.factory = std::move(factory); +} + +Result> EncryptionManagerRegistry::Make( + Options options) { + ICEBERG_PRECHECK(!options.table_key_id.empty(), "Invalid encryption key ID: empty"); + ICEBERG_PRECHECK(options.data_key_length == 16 || options.data_key_length == 24 || + options.data_key_length == 32, + "Invalid data key length: {} (must be 16, 24, or 32)", + options.data_key_length); + ICEBERG_PRECHECK(options.kms != nullptr, + "Cannot create an encryption manager without a KMS client; set the " + "encryption.kms-type or encryption.kms-impl catalog property"); + Factory factory; + { + auto& state = State(); + std::lock_guard lock(state.mutex); + factory = state.factory; + } + if (!factory) { + return NotSupported( + "Table encryption is not available: link iceberg_bundle built with " + "ICEBERG_ENCRYPTION=ON and call iceberg::encryption::RegisterAll()"); + } + return factory(std::move(options)); +} + +} // namespace iceberg diff --git a/src/iceberg/encryption/encryption_manager.h b/src/iceberg/encryption/encryption_manager.h new file mode 100644 index 0000000000..83ccaa99d3 --- /dev/null +++ b/src/iceberg/encryption/encryption_manager.h @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/encryption_manager.h +/// Table encryption manager interface and the registry that creates one. + +#include +#include +#include +#include +#include +#include +#include + +#include "iceberg/encryption/encrypted_key.h" +#include "iceberg/encryption/key_management_client.h" +#include "iceberg/encryption/standard_key_metadata.h" +#include "iceberg/file_io.h" +#include "iceberg/iceberg_export.h" +#include "iceberg/result.h" + +namespace iceberg { + +/// \brief Keys created when the key metadata of a new manifest list is registered. +/// +/// Both must be added to the table metadata `encryption-keys` in the same commit as +/// the snapshot whose `key-id` is `file_key.key_id`. +struct ICEBERG_EXPORT ManifestListEncryptionKeys { + /// The key encryption key, wrapped by the table master key in the KMS. + EncryptedKey key_encryption_key; + /// The manifest list key metadata, encrypted by the key encryption key. + EncryptedKey file_key; +}; + +/// \brief Encrypts and decrypts the files of one table. +/// +/// The standard implementation (StandardEncryptionManager) needs a crypto provider +/// and lives in the bundle library; the core library reaches it through +/// EncryptionManagerRegistry. +class ICEBERG_EXPORT EncryptionManager { + public: + virtual ~EncryptionManager() = default; + + /// \brief Generate key metadata (random data key and AAD prefix) for a new file. + virtual Result NewKeyMetadata() = 0; + + /// \brief Wrap an AES GCM Stream (AGS1) file in a decrypting InputFile. + /// + /// \param encrypted the encrypted file + /// \param key_metadata serialized key metadata, including the file length + virtual Result> NewDecryptingInputFile( + std::unique_ptr encrypted, std::span key_metadata) = 0; + + /// \brief Wrap a file in an AES GCM Stream (AGS1) encrypting OutputFile. + virtual Result> NewEncryptingOutputFile( + std::unique_ptr plain, const StandardKeyMetadata& key_metadata) = 0; + + /// \brief Decrypt the key metadata of a manifest list. + /// + /// \param manifest_list_key_id the snapshot `key-id` + /// \return the serialized StandardKeyMetadata of the manifest list file + virtual Result> DecryptManifestListKeyMetadata( + std::string_view manifest_list_key_id) = 0; + + /// \brief Encrypt the key metadata of a new manifest list with a key encryption key. + /// + /// Creates a key encryption key (wrapped by the table master key) if there is no + /// unexpired one. + virtual Result RegisterManifestListKeyMetadata( + const StandardKeyMetadata& key_metadata) = 0; +}; + +/// \brief Creates the encryption manager of encrypted tables. +/// +/// The bundle library registers the standard implementation (see +/// iceberg::encryption::RegisterAll()). Without it, encrypted tables cannot be read or +/// written. +class ICEBERG_EXPORT EncryptionManagerRegistry { + public: + struct Options { + /// The table master key ID in the KMS (table property `encryption.key-id`), taken + /// from a trusted source. + std::string table_key_id; + /// Length of generated data keys: 16, 24 or 32 bytes. + int32_t data_key_length = 16; + /// The table metadata `encryption-keys`. + std::vector encryption_keys; + /// The catalog's KMS client. + std::shared_ptr kms; + }; + + using Factory = + std::function>(Options options)>; + + /// \brief Register the encryption manager implementation. + static void Register(Factory factory); + + /// \brief Create an encryption manager. + static Result> Make(Options options); +}; + +} // namespace iceberg diff --git a/src/iceberg/encryption/encryption_register.cc b/src/iceberg/encryption/encryption_register.cc new file mode 100644 index 0000000000..3df7383c2b --- /dev/null +++ b/src/iceberg/encryption/encryption_register.cc @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/encryption_register.h" + +#if ICEBERG_ENCRYPTION_ENABLED +# include "iceberg/encryption/standard_encryption_manager.h" +#endif + +namespace iceberg::encryption { + +void RegisterAll() { +#if ICEBERG_ENCRYPTION_ENABLED + RegisterStandardEncryptionManager(); +#endif +} + +bool IsEncryptionAvailable() { return ICEBERG_ENCRYPTION_ENABLED; } + +} // namespace iceberg::encryption diff --git a/src/iceberg/encryption/encryption_register.h b/src/iceberg/encryption/encryption_register.h new file mode 100644 index 0000000000..beacad013e --- /dev/null +++ b/src/iceberg/encryption/encryption_register.h @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/encryption_register.h +/// Registration of the table encryption implementation of the bundle library. + +#include "iceberg/iceberg_bundle_export.h" + +namespace iceberg::encryption { + +/// \brief Register the standard encryption manager, if the bundle was built with +/// ICEBERG_ENCRYPTION=ON. Otherwise a no-op, and encrypted tables are not supported. +ICEBERG_BUNDLE_EXPORT void RegisterAll(); + +/// \brief Whether the bundle was built with table encryption support. +ICEBERG_BUNDLE_EXPORT bool IsEncryptionAvailable(); + +} // namespace iceberg::encryption diff --git a/src/iceberg/encryption/standard_encryption_manager.cc b/src/iceberg/encryption/standard_encryption_manager.cc new file mode 100644 index 0000000000..40e3fb673a --- /dev/null +++ b/src/iceberg/encryption/standard_encryption_manager.cc @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/standard_encryption_manager.h" + +#include +#include +#include + +#include "iceberg/encryption/aes_gcm_internal.h" +#include "iceberg/encryption/aes_gcm_stream.h" +#include "iceberg/util/base64.h" +#include "iceberg/util/macros.h" + +namespace iceberg { + +namespace { + +using encryption::AesGcmCipher; +using encryption::SecureRandomBytes; + +std::span AsBytes(std::string_view s) { + return {reinterpret_cast(s.data()), s.size()}; +} + +std::string ToString(std::span bytes) { + return {reinterpret_cast(bytes.data()), bytes.size()}; +} + +Result GenerateKeyId() { + std::array id{}; + ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(id)); + return Base64::Encode(ToString(id)); +} + +std::optional ParseTimestamp(const EncryptedKey& key) { + auto it = key.properties.find(std::string(StandardEncryptionManager::kKeyTimestamp)); + if (it == key.properties.end()) { + return std::nullopt; + } + int64_t value = 0; + const auto& str = it->second; + auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), value); + if (ec != std::errc{} || ptr != str.data() + str.size()) { + return std::nullopt; + } + return value; +} + +} // namespace + +Result> StandardEncryptionManager::Make( + EncryptionManagerRegistry::Options options) { + ICEBERG_PRECHECK(!options.table_key_id.empty(), "Invalid encryption key ID: empty"); + ICEBERG_PRECHECK(options.data_key_length == 16 || options.data_key_length == 24 || + options.data_key_length == 32, + "Invalid data key length: {} (must be 16, 24, or 32)", + options.data_key_length); + ICEBERG_PRECHECK(options.kms != nullptr, "Invalid KMS client: null"); + return std::shared_ptr( + new StandardEncryptionManager(std::move(options))); +} + +StandardEncryptionManager::StandardEncryptionManager( + EncryptionManagerRegistry::Options options) + : table_key_id_(std::move(options.table_key_id)), + data_key_length_(options.data_key_length), + kms_(std::move(options.kms)) { + for (auto& key : options.encryption_keys) { + AddKey(std::move(key)); + } +} + +void StandardEncryptionManager::AddKey(EncryptedKey key) { + auto key_id = key.key_id; + if (keys_.insert_or_assign(key_id, std::move(key)).second) { + key_order_.push_back(std::move(key_id)); + } +} + +void StandardEncryptionManager::SetTestTimeShift(std::chrono::milliseconds shift) { + std::lock_guard lock(mutex_); + time_shift_ = shift; +} + +int64_t StandardEncryptionManager::NowMs() const { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch() + time_shift_) + .count(); +} + +Result StandardEncryptionManager::NewKeyMetadata() { + StandardKeyMetadata metadata; + metadata.encryption_key.resize(data_key_length_); + ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(metadata.encryption_key)); + metadata.aad_prefix.emplace(kAadPrefixLength); + ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(*metadata.aad_prefix)); + return metadata; +} + +Result> StandardEncryptionManager::NewDecryptingInputFile( + std::unique_ptr encrypted, std::span key_metadata) { + ICEBERG_PRECHECK(encrypted != nullptr, "Encrypted input file cannot be null"); + ICEBERG_ASSIGN_OR_RAISE(auto metadata, StandardKeyMetadata::Parse(key_metadata)); + if (!metadata.file_length.has_value()) { + // The length must come from trusted key metadata, not from the file system, so that + // truncation is detected (format/gcm-stream-spec.md, "File length"). + return Invalid("Cannot read AES GCM stream {}: key metadata has no file length", + encrypted->location()); + } + return std::make_unique( + std::move(encrypted), std::move(metadata.encryption_key), + metadata.aad_prefix.value_or(std::vector{}), *metadata.file_length); +} + +Result> StandardEncryptionManager::NewEncryptingOutputFile( + std::unique_ptr plain, const StandardKeyMetadata& key_metadata) { + ICEBERG_PRECHECK(plain != nullptr, "Output file cannot be null"); + return std::make_unique( + std::move(plain), key_metadata.encryption_key, + key_metadata.aad_prefix.value_or(std::vector{})); +} + +Result> StandardEncryptionManager::UnwrapKek( + const std::string& kek_id) { + int64_t now = NowMs(); + if (auto it = unwrapped_keks_.find(kek_id); it != unwrapped_keks_.end()) { + if (now - it->second.unwrapped_at_ms < kUnwrappedKekCacheExpiry.count()) { + return it->second.key; + } + unwrapped_keks_.erase(it); + } + auto it = keys_.find(kek_id); + if (it == keys_.end()) { + return Invalid("Cannot find key encryption key with id {}", kek_id); + } + ICEBERG_ASSIGN_OR_RAISE( + auto kek, + kms_->UnwrapKey(AsBytes(it->second.encrypted_key_metadata), table_key_id_)); + unwrapped_keks_.insert_or_assign(kek_id, CachedKek{kek, now}); + return kek; +} + +Result> StandardEncryptionManager::DecryptManifestListKeyMetadata( + std::string_view manifest_list_key_id) { + std::lock_guard lock(mutex_); + auto it = keys_.find(std::string(manifest_list_key_id)); + if (it == keys_.end()) { + return Invalid("Cannot find manifest list key metadata with id {}", + manifest_list_key_id); + } + const EncryptedKey& manifest_list_key = it->second; + if (!manifest_list_key.encrypted_by_id.has_value() || + *manifest_list_key.encrypted_by_id == table_key_id_) { + return Invalid("{} is not manifest list key metadata", manifest_list_key_id); + } + + const std::string& kek_id = *manifest_list_key.encrypted_by_id; + ICEBERG_ASSIGN_OR_RAISE(auto kek, UnwrapKek(kek_id)); + auto timestamp = keys_.at(kek_id).properties.find(std::string(kKeyTimestamp)); + if (timestamp == keys_.at(kek_id).properties.end()) { + return Invalid("Key encryption key {} must be timestamped", kek_id); + } + + // The KEK timestamp is the AAD, to prevent timestamp tampering attacks. + ICEBERG_ASSIGN_OR_RAISE(auto cipher, AesGcmCipher::Make(kek)); + return cipher->Decrypt(AsBytes(manifest_list_key.encrypted_key_metadata), + AsBytes(timestamp->second)); +} + +Result StandardEncryptionManager::CurrentKekId() { + int64_t now = NowMs(); + for (const auto& key_id : key_order_) { + const EncryptedKey& key = keys_.at(key_id); + if (key.encrypted_by_id != table_key_id_) { + continue; + } + auto timestamp = ParseTimestamp(key); + if (timestamp.has_value() && now - *timestamp < kKekLifespan.count()) { + return key_id; + } + } + + // No unexpired key encryption key: create one, wrapped by the table master key. + std::vector kek(data_key_length_); + ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(kek)); + ICEBERG_ASSIGN_OR_RAISE(auto wrapped, kms_->WrapKey(kek, table_key_id_)); + ICEBERG_ASSIGN_OR_RAISE(auto kek_id, GenerateKeyId()); + AddKey(EncryptedKey{.key_id = kek_id, + .encrypted_key_metadata = ToString(wrapped), + .encrypted_by_id = table_key_id_, + .properties = {{std::string(kKeyTimestamp), std::to_string(now)}}}); + unwrapped_keks_.insert_or_assign(kek_id, CachedKek{std::move(kek), now}); + return kek_id; +} + +Result +StandardEncryptionManager::RegisterManifestListKeyMetadata( + const StandardKeyMetadata& key_metadata) { + ICEBERG_PRECHECK(key_metadata.file_length.has_value(), + "Manifest list key metadata must include the file length"); + std::lock_guard lock(mutex_); + ICEBERG_ASSIGN_OR_RAISE(auto kek_id, CurrentKekId()); + ICEBERG_ASSIGN_OR_RAISE(auto kek, UnwrapKek(kek_id)); + const EncryptedKey& kek_entry = keys_.at(kek_id); + const std::string& timestamp = kek_entry.properties.at(std::string(kKeyTimestamp)); + + ICEBERG_ASSIGN_OR_RAISE(auto cipher, AesGcmCipher::Make(kek)); + ICEBERG_ASSIGN_OR_RAISE(auto encrypted, + cipher->Encrypt(key_metadata.Serialize(), AsBytes(timestamp))); + ICEBERG_ASSIGN_OR_RAISE(auto file_key_id, GenerateKeyId()); + EncryptedKey file_key{.key_id = file_key_id, + .encrypted_key_metadata = ToString(encrypted), + .encrypted_by_id = kek_id}; + AddKey(file_key); + return ManifestListEncryptionKeys{.key_encryption_key = keys_.at(kek_id), + .file_key = std::move(file_key)}; +} + +std::vector StandardEncryptionManager::encryption_keys() const { + std::lock_guard lock(mutex_); + std::vector result; + result.reserve(key_order_.size()); + for (const auto& key_id : key_order_) { + result.push_back(keys_.at(key_id)); + } + return result; +} + +namespace encryption { + +void RegisterStandardEncryptionManager() { + EncryptionManagerRegistry::Register([](EncryptionManagerRegistry::Options options) + -> Result> { + ICEBERG_ASSIGN_OR_RAISE(auto manager, + StandardEncryptionManager::Make(std::move(options))); + return manager; + }); +} + +namespace { + +[[maybe_unused]] const bool kStandardEncryptionManagerRegistered = []() { + RegisterStandardEncryptionManager(); + return true; +}(); + +} // namespace + +} // namespace encryption + +} // namespace iceberg diff --git a/src/iceberg/encryption/standard_encryption_manager.h b/src/iceberg/encryption/standard_encryption_manager.h new file mode 100644 index 0000000000..19a242dec1 --- /dev/null +++ b/src/iceberg/encryption/standard_encryption_manager.h @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/standard_encryption_manager.h +/// Envelope encryption manager, compatible with Java's StandardEncryptionManager. + +#include +#include +#include +#include +#include +#include + +#include "iceberg/encryption/encryption_manager.h" +#include "iceberg/iceberg_bundle_export.h" + +namespace iceberg { + +/// \brief Standard Iceberg envelope encryption. +/// +/// Key hierarchy: +/// - table master key: in the KMS, ID in table property `encryption.key-id`; +/// - key encryption keys (KEK): wrapped by the KMS and kept in `encryption-keys` +/// with `encrypted-by-id` = the table key ID and a KEY_TIMESTAMP property. A KEK is +/// used for 730 days (NIST SP 800-57), then a new one is created; +/// - manifest list key metadata: AES-GCM encrypted by a KEK with the KEK timestamp as +/// AAD, kept in `encryption-keys` and referenced by the snapshot `key-id`; +/// - manifest key metadata: in the manifest list `key_metadata` field; +/// - data and delete file key metadata: in the manifest `key_metadata` field. +/// +/// Unwrapped KEKs are cached for one hour. Thread-safe. +class ICEBERG_BUNDLE_EXPORT StandardEncryptionManager : public EncryptionManager { + public: + static constexpr std::string_view kKeyTimestamp = "KEY_TIMESTAMP"; + static constexpr int32_t kAadPrefixLength = 16; + static constexpr std::chrono::milliseconds kKekLifespan{730LL * 24 * 3600 * 1000}; + static constexpr std::chrono::milliseconds kUnwrappedKekCacheExpiry{3600LL * 1000}; + + static Result> Make( + EncryptionManagerRegistry::Options options); + + Result NewKeyMetadata() override; + Result> NewDecryptingInputFile( + std::unique_ptr encrypted, + std::span key_metadata) override; + Result> NewEncryptingOutputFile( + std::unique_ptr plain, + const StandardKeyMetadata& key_metadata) override; + Result> DecryptManifestListKeyMetadata( + std::string_view manifest_list_key_id) override; + Result RegisterManifestListKeyMetadata( + const StandardKeyMetadata& key_metadata) override; + + /// \brief All keys: those from table metadata and those created by this manager. + std::vector encryption_keys() const; + + const std::string& table_key_id() const { return table_key_id_; } + + /// \brief Shift the clock, for tests of KEK rotation and cache expiry. + void SetTestTimeShift(std::chrono::milliseconds shift); + + private: + struct CachedKek { + std::vector key; + int64_t unwrapped_at_ms; + }; + + explicit StandardEncryptionManager(EncryptionManagerRegistry::Options options); + + // The following require mutex_ to be held. + Result> UnwrapKek(const std::string& kek_id); + Result CurrentKekId(); + void AddKey(EncryptedKey key); + + int64_t NowMs() const; + + const std::string table_key_id_; + const int32_t data_key_length_; + const std::shared_ptr kms_; + + mutable std::mutex mutex_; + std::chrono::milliseconds time_shift_{0}; + std::vector key_order_; + std::unordered_map keys_; + std::unordered_map unwrapped_keks_; +}; + +namespace encryption { + +/// \brief Register StandardEncryptionManager in EncryptionManagerRegistry. +ICEBERG_BUNDLE_EXPORT void RegisterStandardEncryptionManager(); + +} // namespace encryption + +} // namespace iceberg diff --git a/src/iceberg/test/CMakeLists.txt b/src/iceberg/test/CMakeLists.txt index c69ad54c7d..0a6262d80a 100644 --- a/src/iceberg/test/CMakeLists.txt +++ b/src/iceberg/test/CMakeLists.txt @@ -276,7 +276,11 @@ if(ICEBERG_BUILD_BUNDLE) endif() if(ICEBERG_ENCRYPTION) - add_iceberg_test(crypto_test USE_BUNDLE SOURCES aes_gcm_test.cc) + add_iceberg_test(crypto_test + USE_BUNDLE + SOURCES + aes_gcm_test.cc + standard_encryption_manager_test.cc) endif() add_iceberg_test(scan_test diff --git a/src/iceberg/test/resources/encryption/table/data/00001-1-86fba0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin b/src/iceberg/test/resources/encryption/table/data/00001-1-86fba0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin new file mode 100644 index 0000000000000000000000000000000000000000..9f6665dbf6080d289bb5ac84419b8f17322de177 GIT binary patch literal 463 zcmV;=0WkhSM^iBX01yDI1CcWPktfIHesiQ*`AgAe-Twzi{~KPyO?3H%+-kM>4Y`g+KE-B7FtRvqLIDPQXO5ac!u<1^N2p;k};eWo(GuXBPK zoa%fLKtZt9&ipKrbvh-i>ezOqpm7+QY{jeBp&E3!$vfM_kx+XhQHoC=_%9Iun(uR& zE3ZcPnA=)8HjcH;%c1AJ#+Y5;(x(^6BM4(;ZI<3o4tuJ2g^=8^rW57vyGPRXkTh2{ zu;EGHO^5|6pJfXY=<{>rD8j>eG>T$YuGaoX9!=JLlA7hxlf$)2|Hsx4co)q|db+O# z`scIah&7J}Gp4^wX-2ulNn{t*sBEO-D4?Em5|-M2y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P##jkryT0$rr1aBzSmB?`#S^PF_$@0o_F^n44`DxR z_>cT=td@WwO6DgeSo}2KCrr;vHx1iSLFqaZJKijRcl-a!;<3TJSJB$;yh-vzZsfE@ zhgKs(GEW&po6m&hB1X2>SG7DQGu+t8)!JMu&+Vlg$q7CUon)ZVDque{d&;ROV2$r z@hxZWTE&2?l7TvCFq*ZOushV9?h`YbGOkVqBt&L>1>=@@F3JP1rtEd+3gD8N^|uv^ zcFxM1z@X9msN{1D`f-x`)GJ2jXySa&u(}=Bh1p=3Jk>6uME{qVUhz^_jI5NjTTWon z^vj2YEXa`~8@ixO%20wROlJNNdbb-#feV7sOz_(h$BQ5KidI3 zjuHE5TzN3#l`#?%tZ9C=J{{G8OPgBZ$+lGiD(}J;pWhg#hBO@{gMh}ipj@rd=-DS} h(m#z35LpGotqtY06Xk}KkH8glrT0(+002-yQbqK`evkkF literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/data/data-1.parquet b/src/iceberg/test/resources/encryption/table/data/data-1.parquet new file mode 100644 index 0000000000000000000000000000000000000000..e94835ef5559c071a8e10d9f023d8fe469fb5011 GIT binary patch literal 1793 zcmV+c2mbg_K~hD400007x=cddBLG!>u0aLprMTc!$xo1Hy(CqrRIFV%YhI%V_j0NV z*re7_K@@3!HxM}yauOKK@In${U+L0002T{+D}X%fm)z zkODYP5WX~z(>M;wuW`}_s=Dx~*7)I53vjwxX-KYbnk8jX+J8fa>pGxvlJxTLxhE|< z9)JJ<0RJSs?D4L+LVuiEHqAmbrem`GwKYWBl>UTUr+I_b~+GGpJ{F7=?_ zkwPO3U2XvlMFxC@zZ0aFS-gCZ{M;7Cgh}Z}$VUJG0K4}+ekLXUUrB>Ols zfB*mh81hXt*QMiS)C-F=LSNx%q0c%1mMChy#cb;kUaXHTbia6Pn7&pM)Q&EOYS09l!Pzj2FdHeFRv~Re9g8c)OGPvlMh{}6si-r6 z(XCGQ#-Y5+4LGhtbPmd>+G=cj;Kab z-MBS+xeVqR^1{1w)e`EwFzEZbUl=iu-6Qf10r4yVlz|O#*;f}ji$f9k^@3je3{|Ag zmb%M1&0><%^s}J9?`du-%oqUHnXa!&a+|53>L`14JX!5B;CH?jNMc>%s!Y5XB5UvIbw1 z{>i=__gsKLW~Ps{Y>CaI02$g1VI<*$gee~m;G|=urJvKT94HgERaFMEWLF_=34?%K zi}k|Cra}fmG>DxY#&}iIWB?QW$=9HFl`&(21c;1K04+FZbwZuKd(oB>ZwuYr?zoF4 zadPOU-4sh_rGk`z++%?K%XH}A*IHoUs=S#E4r@r3?&Tk}3pqXDT5ex?kDU9D z=eW?;oW;I1oqk86=7uOT!4PmiyM>e$=G|mpeOvfMwp7T!0(ZiPYljZW z#-1%LapLh%LJUk!1rmfsuTCV!BZ+wRFh6fU#EJ3`?q~-XB(|hRF`!5$wdz#}%du3D? znPb5$Wm6xV_eSzigjDj*u@=B?`2#XOmYGvWP-6S-*&>z3(sIQV6ynflCv=)4%PXc{ z)@cw9W!vtoDN`UPJMkADgl=OYom6Nva}rfSCgc7Ehk!HsbUQU)>Rz2&UW#L0lC+_T zjrVRaR2d;3hOUp#MHfLrf%$%%D5e%gM4~t9b-6~DgVoP?(GY{6K{v&P$L;8HTJ6m& jRpM5mWE7y*>Xfbi(4(}fSG?yh_s)c9Py+w}P(e~f0##m@ literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/data/data-2.avro b/src/iceberg/test/resources/encryption/table/data/data-2.avro new file mode 100644 index 0000000000000000000000000000000000000000..554247456662cd3dc484d06fcecfb7d3e9394940 GIT binary patch literal 445 zcmV;u0Yd&kM^iBX01yD#K-H7-iNDB-9?05xiKX)0V&%d)--EYlbK9-rU`lxOkcx_7 z;aEf5G}6GKOZFBp>V&)ClQIY`+wt0JkHrB+gsqsmVr>@@h4@N$Ik&R87xg(^i{L;mrf#wGlr{jj<$v@Xc zJRqE@Fe18RV*R~$o3^t)fUL! zq(`#^nDJII1{ln!>Gzr4)*r5>|v_BrHgh*rI zzT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FtAtv^tAQ-uv{VkEUX;+ORB?i5Uu7cTs31)ah0y vUP{dSFJ5rzftJWxFFT)d#v}8dp7UYIVT0iRp+*r-a*M^WU|=)l9ReH}7S=;2 literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/metadata/511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro b/src/iceberg/test/resources/encryption/table/metadata/511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro new file mode 100644 index 0000000000000000000000000000000000000000..8be2d3aab9b18f040f36eb167342e4219093ebfa GIT binary patch literal 7886 zcmV;<9x>rTM^iBX01yEDnH_KjpF&5brVBOxK3St^3qK%;PurG)|vLUWV{~XNv=Uog6D>A-A@g z!$PyzO2bOKsARD9WWrbS2OizEn8I^iK$8D|__6Yi33-xJpq|i3MeE=oI=JL_D#FcsOutJ_p!I*3Ka^HPhlj5$sn_D4)O z``(O$W4yqOkeLk{Yr^vaeCFHABh*Qth9B3d!y!kX$XTG(MAai`u_}T1e1$CZ0%uW2 zUZ=!-<41Ms1+twTA$G(k+Siq7eY_u8$_$CUZ>tcEAR$;MXLIy2iglO?KBQ%=jL)-l zc{L4UrJgcCJ=NT9t*c8Ls<(y|s5KAoB-aWgjL?H5uO9-l*~xMFB0dLcwpeT(WDw(2 z!gV~P-@RkTbriKMc1g9!s$C4;uByapyXs(4JtqcY7s>6)o*RS6i*%huMCHj)!lrT_ z;KSoX`0p+=a25QH7jKOnov0Q=Pw`n1atsV4YGuHxofzf+@p*5IKt;-^!1C?_EhnQ9 zPN+Qo4_R9g=6Rg;m*-H*6>b!MqL*8W7w50rV_-rs_e0g;46kBbdf>BC5wD#}i=^}z zmb;6(DgD3mam`CWM*IZ7=MaYg7&Uvd*lvr_% zZs_{%e`|u=7u&v%&N5LiPqt*V>IkWN1N7`hhua(ic^a}?+XOE36qEd!U1ZY1`_;>Q zPpb7jI+rB_Q9-*`^UY0p%{;zGDP{6p3@!yJ+q7w(lU*^ zyrO4k%+%p0>D}p5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8Xh)q)lf|k34;O>7#~-+7iioM$i6NOJFJU zNLl|l9ZZ*JC;!D%Q|1R-c?!qZ`rhQo!7xnMHC4&S*`UEJj2oS}jaYbq01rEzAt;v2 z2RCmY=R79ye_x;MlM@$+aR-EN0u%LSr?7iopX8<7@Aa>8IV34J z*=o4h6=hcZa+Hru%Z>N{H&fBA z^KczaK>11vS5o;ElKV^>)N~_a=2EM=gf?1&#ENC^Rwx z({fvu`?SX!^PxLGB5-fk(g1U{C?{Y{Zlf1AnptwfMs#0*M{^FCQ#x z8C?MZ>fV^+;)ATiM&gCBO2zNB*o$m#rbm~q$lyLkhRm3VMLV5%0C_V}PZURfUU2b< zi~oPZoQ@~4m;bvK4r2(^;57qe1`hJ9$TLNbRFh$4C3gePOi?<`{ZLqe0k*mN%|F1g zLyNR_yNf^CP;7lgOdJId1bFk&{_yR<&hQ3-5JMM|uY~35y7k+?&}BTl&;iN4DXo2J zm_1Hoahe4fO>V9u1OatmQlM_`L#9gRY^Z!XL6`Rz67K^=aEO>vdVv1oAXDXW1}C$D z7NR(!*Kn5i(k0JLpLL$^jYa^spCW*_suGI&!=o{vJWB=$99TUqy!KbUVpEQW_~n4>J>q(|*bdcHtk?W)Iv^*T!L=)kBtZ;o stM5|P5=o7*zvDl?Fcmzii#9^9QmaOj~}-T(jq literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/metadata/95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro b/src/iceberg/test/resources/encryption/table/metadata/95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro new file mode 100644 index 0000000000000000000000000000000000000000..7e81d8faf6e76bd8553c21af3322269a50900f7a GIT binary patch literal 7844 zcmV;V9$Vo-M^iBX01yBWKv1mh=wCmt%sTHW#!@2K4aR;B$aI47-Q4RyOgDDCWHleb zyjve2_Fx7EO)>Qmv_is!i3jQPM*kv~hysMxO37njrJ-?v90o&YzK< z+oKFq_Vsk=;zZX-@eSvz@R3)`gF#q+glacRO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z^dpCXUJeUoHi^Ea)&86KI=t9nrE%h6gn=Q3#U1;9$g;XkCJK^|(&qZ;5ER=PGjpfa zHXr=1I`94ghpr8!v{=>V$mrxglWP)J`DZ9?uY|xV=V(vH25YrbNVdjja-oSqM6`6% zn{Vd?peY)s7$H+=pmhtl%H5`n$g?Qx%KDwtVtN6Vl|t%o!W@^)ous8~Ln?6gTgu^? z@exJy%?diFEt?o7F`I^y&pr?gYTYvD+Q|9J$}cH@+<0Ms+8QWxrRf_2WZ^7Au!iW^ z4&8;LUnj`;@X5&hIBgxJCTp}{j`kt|RZb-0&D5s43SH`olyvp% z(p^Yo8Rf)12>?Wc4VR@{o=QD%M^F@466bmMY6cd?{64bBW6FsG8VMvXrh#o>`FBny zI0<{XJx{4cngA)z!LOv6|5i04Utp7Qk0- zT`a3_Wol2fWb<}R>Inm^qT}b$e&;4l;&{#pE~adHOP+PH6HHOB3P@B;HEcn-!U>Q| z8fN(d#G#jLRlSq&QW#!PX;wji=;nW~L)oHj@811>c`?l)G>4fs{mrur@HbP9Jr-53 zS!Uk8iX3!y&wUUAcC1941{-LkjCKMx~@PIcE6AGO4$1ex$rvzYbD)Q@6X+ z!A#b@X9b=Kff`SQU+#3l3))|9a8GyFB3uAoqAwsOk?_SecOX6Mh*cHq6$6RI9LUAA z1sRO(tmPHgMKEXw4uO3yzx*eS>U}$J|zg literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro b/src/iceberg/test/resources/encryption/table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro new file mode 100644 index 0000000000000000000000000000000000000000..c45ab3ca34cc64d506e857a50b5673efcd9c4343 GIT binary patch literal 4940 zcmV-S6SM3=M^iBX01yCs@X$9^U>TLTcl}m@IC|s5kFZ29cQ@QPHH|9$Re<$GqWZpI zG^(l(xoYBmeLzr~Os0-|v1!i2c<5MNKKfjGaNH_W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Y=-4;LY1_{)I literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/metadata/snap-5555854819025587960-1-d1977369-b04a-4cf3-a491-6090bc1572fc.avro b/src/iceberg/test/resources/encryption/table/metadata/snap-5555854819025587960-1-d1977369-b04a-4cf3-a491-6090bc1572fc.avro new file mode 100644 index 0000000000000000000000000000000000000000..eb6658a6f4acee9d1545225b70cdbaa84586815c GIT binary patch literal 5145 zcmV+!6z1zeM^iBX01yCwPxRffZb(aBXt(gx3u-P|*U66jGzhe%y9W!~o1iV{MhmPhIDbz=5`C5`wguutQo^BuDmwepUFutm&BlLmaT*rT z*ANs`L*>vTCLh+#PF&3HiIeR~Gh%{r4OR9hUPF}6C-vP^-}0oW_+2&5b<^D|{(NJ~ zqcwzz+sJq8?J>obxlb`&T)PFPj0zO;LsUAfL>W#9R)bMXS;S;^V}mnS^JxW~6xfgs z84XuryX>&L)h)PX1k)T5LCh=t7lkS zd#Oeriqg5u-~-*h;F|fZz1+zKU=WN1X(Be-gF!9QGPvP`+*T@Y6s#P&4=c)>;Qu*W zUG{a$Z?Jf^8_B10w`QS58>n_J>cxR_)|}@|!d2#9k+JHwerm`KK{U>N^|FWh_`)!yDM0E~^N6*zgT$?<4IEv+KWG~dS|s9IwMhgkKthy8g;T;r znm$F`whMY+Uw4EDi)|Fk-ja~brjOY-45IdtvX zLVsov78GLb$OmOl0NDi{jph_ZgwOIuF%9wf zyS!--PmeTKzB9eg3WtY7dUBg?L<;E-FE1h0zTcUW6H&g`RK*bR*NdNL0sy~LgC++5 zJ~PsU*3cm?{m|F~4h%9*mDocoBx|ZP1fhNY5jUG9)=MxCAJ|ae;$L#R=WPYd3aU7?fj!$_5zV9X)mY4E!*D zu6U^p)q=oS=6t55MYynO8&EU1)`gRU#}0Ma8SeX&;Gl{uHj>V@0^x&XhApohh1A%T z0>4iDvQUcP^f6sPlP%6%cg?k`Xo>0)2F#vt?}TczerjAD$>#Fzrkb$4bWL$hTL* zYZe|4zgies?AX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z!62hX_kar?o`#=@@c?xAvQe^q86@xNR;z>4r4?NiE{TcA99xxs4qqiJGxGbxniZ<; zy=}XQs~WEkR*vWEUqIjJUiD~(p2v6wa=o*;LM9#EGdrCz~*C@o_1+NiiS54#7+iW#epiT3b5n{NnKlLWiW3DW7 zplBXPa#5aoD<}k2I(s|~6IZAkbQ^x9)6rIE3cGRB&lIDO`+er!Y?8KsC1&AtC}aPK zP=U1k5;CSJG+l15DR-&_0GNRgHvg;pL%$kG^?fxg?7AG}1TB5$uJ+*0pg@n(d zyEEu?@2d}2GzuM-vx1`X5i=0jhAk#I#iwqA?!tI!3le2EW>Ag)=EwnrO^(RZJcHx_ zRBJHTw-`cdR?UnLt&x62Zq`o#C1Z~ids1mW|mr}d&f+Ok0LOUmULb6C@pGO?x zA+6`I0{M|12W+E`YSTNc+uXa$fbTB(RFz!ON~=}k)sNW>_^&jy@ZA=+t+)J1_kSFd zA!KY;l1?N&UBId}O(GYk+MkzJD)Z3Rs2T8p;;NB#pk zXm9}l3b>eh!Zx)hoZVqN1=T|Qj^$}?`guZXf7t5%D5eXFQ+0%|--@cf*L8pc_BAllNz40v7O}zoW=z`!*pbQ^!q54#vgf#ypOPQ1!KpJ1|CrTN__D$6KiI8 zh0wPL5Mf8sZ6-$T_^OF4ii zE6wcXwk;pc95blat^|L_n`VhjlOtQsVyMKq5K-RX3|8NX6cdxz?8Y=SZUgcLd#6YCHou;780O3w7F$O&l5i`hU4 z1$_oJhM31`p^@9fy;+#51g#=~EWStz{E$8lJ)H`|zRfb_m`pjc`PHl$Yu4p2Cq~B9 zbJO=U6$?&I?C}fwZ1comcmH)2l9jwd&n?wJ#-Q H^EC@BbmR}$ literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro b/src/iceberg/test/resources/encryption/table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro new file mode 100644 index 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jql`X5NhWq30&4NGw*bU*P$@YGY@0#DJ*^=HV&5Ol<>eb-Dp>gF zcxV>ZX3u^>BiPn5daOR&t~q?1QADh0UAHvbpVQ3zzZ;kgrm|n^%AL~g(H_bW+yYWr literal 0 HcmV?d00001 diff --git a/src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json new file mode 100644 index 0000000000..274102950f --- /dev/null +++ b/src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json @@ -0,0 +1 @@ +{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":0,"last-updated-ms":1791460592557,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":null,"next-row-id":0,"refs":{},"snapshots":[],"statistics":[],"partition-statistics":[],"snapshot-log":[],"metadata-log":[]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json new file mode 100644 index 0000000000..0ffe050c5d --- /dev/null +++ b/src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json @@ -0,0 +1 @@ +{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":1,"last-updated-ms":1791460593555,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":564307663132197943,"next-row-id":5,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":564307663132197943,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json new file mode 100644 index 0000000000..e724cd20fc --- /dev/null +++ b/src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json @@ -0,0 +1 @@ +{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":2,"last-updated-ms":1791460593713,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":1122461367364127429,"next-row-id":10,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"LU90Mju0jbgvcsbifDCF0A==","encrypted-key-metadata":"2VLA6waTLBagemORlfjUdPRjmo3M3fPei7WkwX/q4S8aEM8CnAW8gllBDpEPXa/70jzMCvlVXkdg5x0CCmzoBKaSkA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":1122461367364127429,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="},{"sequence-number":2,"snapshot-id":1122461367364127429,"parent-snapshot-id":564307663132197943,"timestamp-ms":1791460593713,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"1","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1793","changed-partition-count":"1","total-records":"10","total-files-size":"3584","total-data-files":"2","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro","schema-id":0,"first-row-id":5,"added-rows":5,"key-id":"LU90Mju0jbgvcsbifDCF0A=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943},{"timestamp-ms":1791460593713,"snapshot-id":1122461367364127429}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"},{"timestamp-ms":1791460593555,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v2.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json new file mode 100644 index 0000000000..2426069f2b --- /dev/null +++ b/src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json @@ -0,0 +1 @@ +{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":3,"last-updated-ms":1791460593828,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":5112456484007752895,"next-row-id":13,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"LU90Mju0jbgvcsbifDCF0A==","encrypted-key-metadata":"2VLA6waTLBagemORlfjUdPRjmo3M3fPei7WkwX/q4S8aEM8CnAW8gllBDpEPXa/70jzMCvlVXkdg5x0CCmzoBKaSkA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"ZkXVnuHz4Qlemc4wNaI8Eg==","encrypted-key-metadata":"qz9eUQScTKPymZ8tV+csNKXRhBF2hDHU7s0d7+AbbG10T6Zgqc/BVKXfL5FjYJ2KNQdCxpp4CAm3HlXpFbxR5HA+Kw==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":5112456484007752895,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="},{"sequence-number":2,"snapshot-id":1122461367364127429,"parent-snapshot-id":564307663132197943,"timestamp-ms":1791460593713,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"1","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1793","changed-partition-count":"1","total-records":"10","total-files-size":"3584","total-data-files":"2","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro","schema-id":0,"first-row-id":5,"added-rows":5,"key-id":"LU90Mju0jbgvcsbifDCF0A=="},{"sequence-number":3,"snapshot-id":5112456484007752895,"parent-snapshot-id":1122461367364127429,"timestamp-ms":1791460593828,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"2","manifests-replaced":"0","added-data-files":"1","added-records":"3","added-files-size":"445","changed-partition-count":"1","total-records":"13","total-files-size":"4029","total-data-files":"3","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-5112456484007752895-1-95f19655-198b-4c2a-a7e5-e3cf75d5ab54.avro","schema-id":0,"first-row-id":10,"added-rows":3,"key-id":"ZkXVnuHz4Qlemc4wNaI8Eg=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943},{"timestamp-ms":1791460593713,"snapshot-id":1122461367364127429},{"timestamp-ms":1791460593828,"snapshot-id":5112456484007752895}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"},{"timestamp-ms":1791460593555,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v2.metadata.json"},{"timestamp-ms":1791460593713,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v3.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v5.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v5.metadata.json new file mode 100644 index 0000000000..241ea609c3 --- /dev/null +++ b/src/iceberg/test/resources/encryption/table/metadata/v5.metadata.json @@ -0,0 +1 @@ +{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":4,"last-updated-ms":1791460593995,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":5555854819025587960,"next-row-id":13,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"LU90Mju0jbgvcsbifDCF0A==","encrypted-key-metadata":"2VLA6waTLBagemORlfjUdPRjmo3M3fPei7WkwX/q4S8aEM8CnAW8gllBDpEPXa/70jzMCvlVXkdg5x0CCmzoBKaSkA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"ZkXVnuHz4Qlemc4wNaI8Eg==","encrypted-key-metadata":"qz9eUQScTKPymZ8tV+csNKXRhBF2hDHU7s0d7+AbbG10T6Zgqc/BVKXfL5FjYJ2KNQdCxpp4CAm3HlXpFbxR5HA+Kw==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"VTWjHxdPbZFKJheX7XsR/Q==","encrypted-key-metadata":"EgZwxa5QZHjIWGAyrWOZiTfZEzOuQ1elzfuKke1DqxTQmGSHUTSNSxE0piZMRisSN/Ijp1EF7jbohWPi9OEr0BuBjQ==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":5555854819025587960,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="},{"sequence-number":2,"snapshot-id":1122461367364127429,"parent-snapshot-id":564307663132197943,"timestamp-ms":1791460593713,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"1","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1793","changed-partition-count":"1","total-records":"10","total-files-size":"3584","total-data-files":"2","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro","schema-id":0,"first-row-id":5,"added-rows":5,"key-id":"LU90Mju0jbgvcsbifDCF0A=="},{"sequence-number":3,"snapshot-id":5112456484007752895,"parent-snapshot-id":1122461367364127429,"timestamp-ms":1791460593828,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"2","manifests-replaced":"0","added-data-files":"1","added-records":"3","added-files-size":"445","changed-partition-count":"1","total-records":"13","total-files-size":"4029","total-data-files":"3","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-5112456484007752895-1-95f19655-198b-4c2a-a7e5-e3cf75d5ab54.avro","schema-id":0,"first-row-id":10,"added-rows":3,"key-id":"ZkXVnuHz4Qlemc4wNaI8Eg=="},{"sequence-number":4,"snapshot-id":5555854819025587960,"parent-snapshot-id":5112456484007752895,"timestamp-ms":1791460593995,"summary":{"operation":"delete","manifests-created":"1","manifests-kept":"3","manifests-replaced":"0","added-delete-files":"1","added-dvs":"1","added-files-size":"42","added-position-deletes":"1","changed-partition-count":"1","total-records":"13","total-files-size":"4071","total-data-files":"3","total-delete-files":"1","total-position-deletes":"1","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-5555854819025587960-1-d1977369-b04a-4cf3-a491-6090bc1572fc.avro","schema-id":0,"first-row-id":13,"added-rows":0,"key-id":"VTWjHxdPbZFKJheX7XsR/Q=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943},{"timestamp-ms":1791460593713,"snapshot-id":1122461367364127429},{"timestamp-ms":1791460593828,"snapshot-id":5112456484007752895},{"timestamp-ms":1791460593995,"snapshot-id":5555854819025587960}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"},{"timestamp-ms":1791460593555,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v2.metadata.json"},{"timestamp-ms":1791460593713,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v3.metadata.json"},{"timestamp-ms":1791460593828,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v4.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/version-hint.text b/src/iceberg/test/resources/encryption/table/metadata/version-hint.text new file mode 100644 index 0000000000..7ed6ff82de --- /dev/null +++ b/src/iceberg/test/resources/encryption/table/metadata/version-hint.text @@ -0,0 +1 @@ +5 diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc new file mode 100644 index 0000000000..fb7f2469ed --- /dev/null +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/standard_encryption_manager.h" + +#include + +#include + +#include "iceberg/encryption/encryption_register.h" +#include "iceberg/encryption/in_memory_kms.h" +#include "iceberg/snapshot.h" +#include "iceberg/table_metadata.h" +#include "iceberg/test/matchers.h" +#include "iceberg/test/test_resource.h" + +namespace iceberg { + +namespace { + +/// \brief Deterministic test bytes: byte i is (i * 31 + seed). +std::vector VectorBytes(size_t length, int seed) { + std::vector bytes(length); + for (size_t i = 0; i < length; ++i) { + bytes[i] = static_cast(static_cast(i) * 31 + seed); + } + return bytes; +} + +// The master key for "keyA" used by the Java fixture under +// test/resources/encryption/table. +const std::vector kMasterKeyA = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '0', '1', '2', '3', '4', '5'}; + +/// Counts calls to the KMS. +class CountingKms : public InMemoryKms { + public: + using InMemoryKms::InMemoryKms; + Result> WrapKey(std::span key, + std::string_view id) override { + ++wraps; + return InMemoryKms::WrapKey(key, id); + } + Result> UnwrapKey(std::span wrapped, + std::string_view id) override { + ++unwraps; + return InMemoryKms::UnwrapKey(wrapped, id); + } + int wraps = 0; + int unwraps = 0; +}; + +std::shared_ptr MakeKms() { + return std::make_shared( + std::unordered_map>{{"keyA", kMasterKeyA}}); +} + +} // namespace + +TEST(StandardEncryptionManagerTest, DecryptsJavaManifestListKeys) { + ICEBERG_UNWRAP_OR_FAIL( + auto metadata, + ReadTableMetadataFromResource("encryption/table/metadata/v5.metadata.json")); + ASSERT_EQ(metadata->snapshots.size(), 4); + ASSERT_EQ(metadata->encryption_keys.size(), 5); + + // Through the registry, as catalogs do + encryption::RegisterAll(); + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, EncryptionManagerRegistry::Make( + {.table_key_id = "keyA", + .encryption_keys = metadata->encryption_keys, + .kms = kms})); + + for (const auto& snapshot : metadata->snapshots) { + ASSERT_TRUE(snapshot->key_id.has_value()); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, + manager->DecryptManifestListKeyMetadata(*snapshot->key_id)); + ICEBERG_UNWRAP_OR_FAIL(auto key_metadata, StandardKeyMetadata::Parse(decrypted)); + EXPECT_EQ(key_metadata.encryption_key.size(), 16); + EXPECT_EQ(key_metadata.aad_prefix->size(), 16); + // The trusted length is the stored (encrypted) size of the manifest list file + auto name = std::filesystem::path(snapshot->manifest_list).filename().string(); + EXPECT_EQ( + key_metadata.file_length, + std::filesystem::file_size(GetResourcePath("encryption/table/metadata/" + name))); + } + // One key encryption key for all snapshots, unwrapped once + EXPECT_EQ(kms->unwraps, 1); +} + +TEST(StandardEncryptionManagerTest, RegisterAndDecryptManifestListKeyMetadata) { + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( + {.table_key_id = "keyA", .kms = kms})); + + ICEBERG_UNWRAP_OR_FAIL(auto key_metadata, manager->NewKeyMetadata()); + EXPECT_EQ(key_metadata.encryption_key.size(), 16); + EXPECT_EQ(key_metadata.aad_prefix->size(), 16); + EXPECT_FALSE(key_metadata.file_length.has_value()); + // The manifest list length is required + EXPECT_THAT(manager->RegisterManifestListKeyMetadata(key_metadata), + IsError(ErrorKind::kInvalidArgument)); + key_metadata.file_length = 999; + + ICEBERG_UNWRAP_OR_FAIL(auto keys, + manager->RegisterManifestListKeyMetadata(key_metadata)); + EXPECT_EQ(keys.key_encryption_key.encrypted_by_id, "keyA"); + EXPECT_TRUE(keys.key_encryption_key.properties.contains("KEY_TIMESTAMP")); + EXPECT_EQ(keys.file_key.encrypted_by_id, keys.key_encryption_key.key_id); + EXPECT_EQ(kms->wraps, 1); + EXPECT_EQ(manager->encryption_keys().size(), 2); + + // A reader that only has the committed keys and the KMS can decrypt it + ICEBERG_UNWRAP_OR_FAIL(auto reader, + StandardEncryptionManager::Make( + {.table_key_id = "keyA", + .encryption_keys = {keys.key_encryption_key, keys.file_key}, + .kms = kms})); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, + reader->DecryptManifestListKeyMetadata(keys.file_key.key_id)); + EXPECT_EQ(decrypted, key_metadata.Serialize()); + + // Key encryption keys and unknown IDs are rejected + EXPECT_THAT(reader->DecryptManifestListKeyMetadata(keys.key_encryption_key.key_id), + IsError(ErrorKind::kInvalid)); + EXPECT_THAT(reader->DecryptManifestListKeyMetadata("missing"), + IsError(ErrorKind::kInvalid)); +} + +TEST(StandardEncryptionManagerTest, RotatesKeyEncryptionKeys) { + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( + {.table_key_id = "keyA", .kms = kms})); + StandardKeyMetadata key_metadata{.encryption_key = VectorBytes(16, 1), + .aad_prefix = VectorBytes(16, 2), + .file_length = 100}; + + ICEBERG_UNWRAP_OR_FAIL(auto first, + manager->RegisterManifestListKeyMetadata(key_metadata)); + ICEBERG_UNWRAP_OR_FAIL(auto second, + manager->RegisterManifestListKeyMetadata(key_metadata)); + EXPECT_EQ(second.key_encryption_key.key_id, first.key_encryption_key.key_id); + EXPECT_NE(second.file_key.key_id, first.file_key.key_id); + + manager->SetTestTimeShift(StandardEncryptionManager::kKekLifespan); + ICEBERG_UNWRAP_OR_FAIL(auto third, + manager->RegisterManifestListKeyMetadata(key_metadata)); + EXPECT_NE(third.key_encryption_key.key_id, first.key_encryption_key.key_id); + EXPECT_EQ(kms->wraps, 2); + + // Manifest lists encrypted with the old key encryption key stay readable + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, + manager->DecryptManifestListKeyMetadata(first.file_key.key_id)); + EXPECT_EQ(decrypted, key_metadata.Serialize()); +} + +TEST(StandardEncryptionManagerTest, UnwrappedKeyCacheExpires) { + ICEBERG_UNWRAP_OR_FAIL( + auto metadata, + ReadTableMetadataFromResource("encryption/table/metadata/v5.metadata.json")); + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( + {.table_key_id = "keyA", + .encryption_keys = metadata->encryption_keys, + .kms = kms})); + const auto& key_id = *metadata->snapshots.front()->key_id; + ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); + ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); + EXPECT_EQ(kms->unwraps, 1); + + manager->SetTestTimeShift(StandardEncryptionManager::kUnwrappedKekCacheExpiry); + ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); + EXPECT_EQ(kms->unwraps, 2); +} + +TEST(StandardEncryptionManagerTest, DecryptingFileRequiresLength) { + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( + {.table_key_id = "keyA", .kms = kms})); + StandardKeyMetadata no_length{.encryption_key = VectorBytes(16, 1)}; + + class NullInputFile : public InputFile { + public: + std::string_view location() const override { return "file"; } + Result Size() const override { return 0; } + Result> Open() override { + return NotImplemented(""); + } + }; + EXPECT_THAT(manager->NewDecryptingInputFile(std::make_unique(), + no_length.Serialize()), + IsError(ErrorKind::kInvalid)); +} + +TEST(EncryptionManagerRegistryTest, ValidatesOptions) { + encryption::RegisterAll(); + EXPECT_TRUE(encryption::IsEncryptionAvailable()); + EXPECT_THAT(EncryptionManagerRegistry::Make({.table_key_id = "keyA"}), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(EncryptionManagerRegistry::Make({.table_key_id = "", .kms = MakeKms()}), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(EncryptionManagerRegistry::Make( + {.table_key_id = "keyA", .data_key_length = 20, .kms = MakeKms()}), + IsError(ErrorKind::kInvalidArgument)); +} + +} // namespace iceberg From 76106ce754f6f08f452d90b41c2cdb558d2b30c8 Mon Sep 17 00:00:00 2001 From: shangxinli Date: Sat, 31 Oct 2026 18:02:13 -0700 Subject: [PATCH 2/9] fix: use designated initializers for CachedKek Resolves modernize-use-designated-initializers clang-tidy warnings. --- src/iceberg/encryption/standard_encryption_manager.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/iceberg/encryption/standard_encryption_manager.cc b/src/iceberg/encryption/standard_encryption_manager.cc index 40e3fb673a..1baaa7c4bc 100644 --- a/src/iceberg/encryption/standard_encryption_manager.cc +++ b/src/iceberg/encryption/standard_encryption_manager.cc @@ -153,7 +153,7 @@ Result> StandardEncryptionManager::UnwrapKek( ICEBERG_ASSIGN_OR_RAISE( auto kek, kms_->UnwrapKey(AsBytes(it->second.encrypted_key_metadata), table_key_id_)); - unwrapped_keks_.insert_or_assign(kek_id, CachedKek{kek, now}); + unwrapped_keks_.insert_or_assign(kek_id, CachedKek{.key = kek, .unwrapped_at_ms = now}); return kek; } @@ -206,7 +206,8 @@ Result StandardEncryptionManager::CurrentKekId() { .encrypted_key_metadata = ToString(wrapped), .encrypted_by_id = table_key_id_, .properties = {{std::string(kKeyTimestamp), std::to_string(now)}}}); - unwrapped_keks_.insert_or_assign(kek_id, CachedKek{std::move(kek), now}); + unwrapped_keks_.insert_or_assign( + kek_id, CachedKek{.key = std::move(kek), .unwrapped_at_ms = now}); return kek_id; } From a0dbb5719b6950bd4cf920ce6bc874edf3cccaff Mon Sep 17 00:00:00 2001 From: shangxinli Date: Wed, 4 Nov 2026 08:27:31 -0800 Subject: [PATCH 3/9] fix(encryption): install missing public headers and guard timestamp overflow Register encryption_manager.h, encryption_register.h, and standard_encryption_manager.h in the public header install lists so installed consumers can include the new encryption APIs. encryption_register.h is grouped as a bundle header (not encryption-only) so it stays available when the bundle is built with encryption disabled. Also reject negative KEY_TIMESTAMP values in ParseTimestamp to avoid signed overflow in CurrentKekId's now - timestamp comparison when the stored timestamp is corrupted to INT64_MIN. --- src/iceberg/cpp20_compatibility_internal.h | 3 ++ src/iceberg/encryption/CMakeLists.txt | 17 ++++++++--- .../encryption/standard_encryption_manager.cc | 2 +- .../test/standard_encryption_manager_test.cc | 30 +++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/iceberg/cpp20_compatibility_internal.h b/src/iceberg/cpp20_compatibility_internal.h index 5c2115c21c..63e4a82c55 100644 --- a/src/iceberg/cpp20_compatibility_internal.h +++ b/src/iceberg/cpp20_compatibility_internal.h @@ -50,6 +50,7 @@ #include "iceberg/deletes/position_delete_range_consumer.h" #include "iceberg/deletes/roaring_position_bitmap.h" #include "iceberg/encryption/encrypted_key.h" +#include "iceberg/encryption/encryption_manager.h" #include "iceberg/encryption/key_management_client.h" #include "iceberg/encryption/standard_key_metadata.h" #include "iceberg/exception.h" @@ -222,6 +223,7 @@ # include "iceberg/avro/avro_reader.h" # include "iceberg/avro/avro_register.h" # include "iceberg/avro/avro_writer.h" +# include "iceberg/encryption/encryption_register.h" # include "iceberg/parquet/parquet_reader.h" # include "iceberg/parquet/parquet_register.h" # include "iceberg/parquet/parquet_writer.h" @@ -230,6 +232,7 @@ #ifdef ICEBERG_PUBLIC_HEADERS_ENCRYPTION # include "iceberg/encryption/aes_gcm_stream.h" # include "iceberg/encryption/in_memory_kms.h" +# include "iceberg/encryption/standard_encryption_manager.h" #endif // ICEBERG_PUBLIC_HEADERS_ENCRYPTION #ifdef ICEBERG_PUBLIC_HEADERS_HIVE diff --git a/src/iceberg/encryption/CMakeLists.txt b/src/iceberg/encryption/CMakeLists.txt index c490aa79ca..932b1deb75 100644 --- a/src/iceberg/encryption/CMakeLists.txt +++ b/src/iceberg/encryption/CMakeLists.txt @@ -18,13 +18,22 @@ iceberg_install_all_headers(iceberg/encryption PATTERN encrypted_key.h + encryption_manager.h key_management_client.h standard_key_metadata.h) -if(ICEBERG_BUILD_BUNDLE AND ICEBERG_ENCRYPTION) +if(ICEBERG_BUILD_BUNDLE) iceberg_install_all_headers(iceberg/encryption PATTERN - aes_gcm_stream.h - in_memory_kms.h + encryption_register.h HEADER_GROUP - ICEBERG_PUBLIC_HEADERS_ENCRYPTION) + ICEBERG_PUBLIC_HEADERS_BUNDLE) + if(ICEBERG_ENCRYPTION) + iceberg_install_all_headers(iceberg/encryption + PATTERN + aes_gcm_stream.h + in_memory_kms.h + standard_encryption_manager.h + HEADER_GROUP + ICEBERG_PUBLIC_HEADERS_ENCRYPTION) + endif() endif() diff --git a/src/iceberg/encryption/standard_encryption_manager.cc b/src/iceberg/encryption/standard_encryption_manager.cc index 1baaa7c4bc..fc4356758f 100644 --- a/src/iceberg/encryption/standard_encryption_manager.cc +++ b/src/iceberg/encryption/standard_encryption_manager.cc @@ -57,7 +57,7 @@ std::optional ParseTimestamp(const EncryptedKey& key) { int64_t value = 0; const auto& str = it->second; auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), value); - if (ec != std::errc{} || ptr != str.data() + str.size()) { + if (ec != std::errc{} || ptr != str.data() + str.size() || value < 0) { return std::nullopt; } return value; diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc index fb7f2469ed..9bc7fe9479 100644 --- a/src/iceberg/test/standard_encryption_manager_test.cc +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -171,6 +171,36 @@ TEST(StandardEncryptionManagerTest, RotatesKeyEncryptionKeys) { EXPECT_EQ(decrypted, key_metadata.Serialize()); } +TEST(StandardEncryptionManagerTest, IgnoresOutOfRangeKeyTimestamp) { + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( + {.table_key_id = "keyA", .kms = kms})); + StandardKeyMetadata key_metadata{.encryption_key = VectorBytes(16, 1), + .aad_prefix = VectorBytes(16, 2), + .file_length = 100}; + ICEBERG_UNWRAP_OR_FAIL(auto first, + manager->RegisterManifestListKeyMetadata(key_metadata)); + EXPECT_EQ(kms->wraps, 1); + + // A KEK whose KEY_TIMESTAMP is corrupted to INT64_MIN must never reach the + // "now - timestamp" subtraction, which would overflow. It should instead be + // treated as unparseable, forcing a fresh key encryption key to be created. + std::vector keys = manager->encryption_keys(); + for (auto& key : keys) { + if (key.encrypted_by_id == "keyA") { + key.properties[std::string(StandardEncryptionManager::kKeyTimestamp)] = + "-9223372036854775808"; + } + } + ICEBERG_UNWRAP_OR_FAIL( + auto reader, StandardEncryptionManager::Make( + {.table_key_id = "keyA", .encryption_keys = keys, .kms = kms})); + ICEBERG_UNWRAP_OR_FAIL(auto second, + reader->RegisterManifestListKeyMetadata(key_metadata)); + EXPECT_NE(second.key_encryption_key.key_id, first.key_encryption_key.key_id); + EXPECT_EQ(kms->wraps, 2); +} + TEST(StandardEncryptionManagerTest, UnwrappedKeyCacheExpires) { ICEBERG_UNWRAP_OR_FAIL( auto metadata, From b25d647a99361b87168bcb9112f7c31a19cd2251 Mon Sep 17 00:00:00 2001 From: shangxinli Date: Thu, 5 Nov 2026 10:59:37 -0800 Subject: [PATCH 4/9] test(encryption): remove unused manifest/data fixture files Keep only v5.metadata.json and the 4 manifest-list avro files its snapshots reference at runtime; v1-v4.metadata.json, version-hint.text, the per-snapshot m0.avro manifest files, and the sample data files under data/ are not read by any test. --- ...a0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin | Bin 463 -> 0 bytes .../encryption/table/data/data-0.parquet | Bin 1791 -> 0 bytes .../encryption/table/data/data-1.parquet | Bin 1793 -> 0 bytes .../resources/encryption/table/data/data-2.avro | Bin 445 -> 0 bytes .../462964d7-9cf9-4547-a01b-29e4eef4bc25-m0.avro | Bin 7889 -> 0 bytes .../511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro | Bin 7886 -> 0 bytes .../95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro | Bin 7844 -> 0 bytes .../d1977369-b04a-4cf3-a491-6090bc1572fc-m0.avro | Bin 7909 -> 0 bytes .../encryption/table/metadata/v1.metadata.json | 1 - .../encryption/table/metadata/v2.metadata.json | 1 - .../encryption/table/metadata/v3.metadata.json | 1 - .../encryption/table/metadata/v4.metadata.json | 1 - .../encryption/table/metadata/version-hint.text | 1 - 13 files changed, 5 deletions(-) delete mode 100644 src/iceberg/test/resources/encryption/table/data/00001-1-86fba0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin delete mode 100644 src/iceberg/test/resources/encryption/table/data/data-0.parquet delete mode 100644 src/iceberg/test/resources/encryption/table/data/data-1.parquet delete mode 100644 src/iceberg/test/resources/encryption/table/data/data-2.avro delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/462964d7-9cf9-4547-a01b-29e4eef4bc25-m0.avro delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/d1977369-b04a-4cf3-a491-6090bc1572fc-m0.avro delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json delete mode 100644 src/iceberg/test/resources/encryption/table/metadata/version-hint.text diff --git a/src/iceberg/test/resources/encryption/table/data/00001-1-86fba0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin b/src/iceberg/test/resources/encryption/table/data/00001-1-86fba0db-c6f6-4ce2-a242-a0745cf50318-00001.puffin deleted file mode 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h_r5Fbqb%-7Q!xKdGmk(006(#Ht+uIk;_W1kWnuHd#zP1 zzk0c`rXh^SSj}HeQ;b_}T>$QOy!v_g8){}UAi}b&Tb&AO{GXh5YeN}L$xu_#1;$rX z{d}Akgau2pIG|IA7nIv%`&Kl5#Jd3&WBmSii2oA$ZCObj^;{r67#BX2ws?;sGEgy0 z{ke#eO?yMZAbkAV7=>h)%@`-l# z?r@0UyRDAB%3&_64f45-GyQ@;p+%{aH?~@l*fO0V?NIqE|LNea z1tt5GU-iRa*q|GK1Qb~6C1QYyZ=+xM!7ArMFIwZ={4ACcrU5nwPkMJX^VW9bjrZ-J zEoy7uQ3@@u=?d6WTHTW^`J)?FgtI_^U{i>OWfPP&upyLkuI|R*QM0}?Gr?&GJ@Mqb zZAF(Rv%|Oc|CnYu|CCQdRFmkP##jkryT0$rr1aBzSmB?`#S^PF_$@0o_F^n44`DxR z_>cT=td@WwO6DgeSo}2KCrr;vHx1iSLFqaZJKijRcl-a!;<3TJSJB$;yh-vzZsfE@ zhgKs(GEW&po6m&hB1X2>SG7DQGu+t8)!JMu&+Vlg$q7CUon)ZVDque{d&;ROV2$r z@hxZWTE&2?l7TvCFq*ZOushV9?h`YbGOkVqBt&L>1>=@@F3JP1rtEd+3gD8N^|uv^ zcFxM1z@X9msN{1D`f-x`)GJ2jXySa&u(}=Bh1p=3Jk>6uME{qVUhz^_jI5NjTTWon z^vj2YEXa`~8@ixO%20wROlJNNdbb-#feV7sOz_(h$BQ5KidI3 zjuHE5TzN3#l`#?%tZ9C=J{{G8OPgBZ$+lGiD(}J;pWhg#hBO@{gMh}ipj@rd=-DS} h(m#z35LpGotqtY06Xk}KkH8glrT0(+002-yQbqK`evkkF diff --git a/src/iceberg/test/resources/encryption/table/data/data-1.parquet b/src/iceberg/test/resources/encryption/table/data/data-1.parquet deleted file mode 100644 index e94835ef5559c071a8e10d9f023d8fe469fb5011..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1793 zcmV+c2m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gVoP?(GY{6K{v&P$L;8HTJ6m& jRpM5mWE7y*>Xfbi(4(}fSG?yh_s)c9Py+w}P(e~f0##m@ diff --git a/src/iceberg/test/resources/encryption/table/data/data-2.avro b/src/iceberg/test/resources/encryption/table/data/data-2.avro deleted file mode 100644 index 554247456662cd3dc484d06fcecfb7d3e9394940..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 445 zcmV;u0Yd&kM^iBX01yD#K-H7-iNDB-9?05xiKX)0V&%d)--EYlbK9-rU`lxOkcx_7 z;aEf5G}6GKOZFBp>V&)ClQIY`+wt0JkHrB+gsqsmVr>@@h4@N$Ik&R87xg(^i{L;mrf#wGlr{jj<$v@Xc zJRqE@Fe18RV*R~$o3^t)fUL! zq(`#^nDJII1{ln!>Gzr4)*r5>|v_BrHgh*rI zzT_hrTY`*?s_Yllc({n(SpBTdR2x6H>e4$g z{TPoY`jJSefbviPsI9wQJG6qQa^!;7t)l6I)X0WQJ?Rl7;@%C(8d!M(h}a8nZ*LSH z-72m1PkYZl4f*qytwTLbP@v>oCV;y=yd5);L~{^K{}pfWn(wk;ZhrwJ{_n%vv{CGv z`G*Bil2pVxCr{i{OFC#?UgIMp=URjhN==#s{f?P5qJPk$m(>k z-8WqjrFwQphF>d+-z+Dk6r@~UH%-D@IU@e>269byAaH3m-;50X0G}X>J`9;TpkX^7 zd^8Nplv8e{3mOUEMiHbX&@ab*;Uhe+>iS{s*{bDSnsWcHAI9@wisv0gU)#4xpjoW3 zA4d-}wrL+#M;BowHW6fsOXt_8_qCVjEt_n*os<4j`sM(B31iraF8{Z&34&4RBQ^xP0<8=q5%euTC6r&Cf+q9}xbgR@Zdt!M@EqyTi~cT#jR9KJ4%Q4`mpL%Dc` zaNs<5fSm8IBTk3#7Hn;Ta9g_}Q8OtZ7FWc@?2PUL*z^Gqx^OEiiJO(!-q}6vOro4J zHBL^ak-S*HRBzAuig+Cd2$68ROz-AH11V+Uc(~tK1SV9gAXvib4YtYD$BcJ<9toM%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q91W1AOqN^W_h>`)fB&92zupSGO-zCK2=`G&S7`kiXx`oyfAVA!@; zOqPrHlnc6&$7~^}WBG}=rj|QgHt}Htxx7qY%{g3eKE9<#$GP*JC;4(raLmFob=lux zjz)l}DXE;=0AG$D=NSzP<@0wT-<8`*^Kg?X0$YK?AfNo6v(6AUIw_Alb-EQCHLALw zul-vy+~G)I_i=dqLr8hLTVU3~0Au(@>D~#J{sL2pyEAjM2pcuVY^DUiS+hkR=v^a zaK4)`X7xO*udu%NKg-FWEUE-*V1dth6pth#_ocW4+n453mLpP3UKJeA5gg5092TW5 zA6X7U=(k9{<-xRLw=OlehS6UBl2kDZy=(_m^sM;dC780KhVWo)1$MmUehvhf#0gX<-509u2O#?FDzG4-s^gnXldsTNG6A0mLC%mk zIslrfLQ=`lA_}!+3a7u#DqbxNaFtAtv^tAQ-uv{VkEUX;+ORB?i5Uu7cTs31)ah0y vUP{dSFJ5rzftJWxFFT)d#v}8dp7UYIVT0iRp+*r-a*M^WU|=)l9ReH}7S=;2 diff --git a/src/iceberg/test/resources/encryption/table/metadata/511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro b/src/iceberg/test/resources/encryption/table/metadata/511c33d0-d9b9-4c80-bce0-b6fe4679785b-m0.avro deleted file mode 100644 index 8be2d3aab9b18f040f36eb167342e4219093ebfa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7886 zcmV;<9x>rTM^iBX01yEDnH_KjpF&5brVBOxK3St^3qK%;PurG)|vLUWV{~XNv=Uog6D>A-A@g z!$PyzO2bOKsARD9WWrbS2OizEn8I^iK$8D|__6Yi33-xJpq|i3MeE=oI=JL_D#FcsOutJ_p!I*3Ka^HPhlj5$sn_D4)O z``(O$W4yqOkeLk{Yr^vaeCFHABh*Qth9B3d!y!kX$XTG(MAai`u_}T1e1$CZ0%uW2 zUZ=!-<41Ms1+twTA$G(k+Siq7eY_u8$_$CUZ>tcEAR$;MXLIy2iglO?KBQ%=jL)-l zc{L4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EQW_~n4>J>q(|*bdcHtk?W)Iv^*T!L=)kBtZ;o stM5|P5=o7*zvDl?Fcmzii#9^9QmaOj~}-T(jq diff --git a/src/iceberg/test/resources/encryption/table/metadata/95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro b/src/iceberg/test/resources/encryption/table/metadata/95f19655-198b-4c2a-a7e5-e3cf75d5ab54-m0.avro deleted file mode 100644 index 7e81d8faf6e76bd8553c21af3322269a50900f7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7844 zcmV;V9$Vo-M^iBX01yBWKv1mh=wCmt%sTHW#!@2K4aR;B$aI47-Q4RyOgDDCWHleb zyjve2_Fx7EO)>Qmv_is!i3jQPM*kv~hysMxO37njrJ-?v90o&YzK< z+oKFq_Vsk=;zZX-@eSvz@R3)`gF#q+glacRO*_254+!VP3B&dRvHGP1Rlu^aghh>U zcq9M-E-Xb-HJUOXKH3!?gn6c2^!=~st5ojQq~3lHek(TSnew!2gQ zD>?J&6}QBUmv`=Sit&;9_y8|1qjJxM?j8{Zyaa1%S?OXh%ZB zva;0&#g}7KM0kpgX~LUE=B7P{jZf5uK3e-dEdgH~2`N$MYz(!iTJ}bJ2IiyQ*qH!d zim|3X`<~jOQ{G$$B)@?>4SJ)hr8tJP7B=>raTI5n?c*nB@SHFp9Y8~NV3U7 z&_?mab-`tg%$gjEC7bLx>5lI-9$R!bRtYSXxS-I;1 z<;oZ=y_ef6o(rg{V=V~aNtbk>J@SMP?VgCw%>J-^&U}wx2)A-y+oX8ck7&(R2{Hqc z#T$A?^bbwG1Cv`!cOs$6<-{3b4NBUq#EhX=qHa9qbx7bE=1#q>(#dm! z^!I2PAXcae!^!;LKIk(O^~g(pD}Pmmnu&-!&In1pnNLj{aJBOqd-T{x<`2vlPUKF1 z<4`((oaZAJC%**sV!xjyv>T8WzposxPX^0%(UAep8FFZNJF%`NA_hcB51THOy7>~%wFWvKhPQX z(hR6&SD($5hJKE8BzE(@`BK=p$rt)Q5(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)Q@6X+ z!A#b@X9b=Kff`SQU+#3l3))|9a8GyFB3uAoqAwsOk?_SecOX6Mh*cHq6$6RI9LUAA z1sRO(tmPHgMKEXw4uO3yzx*eS>U}$J|zg diff --git a/src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json deleted file mode 100644 index 274102950f..0000000000 --- a/src/iceberg/test/resources/encryption/table/metadata/v1.metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":0,"last-updated-ms":1791460592557,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":null,"next-row-id":0,"refs":{},"snapshots":[],"statistics":[],"partition-statistics":[],"snapshot-log":[],"metadata-log":[]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json deleted file mode 100644 index 0ffe050c5d..0000000000 --- a/src/iceberg/test/resources/encryption/table/metadata/v2.metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":1,"last-updated-ms":1791460593555,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":564307663132197943,"next-row-id":5,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":564307663132197943,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json deleted file mode 100644 index e724cd20fc..0000000000 --- a/src/iceberg/test/resources/encryption/table/metadata/v3.metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":2,"last-updated-ms":1791460593713,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":1122461367364127429,"next-row-id":10,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"LU90Mju0jbgvcsbifDCF0A==","encrypted-key-metadata":"2VLA6waTLBagemORlfjUdPRjmo3M3fPei7WkwX/q4S8aEM8CnAW8gllBDpEPXa/70jzMCvlVXkdg5x0CCmzoBKaSkA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":1122461367364127429,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="},{"sequence-number":2,"snapshot-id":1122461367364127429,"parent-snapshot-id":564307663132197943,"timestamp-ms":1791460593713,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"1","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1793","changed-partition-count":"1","total-records":"10","total-files-size":"3584","total-data-files":"2","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro","schema-id":0,"first-row-id":5,"added-rows":5,"key-id":"LU90Mju0jbgvcsbifDCF0A=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943},{"timestamp-ms":1791460593713,"snapshot-id":1122461367364127429}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"},{"timestamp-ms":1791460593555,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v2.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json b/src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json deleted file mode 100644 index 2426069f2b..0000000000 --- a/src/iceberg/test/resources/encryption/table/metadata/v4.metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"format-version":3,"table-uuid":"2091a278-2727-4bc0-8427-ffb04a2b7e6d","location":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table","last-sequence-number":3,"last-updated-ms":1791460593828,"last-column-id":2,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"long"},{"id":2,"name":"data","required":false,"type":"string"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields":[]}],"last-partition-id":999,"default-sort-order-id":0,"sort-orders":[{"order-id":0,"fields":[]}],"properties":{"encryption.key-id":"keyA","write.parquet.compression-codec":"zstd"},"current-snapshot-id":5112456484007752895,"next-row-id":13,"encryption-keys":[{"key-id":"6kMyWaTMFqk5FVecTafB8w==","encrypted-key-metadata":"BA3fkOhBo//37HfxBA1lUEbSrgrv3k06ovUGyi70AINLvvCU9iCUdhwR9lM=","encrypted-by-id":"keyA","properties":{"KEY_TIMESTAMP":"1791460593549"}},{"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ==","encrypted-key-metadata":"UTlv697ZHJpwrMe7rfBpOBNsbrSKKZuHLJm2i/V0DiJmtTR3RxxBhYlxxBaDH6K9kpFRZ1YrkRCYLhgrY5pAyvj9KA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"LU90Mju0jbgvcsbifDCF0A==","encrypted-key-metadata":"2VLA6waTLBagemORlfjUdPRjmo3M3fPei7WkwX/q4S8aEM8CnAW8gllBDpEPXa/70jzMCvlVXkdg5x0CCmzoBKaSkA==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="},{"key-id":"ZkXVnuHz4Qlemc4wNaI8Eg==","encrypted-key-metadata":"qz9eUQScTKPymZ8tV+csNKXRhBF2hDHU7s0d7+AbbG10T6Zgqc/BVKXfL5FjYJ2KNQdCxpp4CAm3HlXpFbxR5HA+Kw==","encrypted-by-id":"6kMyWaTMFqk5FVecTafB8w=="}],"refs":{"main":{"snapshot-id":5112456484007752895,"type":"branch"}},"snapshots":[{"sequence-number":1,"snapshot-id":564307663132197943,"timestamp-ms":1791460593552,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"0","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1791","changed-partition-count":"1","total-records":"5","total-files-size":"1791","total-data-files":"1","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-564307663132197943-1-511c33d0-d9b9-4c80-bce0-b6fe4679785b.avro","schema-id":0,"first-row-id":0,"added-rows":5,"key-id":"9Dpe+fdlQ+4lMH5jW0q1YQ=="},{"sequence-number":2,"snapshot-id":1122461367364127429,"parent-snapshot-id":564307663132197943,"timestamp-ms":1791460593713,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"1","manifests-replaced":"0","added-data-files":"1","added-records":"5","added-files-size":"1793","changed-partition-count":"1","total-records":"10","total-files-size":"3584","total-data-files":"2","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-1122461367364127429-1-462964d7-9cf9-4547-a01b-29e4eef4bc25.avro","schema-id":0,"first-row-id":5,"added-rows":5,"key-id":"LU90Mju0jbgvcsbifDCF0A=="},{"sequence-number":3,"snapshot-id":5112456484007752895,"parent-snapshot-id":1122461367364127429,"timestamp-ms":1791460593828,"summary":{"operation":"append","manifests-created":"1","manifests-kept":"2","manifests-replaced":"0","added-data-files":"1","added-records":"3","added-files-size":"445","changed-partition-count":"1","total-records":"13","total-files-size":"4029","total-data-files":"3","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0","iceberg-version":"Apache Iceberg 1.13.0-SNAPSHOT (commit 4d5811f2c701b15be4379686b17144503ed1e685)"},"manifest-list":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/snap-5112456484007752895-1-95f19655-198b-4c2a-a7e5-e3cf75d5ab54.avro","schema-id":0,"first-row-id":10,"added-rows":3,"key-id":"ZkXVnuHz4Qlemc4wNaI8Eg=="}],"statistics":[],"partition-statistics":[],"snapshot-log":[{"timestamp-ms":1791460593552,"snapshot-id":564307663132197943},{"timestamp-ms":1791460593713,"snapshot-id":1122461367364127429},{"timestamp-ms":1791460593828,"snapshot-id":5112456484007752895}],"metadata-log":[{"timestamp-ms":1791460592557,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v1.metadata.json"},{"timestamp-ms":1791460593555,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v2.metadata.json"},{"timestamp-ms":1791460593713,"metadata-file":"/tmp/iceberg-cpp-encryption-fixture/encrypted_table/metadata/v3.metadata.json"}]} diff --git a/src/iceberg/test/resources/encryption/table/metadata/version-hint.text b/src/iceberg/test/resources/encryption/table/metadata/version-hint.text deleted file mode 100644 index 7ed6ff82de..0000000000 --- a/src/iceberg/test/resources/encryption/table/metadata/version-hint.text +++ /dev/null @@ -1 +0,0 @@ -5 From ed7a7e8a8c15dbfa910667290f2647496cc2a0bc Mon Sep 17 00:00:00 2001 From: Xinli shang Date: Tue, 17 Nov 2026 09:59:39 -0800 Subject: [PATCH 5/9] refactor(encryption): align class hierarchy with Java EncryptionManager design Slim EncryptionManager to Encrypt/Decrypt over EncryptedInputFile and EncryptedOutputFile, with sequential batch defaults, so the base interface no longer leaks standard-encryption-specific types. StandardEncryptionManager keeps its envelope-encryption-specific methods as additional public methods. Add PlaintextEncryptionManager for unencrypted tables, EncryptedFiles as a core factory for wrapping plain files without native (modular) encryption support, and EncryptionUtil as a bundle-only helper that reaches StandardEncryptionManager-specific operations through a generic EncryptionManager pointer via dynamic_cast. --- src/iceberg/CMakeLists.txt | 2 + src/iceberg/cpp20_compatibility_internal.h | 4 + src/iceberg/encryption/CMakeLists.txt | 4 + src/iceberg/encryption/encrypted_file.h | 164 ++++++++++++++++++ src/iceberg/encryption/encrypted_files.cc | 40 +++++ src/iceberg/encryption/encrypted_files.h | 50 ++++++ .../encryption/encryption_key_metadata.h | 75 ++++++++ src/iceberg/encryption/encryption_manager.cc | 34 ++++ src/iceberg/encryption/encryption_manager.h | 77 ++++---- src/iceberg/encryption/encryption_util.cc | 37 ++++ src/iceberg/encryption/encryption_util.h | 48 +++++ .../encryption/standard_encryption_manager.cc | 24 ++- .../encryption/standard_encryption_manager.h | 29 +++- .../encryption/standard_key_metadata.h | 25 ++- .../test/standard_encryption_manager_test.cc | 15 +- .../test/standard_key_metadata_test.cc | 5 +- 16 files changed, 565 insertions(+), 68 deletions(-) create mode 100644 src/iceberg/encryption/encrypted_file.h create mode 100644 src/iceberg/encryption/encrypted_files.cc create mode 100644 src/iceberg/encryption/encrypted_files.h create mode 100644 src/iceberg/encryption/encryption_key_metadata.h create mode 100644 src/iceberg/encryption/encryption_util.cc create mode 100644 src/iceberg/encryption/encryption_util.h diff --git a/src/iceberg/CMakeLists.txt b/src/iceberg/CMakeLists.txt index 1321a82a9a..f9604e2575 100644 --- a/src/iceberg/CMakeLists.txt +++ b/src/iceberg/CMakeLists.txt @@ -33,6 +33,7 @@ set(ICEBERG_SOURCES deletes/position_delete_index.cc deletes/position_delete_range_consumer.cc deletes/roaring_position_bitmap.cc + encryption/encrypted_files.cc encryption/encryption_manager.cc encryption/key_management_client.cc encryption/standard_key_metadata.cc @@ -356,6 +357,7 @@ if(ICEBERG_BUILD_BUNDLE) ICEBERG_BUNDLE_SOURCES encryption/aes_gcm.cc encryption/aes_gcm_stream.cc + encryption/encryption_util.cc encryption/in_memory_kms.cc encryption/standard_encryption_manager.cc) endif() diff --git a/src/iceberg/cpp20_compatibility_internal.h b/src/iceberg/cpp20_compatibility_internal.h index 63e4a82c55..2d037bced7 100644 --- a/src/iceberg/cpp20_compatibility_internal.h +++ b/src/iceberg/cpp20_compatibility_internal.h @@ -49,7 +49,10 @@ #include "iceberg/deletes/position_delete_index.h" #include "iceberg/deletes/position_delete_range_consumer.h" #include "iceberg/deletes/roaring_position_bitmap.h" +#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/encryption/encrypted_files.h" #include "iceberg/encryption/encrypted_key.h" +#include "iceberg/encryption/encryption_key_metadata.h" #include "iceberg/encryption/encryption_manager.h" #include "iceberg/encryption/key_management_client.h" #include "iceberg/encryption/standard_key_metadata.h" @@ -231,6 +234,7 @@ #ifdef ICEBERG_PUBLIC_HEADERS_ENCRYPTION # include "iceberg/encryption/aes_gcm_stream.h" +# include "iceberg/encryption/encryption_util.h" # include "iceberg/encryption/in_memory_kms.h" # include "iceberg/encryption/standard_encryption_manager.h" #endif // ICEBERG_PUBLIC_HEADERS_ENCRYPTION diff --git a/src/iceberg/encryption/CMakeLists.txt b/src/iceberg/encryption/CMakeLists.txt index 932b1deb75..7ddb2797cb 100644 --- a/src/iceberg/encryption/CMakeLists.txt +++ b/src/iceberg/encryption/CMakeLists.txt @@ -17,7 +17,10 @@ iceberg_install_all_headers(iceberg/encryption PATTERN + encrypted_file.h + encrypted_files.h encrypted_key.h + encryption_key_metadata.h encryption_manager.h key_management_client.h standard_key_metadata.h) @@ -31,6 +34,7 @@ if(ICEBERG_BUILD_BUNDLE) iceberg_install_all_headers(iceberg/encryption PATTERN aes_gcm_stream.h + encryption_util.h in_memory_kms.h standard_encryption_manager.h HEADER_GROUP diff --git a/src/iceberg/encryption/encrypted_file.h b/src/iceberg/encryption/encrypted_file.h new file mode 100644 index 0000000000..26461464c2 --- /dev/null +++ b/src/iceberg/encryption/encrypted_file.h @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/encrypted_file.h +/// Pairs a file handle with its key metadata, mirroring Java's +/// EncryptedInputFile / EncryptedOutputFile. + +#include +#include + +#include "iceberg/encryption/encryption_key_metadata.h" +#include "iceberg/file_io.h" +#include "iceberg/iceberg_export.h" + +namespace iceberg { + +/// \brief An encrypted input file together with the key metadata needed to decrypt it. +class ICEBERG_EXPORT EncryptedInputFile { + public: + virtual ~EncryptedInputFile() = default; + + /// \brief Give up the still-encrypted raw input file. + virtual std::unique_ptr ReleaseInputFile() = 0; + + /// \brief The key metadata needed to decrypt this file. + virtual const EncryptionKeyMetadata& key_metadata() const = 0; +}; + +/// \brief EncryptedInputFile backed by a plain InputFile and opaque key metadata. +class ICEBERG_EXPORT BaseEncryptedInputFile : public EncryptedInputFile { + public: + BaseEncryptedInputFile(std::unique_ptr encrypted_file, + std::shared_ptr key_metadata) + : encrypted_file_(std::move(encrypted_file)), + key_metadata_(std::move(key_metadata)) {} + + std::unique_ptr ReleaseInputFile() override { + return std::move(encrypted_file_); + } + + const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } + + private: + std::unique_ptr encrypted_file_; + std::shared_ptr key_metadata_; +}; + +/// \brief An encrypted input file for formats, such as Parquet, that perform their own +/// native (modular) decryption rather than using the AGS1 stream format. +/// +/// Also implements InputFile so that the still-encrypted bytes remain directly +/// readable; the native reader uses key_metadata() to obtain the key parameters needed +/// to decrypt the individual modules it reads. +class ICEBERG_EXPORT NativeEncryptionInputFile : public EncryptedInputFile, + public InputFile { + public: + NativeEncryptionInputFile(std::unique_ptr encrypted_file, + std::shared_ptr key_metadata) + : encrypted_file_(std::move(encrypted_file)), + key_metadata_(std::move(key_metadata)) {} + + // EncryptedInputFile + std::unique_ptr ReleaseInputFile() override { + return std::move(encrypted_file_); + } + const NativeEncryptionKeyMetadata& key_metadata() const override { + return *key_metadata_; + } + + // InputFile, passed through to the still-encrypted raw file. + std::string_view location() const override { return encrypted_file_->location(); } + Result Size() const override { return encrypted_file_->Size(); } + Result> Open() override { + return encrypted_file_->Open(); + } + + private: + std::unique_ptr encrypted_file_; + std::shared_ptr key_metadata_; +}; + +/// \brief An encrypting output file together with the key metadata that was used (or +/// will be used) to encrypt it. +class ICEBERG_EXPORT EncryptedOutputFile { + public: + virtual ~EncryptedOutputFile() = default; + + /// \brief The output file that writers should use. + /// + /// Unlike EncryptedInputFile::ReleaseInputFile, this is a non-consuming accessor: + /// implementations may need to keep ownership to finalize encryption on Close. + virtual OutputFile& encrypting_output_file() const = 0; + + /// \brief The key metadata that was used to encrypt this file. + virtual const EncryptionKeyMetadata& key_metadata() const = 0; +}; + +/// \brief EncryptedOutputFile backed by a plain OutputFile and opaque key metadata. +class ICEBERG_EXPORT BaseEncryptedOutputFile : public EncryptedOutputFile { + public: + BaseEncryptedOutputFile(std::unique_ptr output_file, + std::shared_ptr key_metadata) + : output_file_(std::move(output_file)), key_metadata_(std::move(key_metadata)) {} + + OutputFile& encrypting_output_file() const override { return *output_file_; } + const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } + + private: + std::unique_ptr output_file_; + std::shared_ptr key_metadata_; +}; + +/// \brief An encrypted output file for formats, such as Parquet, that perform their own +/// native (modular) encryption rather than using the AGS1 stream format. +/// +/// Also implements OutputFile so the plaintext bytes can be written directly; the +/// native writer uses key_metadata() to obtain the key parameters it needs to encrypt +/// the individual modules it writes. +class ICEBERG_EXPORT NativeEncryptionOutputFile : public EncryptedOutputFile, + public OutputFile { + public: + NativeEncryptionOutputFile(std::unique_ptr plain_file, + std::shared_ptr key_metadata) + : plain_file_(std::move(plain_file)), key_metadata_(std::move(key_metadata)) {} + + // EncryptedOutputFile + OutputFile& encrypting_output_file() const override { return *plain_file_; } + const NativeEncryptionKeyMetadata& key_metadata() const override { + return *key_metadata_; + } + + // OutputFile, passed through to the plaintext file that the native writer fills in. + std::string_view location() const override { return plain_file_->location(); } + Result> Create() override { + return plain_file_->Create(); + } + Result> CreateOrOverwrite() override { + return plain_file_->CreateOrOverwrite(); + } + + private: + std::unique_ptr plain_file_; + std::shared_ptr key_metadata_; +}; + +} // namespace iceberg diff --git a/src/iceberg/encryption/encrypted_files.cc b/src/iceberg/encryption/encrypted_files.cc new file mode 100644 index 0000000000..ad3c5471f2 --- /dev/null +++ b/src/iceberg/encryption/encrypted_files.cc @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/encrypted_files.h" + +#include + +namespace iceberg { + +std::unique_ptr EncryptedFiles::Encrypted( + std::unique_ptr encrypted_file, + std::shared_ptr key_metadata) { + return std::make_unique(std::move(encrypted_file), + std::move(key_metadata)); +} + +std::unique_ptr EncryptedFiles::Encrypted( + std::unique_ptr output_file, + std::shared_ptr key_metadata) { + return std::make_unique(std::move(output_file), + std::move(key_metadata)); +} + +} // namespace iceberg diff --git a/src/iceberg/encryption/encrypted_files.h b/src/iceberg/encryption/encrypted_files.h new file mode 100644 index 0000000000..ee77cebc31 --- /dev/null +++ b/src/iceberg/encryption/encrypted_files.h @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/encrypted_files.h +/// Builds the generic EncryptedInputFile / EncryptedOutputFile wrappers that +/// EncryptionManager consumes and produces, mirroring Java's EncryptedFiles. + +#include + +#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/iceberg_export.h" + +namespace iceberg { + +/// \brief Builds EncryptedInputFile / EncryptedOutputFile wrappers around a plain file +/// and its key metadata, for callers that do not need the native (modular) encryption +/// wrappers. +class ICEBERG_EXPORT EncryptedFiles { + public: + /// \brief Wrap a still-encrypted input file together with its key metadata. + static std::unique_ptr Encrypted( + std::unique_ptr encrypted_file, + std::shared_ptr key_metadata); + + /// \brief Wrap a plaintext output file together with the key metadata used (or to be + /// used) to encrypt it. + static std::unique_ptr Encrypted( + std::unique_ptr output_file, + std::shared_ptr key_metadata); +}; + +} // namespace iceberg diff --git a/src/iceberg/encryption/encryption_key_metadata.h b/src/iceberg/encryption/encryption_key_metadata.h new file mode 100644 index 0000000000..a169fc727e --- /dev/null +++ b/src/iceberg/encryption/encryption_key_metadata.h @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/encryption_key_metadata.h +/// Opaque, serialized key metadata, mirroring Java's EncryptionKeyMetadata. + +#include +#include +#include +#include + +#include "iceberg/iceberg_export.h" + +namespace iceberg { + +/// \brief Opaque serialized key metadata for one file. +/// +/// Implementations are free to choose any serialization; EncryptionManager and its +/// callers treat the result as an opaque byte buffer. +class ICEBERG_EXPORT EncryptionKeyMetadata { + public: + virtual ~EncryptionKeyMetadata() = default; + + /// \brief The serialized form of this key metadata. + /// + /// Implementations must not cache this value if their fields can change after + /// construction; it is recomputed on every call where that matters. + virtual std::vector buffer() const = 0; +}; + +/// \brief EncryptionKeyMetadata backed by a fixed, already-serialized buffer. +class ICEBERG_EXPORT BaseEncryptionKeyMetadata : public EncryptionKeyMetadata { + public: + explicit BaseEncryptionKeyMetadata(std::vector buffer) + : buffer_(std::move(buffer)) {} + + std::vector buffer() const override { return buffer_; } + + private: + std::vector buffer_; +}; + +/// \brief Key metadata for the native (AES-GCM) encryption key parameters. +/// +/// Exposes the data encryption key and AAD prefix directly, for formats (such as +/// Parquet) that perform their own native encryption rather than using the AGS1 stream +/// format. +class ICEBERG_EXPORT NativeEncryptionKeyMetadata : public EncryptionKeyMetadata { + public: + /// \brief The data encryption key. + virtual const std::vector& EncryptionKey() const = 0; + + /// \brief The AAD prefix (file ID) used to bind ciphertext to this file, if any. + virtual const std::optional>& AadPrefix() const = 0; +}; + +} // namespace iceberg diff --git a/src/iceberg/encryption/encryption_manager.cc b/src/iceberg/encryption/encryption_manager.cc index a49d86d1fc..6702e63ef5 100644 --- a/src/iceberg/encryption/encryption_manager.cc +++ b/src/iceberg/encryption/encryption_manager.cc @@ -25,6 +25,40 @@ namespace iceberg { +Result>> EncryptionManager::Decrypt( + std::vector> encrypted) { + std::vector> decrypted; + decrypted.reserve(encrypted.size()); + for (auto& file : encrypted) { + ICEBERG_ASSIGN_OR_RAISE(auto input_file, Decrypt(std::move(file))); + decrypted.push_back(std::move(input_file)); + } + return decrypted; +} + +Result>> EncryptionManager::Encrypt( + std::vector> plain) { + std::vector> encrypted; + encrypted.reserve(plain.size()); + for (auto& file : plain) { + ICEBERG_ASSIGN_OR_RAISE(auto encrypted_file, Encrypt(std::move(file))); + encrypted.push_back(std::move(encrypted_file)); + } + return encrypted; +} + +Result> PlaintextEncryptionManager::Decrypt( + std::unique_ptr encrypted) { + return encrypted->ReleaseInputFile(); +} + +Result> PlaintextEncryptionManager::Encrypt( + std::unique_ptr plain) { + return std::make_unique( + std::move(plain), + std::make_shared(std::vector{})); +} + namespace { struct RegistryState { diff --git a/src/iceberg/encryption/encryption_manager.h b/src/iceberg/encryption/encryption_manager.h index 83ccaa99d3..e7e79a22ca 100644 --- a/src/iceberg/encryption/encryption_manager.h +++ b/src/iceberg/encryption/encryption_manager.h @@ -25,74 +25,69 @@ #include #include #include -#include #include -#include #include +#include "iceberg/encryption/encrypted_file.h" #include "iceberg/encryption/encrypted_key.h" #include "iceberg/encryption/key_management_client.h" -#include "iceberg/encryption/standard_key_metadata.h" #include "iceberg/file_io.h" #include "iceberg/iceberg_export.h" #include "iceberg/result.h" namespace iceberg { -/// \brief Keys created when the key metadata of a new manifest list is registered. -/// -/// Both must be added to the table metadata `encryption-keys` in the same commit as -/// the snapshot whose `key-id` is `file_key.key_id`. -struct ICEBERG_EXPORT ManifestListEncryptionKeys { - /// The key encryption key, wrapped by the table master key in the KMS. - EncryptedKey key_encryption_key; - /// The manifest list key metadata, encrypted by the key encryption key. - EncryptedKey file_key; -}; - /// \brief Encrypts and decrypts the files of one table. /// -/// The standard implementation (StandardEncryptionManager) needs a crypto provider -/// and lives in the bundle library; the core library reaches it through -/// EncryptionManagerRegistry. +/// This interface does not require a particular key metadata encoding or encryption +/// algorithm; those are the business of the specific implementation (such as +/// StandardEncryptionManager, which needs a crypto provider and lives in the bundle +/// library) and of EncryptedFiles / EncryptionUtil, which build the EncryptedInputFile / +/// EncryptedOutputFile wrappers this interface consumes. The core library reaches the +/// standard implementation through EncryptionManagerRegistry. class ICEBERG_EXPORT EncryptionManager { public: virtual ~EncryptionManager() = default; - /// \brief Generate key metadata (random data key and AAD prefix) for a new file. - virtual Result NewKeyMetadata() = 0; - - /// \brief Wrap an AES GCM Stream (AGS1) file in a decrypting InputFile. - /// - /// \param encrypted the encrypted file - /// \param key_metadata serialized key metadata, including the file length - virtual Result> NewDecryptingInputFile( - std::unique_ptr encrypted, std::span key_metadata) = 0; + /// \brief Decrypt a file, given its raw bytes and key metadata. + virtual Result> Decrypt( + std::unique_ptr encrypted) = 0; - /// \brief Wrap a file in an AES GCM Stream (AGS1) encrypting OutputFile. - virtual Result> NewEncryptingOutputFile( - std::unique_ptr plain, const StandardKeyMetadata& key_metadata) = 0; + /// \brief Wrap a plaintext output file so that it, and its key metadata, can be + /// produced once writing is complete. + virtual Result> Encrypt( + std::unique_ptr plain) = 0; - /// \brief Decrypt the key metadata of a manifest list. + /// \brief Batch variant of Decrypt(std::unique_ptr). /// - /// \param manifest_list_key_id the snapshot `key-id` - /// \return the serialized StandardKeyMetadata of the manifest list file - virtual Result> DecryptManifestListKeyMetadata( - std::string_view manifest_list_key_id) = 0; + /// The default implementation decrypts each file in order; implementations may + /// override it to decrypt more efficiently, for example by batching KMS calls. + virtual Result>> Decrypt( + std::vector> encrypted); + + /// \brief Batch variant of Encrypt(std::unique_ptr). + virtual Result>> Encrypt( + std::vector> plain); +}; - /// \brief Encrypt the key metadata of a new manifest list with a key encryption key. - /// - /// Creates a key encryption key (wrapped by the table master key) if there is no - /// unexpired one. - virtual Result RegisterManifestListKeyMetadata( - const StandardKeyMetadata& key_metadata) = 0; +/// \brief An EncryptionManager for unencrypted tables; wraps files without encrypting +/// them. +class ICEBERG_EXPORT PlaintextEncryptionManager : public EncryptionManager { + public: + Result> Decrypt( + std::unique_ptr encrypted) override; + + Result> Encrypt( + std::unique_ptr plain) override; }; /// \brief Creates the encryption manager of encrypted tables. /// /// The bundle library registers the standard implementation (see /// iceberg::encryption::RegisterAll()). Without it, encrypted tables cannot be read or -/// written. +/// written. A registry is used so that the core library can reach a standard-specific +/// implementation without depending on it directly; Options is therefore +/// standard-specific and not part of the general EncryptionManager contract. class ICEBERG_EXPORT EncryptionManagerRegistry { public: struct Options { diff --git a/src/iceberg/encryption/encryption_util.cc b/src/iceberg/encryption/encryption_util.cc new file mode 100644 index 0000000000..bfa981ca0f --- /dev/null +++ b/src/iceberg/encryption/encryption_util.cc @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/encryption_util.h" + +#include "iceberg/encryption/standard_encryption_manager.h" + +namespace iceberg { + +Result> EncryptionUtil::DecryptManifestListKeyMetadata( + const std::shared_ptr& manager, + std::string_view manifest_list_key_id) { + auto* standard = dynamic_cast(manager.get()); + if (standard == nullptr) { + return NotSupported( + "Manifest list key metadata decryption requires StandardEncryptionManager"); + } + return standard->DecryptManifestListKeyMetadata(manifest_list_key_id); +} + +} // namespace iceberg diff --git a/src/iceberg/encryption/encryption_util.h b/src/iceberg/encryption/encryption_util.h new file mode 100644 index 0000000000..d8c9ff1e08 --- /dev/null +++ b/src/iceberg/encryption/encryption_util.h @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/encryption_util.h +/// Helpers that reach standard-specific encryption operations through the generic +/// EncryptionManager interface, mirroring Java's EncryptionUtil. + +#include +#include +#include +#include + +#include "iceberg/encryption/encryption_manager.h" +#include "iceberg/iceberg_bundle_export.h" +#include "iceberg/result.h" + +namespace iceberg { + +/// \brief Standard-specific operations reached through a generic EncryptionManager. +class ICEBERG_BUNDLE_EXPORT EncryptionUtil { + public: + /// \brief Decrypt manifest list key metadata, as stored in a snapshot's `key-id`. + /// + /// Fails with NotSupported if manager is not backed by StandardEncryptionManager. + static Result> DecryptManifestListKeyMetadata( + const std::shared_ptr& manager, + std::string_view manifest_list_key_id); +}; + +} // namespace iceberg diff --git a/src/iceberg/encryption/standard_encryption_manager.cc b/src/iceberg/encryption/standard_encryption_manager.cc index fc4356758f..5f637c726b 100644 --- a/src/iceberg/encryption/standard_encryption_manager.cc +++ b/src/iceberg/encryption/standard_encryption_manager.cc @@ -211,8 +211,7 @@ Result StandardEncryptionManager::CurrentKekId() { return kek_id; } -Result -StandardEncryptionManager::RegisterManifestListKeyMetadata( +Result StandardEncryptionManager::RegisterManifestListKeyMetadata( const StandardKeyMetadata& key_metadata) { ICEBERG_PRECHECK(key_metadata.file_length.has_value(), "Manifest list key metadata must include the file length"); @@ -230,8 +229,25 @@ StandardEncryptionManager::RegisterManifestListKeyMetadata( .encrypted_key_metadata = ToString(encrypted), .encrypted_by_id = kek_id}; AddKey(file_key); - return ManifestListEncryptionKeys{.key_encryption_key = keys_.at(kek_id), - .file_key = std::move(file_key)}; + return FileEncryptionKeys{.key_encryption_key = keys_.at(kek_id), + .file_key = std::move(file_key)}; +} + +Result> StandardEncryptionManager::Decrypt( + std::unique_ptr encrypted) { + ICEBERG_PRECHECK(encrypted != nullptr, "Encrypted input file cannot be null"); + std::vector key_metadata = encrypted->key_metadata().buffer(); + return NewDecryptingInputFile(encrypted->ReleaseInputFile(), key_metadata); +} + +Result> StandardEncryptionManager::Encrypt( + std::unique_ptr plain) { + ICEBERG_ASSIGN_OR_RAISE(auto key_metadata, NewKeyMetadata()); + ICEBERG_ASSIGN_OR_RAISE(auto encrypting_output_file, + NewEncryptingOutputFile(std::move(plain), key_metadata)); + return std::make_unique( + std::move(encrypting_output_file), + std::make_shared(key_metadata.Serialize())); } std::vector StandardEncryptionManager::encryption_keys() const { diff --git a/src/iceberg/encryption/standard_encryption_manager.h b/src/iceberg/encryption/standard_encryption_manager.h index 19a242dec1..4aa2410967 100644 --- a/src/iceberg/encryption/standard_encryption_manager.h +++ b/src/iceberg/encryption/standard_encryption_manager.h @@ -30,10 +30,19 @@ #include #include "iceberg/encryption/encryption_manager.h" +#include "iceberg/encryption/standard_key_metadata.h" #include "iceberg/iceberg_bundle_export.h" namespace iceberg { +/// \brief The two keys produced by registering a manifest list's key metadata. +struct ICEBERG_BUNDLE_EXPORT FileEncryptionKeys { + /// The key encryption key, wrapped by the table master key in the KMS. + EncryptedKey key_encryption_key; + /// The manifest list key metadata, encrypted by the key encryption key. + EncryptedKey file_key; +}; + /// \brief Standard Iceberg envelope encryption. /// /// Key hierarchy: @@ -57,17 +66,21 @@ class ICEBERG_BUNDLE_EXPORT StandardEncryptionManager : public EncryptionManager static Result> Make( EncryptionManagerRegistry::Options options); - Result NewKeyMetadata() override; + // EncryptionManager + Result> Decrypt( + std::unique_ptr encrypted) override; + Result> Encrypt( + std::unique_ptr plain) override; + + Result NewKeyMetadata(); Result> NewDecryptingInputFile( - std::unique_ptr encrypted, - std::span key_metadata) override; + std::unique_ptr encrypted, std::span key_metadata); Result> NewEncryptingOutputFile( - std::unique_ptr plain, - const StandardKeyMetadata& key_metadata) override; + std::unique_ptr plain, const StandardKeyMetadata& key_metadata); Result> DecryptManifestListKeyMetadata( - std::string_view manifest_list_key_id) override; - Result RegisterManifestListKeyMetadata( - const StandardKeyMetadata& key_metadata) override; + std::string_view manifest_list_key_id); + Result RegisterManifestListKeyMetadata( + const StandardKeyMetadata& key_metadata); /// \brief All keys: those from table metadata and those created by this manager. std::vector encryption_keys() const; diff --git a/src/iceberg/encryption/standard_key_metadata.h b/src/iceberg/encryption/standard_key_metadata.h index 7e788eae56..47e8507a60 100644 --- a/src/iceberg/encryption/standard_key_metadata.h +++ b/src/iceberg/encryption/standard_key_metadata.h @@ -27,6 +27,7 @@ #include #include +#include "iceberg/encryption/encryption_key_metadata.h" #include "iceberg/iceberg_export.h" #include "iceberg/result.h" @@ -46,7 +47,7 @@ namespace iceberg { /// version (1) followed by an Avro binary encoded record with the fields /// `encryption_key: bytes`, `aad_prefix: union{null, bytes}` and /// `file_length: union{null, long}`. -struct ICEBERG_EXPORT StandardKeyMetadata { +struct ICEBERG_EXPORT StandardKeyMetadata : public NativeEncryptionKeyMetadata { static constexpr uint8_t kV1 = 1; /// \brief The data encryption key (16, 24 or 32 bytes). @@ -56,6 +57,16 @@ struct ICEBERG_EXPORT StandardKeyMetadata { /// \brief The encrypted (stored) file length, required to read AES GCM streams. std::optional file_length; + StandardKeyMetadata() = default; + + explicit StandardKeyMetadata( + std::vector encryption_key, + std::optional> aad_prefix = std::nullopt, + std::optional file_length = std::nullopt) + : encryption_key(std::move(encryption_key)), + aad_prefix(std::move(aad_prefix)), + file_length(file_length) {} + /// \brief Parse serialized key metadata. static Result Parse(std::span buffer); @@ -65,8 +76,16 @@ struct ICEBERG_EXPORT StandardKeyMetadata { /// \brief Return a copy with the given encrypted file length. StandardKeyMetadata WithFileLength(int64_t length) const; - friend bool operator==(const StandardKeyMetadata&, - const StandardKeyMetadata&) = default; + std::vector buffer() const override { return Serialize(); } + const std::vector& EncryptionKey() const override { return encryption_key; } + const std::optional>& AadPrefix() const override { + return aad_prefix; + } + + friend bool operator==(const StandardKeyMetadata& lhs, const StandardKeyMetadata& rhs) { + return lhs.encryption_key == rhs.encryption_key && lhs.aad_prefix == rhs.aad_prefix && + lhs.file_length == rhs.file_length; + } }; } // namespace iceberg diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc index 9bc7fe9479..3f40151d16 100644 --- a/src/iceberg/test/standard_encryption_manager_test.cc +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -24,6 +24,7 @@ #include #include "iceberg/encryption/encryption_register.h" +#include "iceberg/encryption/encryption_util.h" #include "iceberg/encryption/in_memory_kms.h" #include "iceberg/snapshot.h" #include "iceberg/table_metadata.h" @@ -90,8 +91,8 @@ TEST(StandardEncryptionManagerTest, DecryptsJavaManifestListKeys) { for (const auto& snapshot : metadata->snapshots) { ASSERT_TRUE(snapshot->key_id.has_value()); - ICEBERG_UNWRAP_OR_FAIL(auto decrypted, - manager->DecryptManifestListKeyMetadata(*snapshot->key_id)); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, EncryptionUtil::DecryptManifestListKeyMetadata( + manager, *snapshot->key_id)); ICEBERG_UNWRAP_OR_FAIL(auto key_metadata, StandardKeyMetadata::Parse(decrypted)); EXPECT_EQ(key_metadata.encryption_key.size(), 16); EXPECT_EQ(key_metadata.aad_prefix->size(), 16); @@ -148,9 +149,7 @@ TEST(StandardEncryptionManagerTest, RotatesKeyEncryptionKeys) { auto kms = MakeKms(); ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( {.table_key_id = "keyA", .kms = kms})); - StandardKeyMetadata key_metadata{.encryption_key = VectorBytes(16, 1), - .aad_prefix = VectorBytes(16, 2), - .file_length = 100}; + StandardKeyMetadata key_metadata(VectorBytes(16, 1), VectorBytes(16, 2), 100); ICEBERG_UNWRAP_OR_FAIL(auto first, manager->RegisterManifestListKeyMetadata(key_metadata)); @@ -175,9 +174,7 @@ TEST(StandardEncryptionManagerTest, IgnoresOutOfRangeKeyTimestamp) { auto kms = MakeKms(); ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( {.table_key_id = "keyA", .kms = kms})); - StandardKeyMetadata key_metadata{.encryption_key = VectorBytes(16, 1), - .aad_prefix = VectorBytes(16, 2), - .file_length = 100}; + StandardKeyMetadata key_metadata(VectorBytes(16, 1), VectorBytes(16, 2), 100); ICEBERG_UNWRAP_OR_FAIL(auto first, manager->RegisterManifestListKeyMetadata(key_metadata)); EXPECT_EQ(kms->wraps, 1); @@ -224,7 +221,7 @@ TEST(StandardEncryptionManagerTest, DecryptingFileRequiresLength) { auto kms = MakeKms(); ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( {.table_key_id = "keyA", .kms = kms})); - StandardKeyMetadata no_length{.encryption_key = VectorBytes(16, 1)}; + StandardKeyMetadata no_length(VectorBytes(16, 1)); class NullInputFile : public InputFile { public: diff --git a/src/iceberg/test/standard_key_metadata_test.cc b/src/iceberg/test/standard_key_metadata_test.cc index dd83c1ce34..695b94dab8 100644 --- a/src/iceberg/test/standard_key_metadata_test.cc +++ b/src/iceberg/test/standard_key_metadata_test.cc @@ -75,7 +75,7 @@ TEST(StandardKeyMetadataTest, ParseJavaVectors) { } TEST(StandardKeyMetadataTest, RoundTrip) { - StandardKeyMetadata metadata{.encryption_key = TestBytes(32, 7)}; + StandardKeyMetadata metadata(TestBytes(32, 7)); ICEBERG_UNWRAP_OR_FAIL(auto parsed, StandardKeyMetadata::Parse(metadata.Serialize())); EXPECT_EQ(parsed, metadata); @@ -90,8 +90,7 @@ TEST(StandardKeyMetadataTest, RoundTrip) { } // A present but empty AAD prefix is distinct from an absent one - StandardKeyMetadata empty_aad{.encryption_key = TestBytes(16, 7), - .aad_prefix = std::vector{}}; + StandardKeyMetadata empty_aad(TestBytes(16, 7), std::vector{}); ICEBERG_UNWRAP_OR_FAIL(auto parsed_empty, StandardKeyMetadata::Parse(empty_aad.Serialize())); ASSERT_TRUE(parsed_empty.aad_prefix.has_value()); From 6723b0f9cb15d86129347618a202d35966514082 Mon Sep 17 00:00:00 2001 From: shangxinli Date: Fri, 27 Nov 2026 14:47:29 -0800 Subject: [PATCH 6/9] fix(encryption): follow Java two-path contract for native key metadata and files - Native wrappers are now abstract: the raw/plain file plus key metadata is the native path, the InputFile/OutputFile methods are the AGS1 stream path. - StandardEncryptionManager::Encrypt/Decrypt return such wrappers; the AGS1 reader is built lazily, so native reads no longer require a file length, and a NativeEncryptionInputFile passed to Decrypt is returned unchanged. - Add FileLength/CopyWithLength to NativeEncryptionKeyMetadata and implement them in StandardKeyMetadata. - Distinguish absent from present-but-empty key metadata (has_value, Empty, Copy). - Expose the batch Encrypt/Decrypt overloads in both managers. --- src/iceberg/encryption/encrypted_file.h | 78 ++--- .../encryption/encryption_key_metadata.h | 53 +++- src/iceberg/encryption/encryption_manager.cc | 5 +- src/iceberg/encryption/encryption_manager.h | 4 + .../encryption/standard_encryption_manager.cc | 127 ++++++++- .../encryption/standard_encryption_manager.h | 20 +- .../encryption/standard_key_metadata.h | 9 + .../test/standard_encryption_manager_test.cc | 268 ++++++++++++++++++ 8 files changed, 500 insertions(+), 64 deletions(-) diff --git a/src/iceberg/encryption/encrypted_file.h b/src/iceberg/encryption/encrypted_file.h index 26461464c2..e49cc77fbc 100644 --- a/src/iceberg/encryption/encrypted_file.h +++ b/src/iceberg/encryption/encrypted_file.h @@ -63,38 +63,21 @@ class ICEBERG_EXPORT BaseEncryptedInputFile : public EncryptedInputFile { std::shared_ptr key_metadata_; }; -/// \brief An encrypted input file for formats, such as Parquet, that perform their own -/// native (modular) decryption rather than using the AGS1 stream format. +/// \brief An encrypted input file that supports both read paths of Java's +/// NativeEncryptionInputFile. /// -/// Also implements InputFile so that the still-encrypted bytes remain directly -/// readable; the native reader uses key_metadata() to obtain the key parameters needed -/// to decrypt the individual modules it reads. +/// - Native path, for formats such as Parquet that perform their own modular decryption: +/// ReleaseInputFile() gives the still-encrypted raw file and key_metadata() gives the +/// key parameters (and AAD prefix) the native reader needs. +/// - Stream path: the InputFile methods read the file as an AES GCM stream (AGS1), +/// decrypting it, and require the encrypted file length in the key metadata. +/// +/// Implementations may defer building the stream reader until the InputFile methods are +/// first used, so native-only callers are not subject to the stream path's requirements. class ICEBERG_EXPORT NativeEncryptionInputFile : public EncryptedInputFile, public InputFile { public: - NativeEncryptionInputFile(std::unique_ptr encrypted_file, - std::shared_ptr key_metadata) - : encrypted_file_(std::move(encrypted_file)), - key_metadata_(std::move(key_metadata)) {} - - // EncryptedInputFile - std::unique_ptr ReleaseInputFile() override { - return std::move(encrypted_file_); - } - const NativeEncryptionKeyMetadata& key_metadata() const override { - return *key_metadata_; - } - - // InputFile, passed through to the still-encrypted raw file. - std::string_view location() const override { return encrypted_file_->location(); } - Result Size() const override { return encrypted_file_->Size(); } - Result> Open() override { - return encrypted_file_->Open(); - } - - private: - std::unique_ptr encrypted_file_; - std::shared_ptr key_metadata_; + const NativeEncryptionKeyMetadata& key_metadata() const override = 0; }; /// \brief An encrypting output file together with the key metadata that was used (or @@ -128,37 +111,32 @@ class ICEBERG_EXPORT BaseEncryptedOutputFile : public EncryptedOutputFile { std::shared_ptr key_metadata_; }; -/// \brief An encrypted output file for formats, such as Parquet, that perform their own -/// native (modular) encryption rather than using the AGS1 stream format. +/// \brief An encrypting output file that supports both write paths of Java's +/// NativeEncryptionOutputFile. /// -/// Also implements OutputFile so the plaintext bytes can be written directly; the -/// native writer uses key_metadata() to obtain the key parameters it needs to encrypt -/// the individual modules it writes. +/// - Native path, for formats such as Parquet that perform their own modular encryption: +/// plain_output_file() gives the file to write the (already encrypted) bytes to and +/// key_metadata() gives the key parameters (and AAD prefix) the native writer needs. +/// - Stream path: encrypting_output_file(), and the OutputFile methods that delegate to +/// it, write the file as an AES GCM stream (AGS1). class ICEBERG_EXPORT NativeEncryptionOutputFile : public EncryptedOutputFile, public OutputFile { public: - NativeEncryptionOutputFile(std::unique_ptr plain_file, - std::shared_ptr key_metadata) - : plain_file_(std::move(plain_file)), key_metadata_(std::move(key_metadata)) {} - - // EncryptedOutputFile - OutputFile& encrypting_output_file() const override { return *plain_file_; } - const NativeEncryptionKeyMetadata& key_metadata() const override { - return *key_metadata_; - } + /// \brief The underlying plain output file, for native writers. + virtual OutputFile& plain_output_file() const = 0; - // OutputFile, passed through to the plaintext file that the native writer fills in. - std::string_view location() const override { return plain_file_->location(); } + const NativeEncryptionKeyMetadata& key_metadata() const override = 0; + + // OutputFile, delegating to the stream path. + std::string_view location() const override { + return encrypting_output_file().location(); + } Result> Create() override { - return plain_file_->Create(); + return encrypting_output_file().Create(); } Result> CreateOrOverwrite() override { - return plain_file_->CreateOrOverwrite(); + return encrypting_output_file().CreateOrOverwrite(); } - - private: - std::unique_ptr plain_file_; - std::shared_ptr key_metadata_; }; } // namespace iceberg diff --git a/src/iceberg/encryption/encryption_key_metadata.h b/src/iceberg/encryption/encryption_key_metadata.h index a169fc727e..c780594ad4 100644 --- a/src/iceberg/encryption/encryption_key_metadata.h +++ b/src/iceberg/encryption/encryption_key_metadata.h @@ -23,11 +23,13 @@ /// Opaque, serialized key metadata, mirroring Java's EncryptionKeyMetadata. #include +#include #include #include #include #include "iceberg/iceberg_export.h" +#include "iceberg/result.h" namespace iceberg { @@ -44,18 +46,46 @@ class ICEBERG_EXPORT EncryptionKeyMetadata { /// Implementations must not cache this value if their fields can change after /// construction; it is recomputed on every call where that matters. virtual std::vector buffer() const = 0; + + /// \brief Whether key metadata is present. + /// + /// Absent key metadata (as for unencrypted files) has an empty buffer(), but so can + /// present key metadata that is zero bytes long; this tells the two apart. + virtual bool has_value() const { return true; } + + /// \brief A copy of this key metadata. + virtual std::shared_ptr Copy() const = 0; }; /// \brief EncryptionKeyMetadata backed by a fixed, already-serialized buffer. +/// +/// The buffer is optional so that absent key metadata (Empty(), as used for unencrypted +/// files) can be told apart from present key metadata that happens to be zero bytes long. class ICEBERG_EXPORT BaseEncryptionKeyMetadata : public EncryptionKeyMetadata { public: - explicit BaseEncryptionKeyMetadata(std::vector buffer) + /// \brief Key metadata with the given bytes; a zero-length buffer is still present. + explicit BaseEncryptionKeyMetadata(std::optional> buffer) : buffer_(std::move(buffer)) {} - std::vector buffer() const override { return buffer_; } + /// \brief Absent key metadata. + static std::shared_ptr Empty() { + return std::make_shared(std::nullopt); + } + + /// \brief Whether key metadata is present, even if it is zero bytes long. + bool has_value() const override { return buffer_.has_value(); } + + /// \brief The key metadata bytes, or an empty buffer if absent. + std::vector buffer() const override { + return buffer_.value_or(std::vector{}); + } + + std::shared_ptr Copy() const override { + return std::make_shared(*this); + } private: - std::vector buffer_; + std::optional> buffer_; }; /// \brief Key metadata for the native (AES-GCM) encryption key parameters. @@ -70,6 +100,23 @@ class ICEBERG_EXPORT NativeEncryptionKeyMetadata : public EncryptionKeyMetadata /// \brief The AAD prefix (file ID) used to bind ciphertext to this file, if any. virtual const std::optional>& AadPrefix() const = 0; + + /// \brief The encrypted (stored) file length, or nullopt if not yet known. + /// + /// Returns NotSupported unless the implementation tracks a file length. + virtual Result> FileLength() const { + return NotSupported("FileLength is not implemented by this key metadata"); + } + + /// \brief A copy of this key metadata, with the same key and AAD prefix, that records + /// the given encrypted file length. + /// + /// Writers call this after closing the file, once the stored length is known. Returns + /// NotSupported unless the implementation tracks a file length. + virtual Result> CopyWithLength( + int64_t length) const { + return NotSupported("CopyWithLength is not implemented by this key metadata"); + } }; } // namespace iceberg diff --git a/src/iceberg/encryption/encryption_manager.cc b/src/iceberg/encryption/encryption_manager.cc index 6702e63ef5..538720d424 100644 --- a/src/iceberg/encryption/encryption_manager.cc +++ b/src/iceberg/encryption/encryption_manager.cc @@ -54,9 +54,8 @@ Result> PlaintextEncryptionManager::Decrypt( Result> PlaintextEncryptionManager::Encrypt( std::unique_ptr plain) { - return std::make_unique( - std::move(plain), - std::make_shared(std::vector{})); + return std::make_unique(std::move(plain), + BaseEncryptionKeyMetadata::Empty()); } namespace { diff --git a/src/iceberg/encryption/encryption_manager.h b/src/iceberg/encryption/encryption_manager.h index e7e79a22ca..c6cde92c7f 100644 --- a/src/iceberg/encryption/encryption_manager.h +++ b/src/iceberg/encryption/encryption_manager.h @@ -74,6 +74,10 @@ class ICEBERG_EXPORT EncryptionManager { /// them. class ICEBERG_EXPORT PlaintextEncryptionManager : public EncryptionManager { public: + // Keep the batch overloads visible: overriding the single-file ones would hide them. + using EncryptionManager::Decrypt; + using EncryptionManager::Encrypt; + Result> Decrypt( std::unique_ptr encrypted) override; diff --git a/src/iceberg/encryption/standard_encryption_manager.cc b/src/iceberg/encryption/standard_encryption_manager.cc index 5f637c726b..97fe947eb9 100644 --- a/src/iceberg/encryption/standard_encryption_manager.cc +++ b/src/iceberg/encryption/standard_encryption_manager.cc @@ -63,6 +63,113 @@ std::optional ParseTimestamp(const EncryptedKey& key) { return value; } +// Forwards to a file owned elsewhere, so one underlying file can serve both the native +// path and the AGS1 stream path of a Native wrapper. +class SharedInputFile : public InputFile { + public: + explicit SharedInputFile(std::shared_ptr file) : file_(std::move(file)) {} + + std::string_view location() const override { return file_->location(); } + Result Size() const override { return file_->Size(); } + Result> Open() override { return file_->Open(); } + + private: + std::shared_ptr file_; +}; + +class SharedOutputFile : public OutputFile { + public: + explicit SharedOutputFile(std::shared_ptr file) : file_(std::move(file)) {} + + std::string_view location() const override { return file_->location(); } + Result> Create() override { + return file_->Create(); + } + Result> CreateOrOverwrite() override { + return file_->CreateOrOverwrite(); + } + + private: + std::shared_ptr file_; +}; + +// Mirrors Java's StandardDecryptedInputFile: the raw file and key metadata are available +// to native readers right away, while the AGS1 reader, which needs the encrypted file +// length from the key metadata, is built on first use of the InputFile methods. +class StandardDecryptedInputFile : public NativeEncryptionInputFile { + public: + StandardDecryptedInputFile(std::shared_ptr raw, StandardKeyMetadata metadata) + : raw_(std::move(raw)), metadata_(std::move(metadata)) {} + + std::unique_ptr ReleaseInputFile() override { + return std::make_unique(raw_); + } + const NativeEncryptionKeyMetadata& key_metadata() const override { return metadata_; } + + std::string_view location() const override { return raw_->location(); } + Result Size() const override { + ICEBERG_ASSIGN_OR_RAISE(auto file, Decrypting()); + return file->Size(); + } + Result> Open() override { + ICEBERG_ASSIGN_OR_RAISE(auto file, Decrypting()); + return file->Open(); + } + + private: + Result Decrypting() const { + if (decrypting_ == nullptr) { + if (!metadata_.file_length.has_value()) { + // The length must come from trusted key metadata, not from the file system, so + // that truncation is detected (format/gcm-stream-spec.md, "File length"). + return Invalid("Cannot read AES GCM stream {}: key metadata has no file length", + raw_->location()); + } + decrypting_ = std::make_unique( + std::make_unique(raw_), metadata_.encryption_key, + metadata_.aad_prefix.value_or(std::vector{}), *metadata_.file_length); + } + return decrypting_.get(); + } + + std::shared_ptr raw_; + StandardKeyMetadata metadata_; + mutable std::unique_ptr decrypting_; +}; + +// Mirrors Java's StandardEncryptedOutputFile: native writers use the plain file and the +// key metadata; the AGS1 writer over the same file and key is built on first use. +class StandardEncryptedOutputFile : public NativeEncryptionOutputFile { + public: + StandardEncryptedOutputFile(std::shared_ptr plain, + StandardKeyMetadata metadata) + : plain_(std::move(plain)), metadata_(std::move(metadata)) {} + + OutputFile& plain_output_file() const override { return *plain_; } + OutputFile& encrypting_output_file() const override { + if (encrypting_ == nullptr) { + encrypting_ = std::make_unique( + std::make_unique(plain_), metadata_.encryption_key, + metadata_.aad_prefix.value_or(std::vector{})); + } + return *encrypting_; + } + const NativeEncryptionKeyMetadata& key_metadata() const override { return metadata_; } + + private: + std::shared_ptr plain_; + StandardKeyMetadata metadata_; + mutable std::unique_ptr encrypting_; +}; + +Result CastOrParse(const EncryptionKeyMetadata& key_metadata) { + if (const auto* standard = dynamic_cast(&key_metadata)) { + return *standard; + } + auto buffer = key_metadata.buffer(); + return StandardKeyMetadata::Parse(buffer); +} + } // namespace Result> StandardEncryptionManager::Make( @@ -236,18 +343,24 @@ Result StandardEncryptionManager::RegisterManifestListKeyMet Result> StandardEncryptionManager::Decrypt( std::unique_ptr encrypted) { ICEBERG_PRECHECK(encrypted != nullptr, "Encrypted input file cannot be null"); - std::vector key_metadata = encrypted->key_metadata().buffer(); - return NewDecryptingInputFile(encrypted->ReleaseInputFile(), key_metadata); + // A native wrapper already carries both the native and the stream path. + if (auto* native = dynamic_cast(encrypted.get())) { + encrypted.release(); + return std::unique_ptr(native); + } + ICEBERG_ASSIGN_OR_RAISE(auto metadata, CastOrParse(encrypted->key_metadata())); + std::shared_ptr raw = encrypted->ReleaseInputFile(); + ICEBERG_PRECHECK(raw != nullptr, "Encrypted input file has no underlying file"); + return std::make_unique(std::move(raw), + std::move(metadata)); } Result> StandardEncryptionManager::Encrypt( std::unique_ptr plain) { + ICEBERG_PRECHECK(plain != nullptr, "Output file cannot be null"); ICEBERG_ASSIGN_OR_RAISE(auto key_metadata, NewKeyMetadata()); - ICEBERG_ASSIGN_OR_RAISE(auto encrypting_output_file, - NewEncryptingOutputFile(std::move(plain), key_metadata)); - return std::make_unique( - std::move(encrypting_output_file), - std::make_shared(key_metadata.Serialize())); + return std::make_unique(std::move(plain), + std::move(key_metadata)); } std::vector StandardEncryptionManager::encryption_keys() const { diff --git a/src/iceberg/encryption/standard_encryption_manager.h b/src/iceberg/encryption/standard_encryption_manager.h index 4aa2410967..18bd5f7861 100644 --- a/src/iceberg/encryption/standard_encryption_manager.h +++ b/src/iceberg/encryption/standard_encryption_manager.h @@ -66,9 +66,27 @@ class ICEBERG_BUNDLE_EXPORT StandardEncryptionManager : public EncryptionManager static Result> Make( EncryptionManagerRegistry::Options options); - // EncryptionManager + // EncryptionManager. The batch overloads are re-exposed because overriding the + // single-file ones would otherwise hide them from callers of the concrete type. + using EncryptionManager::Decrypt; + using EncryptionManager::Encrypt; + + /// \brief Decrypt a file. + /// + /// If the argument is already a NativeEncryptionInputFile it is returned unchanged. + /// Otherwise the result is a NativeEncryptionInputFile (callers can dynamic_cast to it + /// to reach the native path) whose key metadata is parsed here but whose AGS1 stream + /// reader is only built when the file is opened or sized; only that stream path needs + /// the key metadata to carry the encrypted file length. Result> Decrypt( std::unique_ptr encrypted) override; + + /// \brief Wrap a plain output file for encryption. + /// + /// The result is a NativeEncryptionOutputFile (callers can dynamic_cast to it to reach + /// the native path): plain_output_file() is the plain file for native writers, and + /// encrypting_output_file() writes an AGS1 stream with the same key and AAD prefix. + /// Neither is thread-safe. Result> Encrypt( std::unique_ptr plain) override; diff --git a/src/iceberg/encryption/standard_key_metadata.h b/src/iceberg/encryption/standard_key_metadata.h index 47e8507a60..f304ee1d68 100644 --- a/src/iceberg/encryption/standard_key_metadata.h +++ b/src/iceberg/encryption/standard_key_metadata.h @@ -23,6 +23,7 @@ /// Key metadata of the standard Iceberg encryption scheme. #include +#include #include #include #include @@ -77,10 +78,18 @@ struct ICEBERG_EXPORT StandardKeyMetadata : public NativeEncryptionKeyMetadata { StandardKeyMetadata WithFileLength(int64_t length) const; std::vector buffer() const override { return Serialize(); } + std::shared_ptr Copy() const override { + return std::make_shared(*this); + } const std::vector& EncryptionKey() const override { return encryption_key; } const std::optional>& AadPrefix() const override { return aad_prefix; } + Result> FileLength() const override { return file_length; } + Result> CopyWithLength( + int64_t length) const override { + return std::make_shared(WithFileLength(length)); + } friend bool operator==(const StandardKeyMetadata& lhs, const StandardKeyMetadata& rhs) { return lhs.encryption_key == rhs.encryption_key && lhs.aad_prefix == rhs.aad_prefix && diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc index 3f40151d16..db01f3ddd2 100644 --- a/src/iceberg/test/standard_encryption_manager_test.cc +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -20,15 +20,20 @@ #include "iceberg/encryption/standard_encryption_manager.h" #include +#include +#include #include +#include "iceberg/arrow/arrow_io_util.h" +#include "iceberg/encryption/encrypted_files.h" #include "iceberg/encryption/encryption_register.h" #include "iceberg/encryption/encryption_util.h" #include "iceberg/encryption/in_memory_kms.h" #include "iceberg/snapshot.h" #include "iceberg/table_metadata.h" #include "iceberg/test/matchers.h" +#include "iceberg/test/temp_file_test_base.h" #include "iceberg/test/test_resource.h" namespace iceberg { @@ -236,6 +241,269 @@ TEST(StandardEncryptionManagerTest, DecryptingFileRequiresLength) { IsError(ErrorKind::kInvalid)); } +namespace { + +Result> ReadAll(InputFile& file) { + ICEBERG_ASSIGN_OR_RAISE(auto size, file.Size()); + ICEBERG_ASSIGN_OR_RAISE(auto stream, file.Open()); + std::vector out(size); + if (size > 0) { + ICEBERG_RETURN_UNEXPECTED( + stream->ReadFully(0, std::as_writable_bytes(std::span(out)))); + } + return out; +} + +/// A NativeEncryptionKeyMetadata that implements nothing beyond the required members. +class MinimalNativeKeyMetadata : public NativeEncryptionKeyMetadata { + public: + std::vector buffer() const override { return key_; } + std::shared_ptr Copy() const override { + return std::make_shared(*this); + } + const std::vector& EncryptionKey() const override { return key_; } + const std::optional>& AadPrefix() const override { return aad_; } + + private: + std::vector key_ = VectorBytes(16, 1); + std::optional> aad_; +}; + +class StandardEncryptionManagerFileTest : public TempFileTestBase { + protected: + void SetUp() override { + TempFileTestBase::SetUp(); + io_ = std::shared_ptr(arrow::MakeLocalFileIO()); + } + + std::shared_ptr NewManager() { + auto manager = + StandardEncryptionManager::Make({.table_key_id = "keyA", .kms = MakeKms()}); + EXPECT_THAT(manager, IsOk()); + return manager.value(); + } + + std::unique_ptr NewOut(const std::string& path) { + auto out = io_->NewOutputFile(path); + EXPECT_THAT(out, IsOk()); + return std::move(out.value()); + } + + std::unique_ptr NewIn(const std::string& path) { + auto in = io_->NewInputFile(path); + EXPECT_THAT(in, IsOk()); + return std::move(in.value()); + } + + std::string WriteRaw(const std::vector& bytes) { + auto path = CreateNewTempFilePath(); + std::ofstream out(path, std::ios::binary); + out.write(reinterpret_cast(bytes.data()), + static_cast(bytes.size())); + return path; + } + + /// Encrypt and decrypt two files through the batch overloads of `manager`. + template + void RoundTripBatch(Manager& manager) { + const std::vector> plains = {VectorBytes(100, 1), + VectorBytes(3000, 2)}; + std::vector paths = {CreateNewTempFilePath(), CreateNewTempFilePath()}; + std::vector> outs; + for (const auto& path : paths) { + outs.push_back(NewOut(path)); + } + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager.Encrypt(std::move(outs))); + ASSERT_EQ(encrypted.size(), 2u); + + std::vector> ins; + for (size_t i = 0; i < encrypted.size(); ++i) { + ICEBERG_UNWRAP_OR_FAIL(auto stream, + encrypted[i]->encrypting_output_file().CreateOrOverwrite()); + ASSERT_THAT(stream->Write(std::as_bytes(std::span(plains[i]))), IsOk()); + ASSERT_THAT(stream->Close(), IsOk()); + ICEBERG_UNWRAP_OR_FAIL(auto stored, stream->StoredLength()); + + std::shared_ptr key_metadata; + if (const auto* native = dynamic_cast( + &encrypted[i]->key_metadata())) { + ICEBERG_UNWRAP_OR_FAIL(auto with_length, native->CopyWithLength(stored)); + key_metadata = with_length; + } else { + key_metadata = encrypted[i]->key_metadata().Copy(); + } + ins.push_back(EncryptedFiles::Encrypted(NewIn(paths[i]), key_metadata)); + } + + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager.Decrypt(std::move(ins))); + ASSERT_EQ(decrypted.size(), 2u); + for (size_t i = 0; i < decrypted.size(); ++i) { + ICEBERG_UNWRAP_OR_FAIL(auto bytes, ReadAll(*decrypted[i])); + EXPECT_EQ(bytes, plains[i]); + } + } + + std::shared_ptr io_; +}; + +} // namespace + +TEST_F(StandardEncryptionManagerFileTest, BatchOverloadsReachableFromConcreteAndBase) { + auto standard = NewManager(); + std::shared_ptr standard_as_base = standard; + auto plaintext = std::make_shared(); + std::shared_ptr plaintext_as_base = plaintext; + + // Calls through the concrete types only compile if the batch overloads are not hidden. + RoundTripBatch(*standard); + RoundTripBatch(*standard_as_base); + RoundTripBatch(*plaintext); + RoundTripBatch(*plaintext_as_base); +} + +TEST_F(StandardEncryptionManagerFileTest, EncryptExposesNativeAndStreamPaths) { + auto manager = NewManager(); + auto path = CreateNewTempFilePath(); + const auto plain = VectorBytes(5000, 7); + + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager->Encrypt(NewOut(path))); + auto* native = dynamic_cast(encrypted.get()); + ASSERT_NE(native, nullptr); + + // Native path: the plain file, and the key parameters. + EXPECT_EQ(native->plain_output_file().location(), path); + EXPECT_NE(&native->encrypting_output_file(), &native->plain_output_file()); + const auto& key_metadata = native->key_metadata(); + EXPECT_EQ(key_metadata.EncryptionKey().size(), 16u); + ASSERT_TRUE(key_metadata.AadPrefix().has_value()); + EXPECT_EQ(key_metadata.AadPrefix()->size(), + static_cast(StandardEncryptionManager::kAadPrefixLength)); + ICEBERG_UNWRAP_OR_FAIL(auto initial_length, key_metadata.FileLength()); + EXPECT_FALSE(initial_length.has_value()); + + // Stream path: the OutputFile methods write an AGS1 stream. + EXPECT_EQ(native->location(), path); + ICEBERG_UNWRAP_OR_FAIL(auto stream, native->CreateOrOverwrite()); + ASSERT_THAT(stream->Write(std::as_bytes(std::span(plain))), IsOk()); + ASSERT_THAT(stream->Close(), IsOk()); + ICEBERG_UNWRAP_OR_FAIL(auto stored, stream->StoredLength()); + EXPECT_GT(stored, static_cast(plain.size())); + EXPECT_EQ(stored, static_cast(std::filesystem::file_size(path))); + + // The writer records the stored length on a copy that keeps the same key and AAD. + ICEBERG_UNWRAP_OR_FAIL(auto with_length, key_metadata.CopyWithLength(stored)); + EXPECT_EQ(with_length->EncryptionKey(), key_metadata.EncryptionKey()); + EXPECT_EQ(with_length->AadPrefix(), key_metadata.AadPrefix()); + ICEBERG_UNWRAP_OR_FAIL(auto copied_length, with_length->FileLength()); + EXPECT_EQ(copied_length, stored); + ICEBERG_UNWRAP_OR_FAIL(auto original_length, key_metadata.FileLength()); + EXPECT_FALSE(original_length.has_value()); + + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager->Decrypt(EncryptedFiles::Encrypted( + NewIn(path), with_length))); + EXPECT_NE(dynamic_cast(decrypted.get()), nullptr); + ICEBERG_UNWRAP_OR_FAIL(auto bytes, ReadAll(*decrypted)); + EXPECT_EQ(bytes, plain); +} + +TEST_F(StandardEncryptionManagerFileTest, NativeReadDoesNotRequireFileLength) { + auto manager = NewManager(); + const auto raw = VectorBytes(64, 3); + auto path = WriteRaw(raw); + auto no_length = + std::make_shared(VectorBytes(16, 1), VectorBytes(16, 2)); + + // Both an in-memory StandardKeyMetadata and its serialized form are accepted. + std::vector> variants = { + no_length, std::make_shared(no_length->Serialize())}; + for (const auto& key_metadata : variants) { + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager->Decrypt(EncryptedFiles::Encrypted( + NewIn(path), key_metadata))); + auto* native = dynamic_cast(decrypted.get()); + ASSERT_NE(native, nullptr); + EXPECT_EQ(native->key_metadata().EncryptionKey(), no_length->encryption_key); + EXPECT_EQ(native->key_metadata().AadPrefix(), no_length->aad_prefix); + + // Native path: the still-encrypted raw bytes. + auto released = native->ReleaseInputFile(); + ASSERT_NE(released, nullptr); + ICEBERG_UNWRAP_OR_FAIL(auto bytes, ReadAll(*released)); + EXPECT_EQ(bytes, raw); + + // Stream path: needs the file length. + EXPECT_THAT(native->Size(), IsError(ErrorKind::kInvalid)); + EXPECT_THAT(native->Open(), IsError(ErrorKind::kInvalid)); + } +} + +TEST_F(StandardEncryptionManagerFileTest, DecryptReturnsNativeInputUnchanged) { + auto manager = NewManager(); + auto path = WriteRaw(VectorBytes(64, 3)); + auto key_metadata = + std::make_shared(VectorBytes(16, 1), VectorBytes(16, 2)); + + ICEBERG_UNWRAP_OR_FAIL( + auto first, manager->Decrypt(EncryptedFiles::Encrypted(NewIn(path), key_metadata))); + auto* native = dynamic_cast(first.release()); + ASSERT_NE(native, nullptr); + + ICEBERG_UNWRAP_OR_FAIL(auto second, + manager->Decrypt(std::unique_ptr(native))); + EXPECT_EQ(dynamic_cast(second.get()), native); +} + +TEST(NativeEncryptionKeyMetadataTest, StandardKeyMetadataCopiesWithLength) { + StandardKeyMetadata metadata(VectorBytes(16, 1), VectorBytes(16, 2)); + ICEBERG_UNWRAP_OR_FAIL(auto no_length, metadata.FileLength()); + EXPECT_FALSE(no_length.has_value()); + + ICEBERG_UNWRAP_OR_FAIL(auto copy, metadata.CopyWithLength(4242)); + EXPECT_EQ(copy->EncryptionKey(), metadata.encryption_key); + EXPECT_EQ(copy->AadPrefix(), metadata.aad_prefix); + ICEBERG_UNWRAP_OR_FAIL(auto length, copy->FileLength()); + EXPECT_EQ(length, 4242); + EXPECT_FALSE(metadata.file_length.has_value()); +} + +TEST(NativeEncryptionKeyMetadataTest, FileLengthIsNotSupportedByDefault) { + MinimalNativeKeyMetadata metadata; + EXPECT_THAT(metadata.FileLength(), IsError(ErrorKind::kNotSupported)); + EXPECT_THAT(metadata.CopyWithLength(1), IsError(ErrorKind::kNotSupported)); +} + +TEST(BaseEncryptionKeyMetadataTest, DistinguishesAbsentFromEmpty) { + auto absent = BaseEncryptionKeyMetadata::Empty(); + BaseEncryptionKeyMetadata empty_bytes(std::vector{}); + BaseEncryptionKeyMetadata some_bytes(VectorBytes(4, 1)); + + // Through the base interface, as generic code would see it. + const EncryptionKeyMetadata& absent_base = *absent; + const EncryptionKeyMetadata& empty_base = empty_bytes; + EXPECT_FALSE(absent_base.has_value()); + EXPECT_TRUE(empty_base.has_value()); + EXPECT_TRUE(some_bytes.has_value()); + EXPECT_TRUE(StandardKeyMetadata(VectorBytes(16, 1)).has_value()); + EXPECT_TRUE(absent->buffer().empty()); + EXPECT_TRUE(empty_bytes.buffer().empty()); + + // Copies preserve presence. + auto absent_copy = std::dynamic_pointer_cast(absent->Copy()); + auto empty_copy = + std::dynamic_pointer_cast(empty_bytes.Copy()); + ASSERT_NE(absent_copy, nullptr); + ASSERT_NE(empty_copy, nullptr); + EXPECT_FALSE(absent_copy->has_value()); + EXPECT_TRUE(empty_copy->has_value()); + EXPECT_EQ(some_bytes.Copy()->buffer(), some_bytes.buffer()); +} + +TEST_F(StandardEncryptionManagerFileTest, PlaintextManagerReportsAbsentKeyMetadata) { + PlaintextEncryptionManager manager; + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, + manager.Encrypt(NewOut(CreateNewTempFilePath()))); + EXPECT_FALSE(encrypted->key_metadata().has_value()); +} + TEST(EncryptionManagerRegistryTest, ValidatesOptions) { encryption::RegisterAll(); EXPECT_TRUE(encryption::IsEncryptionAvailable()); From 9523992f2346920264981c775fd34659d845bc97 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 2 Dec 2026 13:54:53 +0800 Subject: [PATCH 7/9] follow up on the encryption manager review - Rebased the branch on main. - Added EncryptionUtil::MakeEncryptionManager. It checks the KMS client first, picks plaintext when the table has no key ID, and rejects an explicitly empty ID. - Removed the registry Options struct. Factories now get the keys, table properties, and KMS client directly. Custom factories can use a null KMS; RegisterAll() preserves them, and Make() rejects a null result. - Moved DEK length parsing into the standard factory and reused the AES key-length check. Plaintext reads now warn if key metadata is present. - Renamed the wrapper factories to EncryptedInput and EncryptedOutput, moved the Base wrappers into the .cc file, and added null checks. - Replaced ReleaseInputFile() with DetachInputFile() && and added AsNative() for native input passthrough. AGS1 now opens directly from InputFile&, so the extra shared-file wrapper is gone. Output access stays borrowed. - Made StandardKeyMetadata fields private. The snake_case key and AAD getters return borrowed spans; buffer() still returns owned bytes. Added validated Make factories for metadata, AES-GCM files, and InMemoryKms. - Changed RegisterKeyMetadata to accept NativeEncryptionKeyMetadata. Writers can pass CopyWithLength() directly. Registration also works without a file length; AGS1 reads still require a trusted length. - Kept Encrypt/Decrypt as the file entry points and removed the duplicate AGS1 helpers. Made key generation and test clock controls private. Batch calls still use vectors, with a TODO for lazy streams. - Reject invalid KEK timestamps, timestamp new KEKs after KMS wrapping, and use a monotonic clock for cache expiry. Standard writes require a 16-byte AAD prefix; reads still support files without one. - Added encryption/type_fwd.h, updated header installation and C++20 coverage, and fixed the release RAT exclusion for the encryption fixtures. - Consolidated overlapping tests and moved core-only cases out of the crypto suite. Added coverage for factory selection, KEK rotation and expiry, native/AGS1 ownership, and the manifest-list write/read round trip. The interop test now opens all four Java manifest lists. --- dev/release/rat_exclude_files.txt | 1 + src/iceberg/cpp20_compatibility_internal.h | 1 + src/iceberg/encryption/CMakeLists.txt | 3 +- src/iceberg/encryption/aes_gcm_internal.h | 14 + src/iceberg/encryption/aes_gcm_stream.cc | 71 +- src/iceberg/encryption/aes_gcm_stream.h | 18 +- src/iceberg/encryption/encrypted_file.h | 61 +- src/iceberg/encryption/encrypted_files.cc | 84 ++- src/iceberg/encryption/encrypted_files.h | 21 +- .../encryption/encryption_key_metadata.h | 15 +- src/iceberg/encryption/encryption_manager.cc | 51 +- src/iceberg/encryption/encryption_manager.h | 49 +- .../encryption/encryption_manager_internal.h | 31 + src/iceberg/encryption/encryption_register.cc | 6 +- src/iceberg/encryption/encryption_register.h | 4 +- src/iceberg/encryption/encryption_util.cc | 19 + src/iceberg/encryption/encryption_util.h | 16 +- src/iceberg/encryption/in_memory_kms.cc | 21 +- src/iceberg/encryption/in_memory_kms.h | 10 +- .../encryption/standard_encryption_manager.cc | 328 ++++----- .../encryption/standard_encryption_manager.h | 71 +- .../encryption/standard_key_metadata.cc | 54 +- .../encryption/standard_key_metadata.h | 54 +- src/iceberg/encryption/type_fwd.h | 41 ++ src/iceberg/test/CMakeLists.txt | 6 +- src/iceberg/test/aes_gcm_test.cc | 60 +- src/iceberg/test/encryption_manager_test.cc | 123 ++++ .../test/standard_encryption_manager_test.cc | 653 +++++++++--------- .../test/standard_key_metadata_test.cc | 61 +- src/iceberg/type_fwd.h | 5 +- 30 files changed, 1198 insertions(+), 754 deletions(-) create mode 100644 src/iceberg/encryption/encryption_manager_internal.h create mode 100644 src/iceberg/encryption/type_fwd.h create mode 100644 src/iceberg/test/encryption_manager_test.cc diff --git a/dev/release/rat_exclude_files.txt b/dev/release/rat_exclude_files.txt index 7b5b3b10c8..07afcd6df2 100644 --- a/dev/release/rat_exclude_files.txt +++ b/dev/release/rat_exclude_files.txt @@ -27,3 +27,4 @@ requirements.txt test/resources/** *.json src/iceberg/util/murmurhash3_internal.* +src/iceberg/test/resources/encryption/** diff --git a/src/iceberg/cpp20_compatibility_internal.h b/src/iceberg/cpp20_compatibility_internal.h index 2d037bced7..93d716e950 100644 --- a/src/iceberg/cpp20_compatibility_internal.h +++ b/src/iceberg/cpp20_compatibility_internal.h @@ -56,6 +56,7 @@ #include "iceberg/encryption/encryption_manager.h" #include "iceberg/encryption/key_management_client.h" #include "iceberg/encryption/standard_key_metadata.h" +#include "iceberg/encryption/type_fwd.h" #include "iceberg/exception.h" #include "iceberg/expression/aggregate.h" #include "iceberg/expression/binder.h" diff --git a/src/iceberg/encryption/CMakeLists.txt b/src/iceberg/encryption/CMakeLists.txt index 7ddb2797cb..6b48efbc2d 100644 --- a/src/iceberg/encryption/CMakeLists.txt +++ b/src/iceberg/encryption/CMakeLists.txt @@ -23,7 +23,8 @@ iceberg_install_all_headers(iceberg/encryption encryption_key_metadata.h encryption_manager.h key_management_client.h - standard_key_metadata.h) + standard_key_metadata.h + type_fwd.h) if(ICEBERG_BUILD_BUNDLE) iceberg_install_all_headers(iceberg/encryption PATTERN diff --git a/src/iceberg/encryption/aes_gcm_internal.h b/src/iceberg/encryption/aes_gcm_internal.h index e09a7802e7..1e35ffc6f8 100644 --- a/src/iceberg/encryption/aes_gcm_internal.h +++ b/src/iceberg/encryption/aes_gcm_internal.h @@ -22,18 +22,32 @@ /// \file iceberg/encryption/aes_gcm_internal.h /// AES GCM cipher compatible with Java's org.apache.iceberg.encryption.Ciphers. +#include #include #include #include #include #include "iceberg/result.h" +#include "iceberg/type_fwd.h" namespace iceberg::encryption { inline constexpr int32_t kNonceLength = 12; inline constexpr int32_t kGcmTagLength = 16; +inline constexpr bool IsValidAesKeyLength(std::size_t length) { + return length == 16 || length == 24 || length == 32; +} + +Result AesGcmPlaintextLength(std::span key, + int64_t encrypted_length); + +/// \brief Open an AGS1 stream that owns its underlying stream. +Result> OpenAesGcmInputStream( + InputFile& source, std::span key, std::span aad_prefix, + int64_t encrypted_length); + /// \brief Fill `out` with cryptographically secure random bytes. Status SecureRandomBytes(std::span out); diff --git a/src/iceberg/encryption/aes_gcm_stream.cc b/src/iceberg/encryption/aes_gcm_stream.cc index 7fb545dbf9..fb4b9be447 100644 --- a/src/iceberg/encryption/aes_gcm_stream.cc +++ b/src/iceberg/encryption/aes_gcm_stream.cc @@ -320,29 +320,72 @@ Result AesGcmStream::PlaintextLength(int64_t encrypted_length) { return num_full_blocks * kPlainBlockSize + last_plain; } +namespace encryption { + +Result AesGcmPlaintextLength(std::span key, + int64_t encrypted_length) { + ICEBERG_PRECHECK(IsValidAesKeyLength(key.size()), + "Invalid encryption key length: {} (must be 16, 24 or 32 bytes)", + key.size()); + return AesGcmStream::PlaintextLength(encrypted_length); +} + +Result> OpenAesGcmInputStream( + InputFile& source, std::span key, std::span aad_prefix, + int64_t encrypted_length) { + ICEBERG_ASSIGN_OR_RAISE(auto plaintext_length, + AesGcmPlaintextLength(key, encrypted_length)); + ICEBERG_ASSIGN_OR_RAISE(auto cipher, AesGcmCipher::Make(key)); + ICEBERG_ASSIGN_OR_RAISE(auto stream, source.Open()); + auto decrypted = std::make_unique( + std::move(stream), std::move(cipher), + std::vector(aad_prefix.begin(), aad_prefix.end()), encrypted_length, + plaintext_length); + ICEBERG_RETURN_UNEXPECTED(decrypted->ValidateHeader()); + ICEBERG_RETURN_UNEXPECTED(decrypted->ValidateEmptyStream()); + return decrypted; +} + +} // namespace encryption + +Result> AesGcmInputFile::Make( + std::unique_ptr source, std::span key, + std::span aad_prefix, int64_t encrypted_length) { + ICEBERG_PRECHECK(source != nullptr, "Encrypted input file cannot be null"); + ICEBERG_ASSIGN_OR_RAISE(auto plaintext_length, + encryption::AesGcmPlaintextLength(key, encrypted_length)); + return std::unique_ptr(new AesGcmInputFile( + std::move(source), {key.begin(), key.end()}, {aad_prefix.begin(), aad_prefix.end()}, + encrypted_length, plaintext_length)); +} + AesGcmInputFile::AesGcmInputFile(std::unique_ptr source, std::vector key, std::vector aad_prefix, - int64_t encrypted_length) + int64_t encrypted_length, int64_t plaintext_length) : source_(std::move(source)), key_(std::move(key)), aad_prefix_(std::move(aad_prefix)), - encrypted_length_(encrypted_length) {} + encrypted_length_(encrypted_length), + plaintext_length_(plaintext_length) {} -Result AesGcmInputFile::Size() const { - return AesGcmStream::PlaintextLength(encrypted_length_); -} +Result AesGcmInputFile::Size() const { return plaintext_length_; } Result> AesGcmInputFile::Open() { - ICEBERG_ASSIGN_OR_RAISE(auto plain_size, - AesGcmStream::PlaintextLength(encrypted_length_)); - ICEBERG_ASSIGN_OR_RAISE(auto cipher, AesGcmCipher::Make(key_)); - ICEBERG_ASSIGN_OR_RAISE(auto source, source_->Open()); - auto stream = std::make_unique( - std::move(source), std::move(cipher), aad_prefix_, encrypted_length_, plain_size); - ICEBERG_RETURN_UNEXPECTED(stream->ValidateHeader()); - ICEBERG_RETURN_UNEXPECTED(stream->ValidateEmptyStream()); - return stream; + return encryption::OpenAesGcmInputStream(*source_, key_, aad_prefix_, + encrypted_length_); +} + +Result> AesGcmOutputFile::Make( + std::unique_ptr target, std::span key, + std::span aad_prefix) { + ICEBERG_PRECHECK(target != nullptr, "Output file cannot be null"); + ICEBERG_PRECHECK(encryption::IsValidAesKeyLength(key.size()), + "Invalid encryption key length: {} (must be 16, 24 or 32 bytes)", + key.size()); + return std::unique_ptr( + new AesGcmOutputFile(std::move(target), {key.begin(), key.end()}, + {aad_prefix.begin(), aad_prefix.end()})); } AesGcmOutputFile::AesGcmOutputFile(std::unique_ptr target, diff --git a/src/iceberg/encryption/aes_gcm_stream.h b/src/iceberg/encryption/aes_gcm_stream.h index 766eb85eb4..8675425024 100644 --- a/src/iceberg/encryption/aes_gcm_stream.h +++ b/src/iceberg/encryption/aes_gcm_stream.h @@ -66,31 +66,41 @@ struct AesGcmStream { /// truncation of the file is detected. class ICEBERG_BUNDLE_EXPORT AesGcmInputFile : public InputFile { public: - AesGcmInputFile(std::unique_ptr source, std::vector key, - std::vector aad_prefix, int64_t encrypted_length); + static Result> Make( + std::unique_ptr source, std::span key, + std::span aad_prefix, int64_t encrypted_length); std::string_view location() const override { return source_->location(); } Result Size() const override; Result> Open() override; private: + AesGcmInputFile(std::unique_ptr source, std::vector key, + std::vector aad_prefix, int64_t encrypted_length, + int64_t plaintext_length); + std::unique_ptr source_; std::vector key_; std::vector aad_prefix_; int64_t encrypted_length_; + int64_t plaintext_length_; }; /// \brief An OutputFile that writes an AGS1 file. class ICEBERG_BUNDLE_EXPORT AesGcmOutputFile : public OutputFile { public: - AesGcmOutputFile(std::unique_ptr target, std::vector key, - std::vector aad_prefix); + static Result> Make( + std::unique_ptr target, std::span key, + std::span aad_prefix); std::string_view location() const override { return target_->location(); } Result> Create() override; Result> CreateOrOverwrite() override; private: + AesGcmOutputFile(std::unique_ptr target, std::vector key, + std::vector aad_prefix); + std::unique_ptr target_; std::vector key_; std::vector aad_prefix_; diff --git a/src/iceberg/encryption/encrypted_file.h b/src/iceberg/encryption/encrypted_file.h index e49cc77fbc..e5e514d539 100644 --- a/src/iceberg/encryption/encrypted_file.h +++ b/src/iceberg/encryption/encrypted_file.h @@ -24,9 +24,9 @@ /// EncryptedInputFile / EncryptedOutputFile. #include -#include #include "iceberg/encryption/encryption_key_metadata.h" +#include "iceberg/encryption/type_fwd.h" #include "iceberg/file_io.h" #include "iceberg/iceberg_export.h" @@ -37,38 +37,30 @@ class ICEBERG_EXPORT EncryptedInputFile { public: virtual ~EncryptedInputFile() = default; - /// \brief Give up the still-encrypted raw input file. - virtual std::unique_ptr ReleaseInputFile() = 0; + /// \brief Take ownership of a native wrapper, or leave encrypted intact and return + /// null. + static std::unique_ptr AsNative( + std::unique_ptr& encrypted); + + /// \brief Transfer ownership of the still-encrypted raw input file. + /// + /// Returns nullptr if the wrapper has no file. Use the returned handle for file access + /// after detaching. + virtual std::unique_ptr DetachInputFile() && = 0; /// \brief The key metadata needed to decrypt this file. virtual const EncryptionKeyMetadata& key_metadata() const = 0; -}; - -/// \brief EncryptedInputFile backed by a plain InputFile and opaque key metadata. -class ICEBERG_EXPORT BaseEncryptedInputFile : public EncryptedInputFile { - public: - BaseEncryptedInputFile(std::unique_ptr encrypted_file, - std::shared_ptr key_metadata) - : encrypted_file_(std::move(encrypted_file)), - key_metadata_(std::move(key_metadata)) {} - - std::unique_ptr ReleaseInputFile() override { - return std::move(encrypted_file_); - } - - const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } private: - std::unique_ptr encrypted_file_; - std::shared_ptr key_metadata_; + virtual NativeEncryptionInputFile* native_input_file() noexcept { return nullptr; } }; /// \brief An encrypted input file that supports both read paths of Java's /// NativeEncryptionInputFile. /// /// - Native path, for formats such as Parquet that perform their own modular decryption: -/// ReleaseInputFile() gives the still-encrypted raw file and key_metadata() gives the -/// key parameters (and AAD prefix) the native reader needs. +/// key_metadata() gives the key parameters (and AAD prefix) the native reader needs. +/// DetachInputFile() then transfers the still-encrypted raw file. /// - Stream path: the InputFile methods read the file as an AES GCM stream (AGS1), /// decrypting it, and require the encrypted file length in the key metadata. /// @@ -78,6 +70,9 @@ class ICEBERG_EXPORT NativeEncryptionInputFile : public EncryptedInputFile, public InputFile { public: const NativeEncryptionKeyMetadata& key_metadata() const override = 0; + + private: + NativeEncryptionInputFile* native_input_file() noexcept final { return this; } }; /// \brief An encrypting output file together with the key metadata that was used (or @@ -86,31 +81,13 @@ class ICEBERG_EXPORT EncryptedOutputFile { public: virtual ~EncryptedOutputFile() = default; - /// \brief The output file that writers should use. - /// - /// Unlike EncryptedInputFile::ReleaseInputFile, this is a non-consuming accessor: - /// implementations may need to keep ownership to finalize encryption on Close. + /// \brief Borrow the encrypting output file from this wrapper. virtual OutputFile& encrypting_output_file() const = 0; /// \brief The key metadata that was used to encrypt this file. virtual const EncryptionKeyMetadata& key_metadata() const = 0; }; -/// \brief EncryptedOutputFile backed by a plain OutputFile and opaque key metadata. -class ICEBERG_EXPORT BaseEncryptedOutputFile : public EncryptedOutputFile { - public: - BaseEncryptedOutputFile(std::unique_ptr output_file, - std::shared_ptr key_metadata) - : output_file_(std::move(output_file)), key_metadata_(std::move(key_metadata)) {} - - OutputFile& encrypting_output_file() const override { return *output_file_; } - const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } - - private: - std::unique_ptr output_file_; - std::shared_ptr key_metadata_; -}; - /// \brief An encrypting output file that supports both write paths of Java's /// NativeEncryptionOutputFile. /// @@ -131,9 +108,11 @@ class ICEBERG_EXPORT NativeEncryptionOutputFile : public EncryptedOutputFile, std::string_view location() const override { return encrypting_output_file().location(); } + Result> Create() override { return encrypting_output_file().Create(); } + Result> CreateOrOverwrite() override { return encrypting_output_file().CreateOrOverwrite(); } diff --git a/src/iceberg/encryption/encrypted_files.cc b/src/iceberg/encryption/encrypted_files.cc index ad3c5471f2..7188ae90e7 100644 --- a/src/iceberg/encryption/encrypted_files.cc +++ b/src/iceberg/encryption/encrypted_files.cc @@ -21,20 +21,88 @@ #include +#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/util/macros.h" + namespace iceberg { -std::unique_ptr EncryptedFiles::Encrypted( - std::unique_ptr encrypted_file, +namespace { + +class BaseEncryptedInputFile final : public EncryptedInputFile { + public: + static Result> Make( + std::unique_ptr encrypted_input_file, + std::shared_ptr key_metadata) { + ICEBERG_PRECHECK(encrypted_input_file != nullptr, + "Encrypted input file cannot be null"); + ICEBERG_PRECHECK(key_metadata != nullptr, "Key metadata cannot be null"); + return std::unique_ptr(new BaseEncryptedInputFile( + std::move(encrypted_input_file), std::move(key_metadata))); + } + + std::unique_ptr DetachInputFile() && override { + return std::move(encrypted_input_file_); + } + + const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } + + private: + BaseEncryptedInputFile(std::unique_ptr encrypted_input_file, + std::shared_ptr key_metadata) + : encrypted_input_file_(std::move(encrypted_input_file)), + key_metadata_(std::move(key_metadata)) {} + + std::unique_ptr encrypted_input_file_; + std::shared_ptr key_metadata_; +}; + +class BaseEncryptedOutputFile final : public EncryptedOutputFile { + public: + static Result> Make( + std::unique_ptr encrypting_output_file, + std::shared_ptr key_metadata) { + ICEBERG_PRECHECK(encrypting_output_file != nullptr, "Output file cannot be null"); + ICEBERG_PRECHECK(key_metadata != nullptr, "Key metadata cannot be null"); + return std::unique_ptr(new BaseEncryptedOutputFile( + std::move(encrypting_output_file), std::move(key_metadata))); + } + + OutputFile& encrypting_output_file() const override { return *encrypting_output_file_; } + const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } + + private: + BaseEncryptedOutputFile(std::unique_ptr encrypting_output_file, + std::shared_ptr key_metadata) + : encrypting_output_file_(std::move(encrypting_output_file)), + key_metadata_(std::move(key_metadata)) {} + + std::unique_ptr encrypting_output_file_; + std::shared_ptr key_metadata_; +}; + +} // namespace + +std::unique_ptr EncryptedInputFile::AsNative( + std::unique_ptr& encrypted) { + auto* native = encrypted ? encrypted->native_input_file() : nullptr; + if (native != nullptr) { + encrypted.release(); + } + return std::unique_ptr(native); +} + +Result> EncryptedFiles::EncryptedInput( + std::unique_ptr encrypted_input_file, std::shared_ptr key_metadata) { - return std::make_unique(std::move(encrypted_file), - std::move(key_metadata)); + return BaseEncryptedInputFile::Make(std::move(encrypted_input_file), + std::move(key_metadata)); } -std::unique_ptr EncryptedFiles::Encrypted( - std::unique_ptr output_file, +Result> EncryptedFiles::EncryptedOutput( + std::unique_ptr encrypting_output_file, std::shared_ptr key_metadata) { - return std::make_unique(std::move(output_file), - std::move(key_metadata)); + return BaseEncryptedOutputFile::Make(std::move(encrypting_output_file), + std::move(key_metadata)); } } // namespace iceberg diff --git a/src/iceberg/encryption/encrypted_files.h b/src/iceberg/encryption/encrypted_files.h index ee77cebc31..b81ddab6a5 100644 --- a/src/iceberg/encryption/encrypted_files.h +++ b/src/iceberg/encryption/encrypted_files.h @@ -25,25 +25,26 @@ #include -#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/encryption/type_fwd.h" #include "iceberg/iceberg_export.h" +#include "iceberg/result.h" +#include "iceberg/type_fwd.h" namespace iceberg { -/// \brief Builds EncryptedInputFile / EncryptedOutputFile wrappers around a plain file -/// and its key metadata, for callers that do not need the native (modular) encryption -/// wrappers. +/// \brief Pairs existing input and output files with their key metadata. class ICEBERG_EXPORT EncryptedFiles { public: /// \brief Wrap a still-encrypted input file together with its key metadata. - static std::unique_ptr Encrypted( - std::unique_ptr encrypted_file, + static Result> EncryptedInput( + std::unique_ptr encrypted_input_file, std::shared_ptr key_metadata); - /// \brief Wrap a plaintext output file together with the key metadata used (or to be - /// used) to encrypt it. - static std::unique_ptr Encrypted( - std::unique_ptr output_file, + /// \brief Pair an existing encrypting output file with its key metadata. + /// + /// To encrypt a plain output file, use EncryptionManager::Encrypt. + static Result> EncryptedOutput( + std::unique_ptr encrypting_output_file, std::shared_ptr key_metadata); }; diff --git a/src/iceberg/encryption/encryption_key_metadata.h b/src/iceberg/encryption/encryption_key_metadata.h index c780594ad4..82658a6cc1 100644 --- a/src/iceberg/encryption/encryption_key_metadata.h +++ b/src/iceberg/encryption/encryption_key_metadata.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -41,10 +42,7 @@ class ICEBERG_EXPORT EncryptionKeyMetadata { public: virtual ~EncryptionKeyMetadata() = default; - /// \brief The serialized form of this key metadata. - /// - /// Implementations must not cache this value if their fields can change after - /// construction; it is recomputed on every call where that matters. + /// \brief Return an owning copy of the current serialized key metadata. virtual std::vector buffer() const = 0; /// \brief Whether key metadata is present. @@ -93,19 +91,20 @@ class ICEBERG_EXPORT BaseEncryptionKeyMetadata : public EncryptionKeyMetadata { /// Exposes the data encryption key and AAD prefix directly, for formats (such as /// Parquet) that perform their own native encryption rather than using the AGS1 stream /// format. +/// Key and AAD views borrow storage from this object. class ICEBERG_EXPORT NativeEncryptionKeyMetadata : public EncryptionKeyMetadata { public: /// \brief The data encryption key. - virtual const std::vector& EncryptionKey() const = 0; + virtual std::span encryption_key() const = 0; /// \brief The AAD prefix (file ID) used to bind ciphertext to this file, if any. - virtual const std::optional>& AadPrefix() const = 0; + virtual std::optional> aad_prefix() const = 0; /// \brief The encrypted (stored) file length, or nullopt if not yet known. /// /// Returns NotSupported unless the implementation tracks a file length. - virtual Result> FileLength() const { - return NotSupported("FileLength is not implemented by this key metadata"); + virtual Result> file_length() const { + return NotSupported("file_length is not implemented by this key metadata"); } /// \brief A copy of this key metadata, with the same key and AAD prefix, that records diff --git a/src/iceberg/encryption/encryption_manager.cc b/src/iceberg/encryption/encryption_manager.cc index 538720d424..da1f701462 100644 --- a/src/iceberg/encryption/encryption_manager.cc +++ b/src/iceberg/encryption/encryption_manager.cc @@ -20,7 +20,12 @@ #include "iceberg/encryption/encryption_manager.h" #include +#include +#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/encryption/encrypted_files.h" +#include "iceberg/encryption/encryption_manager_internal.h" +#include "iceberg/logging/log_macros.h" #include "iceberg/util/macros.h" namespace iceberg { @@ -49,13 +54,21 @@ Result>> EncryptionManager::Enc Result> PlaintextEncryptionManager::Decrypt( std::unique_ptr encrypted) { - return encrypted->ReleaseInputFile(); + ICEBERG_PRECHECK(encrypted != nullptr, "Encrypted input file cannot be null"); + if (encrypted->key_metadata().has_value()) { + ICEBERG_LOG_WARN( + "File encryption key metadata is present, but no encryption has been " + "configured."); + } + auto input = std::move(*encrypted).DetachInputFile(); + ICEBERG_PRECHECK(input != nullptr, "Encrypted input file has no underlying file"); + return input; } Result> PlaintextEncryptionManager::Encrypt( std::unique_ptr plain) { - return std::make_unique(std::move(plain), - BaseEncryptionKeyMetadata::Empty()); + return EncryptedFiles::EncryptedOutput(std::move(plain), + BaseEncryptionKeyMetadata::Empty()); } namespace { @@ -75,19 +88,21 @@ RegistryState& State() { void EncryptionManagerRegistry::Register(Factory factory) { auto& state = State(); std::lock_guard lock(state.mutex); - state.factory = std::move(factory); + state.factory.swap(factory); +} + +void internal::RegisterDefaultEncryptionManagerFactory( + EncryptionManagerRegistry::Factory factory) { + auto& state = State(); + std::lock_guard lock(state.mutex); + if (!state.factory) { + state.factory.swap(factory); + } } Result> EncryptionManagerRegistry::Make( - Options options) { - ICEBERG_PRECHECK(!options.table_key_id.empty(), "Invalid encryption key ID: empty"); - ICEBERG_PRECHECK(options.data_key_length == 16 || options.data_key_length == 24 || - options.data_key_length == 32, - "Invalid data key length: {} (must be 16, 24, or 32)", - options.data_key_length); - ICEBERG_PRECHECK(options.kms != nullptr, - "Cannot create an encryption manager without a KMS client; set the " - "encryption.kms-type or encryption.kms-impl catalog property"); + const std::vector& keys, const TableProperties& table_properties, + std::shared_ptr kms_client) { Factory factory; { auto& state = State(); @@ -96,10 +111,14 @@ Result> EncryptionManagerRegistry::Make( } if (!factory) { return NotSupported( - "Table encryption is not available: link iceberg_bundle built with " - "ICEBERG_ENCRYPTION=ON and call iceberg::encryption::RegisterAll()"); + "No encryption manager factory registered. For standard encryption, link " + "iceberg_bundle built with ICEBERG_ENCRYPTION=ON and call " + "iceberg::encryption::RegisterAll()"); } - return factory(std::move(options)); + ICEBERG_ASSIGN_OR_RAISE(auto manager, + factory(keys, table_properties, std::move(kms_client))); + ICEBERG_PRECHECK(manager != nullptr, "Encryption manager factory returned null"); + return manager; } } // namespace iceberg diff --git a/src/iceberg/encryption/encryption_manager.h b/src/iceberg/encryption/encryption_manager.h index c6cde92c7f..41422e1f5d 100644 --- a/src/iceberg/encryption/encryption_manager.h +++ b/src/iceberg/encryption/encryption_manager.h @@ -22,18 +22,14 @@ /// \file iceberg/encryption/encryption_manager.h /// Table encryption manager interface and the registry that creates one. -#include #include #include -#include #include -#include "iceberg/encryption/encrypted_file.h" -#include "iceberg/encryption/encrypted_key.h" -#include "iceberg/encryption/key_management_client.h" -#include "iceberg/file_io.h" +#include "iceberg/encryption/type_fwd.h" #include "iceberg/iceberg_export.h" #include "iceberg/result.h" +#include "iceberg/type_fwd.h" namespace iceberg { @@ -42,9 +38,9 @@ namespace iceberg { /// This interface does not require a particular key metadata encoding or encryption /// algorithm; those are the business of the specific implementation (such as /// StandardEncryptionManager, which needs a crypto provider and lives in the bundle -/// library) and of EncryptedFiles / EncryptionUtil, which build the EncryptedInputFile / -/// EncryptedOutputFile wrappers this interface consumes. The core library reaches the -/// standard implementation through EncryptionManagerRegistry. +/// library). EncryptedFiles builds the EncryptedInputFile / EncryptedOutputFile +/// wrappers. The core library reaches the standard implementation through +/// EncryptionManagerRegistry. class ICEBERG_EXPORT EncryptionManager { public: virtual ~EncryptionManager() = default; @@ -62,6 +58,8 @@ class ICEBERG_EXPORT EncryptionManager { /// /// The default implementation decrypts each file in order; implementations may /// override it to decrypt more efficiently, for example by batching KMS calls. + /// TODO(encryption): Support lazy batches with Stream so callers can consume files on + /// demand. virtual Result>> Decrypt( std::vector> encrypted); @@ -87,33 +85,22 @@ class ICEBERG_EXPORT PlaintextEncryptionManager : public EncryptionManager { /// \brief Creates the encryption manager of encrypted tables. /// -/// The bundle library registers the standard implementation (see -/// iceberg::encryption::RegisterAll()). Without it, encrypted tables cannot be read or -/// written. A registry is used so that the core library can reach a standard-specific -/// implementation without depending on it directly; Options is therefore -/// standard-specific and not part of the general EncryptionManager contract. +/// The bundle library supplies the standard implementation as a default (see +/// iceberg::encryption::RegisterAll()). An explicitly registered factory takes +/// precedence. Each factory validates its own properties. class ICEBERG_EXPORT EncryptionManagerRegistry { public: - struct Options { - /// The table master key ID in the KMS (table property `encryption.key-id`), taken - /// from a trusted source. - std::string table_key_id; - /// Length of generated data keys: 16, 24 or 32 bytes. - int32_t data_key_length = 16; - /// The table metadata `encryption-keys`. - std::vector encryption_keys; - /// The catalog's KMS client. - std::shared_ptr kms; - }; - - using Factory = - std::function>(Options options)>; - - /// \brief Register the encryption manager implementation. + using Factory = std::function>( + const std::vector& keys, const TableProperties& table_properties, + std::shared_ptr kms_client)>; + + /// \brief Replace the current factory, or clear it by passing an empty factory. static void Register(Factory factory); /// \brief Create an encryption manager. - static Result> Make(Options options); + static Result> Make( + const std::vector& keys, const TableProperties& table_properties, + std::shared_ptr kms_client); }; } // namespace iceberg diff --git a/src/iceberg/encryption/encryption_manager_internal.h b/src/iceberg/encryption/encryption_manager_internal.h new file mode 100644 index 0000000000..2f9d16616d --- /dev/null +++ b/src/iceberg/encryption/encryption_manager_internal.h @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +#include "iceberg/encryption/encryption_manager.h" +#include "iceberg/iceberg_export.h" + +namespace iceberg::internal { + +/// \brief Install the bundle's default factory if the registry is empty. +ICEBERG_EXPORT void RegisterDefaultEncryptionManagerFactory( + EncryptionManagerRegistry::Factory factory); + +} // namespace iceberg::internal diff --git a/src/iceberg/encryption/encryption_register.cc b/src/iceberg/encryption/encryption_register.cc index 3df7383c2b..2bb2560510 100644 --- a/src/iceberg/encryption/encryption_register.cc +++ b/src/iceberg/encryption/encryption_register.cc @@ -19,12 +19,12 @@ #include "iceberg/encryption/encryption_register.h" +namespace iceberg::encryption { + #if ICEBERG_ENCRYPTION_ENABLED -# include "iceberg/encryption/standard_encryption_manager.h" +void RegisterStandardEncryptionManager(); #endif -namespace iceberg::encryption { - void RegisterAll() { #if ICEBERG_ENCRYPTION_ENABLED RegisterStandardEncryptionManager(); diff --git a/src/iceberg/encryption/encryption_register.h b/src/iceberg/encryption/encryption_register.h index beacad013e..c8f0cc26fa 100644 --- a/src/iceberg/encryption/encryption_register.h +++ b/src/iceberg/encryption/encryption_register.h @@ -26,8 +26,8 @@ namespace iceberg::encryption { -/// \brief Register the standard encryption manager, if the bundle was built with -/// ICEBERG_ENCRYPTION=ON. Otherwise a no-op, and encrypted tables are not supported. +/// \brief Register the standard factory if encryption is enabled in the bundle and +/// the registry is empty. ICEBERG_BUNDLE_EXPORT void RegisterAll(); /// \brief Whether the bundle was built with table encryption support. diff --git a/src/iceberg/encryption/encryption_util.cc b/src/iceberg/encryption/encryption_util.cc index bfa981ca0f..93f09f30ca 100644 --- a/src/iceberg/encryption/encryption_util.cc +++ b/src/iceberg/encryption/encryption_util.cc @@ -19,10 +19,29 @@ #include "iceberg/encryption/encryption_util.h" +#include + +#include "iceberg/encryption/encryption_manager.h" #include "iceberg/encryption/standard_encryption_manager.h" +#include "iceberg/table_properties.h" +#include "iceberg/util/macros.h" namespace iceberg { +Result> EncryptionUtil::MakeEncryptionManager( + const std::vector& keys, const TableProperties& table_properties, + std::shared_ptr kms_client) { + ICEBERG_PRECHECK(kms_client != nullptr, "Invalid KMS client: null"); + const auto& properties = table_properties.configs(); + auto key_id = properties.find(TableProperties::kEncryptionTableKey.key()); + if (key_id == properties.end()) { + static const auto plaintext = std::make_shared(); + return plaintext; + } + ICEBERG_PRECHECK(!key_id->second.empty(), "Invalid encryption key ID: empty"); + return EncryptionManagerRegistry::Make(keys, table_properties, std::move(kms_client)); +} + Result> EncryptionUtil::DecryptManifestListKeyMetadata( const std::shared_ptr& manager, std::string_view manifest_list_key_id) { diff --git a/src/iceberg/encryption/encryption_util.h b/src/iceberg/encryption/encryption_util.h index d8c9ff1e08..8e846fc0f4 100644 --- a/src/iceberg/encryption/encryption_util.h +++ b/src/iceberg/encryption/encryption_util.h @@ -28,16 +28,26 @@ #include #include -#include "iceberg/encryption/encryption_manager.h" +#include "iceberg/encryption/type_fwd.h" #include "iceberg/iceberg_bundle_export.h" #include "iceberg/result.h" +#include "iceberg/type_fwd.h" namespace iceberg { -/// \brief Standard-specific operations reached through a generic EncryptionManager. +/// \brief Manager construction and standard-specific operations. class ICEBERG_BUNDLE_EXPORT EncryptionUtil { public: - /// \brief Decrypt manifest list key metadata, as stored in a snapshot's `key-id`. + /// \brief Select plaintext for an unencrypted table, or the registered factory when + /// the table has an encryption key ID. + /// + /// Requires a KMS client even for unencrypted tables. The table key ID must come + /// from a trusted source, such as the catalog. + static Result> MakeEncryptionManager( + const std::vector& keys, const TableProperties& table_properties, + std::shared_ptr kms_client); + + /// \brief Decrypt the manifest list key metadata referenced by a snapshot's `key-id`. /// /// Fails with NotSupported if manager is not backed by StandardEncryptionManager. static Result> DecryptManifestListKeyMetadata( diff --git a/src/iceberg/encryption/in_memory_kms.cc b/src/iceberg/encryption/in_memory_kms.cc index 31e1eedb7b..30a3f54045 100644 --- a/src/iceberg/encryption/in_memory_kms.cc +++ b/src/iceberg/encryption/in_memory_kms.cc @@ -19,16 +19,33 @@ #include "iceberg/encryption/in_memory_kms.h" +#include + #include "iceberg/encryption/aes_gcm_internal.h" #include "iceberg/util/base64.h" #include "iceberg/util/macros.h" namespace iceberg { +Result> InMemoryKms::Make( + std::unordered_map> master_keys) { + for (const auto& [id, key] : master_keys) { + ICEBERG_PRECHECK(!id.empty(), "Master key ID cannot be empty"); + ICEBERG_PRECHECK(encryption::IsValidAesKeyLength(key.size()), + "Master key {} must be 16, 24 or 32 bytes, got {}", id, key.size()); + } + return std::unique_ptr(new InMemoryKms(std::move(master_keys))); +} + +InMemoryKms::InMemoryKms( + std::unordered_map> master_keys) + : master_keys_(std::move(master_keys)) {} + void InMemoryKms::Register() { KmsRegistry::Register(std::string(kName), []() -> Result> { - return std::make_unique(); + ICEBERG_ASSIGN_OR_RAISE(auto kms, Make()); + return kms; }); } @@ -44,7 +61,7 @@ Status InMemoryKms::Initialize( auto id = name.substr(kKeyPropertyPrefix.size()); ICEBERG_PRECHECK(!id.empty(), "Master key property {} has an empty key id", name); ICEBERG_ASSIGN_OR_RAISE(auto key, Base64::Decode(value)); - ICEBERG_PRECHECK(key.size() == 16 || key.size() == 24 || key.size() == 32, + ICEBERG_PRECHECK(encryption::IsValidAesKeyLength(key.size()), "Master key {} must be 16, 24 or 32 bytes, got {}", name, key.size()); decoded.insert_or_assign(std::move(id), std::vector(key.begin(), key.end())); diff --git a/src/iceberg/encryption/in_memory_kms.h b/src/iceberg/encryption/in_memory_kms.h index b97025cac4..2c5fd81632 100644 --- a/src/iceberg/encryption/in_memory_kms.h +++ b/src/iceberg/encryption/in_memory_kms.h @@ -23,6 +23,7 @@ /// KMS client with master keys held in memory, for tests and local development. #include +#include #include #include #include @@ -41,15 +42,14 @@ namespace iceberg { /// without AAD. class ICEBERG_BUNDLE_EXPORT InMemoryKms : public KeyManagementClient { public: - /// \brief The name used with `encryption.kms-impl` after RegisterInMemoryKms(). + /// \brief The name used with `encryption.kms-impl` after Register(). static constexpr std::string_view kName = "in-memory"; /// \brief Catalog property prefix for master keys: `encryption.in-memory-kms.key.` /// = Base64 of the key bytes. static constexpr std::string_view kKeyPropertyPrefix = "encryption.in-memory-kms.key."; - InMemoryKms() = default; - explicit InMemoryKms(std::unordered_map> master_keys) - : master_keys_(std::move(master_keys)) {} + static Result> Make( + std::unordered_map> master_keys = {}); /// \brief Register this client in KmsRegistry under kName. static void Register(); @@ -64,6 +64,8 @@ class ICEBERG_BUNDLE_EXPORT InMemoryKms : public KeyManagementClient { std::string_view wrapping_key_id) override; private: + explicit InMemoryKms(std::unordered_map> master_keys); + Result*> MasterKey(std::string_view id) const; std::unordered_map> master_keys_; diff --git a/src/iceberg/encryption/standard_encryption_manager.cc b/src/iceberg/encryption/standard_encryption_manager.cc index 97fe947eb9..9f62189aab 100644 --- a/src/iceberg/encryption/standard_encryption_manager.cc +++ b/src/iceberg/encryption/standard_encryption_manager.cc @@ -21,12 +21,18 @@ #include #include -#include +#include #include "iceberg/encryption/aes_gcm_internal.h" #include "iceberg/encryption/aes_gcm_stream.h" +#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/encryption/encryption_manager_internal.h" +#include "iceberg/encryption/key_management_client.h" +#include "iceberg/encryption/standard_key_metadata.h" +#include "iceberg/table_properties.h" #include "iceberg/util/base64.h" #include "iceberg/util/macros.h" +#include "iceberg/util/string_util.h" namespace iceberg { @@ -49,117 +55,91 @@ Result GenerateKeyId() { return Base64::Encode(ToString(id)); } -std::optional ParseTimestamp(const EncryptedKey& key) { +Result ParseTimestamp(const EncryptedKey& key) { auto it = key.properties.find(std::string(StandardEncryptionManager::kKeyTimestamp)); if (it == key.properties.end()) { - return std::nullopt; + return Invalid("Key encryption key {} must be timestamped", key.key_id); } int64_t value = 0; const auto& str = it->second; auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), value); if (ec != std::errc{} || ptr != str.data() + str.size() || value < 0) { - return std::nullopt; + return Invalid("Invalid KEY_TIMESTAMP for key encryption key {}", key.key_id); } return value; } -// Forwards to a file owned elsewhere, so one underlying file can serve both the native -// path and the AGS1 stream path of a Native wrapper. -class SharedInputFile : public InputFile { - public: - explicit SharedInputFile(std::shared_ptr file) : file_(std::move(file)) {} - - std::string_view location() const override { return file_->location(); } - Result Size() const override { return file_->Size(); } - Result> Open() override { return file_->Open(); } - - private: - std::shared_ptr file_; -}; - -class SharedOutputFile : public OutputFile { +class StandardDecryptedInputFile : public NativeEncryptionInputFile { public: - explicit SharedOutputFile(std::shared_ptr file) : file_(std::move(file)) {} + StandardDecryptedInputFile(std::unique_ptr encrypted_input_file, + StandardKeyMetadata key_metadata) + : encrypted_input_file_(std::move(encrypted_input_file)), + key_metadata_(std::move(key_metadata)) {} - std::string_view location() const override { return file_->location(); } - Result> Create() override { - return file_->Create(); - } - Result> CreateOrOverwrite() override { - return file_->CreateOrOverwrite(); + std::unique_ptr DetachInputFile() && override { + return std::move(encrypted_input_file_); } - private: - std::shared_ptr file_; -}; - -// Mirrors Java's StandardDecryptedInputFile: the raw file and key metadata are available -// to native readers right away, while the AGS1 reader, which needs the encrypted file -// length from the key metadata, is built on first use of the InputFile methods. -class StandardDecryptedInputFile : public NativeEncryptionInputFile { - public: - StandardDecryptedInputFile(std::shared_ptr raw, StandardKeyMetadata metadata) - : raw_(std::move(raw)), metadata_(std::move(metadata)) {} + const NativeEncryptionKeyMetadata& key_metadata() const override { + return key_metadata_; + } - std::unique_ptr ReleaseInputFile() override { - return std::make_unique(raw_); + std::string_view location() const override { + return encrypted_input_file_ ? encrypted_input_file_->location() : std::string_view{}; } - const NativeEncryptionKeyMetadata& key_metadata() const override { return metadata_; } - std::string_view location() const override { return raw_->location(); } Result Size() const override { - ICEBERG_ASSIGN_OR_RAISE(auto file, Decrypting()); - return file->Size(); + ICEBERG_ASSIGN_OR_RAISE(auto encrypted_length, EncryptedLength()); + return encryption::AesGcmPlaintextLength(key_metadata_.encryption_key(), + encrypted_length); } + Result> Open() override { - ICEBERG_ASSIGN_OR_RAISE(auto file, Decrypting()); - return file->Open(); + ICEBERG_ASSIGN_OR_RAISE(auto encrypted_length, EncryptedLength()); + return encryption::OpenAesGcmInputStream( + *encrypted_input_file_, key_metadata_.encryption_key(), + key_metadata_.aad_prefix().value_or(std::span{}), + encrypted_length); } private: - Result Decrypting() const { - if (decrypting_ == nullptr) { - if (!metadata_.file_length.has_value()) { - // The length must come from trusted key metadata, not from the file system, so - // that truncation is detected (format/gcm-stream-spec.md, "File length"). - return Invalid("Cannot read AES GCM stream {}: key metadata has no file length", - raw_->location()); - } - decrypting_ = std::make_unique( - std::make_unique(raw_), metadata_.encryption_key, - metadata_.aad_prefix.value_or(std::vector{}), *metadata_.file_length); + Result EncryptedLength() const { + ICEBERG_PRECHECK(encrypted_input_file_ != nullptr, + "Encrypted input file was detached"); + ICEBERG_ASSIGN_OR_RAISE(auto file_length, key_metadata_.file_length()); + // The length must come from trusted key metadata to detect truncation. + if (!file_length.has_value()) { + return Invalid("Cannot read AES GCM stream {}: key metadata has no file length", + encrypted_input_file_->location()); } - return decrypting_.get(); + return *file_length; } - std::shared_ptr raw_; - StandardKeyMetadata metadata_; - mutable std::unique_ptr decrypting_; + std::unique_ptr encrypted_input_file_; + StandardKeyMetadata key_metadata_; }; -// Mirrors Java's StandardEncryptedOutputFile: native writers use the plain file and the -// key metadata; the AGS1 writer over the same file and key is built on first use. class StandardEncryptedOutputFile : public NativeEncryptionOutputFile { public: - StandardEncryptedOutputFile(std::shared_ptr plain, - StandardKeyMetadata metadata) - : plain_(std::move(plain)), metadata_(std::move(metadata)) {} - - OutputFile& plain_output_file() const override { return *plain_; } - OutputFile& encrypting_output_file() const override { - if (encrypting_ == nullptr) { - encrypting_ = std::make_unique( - std::make_unique(plain_), metadata_.encryption_key, - metadata_.aad_prefix.value_or(std::vector{})); - } - return *encrypting_; + StandardEncryptedOutputFile(std::unique_ptr encrypting_output_file, + OutputFile& plain_output_file, + StandardKeyMetadata key_metadata) + : encrypting_output_file_(std::move(encrypting_output_file)), + plain_output_file_(plain_output_file), + key_metadata_(std::move(key_metadata)) {} + + OutputFile& plain_output_file() const override { return plain_output_file_; } + + OutputFile& encrypting_output_file() const override { return *encrypting_output_file_; } + + const NativeEncryptionKeyMetadata& key_metadata() const override { + return key_metadata_; } - const NativeEncryptionKeyMetadata& key_metadata() const override { return metadata_; } private: - std::shared_ptr plain_; - StandardKeyMetadata metadata_; - mutable std::unique_ptr encrypting_; + std::unique_ptr encrypting_output_file_; + OutputFile& plain_output_file_; // Owned by encrypting_output_file_. + StandardKeyMetadata key_metadata_; }; Result CastOrParse(const EncryptionKeyMetadata& key_metadata) { @@ -170,105 +150,92 @@ Result CastOrParse(const EncryptionKeyMetadata& key_metadat return StandardKeyMetadata::Parse(buffer); } +Result> MakeStandardEncryptionManager( + const std::vector& keys, const TableProperties& table_properties, + std::shared_ptr kms_client) { + const auto& dek = TableProperties::kEncryptionDekLength; + auto data_key_length = dek.value(); + const auto& properties = table_properties.configs(); + if (auto it = properties.find(dek.key()); it != properties.end()) { + ICEBERG_ASSIGN_OR_RAISE(data_key_length, + StringUtils::ParseNumber(it->second)); + } + return StandardEncryptionManager::Make( + keys, table_properties.Get(TableProperties::kEncryptionTableKey), data_key_length, + std::move(kms_client)); +} + } // namespace Result> StandardEncryptionManager::Make( - EncryptionManagerRegistry::Options options) { - ICEBERG_PRECHECK(!options.table_key_id.empty(), "Invalid encryption key ID: empty"); - ICEBERG_PRECHECK(options.data_key_length == 16 || options.data_key_length == 24 || - options.data_key_length == 32, + std::vector keys, std::string table_key_id, int32_t data_key_length, + std::shared_ptr kms_client) { + ICEBERG_PRECHECK(!table_key_id.empty(), "Invalid encryption key ID: empty"); + ICEBERG_PRECHECK(encryption::IsValidAesKeyLength(data_key_length), "Invalid data key length: {} (must be 16, 24, or 32)", - options.data_key_length); - ICEBERG_PRECHECK(options.kms != nullptr, "Invalid KMS client: null"); - return std::shared_ptr( - new StandardEncryptionManager(std::move(options))); + data_key_length); + ICEBERG_PRECHECK(kms_client != nullptr, "Invalid KMS client: null"); + return std::shared_ptr(new StandardEncryptionManager( + std::move(keys), std::move(table_key_id), data_key_length, std::move(kms_client))); } StandardEncryptionManager::StandardEncryptionManager( - EncryptionManagerRegistry::Options options) - : table_key_id_(std::move(options.table_key_id)), - data_key_length_(options.data_key_length), - kms_(std::move(options.kms)) { - for (auto& key : options.encryption_keys) { + std::vector keys, std::string table_key_id, int32_t data_key_length, + std::shared_ptr kms_client) + : table_key_id_(std::move(table_key_id)), + data_key_length_(data_key_length), + kms_client_(std::move(kms_client)) { + for (auto& key : keys) { AddKey(std::move(key)); } } void StandardEncryptionManager::AddKey(EncryptedKey key) { auto key_id = key.key_id; - if (keys_.insert_or_assign(key_id, std::move(key)).second) { - key_order_.push_back(std::move(key_id)); + if (encryption_keys_.insert_or_assign(key_id, std::move(key)).second) { + encryption_key_order_.push_back(std::move(key_id)); } } -void StandardEncryptionManager::SetTestTimeShift(std::chrono::milliseconds shift) { - std::lock_guard lock(mutex_); - time_shift_ = shift; -} - -int64_t StandardEncryptionManager::NowMs() const { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch() + time_shift_) +int64_t StandardEncryptionManager::CurrentTimeMillis() const { + auto now = std::chrono::system_clock::now().time_since_epoch(); + return (std::chrono::duration_cast(now) + test_time_shift_) .count(); } Result StandardEncryptionManager::NewKeyMetadata() { - StandardKeyMetadata metadata; - metadata.encryption_key.resize(data_key_length_); - ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(metadata.encryption_key)); - metadata.aad_prefix.emplace(kAadPrefixLength); - ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(*metadata.aad_prefix)); - return metadata; -} - -Result> StandardEncryptionManager::NewDecryptingInputFile( - std::unique_ptr encrypted, std::span key_metadata) { - ICEBERG_PRECHECK(encrypted != nullptr, "Encrypted input file cannot be null"); - ICEBERG_ASSIGN_OR_RAISE(auto metadata, StandardKeyMetadata::Parse(key_metadata)); - if (!metadata.file_length.has_value()) { - // The length must come from trusted key metadata, not from the file system, so that - // truncation is detected (format/gcm-stream-spec.md, "File length"). - return Invalid("Cannot read AES GCM stream {}: key metadata has no file length", - encrypted->location()); - } - return std::make_unique( - std::move(encrypted), std::move(metadata.encryption_key), - metadata.aad_prefix.value_or(std::vector{}), *metadata.file_length); -} - -Result> StandardEncryptionManager::NewEncryptingOutputFile( - std::unique_ptr plain, const StandardKeyMetadata& key_metadata) { - ICEBERG_PRECHECK(plain != nullptr, "Output file cannot be null"); - return std::make_unique( - std::move(plain), key_metadata.encryption_key, - key_metadata.aad_prefix.value_or(std::vector{})); + std::vector encryption_key(data_key_length_); + ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(encryption_key)); + std::vector aad_prefix(kAadPrefixLength); + ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(aad_prefix)); + return StandardKeyMetadata::Make(std::move(encryption_key), std::move(aad_prefix)); } Result> StandardEncryptionManager::UnwrapKek( const std::string& kek_id) { - int64_t now = NowMs(); - if (auto it = unwrapped_keks_.find(kek_id); it != unwrapped_keks_.end()) { - if (now - it->second.unwrapped_at_ms < kUnwrappedKekCacheExpiry.count()) { + if (auto it = unwrapped_key_cache_.find(kek_id); it != unwrapped_key_cache_.end()) { + const auto age = std::chrono::steady_clock::now() - it->second.cached_at; + if (age < kUnwrappedKekCacheExpiry) { return it->second.key; } - unwrapped_keks_.erase(it); + unwrapped_key_cache_.erase(it); } - auto it = keys_.find(kek_id); - if (it == keys_.end()) { + auto it = encryption_keys_.find(kek_id); + if (it == encryption_keys_.end()) { return Invalid("Cannot find key encryption key with id {}", kek_id); } ICEBERG_ASSIGN_OR_RAISE( auto kek, - kms_->UnwrapKey(AsBytes(it->second.encrypted_key_metadata), table_key_id_)); - unwrapped_keks_.insert_or_assign(kek_id, CachedKek{.key = kek, .unwrapped_at_ms = now}); + kms_client_->UnwrapKey(AsBytes(it->second.encrypted_key_metadata), table_key_id_)); + unwrapped_key_cache_.insert_or_assign(kek_id, CachedKek{.key = kek}); return kek; } Result> StandardEncryptionManager::DecryptManifestListKeyMetadata( std::string_view manifest_list_key_id) { std::lock_guard lock(mutex_); - auto it = keys_.find(std::string(manifest_list_key_id)); - if (it == keys_.end()) { + auto it = encryption_keys_.find(std::string(manifest_list_key_id)); + if (it == encryption_keys_.end()) { return Invalid("Cannot find manifest list key metadata with id {}", manifest_list_key_id); } @@ -280,8 +247,9 @@ Result> StandardEncryptionManager::DecryptManifestListKeyMe const std::string& kek_id = *manifest_list_key.encrypted_by_id; ICEBERG_ASSIGN_OR_RAISE(auto kek, UnwrapKek(kek_id)); - auto timestamp = keys_.at(kek_id).properties.find(std::string(kKeyTimestamp)); - if (timestamp == keys_.at(kek_id).properties.end()) { + auto timestamp = + encryption_keys_.at(kek_id).properties.find(std::string(kKeyTimestamp)); + if (timestamp == encryption_keys_.at(kek_id).properties.end()) { return Invalid("Key encryption key {} must be timestamped", kek_id); } @@ -291,15 +259,15 @@ Result> StandardEncryptionManager::DecryptManifestListKeyMe AsBytes(timestamp->second)); } -Result StandardEncryptionManager::CurrentKekId() { - int64_t now = NowMs(); - for (const auto& key_id : key_order_) { - const EncryptedKey& key = keys_.at(key_id); +Result StandardEncryptionManager::KeyEncryptionKeyId() { + const int64_t now = CurrentTimeMillis(); + for (const auto& key_id : encryption_key_order_) { + const EncryptedKey& key = encryption_keys_.at(key_id); if (key.encrypted_by_id != table_key_id_) { continue; } - auto timestamp = ParseTimestamp(key); - if (timestamp.has_value() && now - *timestamp < kKekLifespan.count()) { + ICEBERG_ASSIGN_OR_RAISE(auto timestamp, ParseTimestamp(key)); + if (timestamp > now || now - timestamp < kKekLifespan.count()) { return key_id; } } @@ -307,49 +275,47 @@ Result StandardEncryptionManager::CurrentKekId() { // No unexpired key encryption key: create one, wrapped by the table master key. std::vector kek(data_key_length_); ICEBERG_RETURN_UNEXPECTED(SecureRandomBytes(kek)); - ICEBERG_ASSIGN_OR_RAISE(auto wrapped, kms_->WrapKey(kek, table_key_id_)); + ICEBERG_ASSIGN_OR_RAISE(auto wrapped, kms_client_->WrapKey(kek, table_key_id_)); + const int64_t timestamp = CurrentTimeMillis(); ICEBERG_ASSIGN_OR_RAISE(auto kek_id, GenerateKeyId()); - AddKey(EncryptedKey{.key_id = kek_id, - .encrypted_key_metadata = ToString(wrapped), - .encrypted_by_id = table_key_id_, - .properties = {{std::string(kKeyTimestamp), std::to_string(now)}}}); - unwrapped_keks_.insert_or_assign( - kek_id, CachedKek{.key = std::move(kek), .unwrapped_at_ms = now}); + AddKey(EncryptedKey{ + .key_id = kek_id, + .encrypted_key_metadata = ToString(wrapped), + .encrypted_by_id = table_key_id_, + .properties = {{std::string(kKeyTimestamp), std::to_string(timestamp)}}}); + unwrapped_key_cache_.insert_or_assign(kek_id, CachedKek{.key = std::move(kek)}); return kek_id; } -Result StandardEncryptionManager::RegisterManifestListKeyMetadata( - const StandardKeyMetadata& key_metadata) { - ICEBERG_PRECHECK(key_metadata.file_length.has_value(), - "Manifest list key metadata must include the file length"); +Result StandardEncryptionManager::RegisterKeyMetadata( + const NativeEncryptionKeyMetadata& key_metadata) { + auto serialized = key_metadata.buffer(); std::lock_guard lock(mutex_); - ICEBERG_ASSIGN_OR_RAISE(auto kek_id, CurrentKekId()); + ICEBERG_ASSIGN_OR_RAISE(auto kek_id, KeyEncryptionKeyId()); ICEBERG_ASSIGN_OR_RAISE(auto kek, UnwrapKek(kek_id)); - const EncryptedKey& kek_entry = keys_.at(kek_id); + const EncryptedKey& kek_entry = encryption_keys_.at(kek_id); const std::string& timestamp = kek_entry.properties.at(std::string(kKeyTimestamp)); ICEBERG_ASSIGN_OR_RAISE(auto cipher, AesGcmCipher::Make(kek)); ICEBERG_ASSIGN_OR_RAISE(auto encrypted, - cipher->Encrypt(key_metadata.Serialize(), AsBytes(timestamp))); + cipher->Encrypt(serialized, AsBytes(timestamp))); ICEBERG_ASSIGN_OR_RAISE(auto file_key_id, GenerateKeyId()); EncryptedKey file_key{.key_id = file_key_id, .encrypted_key_metadata = ToString(encrypted), .encrypted_by_id = kek_id}; AddKey(file_key); - return FileEncryptionKeys{.key_encryption_key = keys_.at(kek_id), + return FileEncryptionKeys{.key_encryption_key = encryption_keys_.at(kek_id), .file_key = std::move(file_key)}; } Result> StandardEncryptionManager::Decrypt( std::unique_ptr encrypted) { ICEBERG_PRECHECK(encrypted != nullptr, "Encrypted input file cannot be null"); - // A native wrapper already carries both the native and the stream path. - if (auto* native = dynamic_cast(encrypted.get())) { - encrypted.release(); - return std::unique_ptr(native); + if (auto native = EncryptedInputFile::AsNative(encrypted)) { + return native; } ICEBERG_ASSIGN_OR_RAISE(auto metadata, CastOrParse(encrypted->key_metadata())); - std::shared_ptr raw = encrypted->ReleaseInputFile(); + auto raw = std::move(*encrypted).DetachInputFile(); ICEBERG_PRECHECK(raw != nullptr, "Encrypted input file has no underlying file"); return std::make_unique(std::move(raw), std::move(metadata)); @@ -359,16 +325,24 @@ Result> StandardEncryptionManager::Encrypt( std::unique_ptr plain) { ICEBERG_PRECHECK(plain != nullptr, "Output file cannot be null"); ICEBERG_ASSIGN_OR_RAISE(auto key_metadata, NewKeyMetadata()); - return std::make_unique(std::move(plain), - std::move(key_metadata)); + const auto aad_prefix = key_metadata.aad_prefix(); + ICEBERG_CHECK(aad_prefix.has_value() && aad_prefix->size() == kAadPrefixLength, + "Standard encryption requires a {}-byte AAD prefix", kAadPrefixLength); + auto* plain_output_file = plain.get(); + ICEBERG_ASSIGN_OR_RAISE( + auto encrypting_output_file, + AesGcmOutputFile::Make(std::move(plain), key_metadata.encryption_key(), + *aad_prefix)); + return std::make_unique( + std::move(encrypting_output_file), *plain_output_file, std::move(key_metadata)); } std::vector StandardEncryptionManager::encryption_keys() const { std::lock_guard lock(mutex_); std::vector result; - result.reserve(key_order_.size()); - for (const auto& key_id : key_order_) { - result.push_back(keys_.at(key_id)); + result.reserve(encryption_key_order_.size()); + for (const auto& key_id : encryption_key_order_) { + result.push_back(encryption_keys_.at(key_id)); } return result; } @@ -376,12 +350,8 @@ std::vector StandardEncryptionManager::encryption_keys() const { namespace encryption { void RegisterStandardEncryptionManager() { - EncryptionManagerRegistry::Register([](EncryptionManagerRegistry::Options options) - -> Result> { - ICEBERG_ASSIGN_OR_RAISE(auto manager, - StandardEncryptionManager::Make(std::move(options))); - return manager; - }); + ::iceberg::internal::RegisterDefaultEncryptionManagerFactory( + MakeStandardEncryptionManager); } namespace { diff --git a/src/iceberg/encryption/standard_encryption_manager.h b/src/iceberg/encryption/standard_encryption_manager.h index 18bd5f7861..aaa6ae0c0b 100644 --- a/src/iceberg/encryption/standard_encryption_manager.h +++ b/src/iceberg/encryption/standard_encryption_manager.h @@ -29,8 +29,9 @@ #include #include +#include "iceberg/encryption/encrypted_key.h" #include "iceberg/encryption/encryption_manager.h" -#include "iceberg/encryption/standard_key_metadata.h" +#include "iceberg/encryption/type_fwd.h" #include "iceberg/iceberg_bundle_export.h" namespace iceberg { @@ -55,7 +56,7 @@ struct ICEBERG_BUNDLE_EXPORT FileEncryptionKeys { /// - manifest key metadata: in the manifest list `key_metadata` field; /// - data and delete file key metadata: in the manifest `key_metadata` field. /// -/// Unwrapped KEKs are cached for one hour. Thread-safe. +/// The thread-safe manager reuses an unwrapped KEK for up to one hour. class ICEBERG_BUNDLE_EXPORT StandardEncryptionManager : public EncryptionManager { public: static constexpr std::string_view kKeyTimestamp = "KEY_TIMESTAMP"; @@ -64,81 +65,63 @@ class ICEBERG_BUNDLE_EXPORT StandardEncryptionManager : public EncryptionManager static constexpr std::chrono::milliseconds kUnwrappedKekCacheExpiry{3600LL * 1000}; static Result> Make( - EncryptionManagerRegistry::Options options); + std::vector keys, std::string table_key_id, int32_t data_key_length, + std::shared_ptr kms_client); - // EncryptionManager. The batch overloads are re-exposed because overriding the - // single-file ones would otherwise hide them from callers of the concrete type. using EncryptionManager::Decrypt; using EncryptionManager::Encrypt; - /// \brief Decrypt a file. + /// \brief Return a NativeEncryptionInputFile, preserving an existing native wrapper. /// - /// If the argument is already a NativeEncryptionInputFile it is returned unchanged. - /// Otherwise the result is a NativeEncryptionInputFile (callers can dynamic_cast to it - /// to reach the native path) whose key metadata is parsed here but whose AGS1 stream - /// reader is only built when the file is opened or sized; only that stream path needs - /// the key metadata to carry the encrypted file length. + /// AGS1 Size() and Open() require the encrypted file length in the key metadata. Result> Decrypt( std::unique_ptr encrypted) override; - /// \brief Wrap a plain output file for encryption. + /// \brief Return a NativeEncryptionOutputFile for native encryption or AGS1 streaming. /// - /// The result is a NativeEncryptionOutputFile (callers can dynamic_cast to it to reach - /// the native path): plain_output_file() is the plain file for native writers, and - /// encrypting_output_file() writes an AGS1 stream with the same key and AAD prefix. - /// Neither is thread-safe. + /// Both paths use the same key and AAD prefix. The wrapper is not thread-safe. Result> Encrypt( std::unique_ptr plain) override; - Result NewKeyMetadata(); - Result> NewDecryptingInputFile( - std::unique_ptr encrypted, std::span key_metadata); - Result> NewEncryptingOutputFile( - std::unique_ptr plain, const StandardKeyMetadata& key_metadata); Result> DecryptManifestListKeyMetadata( std::string_view manifest_list_key_id); - Result RegisterManifestListKeyMetadata( - const StandardKeyMetadata& key_metadata); + + Result RegisterKeyMetadata( + const NativeEncryptionKeyMetadata& key_metadata); /// \brief All keys: those from table metadata and those created by this manager. std::vector encryption_keys() const; - const std::string& table_key_id() const { return table_key_id_; } - - /// \brief Shift the clock, for tests of KEK rotation and cache expiry. - void SetTestTimeShift(std::chrono::milliseconds shift); - private: + friend struct StandardEncryptionManagerTestAccess; + struct CachedKek { std::vector key; - int64_t unwrapped_at_ms; + std::chrono::steady_clock::time_point cached_at = std::chrono::steady_clock::now(); }; - explicit StandardEncryptionManager(EncryptionManagerRegistry::Options options); + StandardEncryptionManager(std::vector keys, std::string table_key_id, + int32_t data_key_length, + std::shared_ptr kms_client); + + Result NewKeyMetadata(); // The following require mutex_ to be held. Result> UnwrapKek(const std::string& kek_id); - Result CurrentKekId(); + Result KeyEncryptionKeyId(); void AddKey(EncryptedKey key); - int64_t NowMs() const; + int64_t CurrentTimeMillis() const; const std::string table_key_id_; const int32_t data_key_length_; - const std::shared_ptr kms_; + const std::shared_ptr kms_client_; mutable std::mutex mutex_; - std::chrono::milliseconds time_shift_{0}; - std::vector key_order_; - std::unordered_map keys_; - std::unordered_map unwrapped_keks_; + std::chrono::milliseconds test_time_shift_{0}; + std::vector encryption_key_order_; + std::unordered_map encryption_keys_; + std::unordered_map unwrapped_key_cache_; }; -namespace encryption { - -/// \brief Register StandardEncryptionManager in EncryptionManagerRegistry. -ICEBERG_BUNDLE_EXPORT void RegisterStandardEncryptionManager(); - -} // namespace encryption - } // namespace iceberg diff --git a/src/iceberg/encryption/standard_key_metadata.cc b/src/iceberg/encryption/standard_key_metadata.cc index 18f2d92ea2..1f2cb33ece 100644 --- a/src/iceberg/encryption/standard_key_metadata.cc +++ b/src/iceberg/encryption/standard_key_metadata.cc @@ -21,6 +21,7 @@ #include +#include "iceberg/encryption/aes_gcm_internal.h" #include "iceberg/util/macros.h" namespace iceberg { @@ -116,6 +117,25 @@ class Decoder { } // namespace +StandardKeyMetadata::StandardKeyMetadata(std::vector encryption_key, + std::optional> aad_prefix, + std::optional file_length) + : encryption_key_(std::move(encryption_key)), + aad_prefix_(std::move(aad_prefix)), + file_length_(file_length) {} + +Result StandardKeyMetadata::Make( + std::vector encryption_key, std::optional> aad_prefix, + std::optional file_length) { + ICEBERG_PRECHECK(encryption::IsValidAesKeyLength(encryption_key.size()), + "Invalid encryption key length: {} (must be 16, 24 or 32 bytes)", + encryption_key.size()); + ICEBERG_PRECHECK(!file_length.has_value() || *file_length >= 0, + "Encrypted file length must be nonnegative"); + return StandardKeyMetadata(std::move(encryption_key), std::move(aad_prefix), + file_length); +} + Result StandardKeyMetadata::Parse(std::span buffer) { if (buffer.empty()) { return Invalid("Empty key metadata"); @@ -126,43 +146,49 @@ Result StandardKeyMetadata::Parse(std::span } Decoder decoder(buffer.subspan(1)); - StandardKeyMetadata metadata; - ICEBERG_ASSIGN_OR_RAISE(metadata.encryption_key, decoder.ReadBytes()); + ICEBERG_ASSIGN_OR_RAISE(auto encryption_key, decoder.ReadBytes()); + std::optional> aad_prefix; ICEBERG_ASSIGN_OR_RAISE(auto has_aad_prefix, decoder.ReadOptionalBranch()); if (has_aad_prefix) { - ICEBERG_ASSIGN_OR_RAISE(metadata.aad_prefix, decoder.ReadBytes()); + ICEBERG_ASSIGN_OR_RAISE(aad_prefix, decoder.ReadBytes()); } + std::optional file_length; ICEBERG_ASSIGN_OR_RAISE(auto has_file_length, decoder.ReadOptionalBranch()); if (has_file_length) { - ICEBERG_ASSIGN_OR_RAISE(metadata.file_length, decoder.ReadLong()); + ICEBERG_ASSIGN_OR_RAISE(file_length, decoder.ReadLong()); } // Trailing bytes are ignored, matching Java, which decodes a single record. - return metadata; + return StandardKeyMetadata(std::move(encryption_key), std::move(aad_prefix), + file_length); } std::vector StandardKeyMetadata::Serialize() const { std::vector out; out.push_back(kV1); - WriteBytes(encryption_key, out); - if (aad_prefix.has_value()) { + WriteBytes(encryption_key_, out); + if (aad_prefix_.has_value()) { WriteLong(1, out); - WriteBytes(*aad_prefix, out); + WriteBytes(*aad_prefix_, out); } else { WriteLong(0, out); } - if (file_length.has_value()) { + if (file_length_.has_value()) { WriteLong(1, out); - WriteLong(*file_length, out); + WriteLong(*file_length_, out); } else { WriteLong(0, out); } return out; } -StandardKeyMetadata StandardKeyMetadata::WithFileLength(int64_t length) const { - StandardKeyMetadata copy = *this; - copy.file_length = length; - return copy; +Result StandardKeyMetadata::WithFileLength(int64_t length) const { + return Make(encryption_key_, aad_prefix_, length); +} + +Result> StandardKeyMetadata::CopyWithLength( + int64_t length) const { + ICEBERG_ASSIGN_OR_RAISE(auto copy, WithFileLength(length)); + return std::make_shared(std::move(copy)); } } // namespace iceberg diff --git a/src/iceberg/encryption/standard_key_metadata.h b/src/iceberg/encryption/standard_key_metadata.h index f304ee1d68..38abb33b49 100644 --- a/src/iceberg/encryption/standard_key_metadata.h +++ b/src/iceberg/encryption/standard_key_metadata.h @@ -48,25 +48,14 @@ namespace iceberg { /// version (1) followed by an Avro binary encoded record with the fields /// `encryption_key: bytes`, `aad_prefix: union{null, bytes}` and /// `file_length: union{null, long}`. -struct ICEBERG_EXPORT StandardKeyMetadata : public NativeEncryptionKeyMetadata { +class ICEBERG_EXPORT StandardKeyMetadata : public NativeEncryptionKeyMetadata { + public: static constexpr uint8_t kV1 = 1; - /// \brief The data encryption key (16, 24 or 32 bytes). - std::vector encryption_key; - /// \brief The AAD prefix (file ID) used to bind ciphertext to this file. - std::optional> aad_prefix; - /// \brief The encrypted (stored) file length, required to read AES GCM streams. - std::optional file_length; - - StandardKeyMetadata() = default; - - explicit StandardKeyMetadata( + static Result Make( std::vector encryption_key, std::optional> aad_prefix = std::nullopt, - std::optional file_length = std::nullopt) - : encryption_key(std::move(encryption_key)), - aad_prefix(std::move(aad_prefix)), - file_length(file_length) {} + std::optional file_length = std::nullopt); /// \brief Parse serialized key metadata. static Result Parse(std::span buffer); @@ -75,26 +64,41 @@ struct ICEBERG_EXPORT StandardKeyMetadata : public NativeEncryptionKeyMetadata { std::vector Serialize() const; /// \brief Return a copy with the given encrypted file length. - StandardKeyMetadata WithFileLength(int64_t length) const; + Result WithFileLength(int64_t length) const; std::vector buffer() const override { return Serialize(); } + std::shared_ptr Copy() const override { return std::make_shared(*this); } - const std::vector& EncryptionKey() const override { return encryption_key; } - const std::optional>& AadPrefix() const override { - return aad_prefix; + + std::span encryption_key() const override { return encryption_key_; } + + std::optional> aad_prefix() const override { + if (!aad_prefix_.has_value()) { + return std::nullopt; + } + return std::span(*aad_prefix_); } - Result> FileLength() const override { return file_length; } + + Result> file_length() const override { return file_length_; } + Result> CopyWithLength( - int64_t length) const override { - return std::make_shared(WithFileLength(length)); - } + int64_t length) const override; friend bool operator==(const StandardKeyMetadata& lhs, const StandardKeyMetadata& rhs) { - return lhs.encryption_key == rhs.encryption_key && lhs.aad_prefix == rhs.aad_prefix && - lhs.file_length == rhs.file_length; + return lhs.encryption_key_ == rhs.encryption_key_ && + lhs.aad_prefix_ == rhs.aad_prefix_ && lhs.file_length_ == rhs.file_length_; } + + private: + StandardKeyMetadata(std::vector encryption_key, + std::optional> aad_prefix, + std::optional file_length); + + std::vector encryption_key_; + std::optional> aad_prefix_; + std::optional file_length_; }; } // namespace iceberg diff --git a/src/iceberg/encryption/type_fwd.h b/src/iceberg/encryption/type_fwd.h new file mode 100644 index 0000000000..d8602590b8 --- /dev/null +++ b/src/iceberg/encryption/type_fwd.h @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma once + +/// \file iceberg/encryption/type_fwd.h +/// Forward declarations for table encryption types. + +namespace iceberg { + +struct EncryptedKey; +struct FileEncryptionKeys; + +class EncryptedInputFile; +class EncryptedOutputFile; +class EncryptionKeyMetadata; +class EncryptionManager; +class KeyManagementClient; +class NativeEncryptionInputFile; +class NativeEncryptionKeyMetadata; +class NativeEncryptionOutputFile; +class StandardEncryptionManager; +class StandardKeyMetadata; + +} // namespace iceberg diff --git a/src/iceberg/test/CMakeLists.txt b/src/iceberg/test/CMakeLists.txt index 0a6262d80a..4d9e84a10f 100644 --- a/src/iceberg/test/CMakeLists.txt +++ b/src/iceberg/test/CMakeLists.txt @@ -142,7 +142,11 @@ add_iceberg_test(expression_test residual_evaluator_test.cc strict_metrics_evaluator_test.cc) -add_iceberg_test(encryption_test SOURCES kms_test.cc standard_key_metadata_test.cc) +add_iceberg_test(encryption_test + SOURCES + encryption_manager_test.cc + kms_test.cc + standard_key_metadata_test.cc) add_iceberg_test(json_serde_test SOURCES diff --git a/src/iceberg/test/aes_gcm_test.cc b/src/iceberg/test/aes_gcm_test.cc index e3d1248e75..f9fd3d87d4 100644 --- a/src/iceberg/test/aes_gcm_test.cc +++ b/src/iceberg/test/aes_gcm_test.cc @@ -145,9 +145,11 @@ TEST(AesGcmCipherTest, DecryptsJavaManifestListKeyMetadata) { ICEBERG_UNWRAP_OR_FAIL(auto decrypted, cipher->Decrypt(kJavaManifestListKeyMetadata, AsBytes(kKekTimestamp))); ICEBERG_UNWRAP_OR_FAIL(auto metadata, StandardKeyMetadata::Parse(decrypted)); - EXPECT_EQ(metadata.encryption_key, TestBytes(16, 1)); - EXPECT_EQ(metadata.aad_prefix, TestBytes(16, 2)); - EXPECT_EQ(metadata.file_length, 4242); + EXPECT_TRUE(std::ranges::equal(metadata.encryption_key(), TestBytes(16, 1))); + ASSERT_TRUE(metadata.aad_prefix().has_value()); + EXPECT_TRUE(std::ranges::equal(*metadata.aad_prefix(), TestBytes(16, 2))); + ICEBERG_UNWRAP_OR_FAIL(auto length, metadata.file_length()); + EXPECT_EQ(length, 4242); } class AesGcmStreamTest : public TempFileTestBase { @@ -163,8 +165,9 @@ class AesGcmStreamTest : public TempFileTestBase { size_t chunk = 1 << 20) { auto out = io_->NewOutputFile(path); EXPECT_THAT(out, IsOk()); - AesGcmOutputFile file(std::move(out.value()), key, aad); - auto stream = file.CreateOrOverwrite(); + auto file = AesGcmOutputFile::Make(std::move(out.value()), key, aad); + EXPECT_THAT(file, IsOk()); + auto stream = (*file)->CreateOrOverwrite(); EXPECT_THAT(stream, IsOk()); for (size_t pos = 0; pos < plain.size(); pos += chunk) { auto part = plain.subspan(pos, std::min(chunk, plain.size() - pos)); @@ -184,7 +187,9 @@ class AesGcmStreamTest : public TempFileTestBase { const std::vector& aad, int64_t length) { auto in = io_->NewInputFile(path); EXPECT_THAT(in, IsOk()); - return std::make_unique(std::move(in.value()), key, aad, length); + auto file = AesGcmInputFile::Make(std::move(in.value()), key, aad, length); + EXPECT_THAT(file, IsOk()); + return std::move(file.value()); } // Materialize an inlined Java fixture as a file the reader can open. @@ -281,8 +286,6 @@ TEST_F(AesGcmStreamTest, DetectsTampering) { std::filesystem::resize_file(path, 0); std::ofstream(path, std::ios::binary) << "XXXX0000" << std::string(28, '\0'); EXPECT_THAT(Open(path, key, aad, 36)->Open(), IsError(ErrorKind::kInvalid)); - // Shorter than an empty stream - EXPECT_THAT(Open(path, key, aad, 35)->Open(), IsError(ErrorKind::kInvalid)); } TEST_F(AesGcmStreamTest, AuthenticatesEmptyStream) { @@ -367,12 +370,29 @@ TEST_F(AesGcmStreamTest, RejectsInvalidEncryptedLength) { EXPECT_THAT(AesGcmStream::PlaintextLength(kHeader + kMaxBlocks * kCipherBlock + 1), IsError(ErrorKind::kInvalid)); - // Both Size() and Open() reject it, rather than Open() alone + // Reject the invalid length at construction. auto path = CreateNewTempFilePath(); Write(path, TestBytes(10, 5), kDataKey, kAadPrefix); - auto file = Open(path, kDataKey, kAadPrefix, kHeader + kMaxBlocks * kCipherBlock + 1); - EXPECT_THAT(file->Size(), IsError(ErrorKind::kInvalid)); - EXPECT_THAT(file->Open(), IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto in, io_->NewInputFile(path)); + EXPECT_THAT(AesGcmInputFile::Make(std::move(in), kDataKey, kAadPrefix, + kHeader + kMaxBlocks * kCipherBlock + 1), + IsError(ErrorKind::kInvalid)); +} + +TEST_F(AesGcmStreamTest, RejectsInvalidFileHandlesAndKeys) { + constexpr int64_t kLength = AesGcmStream::kMinStreamLength; + EXPECT_THAT(AesGcmInputFile::Make(nullptr, kDataKey, {}, kLength), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(AesGcmOutputFile::Make(nullptr, kDataKey, {}), + IsError(ErrorKind::kInvalidArgument)); + + auto path = CreateNewTempFilePath(); + ICEBERG_UNWRAP_OR_FAIL(auto in, io_->NewInputFile(path)); + EXPECT_THAT(AesGcmInputFile::Make(std::move(in), {}, {}, kLength), + IsError(ErrorKind::kInvalidArgument)); + ICEBERG_UNWRAP_OR_FAIL(auto out, io_->NewOutputFile(path)); + EXPECT_THAT(AesGcmOutputFile::Make(std::move(out), {}, {}), + IsError(ErrorKind::kInvalidArgument)); } // The key encryption key of the Java fixture table, wrapped by Java's UnitestKMS under @@ -394,14 +414,15 @@ constexpr std::string_view kJavaMasterKeyA = "0123456789012345"; TEST(InMemoryKmsTest, UnwrapsJavaWrappedKey) { auto master_key = AsBytes(kJavaMasterKeyA); - InMemoryKms kms({{"keyA", std::vector(master_key.begin(), master_key.end())}}); - ICEBERG_UNWRAP_OR_FAIL(auto kek, kms.UnwrapKey(kJavaKekWrappedByKeyA, "keyA")); + ICEBERG_UNWRAP_OR_FAIL( + auto kms, InMemoryKms::Make({{"keyA", {master_key.begin(), master_key.end()}}})); + ICEBERG_UNWRAP_OR_FAIL(auto kek, kms->UnwrapKey(kJavaKekWrappedByKeyA, "keyA")); EXPECT_EQ(kek, kJavaKek); - ICEBERG_UNWRAP_OR_FAIL(auto wrapped, kms.WrapKey(kek, "keyA")); - ICEBERG_UNWRAP_OR_FAIL(auto unwrapped, kms.UnwrapKey(wrapped, "keyA")); + ICEBERG_UNWRAP_OR_FAIL(auto wrapped, kms->WrapKey(kek, "keyA")); + ICEBERG_UNWRAP_OR_FAIL(auto unwrapped, kms->UnwrapKey(wrapped, "keyA")); EXPECT_EQ(unwrapped, kJavaKek); - EXPECT_THAT(kms.UnwrapKey(wrapped, "keyB"), IsError(ErrorKind::kNotFound)); + EXPECT_THAT(kms->UnwrapKey(wrapped, "keyB"), IsError(ErrorKind::kNotFound)); } TEST(InMemoryKmsTest, RegistryAndProperties) { @@ -417,6 +438,11 @@ TEST(InMemoryKmsTest, RegistryAndProperties) { } TEST(InMemoryKmsTest, RejectsInvalidMasterKeyProperties) { + EXPECT_THAT(InMemoryKms::Make({{"", std::vector(16)}}), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(InMemoryKms::Make({{"keyA", {1, 2, 3}}}), + IsError(ErrorKind::kInvalidArgument)); + InMemoryKms::Register(); auto load = [](std::string id, std::string value) { return KmsRegistry::FromCatalogProperties( diff --git a/src/iceberg/test/encryption_manager_test.cc b/src/iceberg/test/encryption_manager_test.cc new file mode 100644 index 0000000000..b5af47e109 --- /dev/null +++ b/src/iceberg/test/encryption_manager_test.cc @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/encryption/encryption_manager.h" + +#include + +#include "iceberg/encryption/encrypted_file.h" +#include "iceberg/encryption/encrypted_files.h" +#include "iceberg/encryption/encrypted_key.h" +#include "iceberg/table_properties.h" +#include "iceberg/test/logging_test_helpers.h" +#include "iceberg/test/matchers.h" +#include "iceberg/test/std_io.h" + +namespace iceberg { +namespace { + +class EncryptionManagerRegistryTest : public ::testing::Test { + protected: + void TearDown() override { EncryptionManagerRegistry::Register({}); } +}; + +TEST_F(EncryptionManagerRegistryTest, RegistersCustomFactoryWithoutKms) { + std::vector keys{ + {.key_id = "custom-key", .encrypted_key_metadata = "wrapped"}}; + auto properties = TableProperties::FromMap( + {{"custom.property", "value"}, {"encryption.data-key-length", "custom"}}); + EXPECT_THAT(EncryptionManagerRegistry::Make(keys, properties, nullptr), + IsError(ErrorKind::kNotSupported)); + + auto custom = std::make_shared(); + EncryptionManagerRegistry::Register([&](const std::vector& received_keys, + const TableProperties& received_properties, + std::shared_ptr kms_client) + -> Result> { + EXPECT_EQ(received_keys, keys); + EXPECT_EQ(received_properties.configs(), properties.configs()); + EXPECT_EQ(kms_client, nullptr); + return custom; + }); + ICEBERG_UNWRAP_OR_FAIL(auto direct, + EncryptionManagerRegistry::Make(keys, properties, nullptr)); + EXPECT_EQ(direct, custom); + + custom.reset(); + EXPECT_THAT(EncryptionManagerRegistry::Make(keys, properties, nullptr), + IsError(ErrorKind::kInvalidArgument)); +} + +TEST(PlaintextEncryptionManagerTest, RejectsNullFileHandles) { + PlaintextEncryptionManager manager; + std::vector> inputs(1); + EXPECT_THAT(manager.Decrypt(std::move(inputs)), IsError(ErrorKind::kInvalidArgument)); + std::vector> outputs(1); + EXPECT_THAT(manager.Encrypt(std::move(outputs)), IsError(ErrorKind::kInvalidArgument)); +} + +TEST(EncryptedFilesTest, RejectsNullArguments) { + auto metadata = BaseEncryptionKeyMetadata::Empty(); + EXPECT_THAT(EncryptedFiles::EncryptedInput(nullptr, metadata), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(EncryptedFiles::EncryptedOutput(nullptr, metadata), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT( + EncryptedFiles::EncryptedInput(std::make_unique("in"), nullptr), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(EncryptedFiles::EncryptedOutput( + std::make_unique("out"), nullptr), + IsError(ErrorKind::kInvalidArgument)); +} + +TEST(PlaintextEncryptionManagerTest, WarnsWhenKeyMetadataIsPresent) { + PlaintextEncryptionManager manager; + auto logger = std::make_shared(); + ScopedLogger bind(logger); + auto present_empty = + std::make_shared(std::vector{}); + for (const auto& metadata : {BaseEncryptionKeyMetadata::Empty(), present_empty}) { + auto input = std::make_unique("in"); + auto* raw = input.get(); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, + EncryptedFiles::EncryptedInput(std::move(input), metadata)); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager.Decrypt(std::move(encrypted))); + EXPECT_EQ(decrypted.get(), raw); + EXPECT_EQ(logger->count(), metadata->has_value() ? 1u : 0u); + } + EXPECT_THAT(logger->records(), ::testing::ElementsAre(::testing::Field( + &LogMessage::level, LogLevel::kWarn))); +} + +TEST(BaseEncryptionKeyMetadataTest, DistinguishesAbsentFromEmpty) { + auto absent = BaseEncryptionKeyMetadata::Empty(); + BaseEncryptionKeyMetadata empty(std::vector{}); + EXPECT_FALSE(absent->has_value()); + EXPECT_TRUE(empty.has_value()); + EXPECT_TRUE(absent->buffer().empty()); + EXPECT_EQ(absent->buffer(), empty.buffer()); + EXPECT_FALSE(absent->Copy()->has_value()); + EXPECT_TRUE(empty.Copy()->has_value()); + + BaseEncryptionKeyMetadata bytes(std::vector{1, 2}); + EXPECT_EQ(bytes.Copy()->buffer(), bytes.buffer()); +} + +} // namespace +} // namespace iceberg diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc index db01f3ddd2..c12598188a 100644 --- a/src/iceberg/test/standard_encryption_manager_test.cc +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -19,17 +19,26 @@ #include "iceberg/encryption/standard_encryption_manager.h" +#include +#include #include -#include +#include +#include #include +#include +#include +#include +#include #include #include "iceberg/arrow/arrow_io_util.h" +#include "iceberg/encryption/encrypted_file.h" #include "iceberg/encryption/encrypted_files.h" #include "iceberg/encryption/encryption_register.h" #include "iceberg/encryption/encryption_util.h" #include "iceberg/encryption/in_memory_kms.h" +#include "iceberg/encryption/standard_key_metadata.h" #include "iceberg/snapshot.h" #include "iceberg/table_metadata.h" #include "iceberg/test/matchers.h" @@ -40,41 +49,42 @@ namespace iceberg { namespace { -/// \brief Deterministic test bytes: byte i is (i * 31 + seed). -std::vector VectorBytes(size_t length, int seed) { - std::vector bytes(length); - for (size_t i = 0; i < length; ++i) { - bytes[i] = static_cast(static_cast(i) * 31 + seed); - } - return bytes; -} - // The master key for "keyA" used by the Java fixture under // test/resources/encryption/table. const std::vector kMasterKeyA = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5'}; /// Counts calls to the KMS. -class CountingKms : public InMemoryKms { +class CountingKms : public KeyManagementClient { public: - using InMemoryKms::InMemoryKms; + explicit CountingKms(std::unique_ptr kms) : kms_(std::move(kms)) {} + Result> WrapKey(std::span key, std::string_view id) override { ++wraps; - return InMemoryKms::WrapKey(key, id); + ICEBERG_ASSIGN_OR_RAISE(auto wrapped, kms_->WrapKey(key, id)); + if (after_wrap) { + after_wrap(); + } + return wrapped; } Result> UnwrapKey(std::span wrapped, std::string_view id) override { ++unwraps; - return InMemoryKms::UnwrapKey(wrapped, id); + return kms_->UnwrapKey(wrapped, id); } int wraps = 0; int unwraps = 0; + std::function after_wrap; + + private: + std::unique_ptr kms_; }; std::shared_ptr MakeKms() { - return std::make_shared( - std::unordered_map>{{"keyA", kMasterKeyA}}); + auto kms = InMemoryKms::Make({{"keyA", kMasterKeyA}}); + EXPECT_THAT(kms, IsOk()); + return std::make_shared(std::move(kms.value())); } } // namespace @@ -86,86 +96,85 @@ TEST(StandardEncryptionManagerTest, DecryptsJavaManifestListKeys) { ASSERT_EQ(metadata->snapshots.size(), 4); ASSERT_EQ(metadata->encryption_keys.size(), 5); - // Through the registry, as catalogs do - encryption::RegisterAll(); auto kms = MakeKms(); - ICEBERG_UNWRAP_OR_FAIL(auto manager, EncryptionManagerRegistry::Make( - {.table_key_id = "keyA", - .encryption_keys = metadata->encryption_keys, - .kms = kms})); + auto table_properties = TableProperties::FromMap({{"encryption.key-id", "keyA"}}); + ICEBERG_UNWRAP_OR_FAIL(auto manager, + EncryptionUtil::MakeEncryptionManager(metadata->encryption_keys, + table_properties, kms)); + auto io = arrow::MakeLocalFileIO(); + constexpr std::string_view kAvroMagic = "Obj\x01"; for (const auto& snapshot : metadata->snapshots) { + SCOPED_TRACE(snapshot->manifest_list); ASSERT_TRUE(snapshot->key_id.has_value()); ICEBERG_UNWRAP_OR_FAIL(auto decrypted, EncryptionUtil::DecryptManifestListKeyMetadata( manager, *snapshot->key_id)); ICEBERG_UNWRAP_OR_FAIL(auto key_metadata, StandardKeyMetadata::Parse(decrypted)); - EXPECT_EQ(key_metadata.encryption_key.size(), 16); - EXPECT_EQ(key_metadata.aad_prefix->size(), 16); + EXPECT_EQ(key_metadata.encryption_key().size(), 16); + const auto aad_prefix = key_metadata.aad_prefix(); + ASSERT_TRUE(aad_prefix.has_value()); + EXPECT_EQ(aad_prefix->size(), 16); // The trusted length is the stored (encrypted) size of the manifest list file auto name = std::filesystem::path(snapshot->manifest_list).filename().string(); - EXPECT_EQ( - key_metadata.file_length, - std::filesystem::file_size(GetResourcePath("encryption/table/metadata/" + name))); + auto path = GetResourcePath("encryption/table/metadata/" + name); + ICEBERG_UNWRAP_OR_FAIL(auto raw, io->NewInputFile(path)); + ICEBERG_UNWRAP_OR_FAIL(auto stored_length, raw->Size()); + ICEBERG_UNWRAP_OR_FAIL(auto file_length, key_metadata.file_length()); + EXPECT_EQ(file_length, stored_length); + + ICEBERG_UNWRAP_OR_FAIL( + auto encrypted, EncryptedFiles::EncryptedInput( + std::move(raw), std::make_shared( + std::move(decrypted)))); + ICEBERG_UNWRAP_OR_FAIL(auto manifest_list, manager->Decrypt(std::move(encrypted))); + ICEBERG_UNWRAP_OR_FAIL(auto stream, manifest_list->Open()); + std::string magic(kAvroMagic.size(), '\0'); + ASSERT_THAT(stream->ReadFully(0, std::as_writable_bytes(std::span(magic))), IsOk()); + EXPECT_EQ(magic, kAvroMagic); } // One key encryption key for all snapshots, unwrapped once EXPECT_EQ(kms->unwraps, 1); } -TEST(StandardEncryptionManagerTest, RegisterAndDecryptManifestListKeyMetadata) { - auto kms = MakeKms(); - ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( - {.table_key_id = "keyA", .kms = kms})); - - ICEBERG_UNWRAP_OR_FAIL(auto key_metadata, manager->NewKeyMetadata()); - EXPECT_EQ(key_metadata.encryption_key.size(), 16); - EXPECT_EQ(key_metadata.aad_prefix->size(), 16); - EXPECT_FALSE(key_metadata.file_length.has_value()); - // The manifest list length is required - EXPECT_THAT(manager->RegisterManifestListKeyMetadata(key_metadata), - IsError(ErrorKind::kInvalidArgument)); - key_metadata.file_length = 999; +struct StandardEncryptionManagerTestAccess { + static void SetTimeShift(StandardEncryptionManager& manager, + std::chrono::milliseconds shift) { + std::lock_guard lock(manager.mutex_); + manager.test_time_shift_ = shift; + } - ICEBERG_UNWRAP_OR_FAIL(auto keys, - manager->RegisterManifestListKeyMetadata(key_metadata)); - EXPECT_EQ(keys.key_encryption_key.encrypted_by_id, "keyA"); - EXPECT_TRUE(keys.key_encryption_key.properties.contains("KEY_TIMESTAMP")); - EXPECT_EQ(keys.file_key.encrypted_by_id, keys.key_encryption_key.key_id); - EXPECT_EQ(kms->wraps, 1); - EXPECT_EQ(manager->encryption_keys().size(), 2); - - // A reader that only has the committed keys and the KMS can decrypt it - ICEBERG_UNWRAP_OR_FAIL(auto reader, - StandardEncryptionManager::Make( - {.table_key_id = "keyA", - .encryption_keys = {keys.key_encryption_key, keys.file_key}, - .kms = kms})); - ICEBERG_UNWRAP_OR_FAIL(auto decrypted, - reader->DecryptManifestListKeyMetadata(keys.file_key.key_id)); - EXPECT_EQ(decrypted, key_metadata.Serialize()); + static void AdvanceCacheAge(StandardEncryptionManager& manager, + std::chrono::milliseconds elapsed) { + std::lock_guard lock(manager.mutex_); + for (auto& [id, entry] : manager.unwrapped_key_cache_) { + entry.cached_at -= elapsed; + } + } - // Key encryption keys and unknown IDs are rejected - EXPECT_THAT(reader->DecryptManifestListKeyMetadata(keys.key_encryption_key.key_id), - IsError(ErrorKind::kInvalid)); - EXPECT_THAT(reader->DecryptManifestListKeyMetadata("missing"), - IsError(ErrorKind::kInvalid)); -} + static int64_t AdvanceTimeDuringWrap(StandardEncryptionManager& manager, + std::chrono::milliseconds elapsed) { + // RegisterKeyMetadata holds the mutex while calling WrapKey. + manager.test_time_shift_ += elapsed; + return manager.CurrentTimeMillis(); + } +}; TEST(StandardEncryptionManagerTest, RotatesKeyEncryptionKeys) { auto kms = MakeKms(); - ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( - {.table_key_id = "keyA", .kms = kms})); - StandardKeyMetadata key_metadata(VectorBytes(16, 1), VectorBytes(16, 2), 100); + ICEBERG_UNWRAP_OR_FAIL(auto manager, + StandardEncryptionManager::Make({}, "keyA", 16, kms)); + ICEBERG_UNWRAP_OR_FAIL( + auto key_metadata, + StandardKeyMetadata::Make(std::vector(16, 1), std::nullopt, 100)); - ICEBERG_UNWRAP_OR_FAIL(auto first, - manager->RegisterManifestListKeyMetadata(key_metadata)); - ICEBERG_UNWRAP_OR_FAIL(auto second, - manager->RegisterManifestListKeyMetadata(key_metadata)); + ICEBERG_UNWRAP_OR_FAIL(auto first, manager->RegisterKeyMetadata(key_metadata)); + ICEBERG_UNWRAP_OR_FAIL(auto second, manager->RegisterKeyMetadata(key_metadata)); EXPECT_EQ(second.key_encryption_key.key_id, first.key_encryption_key.key_id); EXPECT_NE(second.file_key.key_id, first.file_key.key_id); - manager->SetTestTimeShift(StandardEncryptionManager::kKekLifespan); - ICEBERG_UNWRAP_OR_FAIL(auto third, - manager->RegisterManifestListKeyMetadata(key_metadata)); + StandardEncryptionManagerTestAccess::SetTimeShift( + *manager, StandardEncryptionManager::kKekLifespan); + ICEBERG_UNWRAP_OR_FAIL(auto third, manager->RegisterKeyMetadata(key_metadata)); EXPECT_NE(third.key_encryption_key.key_id, first.key_encryption_key.key_id); EXPECT_EQ(kms->wraps, 2); @@ -175,32 +184,46 @@ TEST(StandardEncryptionManagerTest, RotatesKeyEncryptionKeys) { EXPECT_EQ(decrypted, key_metadata.Serialize()); } -TEST(StandardEncryptionManagerTest, IgnoresOutOfRangeKeyTimestamp) { +TEST(StandardEncryptionManagerTest, RejectsInvalidKeyTimestamp) { auto kms = MakeKms(); - ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( - {.table_key_id = "keyA", .kms = kms})); - StandardKeyMetadata key_metadata(VectorBytes(16, 1), VectorBytes(16, 2), 100); - ICEBERG_UNWRAP_OR_FAIL(auto first, - manager->RegisterManifestListKeyMetadata(key_metadata)); - EXPECT_EQ(kms->wraps, 1); - - // A KEK whose KEY_TIMESTAMP is corrupted to INT64_MIN must never reach the - // "now - timestamp" subtraction, which would overflow. It should instead be - // treated as unparseable, forcing a fresh key encryption key to be created. - std::vector keys = manager->encryption_keys(); - for (auto& key : keys) { - if (key.encrypted_by_id == "keyA") { - key.properties[std::string(StandardEncryptionManager::kKeyTimestamp)] = - "-9223372036854775808"; + ICEBERG_UNWRAP_OR_FAIL( + auto key_metadata, + StandardKeyMetadata::Make(std::vector(16, 1), std::nullopt, 100)); + + const std::vector> invalid_timestamps = { + std::nullopt, "", "123x", "9223372036854775808", "-1", "-9223372036854775808"}; + for (const auto& timestamp : invalid_timestamps) { + SCOPED_TRACE(timestamp.value_or("")); + EncryptedKey kek{.key_id = "invalid-kek", .encrypted_by_id = "keyA"}; + if (timestamp.has_value()) { + kek.properties.emplace(StandardEncryptionManager::kKeyTimestamp, *timestamp); } + ICEBERG_UNWRAP_OR_FAIL(auto manager, + StandardEncryptionManager::Make({kek}, "keyA", 16, kms)); + EXPECT_THAT(manager->RegisterKeyMetadata(key_metadata), IsError(ErrorKind::kInvalid)); + EXPECT_EQ(kms->wraps, 0); + EXPECT_EQ(kms->unwraps, 0); } - ICEBERG_UNWRAP_OR_FAIL( - auto reader, StandardEncryptionManager::Make( - {.table_key_id = "keyA", .encryption_keys = keys, .kms = kms})); - ICEBERG_UNWRAP_OR_FAIL(auto second, - reader->RegisterManifestListKeyMetadata(key_metadata)); - EXPECT_NE(second.key_encryption_key.key_id, first.key_encryption_key.key_id); - EXPECT_EQ(kms->wraps, 2); +} + +TEST(StandardEncryptionManagerTest, TimestampsKeyAfterWrap) { + auto kms = MakeKms(); + ICEBERG_UNWRAP_OR_FAIL(auto manager, + StandardEncryptionManager::Make({}, "keyA", 16, kms)); + ICEBERG_UNWRAP_OR_FAIL(auto key_metadata, + StandardKeyMetadata::Make(std::vector(16, 1))); + std::optional wrap_time; + kms->after_wrap = [&] { + wrap_time = StandardEncryptionManagerTestAccess::AdvanceTimeDuringWrap( + *manager, std::chrono::hours{1}); + }; + + ICEBERG_UNWRAP_OR_FAIL(auto keys, manager->RegisterKeyMetadata(key_metadata)); + ASSERT_TRUE(wrap_time.has_value()); + const auto& properties = keys.key_encryption_key.properties; + auto timestamp = properties.find(std::string(StandardEncryptionManager::kKeyTimestamp)); + ASSERT_NE(timestamp, properties.end()); + EXPECT_GE(std::stoll(timestamp->second), *wrap_time); } TEST(StandardEncryptionManagerTest, UnwrappedKeyCacheExpires) { @@ -209,176 +232,135 @@ TEST(StandardEncryptionManagerTest, UnwrappedKeyCacheExpires) { ReadTableMetadataFromResource("encryption/table/metadata/v5.metadata.json")); auto kms = MakeKms(); ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( - {.table_key_id = "keyA", - .encryption_keys = metadata->encryption_keys, - .kms = kms})); + metadata->encryption_keys, "keyA", 16, kms)); const auto& key_id = *metadata->snapshots.front()->key_id; ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); EXPECT_EQ(kms->unwraps, 1); - manager->SetTestTimeShift(StandardEncryptionManager::kUnwrappedKekCacheExpiry); + const auto ttl = StandardEncryptionManager::kUnwrappedKekCacheExpiry; + StandardEncryptionManagerTestAccess::SetTimeShift(*manager, ttl); ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); - EXPECT_EQ(kms->unwraps, 2); -} + EXPECT_EQ(kms->unwraps, 1); -TEST(StandardEncryptionManagerTest, DecryptingFileRequiresLength) { - auto kms = MakeKms(); - ICEBERG_UNWRAP_OR_FAIL(auto manager, StandardEncryptionManager::Make( - {.table_key_id = "keyA", .kms = kms})); - StandardKeyMetadata no_length(VectorBytes(16, 1)); - - class NullInputFile : public InputFile { - public: - std::string_view location() const override { return "file"; } - Result Size() const override { return 0; } - Result> Open() override { - return NotImplemented(""); - } - }; - EXPECT_THAT(manager->NewDecryptingInputFile(std::make_unique(), - no_length.Serialize()), - IsError(ErrorKind::kInvalid)); + StandardEncryptionManagerTestAccess::SetTimeShift(*manager, -ttl); + StandardEncryptionManagerTestAccess::AdvanceCacheAge(*manager, ttl); + ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); + EXPECT_EQ(kms->unwraps, 2); } namespace { -Result> ReadAll(InputFile& file) { +Result ReadAll(InputFile& file) { ICEBERG_ASSIGN_OR_RAISE(auto size, file.Size()); ICEBERG_ASSIGN_OR_RAISE(auto stream, file.Open()); - std::vector out(size); - if (size > 0) { - ICEBERG_RETURN_UNEXPECTED( - stream->ReadFully(0, std::as_writable_bytes(std::span(out)))); - } + std::string out(size, '\0'); + ICEBERG_RETURN_UNEXPECTED(stream->ReadFully(0, std::as_writable_bytes(std::span(out)))); return out; } /// A NativeEncryptionKeyMetadata that implements nothing beyond the required members. class MinimalNativeKeyMetadata : public NativeEncryptionKeyMetadata { public: - std::vector buffer() const override { return key_; } + std::vector buffer() const override { return {0xf0, 0x01, 0x23}; } std::shared_ptr Copy() const override { return std::make_shared(*this); } - const std::vector& EncryptionKey() const override { return key_; } - const std::optional>& AadPrefix() const override { return aad_; } + std::span encryption_key() const override { return key_; } + std::optional> aad_prefix() const override { + return std::nullopt; + } private: - std::vector key_ = VectorBytes(16, 1); - std::optional> aad_; + std::vector key_ = std::vector(16, 1); }; class StandardEncryptionManagerFileTest : public TempFileTestBase { protected: void SetUp() override { TempFileTestBase::SetUp(); - io_ = std::shared_ptr(arrow::MakeLocalFileIO()); + ICEBERG_UNWRAP_OR_FAIL(manager_, + StandardEncryptionManager::Make({}, "keyA", 16, kms_)); } - std::shared_ptr NewManager() { - auto manager = - StandardEncryptionManager::Make({.table_key_id = "keyA", .kms = MakeKms()}); - EXPECT_THAT(manager, IsOk()); - return manager.value(); - } - - std::unique_ptr NewOut(const std::string& path) { - auto out = io_->NewOutputFile(path); - EXPECT_THAT(out, IsOk()); - return std::move(out.value()); - } - - std::unique_ptr NewIn(const std::string& path) { - auto in = io_->NewInputFile(path); - EXPECT_THAT(in, IsOk()); - return std::move(in.value()); - } - - std::string WriteRaw(const std::vector& bytes) { - auto path = CreateNewTempFilePath(); - std::ofstream out(path, std::ios::binary); - out.write(reinterpret_cast(bytes.data()), - static_cast(bytes.size())); - return path; - } - - /// Encrypt and decrypt two files through the batch overloads of `manager`. template - void RoundTripBatch(Manager& manager) { - const std::vector> plains = {VectorBytes(100, 1), - VectorBytes(3000, 2)}; - std::vector paths = {CreateNewTempFilePath(), CreateNewTempFilePath()}; - std::vector> outs; + void CheckBatch(Manager* manager, bool expect_key_metadata) { + EncryptionManager* base = manager; + ICEBERG_UNWRAP_OR_FAIL(auto empty_outputs, + base->Encrypt(std::vector>{})); + EXPECT_TRUE(empty_outputs.empty()); + ICEBERG_UNWRAP_OR_FAIL( + auto empty_inputs, + manager->Decrypt(std::vector>{})); + EXPECT_TRUE(empty_inputs.empty()); + + std::vector paths{CreateNewTempFilePath(), CreateNewTempFilePath()}; + std::vector> outputs; for (const auto& path : paths) { - outs.push_back(NewOut(path)); + ICEBERG_UNWRAP_OR_FAIL(auto output, io_->NewOutputFile(path)); + outputs.push_back(std::move(output)); } - ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager.Encrypt(std::move(outs))); - ASSERT_EQ(encrypted.size(), 2u); - - std::vector> ins; - for (size_t i = 0; i < encrypted.size(); ++i) { - ICEBERG_UNWRAP_OR_FAIL(auto stream, - encrypted[i]->encrypting_output_file().CreateOrOverwrite()); - ASSERT_THAT(stream->Write(std::as_bytes(std::span(plains[i]))), IsOk()); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager->Encrypt(std::move(outputs))); + ASSERT_EQ(encrypted.size(), paths.size()); + + std::vector> inputs; + for (size_t i = 0; i < paths.size(); ++i) { + auto& output = encrypted[i]->encrypting_output_file(); + EXPECT_EQ(output.location(), paths[i]); + ICEBERG_UNWRAP_OR_FAIL(auto stream, output.Create()); + ASSERT_THAT(stream->Write(std::as_bytes(std::span(paths[i]))), IsOk()); ASSERT_THAT(stream->Close(), IsOk()); - ICEBERG_UNWRAP_OR_FAIL(auto stored, stream->StoredLength()); - - std::shared_ptr key_metadata; - if (const auto* native = dynamic_cast( - &encrypted[i]->key_metadata())) { - ICEBERG_UNWRAP_OR_FAIL(auto with_length, native->CopyWithLength(stored)); - key_metadata = with_length; + const auto& metadata = encrypted[i]->key_metadata(); + EXPECT_EQ(metadata.has_value(), expect_key_metadata); + std::shared_ptr key; + if (expect_key_metadata) { + auto* native = dynamic_cast(&metadata); + ASSERT_NE(native, nullptr); + ICEBERG_UNWRAP_OR_FAIL(auto stored, stream->StoredLength()); + ICEBERG_UNWRAP_OR_FAIL(key, native->CopyWithLength(stored)); } else { - key_metadata = encrypted[i]->key_metadata().Copy(); + key = metadata.Copy(); } - ins.push_back(EncryptedFiles::Encrypted(NewIn(paths[i]), key_metadata)); + ICEBERG_UNWRAP_OR_FAIL(auto input, io_->NewInputFile(paths[i])); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted_input, EncryptedFiles::EncryptedInput( + std::move(input), std::move(key))); + inputs.push_back(std::move(encrypted_input)); } - - ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager.Decrypt(std::move(ins))); - ASSERT_EQ(decrypted.size(), 2u); - for (size_t i = 0; i < decrypted.size(); ++i) { - ICEBERG_UNWRAP_OR_FAIL(auto bytes, ReadAll(*decrypted[i])); - EXPECT_EQ(bytes, plains[i]); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, base->Decrypt(std::move(inputs))); + ASSERT_EQ(decrypted.size(), paths.size()); + for (size_t i = 0; i < paths.size(); ++i) { + EXPECT_THAT(ReadAll(*decrypted[i]), HasValue(::testing::Eq(paths[i]))); } } - std::shared_ptr io_; + std::unique_ptr io_ = arrow::MakeLocalFileIO(); + std::shared_ptr kms_ = MakeKms(); + std::shared_ptr manager_; }; } // namespace TEST_F(StandardEncryptionManagerFileTest, BatchOverloadsReachableFromConcreteAndBase) { - auto standard = NewManager(); - std::shared_ptr standard_as_base = standard; - auto plaintext = std::make_shared(); - std::shared_ptr plaintext_as_base = plaintext; - - // Calls through the concrete types only compile if the batch overloads are not hidden. - RoundTripBatch(*standard); - RoundTripBatch(*standard_as_base); - RoundTripBatch(*plaintext); - RoundTripBatch(*plaintext_as_base); + PlaintextEncryptionManager plaintext; + CheckBatch(&plaintext, false); + CheckBatch(manager_.get(), true); } -TEST_F(StandardEncryptionManagerFileTest, EncryptExposesNativeAndStreamPaths) { - auto manager = NewManager(); +TEST_F(StandardEncryptionManagerFileTest, ReadsStreamWithRegisteredManifestListKeys) { auto path = CreateNewTempFilePath(); - const auto plain = VectorBytes(5000, 7); - - ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager->Encrypt(NewOut(path))); + const std::string plain = "manifest list"; + ICEBERG_UNWRAP_OR_FAIL(auto output, io_->NewOutputFile(path)); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager_->Encrypt(std::move(output))); auto* native = dynamic_cast(encrypted.get()); ASSERT_NE(native, nullptr); - // Native path: the plain file, and the key parameters. - EXPECT_EQ(native->plain_output_file().location(), path); - EXPECT_NE(&native->encrypting_output_file(), &native->plain_output_file()); const auto& key_metadata = native->key_metadata(); - EXPECT_EQ(key_metadata.EncryptionKey().size(), 16u); - ASSERT_TRUE(key_metadata.AadPrefix().has_value()); - EXPECT_EQ(key_metadata.AadPrefix()->size(), + EXPECT_EQ(key_metadata.encryption_key().size(), 16u); + const auto aad_prefix = key_metadata.aad_prefix(); + ASSERT_TRUE(aad_prefix.has_value()); + EXPECT_EQ(aad_prefix->size(), static_cast(StandardEncryptionManager::kAadPrefixLength)); - ICEBERG_UNWRAP_OR_FAIL(auto initial_length, key_metadata.FileLength()); + ICEBERG_UNWRAP_OR_FAIL(auto initial_length, key_metadata.file_length()); EXPECT_FALSE(initial_length.has_value()); // Stream path: the OutputFile methods write an AGS1 stream. @@ -392,128 +374,183 @@ TEST_F(StandardEncryptionManagerFileTest, EncryptExposesNativeAndStreamPaths) { // The writer records the stored length on a copy that keeps the same key and AAD. ICEBERG_UNWRAP_OR_FAIL(auto with_length, key_metadata.CopyWithLength(stored)); - EXPECT_EQ(with_length->EncryptionKey(), key_metadata.EncryptionKey()); - EXPECT_EQ(with_length->AadPrefix(), key_metadata.AadPrefix()); - ICEBERG_UNWRAP_OR_FAIL(auto copied_length, with_length->FileLength()); + EXPECT_TRUE( + std::ranges::equal(with_length->encryption_key(), key_metadata.encryption_key())); + const auto copied_aad_prefix = with_length->aad_prefix(); + ASSERT_TRUE(copied_aad_prefix.has_value()); + EXPECT_TRUE(std::ranges::equal(*copied_aad_prefix, *aad_prefix)); + ICEBERG_UNWRAP_OR_FAIL(auto copied_length, with_length->file_length()); EXPECT_EQ(copied_length, stored); - ICEBERG_UNWRAP_OR_FAIL(auto original_length, key_metadata.FileLength()); + ICEBERG_UNWRAP_OR_FAIL(auto original_length, key_metadata.file_length()); EXPECT_FALSE(original_length.has_value()); - ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager->Decrypt(EncryptedFiles::Encrypted( - NewIn(path), with_length))); - EXPECT_NE(dynamic_cast(decrypted.get()), nullptr); - ICEBERG_UNWRAP_OR_FAIL(auto bytes, ReadAll(*decrypted)); + ICEBERG_UNWRAP_OR_FAIL(auto keys, manager_->RegisterKeyMetadata(*with_length)); + EXPECT_EQ(keys.key_encryption_key.encrypted_by_id, "keyA"); + EXPECT_TRUE(keys.key_encryption_key.properties.contains("KEY_TIMESTAMP")); + EXPECT_EQ(keys.file_key.encrypted_by_id, keys.key_encryption_key.key_id); + EXPECT_EQ(kms_->wraps, 1); + EXPECT_EQ(manager_->encryption_keys().size(), 2u); + ICEBERG_UNWRAP_OR_FAIL( + auto reader, StandardEncryptionManager::Make( + {keys.key_encryption_key, keys.file_key}, "keyA", 16, MakeKms())); + EXPECT_THAT(reader->DecryptManifestListKeyMetadata(keys.key_encryption_key.key_id), + IsError(ErrorKind::kInvalid)); + EXPECT_THAT(reader->DecryptManifestListKeyMetadata("missing"), + IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto serialized, EncryptionUtil::DecryptManifestListKeyMetadata( + reader, keys.file_key.key_id)); + EXPECT_EQ(serialized, with_length->buffer()); + ICEBERG_UNWRAP_OR_FAIL(auto raw, io_->NewInputFile(path)); + ICEBERG_UNWRAP_OR_FAIL(auto input, + EncryptedFiles::EncryptedInput( + std::move(raw), std::make_shared( + std::move(serialized)))); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, reader->Decrypt(std::move(input))); + ICEBERG_UNWRAP_OR_FAIL(auto size, decrypted->Size()); + ASSERT_EQ(size, static_cast(plain.size())); + ICEBERG_UNWRAP_OR_FAIL(auto read_stream, decrypted->Open()); + auto* native_input = dynamic_cast(decrypted.get()); + ASSERT_NE(native_input, nullptr); + auto detached = std::move(*native_input).DetachInputFile(); + ASSERT_NE(detached, nullptr); + decrypted.reset(); + detached.reset(); + + std::string bytes(plain.size(), '\0'); + ASSERT_THAT(read_stream->ReadFully(0, std::as_writable_bytes(std::span(bytes))), + IsOk()); EXPECT_EQ(bytes, plain); } -TEST_F(StandardEncryptionManagerFileTest, NativeReadDoesNotRequireFileLength) { - auto manager = NewManager(); - const auto raw = VectorBytes(64, 3); - auto path = WriteRaw(raw); - auto no_length = - std::make_shared(VectorBytes(16, 1), VectorBytes(16, 2)); +TEST_F(StandardEncryptionManagerFileTest, NativeFilesExposeRawBytesWithoutFileLength) { + const std::string raw = "native format bytes"; + auto path = CreateNewTempFilePath(); + ICEBERG_UNWRAP_OR_FAIL(auto output, io_->NewOutputFile(path)); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager_->Encrypt(std::move(output))); + auto* native_output = dynamic_cast(encrypted.get()); + ASSERT_NE(native_output, nullptr); + ICEBERG_UNWRAP_OR_FAIL(auto stream, native_output->plain_output_file().Create()); + ASSERT_THAT(stream->Write(std::as_bytes(std::span(raw))), IsOk()); + ASSERT_THAT(stream->Close(), IsOk()); - // Both an in-memory StandardKeyMetadata and its serialized form are accepted. + const auto& metadata = native_output->key_metadata(); + const auto aad_prefix = metadata.aad_prefix(); + ASSERT_TRUE(aad_prefix.has_value()); std::vector> variants = { - no_length, std::make_shared(no_length->Serialize())}; + metadata.Copy(), std::make_shared(metadata.buffer())}; for (const auto& key_metadata : variants) { - ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager->Decrypt(EncryptedFiles::Encrypted( - NewIn(path), key_metadata))); + ICEBERG_UNWRAP_OR_FAIL(auto input, io_->NewInputFile(path)); + auto* raw_handle = input.get(); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted_input, EncryptedFiles::EncryptedInput( + std::move(input), key_metadata)); + auto* wrapper = encrypted_input.get(); + EXPECT_EQ(EncryptedInputFile::AsNative(encrypted_input), nullptr); + ASSERT_EQ(encrypted_input.get(), wrapper); + ICEBERG_UNWRAP_OR_FAIL(auto decrypted, manager_->Decrypt(std::move(encrypted_input))); auto* native = dynamic_cast(decrypted.get()); ASSERT_NE(native, nullptr); - EXPECT_EQ(native->key_metadata().EncryptionKey(), no_length->encryption_key); - EXPECT_EQ(native->key_metadata().AadPrefix(), no_length->aad_prefix); - - // Native path: the still-encrypted raw bytes. - auto released = native->ReleaseInputFile(); - ASSERT_NE(released, nullptr); - ICEBERG_UNWRAP_OR_FAIL(auto bytes, ReadAll(*released)); - EXPECT_EQ(bytes, raw); - - // Stream path: needs the file length. + EXPECT_TRUE(std::ranges::equal(native->key_metadata().encryption_key(), + metadata.encryption_key())); + const auto actual_aad_prefix = native->key_metadata().aad_prefix(); + ASSERT_TRUE(actual_aad_prefix.has_value()); + EXPECT_TRUE(std::ranges::equal(*actual_aad_prefix, *aad_prefix)); EXPECT_THAT(native->Size(), IsError(ErrorKind::kInvalid)); EXPECT_THAT(native->Open(), IsError(ErrorKind::kInvalid)); + decrypted.release(); + ICEBERG_UNWRAP_OR_FAIL( + auto second, manager_->Decrypt(std::unique_ptr(native))); + ASSERT_EQ(dynamic_cast(second.get()), native); + + auto detached = std::move(*native).DetachInputFile(); + ASSERT_EQ(detached.get(), raw_handle); + EXPECT_EQ(std::move(*native).DetachInputFile(), nullptr); + second.reset(); + EXPECT_THAT(ReadAll(*detached), HasValue(::testing::Eq(raw))); } } -TEST_F(StandardEncryptionManagerFileTest, DecryptReturnsNativeInputUnchanged) { - auto manager = NewManager(); - auto path = WriteRaw(VectorBytes(64, 3)); - auto key_metadata = - std::make_shared(VectorBytes(16, 1), VectorBytes(16, 2)); - - ICEBERG_UNWRAP_OR_FAIL( - auto first, manager->Decrypt(EncryptedFiles::Encrypted(NewIn(path), key_metadata))); - auto* native = dynamic_cast(first.release()); - ASSERT_NE(native, nullptr); - - ICEBERG_UNWRAP_OR_FAIL(auto second, - manager->Decrypt(std::unique_ptr(native))); - EXPECT_EQ(dynamic_cast(second.get()), native); -} - -TEST(NativeEncryptionKeyMetadataTest, StandardKeyMetadataCopiesWithLength) { - StandardKeyMetadata metadata(VectorBytes(16, 1), VectorBytes(16, 2)); - ICEBERG_UNWRAP_OR_FAIL(auto no_length, metadata.FileLength()); - EXPECT_FALSE(no_length.has_value()); - - ICEBERG_UNWRAP_OR_FAIL(auto copy, metadata.CopyWithLength(4242)); - EXPECT_EQ(copy->EncryptionKey(), metadata.encryption_key); - EXPECT_EQ(copy->AadPrefix(), metadata.aad_prefix); - ICEBERG_UNWRAP_OR_FAIL(auto length, copy->FileLength()); - EXPECT_EQ(length, 4242); - EXPECT_FALSE(metadata.file_length.has_value()); -} - -TEST(NativeEncryptionKeyMetadataTest, FileLengthIsNotSupportedByDefault) { +TEST(StandardEncryptionManagerTest, RegistersOpaqueNativeMetadataWithoutFileLength) { MinimalNativeKeyMetadata metadata; - EXPECT_THAT(metadata.FileLength(), IsError(ErrorKind::kNotSupported)); + EXPECT_THAT(metadata.file_length(), IsError(ErrorKind::kNotSupported)); EXPECT_THAT(metadata.CopyWithLength(1), IsError(ErrorKind::kNotSupported)); + ICEBERG_UNWRAP_OR_FAIL(auto manager, + StandardEncryptionManager::Make({}, "keyA", 16, MakeKms())); + ICEBERG_UNWRAP_OR_FAIL(auto keys, manager->RegisterKeyMetadata(metadata)); + EXPECT_THAT(manager->DecryptManifestListKeyMetadata(keys.file_key.key_id), + HasValue(::testing::Eq(metadata.buffer()))); } -TEST(BaseEncryptionKeyMetadataTest, DistinguishesAbsentFromEmpty) { - auto absent = BaseEncryptionKeyMetadata::Empty(); - BaseEncryptionKeyMetadata empty_bytes(std::vector{}); - BaseEncryptionKeyMetadata some_bytes(VectorBytes(4, 1)); - - // Through the base interface, as generic code would see it. - const EncryptionKeyMetadata& absent_base = *absent; - const EncryptionKeyMetadata& empty_base = empty_bytes; - EXPECT_FALSE(absent_base.has_value()); - EXPECT_TRUE(empty_base.has_value()); - EXPECT_TRUE(some_bytes.has_value()); - EXPECT_TRUE(StandardKeyMetadata(VectorBytes(16, 1)).has_value()); - EXPECT_TRUE(absent->buffer().empty()); - EXPECT_TRUE(empty_bytes.buffer().empty()); - - // Copies preserve presence. - auto absent_copy = std::dynamic_pointer_cast(absent->Copy()); - auto empty_copy = - std::dynamic_pointer_cast(empty_bytes.Copy()); - ASSERT_NE(absent_copy, nullptr); - ASSERT_NE(empty_copy, nullptr); - EXPECT_FALSE(absent_copy->has_value()); - EXPECT_TRUE(empty_copy->has_value()); - EXPECT_EQ(some_bytes.Copy()->buffer(), some_bytes.buffer()); -} - -TEST_F(StandardEncryptionManagerFileTest, PlaintextManagerReportsAbsentKeyMetadata) { - PlaintextEncryptionManager manager; - ICEBERG_UNWRAP_OR_FAIL(auto encrypted, - manager.Encrypt(NewOut(CreateNewTempFilePath()))); - EXPECT_FALSE(encrypted->key_metadata().has_value()); -} +class EncryptionUtilTest : public ::testing::Test { + protected: + void TearDown() override { + EncryptionManagerRegistry::Register({}); + encryption::RegisterAll(); + } +}; -TEST(EncryptionManagerRegistryTest, ValidatesOptions) { +TEST_F(EncryptionUtilTest, SelectsManagerByTableKeyId) { + auto kms = MakeKms(); + auto custom = std::make_shared(); + int factory_calls = 0; encryption::RegisterAll(); - EXPECT_TRUE(encryption::IsEncryptionAvailable()); - EXPECT_THAT(EncryptionManagerRegistry::Make({.table_key_id = "keyA"}), + EncryptionManagerRegistry::Register([&](const std::vector&, + const TableProperties&, + std::shared_ptr kms_client) + -> Result> { + ++factory_calls; + EXPECT_EQ(kms_client, kms); + return custom; + }); + encryption::RegisterAll(); + auto properties = TableProperties::FromMap({{"encryption.data-key-length", "unused"}}); + EXPECT_THAT(EncryptionUtil::MakeEncryptionManager({}, properties, nullptr), IsError(ErrorKind::kInvalidArgument)); - EXPECT_THAT(EncryptionManagerRegistry::Make({.table_key_id = "", .kms = MakeKms()}), + ICEBERG_UNWRAP_OR_FAIL(auto plaintext, + EncryptionUtil::MakeEncryptionManager({}, properties, kms)); + EXPECT_NE(dynamic_cast(plaintext.get()), nullptr); + EXPECT_NE(plaintext, custom); + + properties.mutable_configs()["encryption.key-id"] = ""; + EXPECT_THAT(EncryptionUtil::MakeEncryptionManager({}, properties, kms), IsError(ErrorKind::kInvalidArgument)); - EXPECT_THAT(EncryptionManagerRegistry::Make( - {.table_key_id = "keyA", .data_key_length = 20, .kms = MakeKms()}), + properties.mutable_configs()["encryption.key-id"] = "custom-key"; + EXPECT_THAT(EncryptionUtil::MakeEncryptionManager({}, properties, nullptr), IsError(ErrorKind::kInvalidArgument)); + EXPECT_EQ(factory_calls, 0); + ICEBERG_UNWRAP_OR_FAIL(auto selected, + EncryptionUtil::MakeEncryptionManager({}, properties, kms)); + EXPECT_EQ(selected, custom); + EXPECT_EQ(factory_calls, 1); +} + +TEST(StandardEncryptionManagerTest, FactoryUsesTableProperties) { + EncryptionManagerRegistry::Register({}); + encryption::RegisterAll(); + EXPECT_TRUE(encryption::IsEncryptionAvailable()); + auto io = arrow::MakeLocalFileIO(); + auto properties = TableProperties::FromMap({{"encryption.key-id", "keyA"}}); + const auto& dek_length = TableProperties::kEncryptionDekLength.key(); + const std::pair lengths[] = { + {nullptr, 16}, {"16", 16}, {"24", 24}, {"32", 32}}; + for (const auto& [configured, expected] : lengths) { + if (configured) { + properties.mutable_configs()[dek_length] = configured; + } + ICEBERG_UNWRAP_OR_FAIL( + auto manager, EncryptionUtil::MakeEncryptionManager({}, properties, MakeKms())); + ICEBERG_UNWRAP_OR_FAIL(auto output, io->NewOutputFile("data-file.parquet")); + ICEBERG_UNWRAP_OR_FAIL(auto encrypted, manager->Encrypt(std::move(output))); + auto* metadata = + dynamic_cast(&encrypted->key_metadata()); + ASSERT_NE(metadata, nullptr); + EXPECT_EQ(metadata->encryption_key().size(), expected); + } + + for (const auto* invalid : {"20", "invalid", "16x"}) { + properties.mutable_configs()[dek_length] = invalid; + EXPECT_THAT(EncryptionUtil::MakeEncryptionManager({}, properties, MakeKms()), + IsError(ErrorKind::kInvalidArgument)); + } } } // namespace iceberg diff --git a/src/iceberg/test/standard_key_metadata_test.cc b/src/iceberg/test/standard_key_metadata_test.cc index 695b94dab8..3df6ff9653 100644 --- a/src/iceberg/test/standard_key_metadata_test.cc +++ b/src/iceberg/test/standard_key_metadata_test.cc @@ -19,6 +19,7 @@ #include "iceberg/encryption/standard_key_metadata.h" +#include #include #include @@ -60,47 +61,75 @@ TEST(StandardKeyMetadataTest, ParseJavaVectors) { const auto& with_length = kJavaKeyMetadataWithLength; ICEBERG_UNWRAP_OR_FAIL(auto parsed, StandardKeyMetadata::Parse(with_length)); - EXPECT_EQ(parsed.encryption_key, key); - EXPECT_EQ(parsed.aad_prefix, aad_prefix); - EXPECT_EQ(parsed.file_length, 1234567); + EXPECT_TRUE(std::ranges::equal(parsed.encryption_key(), key)); + ASSERT_TRUE(parsed.aad_prefix().has_value()); + EXPECT_TRUE(std::ranges::equal(*parsed.aad_prefix(), aad_prefix)); + ICEBERG_UNWRAP_OR_FAIL(auto length, parsed.file_length()); + EXPECT_EQ(length, 1234567); // Serialization is byte-for-byte identical to Java EXPECT_EQ(parsed.Serialize(), with_length); const auto& without_length = kJavaKeyMetadata; ICEBERG_UNWRAP_OR_FAIL(auto parsed2, StandardKeyMetadata::Parse(without_length)); - EXPECT_EQ(parsed2.encryption_key, key); - EXPECT_FALSE(parsed2.file_length.has_value()); + EXPECT_TRUE(std::ranges::equal(parsed2.encryption_key(), key)); + ICEBERG_UNWRAP_OR_FAIL(auto missing_length, parsed2.file_length()); + EXPECT_FALSE(missing_length.has_value()); EXPECT_EQ(parsed2.Serialize(), without_length); - EXPECT_EQ(parsed2.WithFileLength(1234567).Serialize(), with_length); + ICEBERG_UNWRAP_OR_FAIL(auto resized, parsed2.WithFileLength(1234567)); + EXPECT_EQ(resized.Serialize(), with_length); } TEST(StandardKeyMetadataTest, RoundTrip) { - StandardKeyMetadata metadata(TestBytes(32, 7)); + ICEBERG_UNWRAP_OR_FAIL(auto metadata, StandardKeyMetadata::Make(TestBytes(32, 7))); ICEBERG_UNWRAP_OR_FAIL(auto parsed, StandardKeyMetadata::Parse(metadata.Serialize())); EXPECT_EQ(parsed, metadata); - // Zig-zag varint boundaries, including negative values and ten-byte encodings - for (int64_t length : - {int64_t{0}, int64_t{63}, int64_t{64}, int64_t{1} << 40, int64_t{-1}, - std::numeric_limits::min(), std::numeric_limits::max()}) { - auto with_length = metadata.WithFileLength(length); + // Zig-zag varint boundaries, including a ten-byte encoding. + for (int64_t length : {int64_t{0}, int64_t{63}, int64_t{64}, int64_t{1} << 40, + std::numeric_limits::max()}) { + ICEBERG_UNWRAP_OR_FAIL(auto with_length, metadata.WithFileLength(length)); ICEBERG_UNWRAP_OR_FAIL(auto round_trip, StandardKeyMetadata::Parse(with_length.Serialize())); EXPECT_EQ(round_trip, with_length); } + // Avro accepts signed lengths. Preserve their encoding when reading existing metadata. + auto serialized = metadata.Serialize(); + serialized.back() = 2; // file_length's long branch. + serialized.push_back(1); // -1 + ICEBERG_UNWRAP_OR_FAIL(auto negative, StandardKeyMetadata::Parse(serialized)); + ICEBERG_UNWRAP_OR_FAIL(auto negative_length, negative.file_length()); + EXPECT_EQ(negative_length, -1); + EXPECT_EQ(negative.Serialize(), serialized); + + serialized.pop_back(); + serialized.insert(serialized.end(), 9, 0xff); + serialized.push_back(1); // INT64_MIN + ICEBERG_UNWRAP_OR_FAIL(auto minimum, StandardKeyMetadata::Parse(serialized)); + ICEBERG_UNWRAP_OR_FAIL(auto minimum_length, minimum.file_length()); + EXPECT_EQ(minimum_length, std::numeric_limits::min()); + EXPECT_EQ(minimum.Serialize(), serialized); + // A present but empty AAD prefix is distinct from an absent one - StandardKeyMetadata empty_aad(TestBytes(16, 7), std::vector{}); + ICEBERG_UNWRAP_OR_FAIL(auto empty_aad, StandardKeyMetadata::Make( + TestBytes(16, 7), std::vector{})); ICEBERG_UNWRAP_OR_FAIL(auto parsed_empty, StandardKeyMetadata::Parse(empty_aad.Serialize())); - ASSERT_TRUE(parsed_empty.aad_prefix.has_value()); - EXPECT_TRUE(parsed_empty.aad_prefix->empty()); + ASSERT_TRUE(parsed_empty.aad_prefix().has_value()); + EXPECT_TRUE(parsed_empty.aad_prefix()->empty()); ICEBERG_UNWRAP_OR_FAIL(auto parsed_null, StandardKeyMetadata::Parse(metadata.Serialize())); - EXPECT_FALSE(parsed_null.aad_prefix.has_value()); + EXPECT_FALSE(parsed_null.aad_prefix().has_value()); } TEST(StandardKeyMetadataTest, InvalidInput) { + EXPECT_THAT(StandardKeyMetadata::Make(TestBytes(15, 7)), + IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(StandardKeyMetadata::Make(TestBytes(16, 7), std::nullopt, -1), + IsError(ErrorKind::kInvalidArgument)); + ICEBERG_UNWRAP_OR_FAIL(auto metadata, StandardKeyMetadata::Make(TestBytes(16, 7))); + EXPECT_THAT(metadata.CopyWithLength(-1), IsError(ErrorKind::kInvalidArgument)); + EXPECT_THAT(StandardKeyMetadata::Parse(std::vector{}), IsError(ErrorKind::kInvalid)); // Unknown schema version diff --git a/src/iceberg/type_fwd.h b/src/iceberg/type_fwd.h index 354495e387..47ddcbdf5b 100644 --- a/src/iceberg/type_fwd.h +++ b/src/iceberg/type_fwd.h @@ -21,6 +21,8 @@ #include +#include "iceberg/encryption/type_fwd.h" + /// \file iceberg/type_fwd.h /// Forward declarations and enum definitions. When writing your own headers, /// you can include this instead of the "full" headers to help reduce compile @@ -295,7 +297,4 @@ class MetadataScanTaskReader; class RefsTable; class SnapshotsTable; -/// \brief Table encryption -struct EncryptedKey; - } // namespace iceberg From 01169a2cab18a69e9be18fba17bb1dbfe13d29af Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 2 Dec 2026 14:10:32 +0800 Subject: [PATCH 8/9] test(encryption): tighten AGS1 and key cache regression tests Exercise missing metadata length on a valid AGS1 file and isolate the block-count limit. Verify that cache hits do not extend the KEK lifetime, and propagate setup failures in the stream test helpers. --- src/iceberg/test/aes_gcm_test.cc | 122 +++++++++--------- .../test/standard_encryption_manager_test.cc | 29 +++-- .../test/standard_key_metadata_test.cc | 7 +- 3 files changed, 83 insertions(+), 75 deletions(-) diff --git a/src/iceberg/test/aes_gcm_test.cc b/src/iceberg/test/aes_gcm_test.cc index f9fd3d87d4..5a90cb78be 100644 --- a/src/iceberg/test/aes_gcm_test.cc +++ b/src/iceberg/test/aes_gcm_test.cc @@ -154,42 +154,45 @@ TEST(AesGcmCipherTest, DecryptsJavaManifestListKeyMetadata) { class AesGcmStreamTest : public TempFileTestBase { protected: + static constexpr int64_t kMaxBlocks = std::numeric_limits::max(); + static constexpr int64_t kTooManyBlocksLength = + AesGcmStream::kHeaderLength + (kMaxBlocks + 1) * AesGcmStream::kCipherBlockSize; + void SetUp() override { TempFileTestBase::SetUp(); io_ = std::shared_ptr(arrow::MakeLocalFileIO()); } // Write `plain` as an AGS1 stream and return the stored length. - int64_t Write(const std::string& path, std::span plain, - const std::vector& key, const std::vector& aad, - size_t chunk = 1 << 20) { - auto out = io_->NewOutputFile(path); - EXPECT_THAT(out, IsOk()); - auto file = AesGcmOutputFile::Make(std::move(out.value()), key, aad); - EXPECT_THAT(file, IsOk()); - auto stream = (*file)->CreateOrOverwrite(); - EXPECT_THAT(stream, IsOk()); + Result Write(const std::string& path, std::span plain, + const std::vector& key, const std::vector& aad, + size_t chunk = 1 << 20) { + ICEBERG_ASSIGN_OR_RAISE(auto out, io_->NewOutputFile(path)); + ICEBERG_ASSIGN_OR_RAISE(auto file, AesGcmOutputFile::Make(std::move(out), key, aad)); + ICEBERG_ASSIGN_OR_RAISE(auto stream, file->CreateOrOverwrite()); for (size_t pos = 0; pos < plain.size(); pos += chunk) { auto part = plain.subspan(pos, std::min(chunk, plain.size() - pos)); - EXPECT_THAT((*stream)->Write(std::as_bytes(part)), IsOk()); + ICEBERG_RETURN_UNEXPECTED(stream->Write(std::as_bytes(part))); } - EXPECT_EQ((*stream)->Position().value(), static_cast(plain.size())); - EXPECT_THAT((*stream)->Close(), IsOk()); + ICEBERG_ASSIGN_OR_RAISE(auto position, stream->Position()); + EXPECT_EQ(position, static_cast(plain.size())); + ICEBERG_RETURN_UNEXPECTED(stream->Close()); // Java's AesGcmOutputStream keeps reporting the plaintext length once closed - EXPECT_EQ((*stream)->Position().value(), static_cast(plain.size())); - auto stored = (*stream)->StoredLength().value(); - EXPECT_EQ(stored, static_cast(std::filesystem::file_size(path))); + ICEBERG_ASSIGN_OR_RAISE(position, stream->Position()); + EXPECT_EQ(position, static_cast(plain.size())); + ICEBERG_ASSIGN_OR_RAISE(auto stored, stream->StoredLength()); + ICEBERG_ASSIGN_OR_RAISE(auto input, io_->NewInputFile(path)); + ICEBERG_ASSIGN_OR_RAISE(auto file_size, input->Size()); + EXPECT_EQ(stored, file_size); return stored; } - std::unique_ptr Open(const std::string& path, - const std::vector& key, - const std::vector& aad, int64_t length) { - auto in = io_->NewInputFile(path); - EXPECT_THAT(in, IsOk()); - auto file = AesGcmInputFile::Make(std::move(in.value()), key, aad, length); - EXPECT_THAT(file, IsOk()); - return std::move(file.value()); + Result> Open(const std::string& path, + const std::vector& key, + const std::vector& aad, + int64_t length) { + ICEBERG_ASSIGN_OR_RAISE(auto in, io_->NewInputFile(path)); + return AesGcmInputFile::Make(std::move(in), key, aad, length); } // Materialize an inlined Java fixture as a file the reader can open. @@ -211,7 +214,8 @@ TEST_F(AesGcmStreamTest, ReadsJavaVectors) { {0, &kJavaAgs1Empty}, {1, &kJavaAgs1OneByte}, {100, &kJavaAgs1Hundred}}; for (const auto& [length, encrypted] : vectors) { auto path = WriteRaw(*encrypted); - auto file = Open(path, kDataKey, kAadPrefix, static_cast(encrypted->size())); + ICEBERG_UNWRAP_OR_FAIL(auto file, Open(path, kDataKey, kAadPrefix, + static_cast(encrypted->size()))); ICEBERG_UNWRAP_OR_FAIL(auto plain, ReadAll(*file)); EXPECT_EQ(plain, TestBytes(length, 5)) << "plaintext length " << length; } @@ -221,7 +225,8 @@ TEST_F(AesGcmStreamTest, WritesJavaCompatibleLayout) { // Same plaintext, key and AAD prefix as Java's 100-byte vector: same header and // length (the ciphertext differs only by the random nonce). auto path = CreateNewTempFilePath(); - auto stored = Write(path, TestBytes(100, 5), kDataKey, kAadPrefix); + ICEBERG_UNWRAP_OR_FAIL(auto stored, + Write(path, TestBytes(100, 5), kDataKey, kAadPrefix)); ASSERT_EQ(stored, static_cast(kJavaAgs1Hundred.size())); std::ifstream in(path, std::ios::binary); std::vector header(8); @@ -239,13 +244,13 @@ TEST_F(AesGcmStreamTest, RoundTripAcrossBlocks) { auto path = CreateNewTempFilePath(); auto plain = TestBytes(size, 5); // Odd write sizes exercise writes that straddle blocks - int64_t stored = Write(path, plain, key, aad, /*chunk=*/333331); + ICEBERG_UNWRAP_OR_FAIL(auto stored, Write(path, plain, key, aad, /*chunk=*/333331)); size_t blocks = size == 0 ? 1 : (size + kBlock - 1) / kBlock; EXPECT_EQ(stored, static_cast(8 + size + blocks * 28)); ICEBERG_UNWRAP_OR_FAIL(auto plain_size, AesGcmStream::PlaintextLength(stored)); EXPECT_EQ(plain_size, static_cast(size)); - auto file = Open(path, key, aad, stored); + ICEBERG_UNWRAP_OR_FAIL(auto file, Open(path, key, aad, stored)); ICEBERG_UNWRAP_OR_FAIL(auto read, ReadAll(*file)); EXPECT_EQ(read, plain); @@ -264,51 +269,55 @@ TEST_F(AesGcmStreamTest, DetectsTampering) { auto aad = TestBytes(16, 9); auto path = CreateNewTempFilePath(); auto plain = TestBytes(AesGcmStream::kPlainBlockSize + 100, 5); - int64_t stored = Write(path, plain, key, aad); + ICEBERG_UNWRAP_OR_FAIL(auto stored, Write(path, plain, key, aad)); // Wrong key or AAD prefix (a file swapped in from another manifest entry) - EXPECT_THAT(ReadAll(*Open(path, TestBytes(16, 8), aad, stored)), - IsError(ErrorKind::kInvalid)); - EXPECT_THAT(ReadAll(*Open(path, key, TestBytes(16, 10), stored)), - IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto wrong_key, Open(path, TestBytes(16, 8), aad, stored)); + EXPECT_THAT(ReadAll(*wrong_key), IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto wrong_aad, Open(path, key, TestBytes(16, 10), stored)); + EXPECT_THAT(ReadAll(*wrong_aad), IsError(ErrorKind::kInvalid)); // Truncation: the trusted length from the key metadata no longer matches the file std::filesystem::resize_file(path, 8 + AesGcmStream::kCipherBlockSize); - EXPECT_THAT(ReadAll(*Open(path, key, aad, stored)), IsError(ErrorKind::kIOError)); + ICEBERG_UNWRAP_OR_FAIL(auto file, Open(path, key, aad, stored)); + EXPECT_THAT(ReadAll(*file), IsError(ErrorKind::kIOError)); // AGS1 blocks do not mark the end of the stream: a truncated file read with its own // (untrusted) length still decrypts. This is why readers must take the length from // the key metadata. - auto truncated = Open(path, key, aad, 8 + AesGcmStream::kCipherBlockSize); + ICEBERG_UNWRAP_OR_FAIL(auto truncated, + Open(path, key, aad, 8 + AesGcmStream::kCipherBlockSize)); ICEBERG_UNWRAP_OR_FAIL(auto first_block, ReadAll(*truncated)); EXPECT_EQ(first_block.size(), AesGcmStream::kPlainBlockSize); // Bad magic std::filesystem::resize_file(path, 0); std::ofstream(path, std::ios::binary) << "XXXX0000" << std::string(28, '\0'); - EXPECT_THAT(Open(path, key, aad, 36)->Open(), IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto bad_magic, Open(path, key, aad, 36)); + EXPECT_THAT(bad_magic->Open(), IsError(ErrorKind::kInvalid)); } TEST_F(AesGcmStreamTest, AuthenticatesEmptyStream) { auto key = TestBytes(16, 7); auto aad = TestBytes(16, 9); auto path = CreateNewTempFilePath(); - int64_t stored = Write(path, {}, key, aad); + ICEBERG_UNWRAP_OR_FAIL(auto stored, Write(path, {}, key, aad)); ASSERT_EQ(stored, AesGcmStream::kMinStreamLength); // An empty stream still carries one block with a nonce and a tag, so opening it // authenticates that block even though there is no plaintext to read. - ICEBERG_UNWRAP_OR_FAIL(auto plain, ReadAll(*Open(path, key, aad, stored))); + ICEBERG_UNWRAP_OR_FAIL(auto file, Open(path, key, aad, stored)); + ICEBERG_UNWRAP_OR_FAIL(auto plain, ReadAll(*file)); EXPECT_TRUE(plain.empty()); // Wrong key or AAD prefix (a file swapped in from another manifest entry) - EXPECT_THAT(Open(path, TestBytes(16, 8), aad, stored)->Open(), - IsError(ErrorKind::kInvalid)); - EXPECT_THAT(Open(path, key, TestBytes(16, 10), stored)->Open(), - IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto wrong_key, Open(path, TestBytes(16, 8), aad, stored)); + EXPECT_THAT(wrong_key->Open(), IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto wrong_aad, Open(path, key, TestBytes(16, 10), stored)); + EXPECT_THAT(wrong_aad->Open(), IsError(ErrorKind::kInvalid)); // Truncated to its header behind a trusted length that says otherwise std::filesystem::resize_file(path, AesGcmStream::kHeaderLength); - EXPECT_THAT(Open(path, key, aad, stored)->Open(), IsError(ErrorKind::kIOError)); + EXPECT_THAT(file->Open(), IsError(ErrorKind::kIOError)); // A corrupt tag auto corrupt = WriteRaw(kJavaAgs1Empty); @@ -317,18 +326,18 @@ TEST_F(AesGcmStreamTest, AuthenticatesEmptyStream) { out.seekp(static_cast(kJavaAgs1Empty.size() - 1)); out.put(static_cast(kJavaAgs1Empty.back() ^ 0xFF)); } - EXPECT_THAT( - Open(corrupt, kDataKey, kAadPrefix, static_cast(kJavaAgs1Empty.size())) - ->Open(), - IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto bad_tag, Open(corrupt, kDataKey, kAadPrefix, + static_cast(kJavaAgs1Empty.size()))); + EXPECT_THAT(bad_tag->Open(), IsError(ErrorKind::kInvalid)); } TEST_F(AesGcmStreamTest, RejectsOutOfRangeReadFully) { auto key = TestBytes(16, 7); auto aad = TestBytes(16, 9); auto path = CreateNewTempFilePath(); - int64_t stored = Write(path, TestBytes(100, 5), key, aad); - ICEBERG_UNWRAP_OR_FAIL(auto stream, Open(path, key, aad, stored)->Open()); + ICEBERG_UNWRAP_OR_FAIL(auto stored, Write(path, TestBytes(100, 5), key, aad)); + ICEBERG_UNWRAP_OR_FAIL(auto file, Open(path, key, aad, stored)); + ICEBERG_UNWRAP_OR_FAIL(auto stream, file->Open()); // A position near int64 max must be rejected without overflowing the range check std::vector one(1); @@ -364,22 +373,13 @@ TEST_F(AesGcmStreamTest, RejectsInvalidEncryptedLength) { // More blocks than the int32 block index in the block AAD can address. The check // must happen here rather than when a block is decrypted, so that a caller asking // only for the size never sees a length it could not read back. - constexpr int64_t kMaxBlocks = std::numeric_limits::max(); EXPECT_THAT(AesGcmStream::PlaintextLength(kHeader + kMaxBlocks * kCipherBlock), HasValue(::testing::Eq(kMaxBlocks * AesGcmStream::kPlainBlockSize))); - EXPECT_THAT(AesGcmStream::PlaintextLength(kHeader + kMaxBlocks * kCipherBlock + 1), - IsError(ErrorKind::kInvalid)); - - // Reject the invalid length at construction. - auto path = CreateNewTempFilePath(); - Write(path, TestBytes(10, 5), kDataKey, kAadPrefix); - ICEBERG_UNWRAP_OR_FAIL(auto in, io_->NewInputFile(path)); - EXPECT_THAT(AesGcmInputFile::Make(std::move(in), kDataKey, kAadPrefix, - kHeader + kMaxBlocks * kCipherBlock + 1), + EXPECT_THAT(AesGcmStream::PlaintextLength(kTooManyBlocksLength), IsError(ErrorKind::kInvalid)); } -TEST_F(AesGcmStreamTest, RejectsInvalidFileHandlesAndKeys) { +TEST_F(AesGcmStreamTest, RejectsInvalidFileArguments) { constexpr int64_t kLength = AesGcmStream::kMinStreamLength; EXPECT_THAT(AesGcmInputFile::Make(nullptr, kDataKey, {}, kLength), IsError(ErrorKind::kInvalidArgument)); @@ -390,6 +390,10 @@ TEST_F(AesGcmStreamTest, RejectsInvalidFileHandlesAndKeys) { ICEBERG_UNWRAP_OR_FAIL(auto in, io_->NewInputFile(path)); EXPECT_THAT(AesGcmInputFile::Make(std::move(in), {}, {}, kLength), IsError(ErrorKind::kInvalidArgument)); + ICEBERG_UNWRAP_OR_FAIL(in, io_->NewInputFile(path)); + EXPECT_THAT( + AesGcmInputFile::Make(std::move(in), kDataKey, kAadPrefix, kTooManyBlocksLength), + IsError(ErrorKind::kInvalid)); ICEBERG_UNWRAP_OR_FAIL(auto out, io_->NewOutputFile(path)); EXPECT_THAT(AesGcmOutputFile::Make(std::move(out), {}, {}), IsError(ErrorKind::kInvalidArgument)); diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc index c12598188a..3c0b50bd87 100644 --- a/src/iceberg/test/standard_encryption_manager_test.cc +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -235,16 +235,17 @@ TEST(StandardEncryptionManagerTest, UnwrappedKeyCacheExpires) { metadata->encryption_keys, "keyA", 16, kms)); const auto& key_id = *metadata->snapshots.front()->key_id; ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); - ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); EXPECT_EQ(kms->unwraps, 1); - const auto ttl = StandardEncryptionManager::kUnwrappedKekCacheExpiry; - StandardEncryptionManagerTestAccess::SetTimeShift(*manager, ttl); + StandardEncryptionManagerTestAccess::AdvanceCacheAge(*manager, + std::chrono::minutes{59}); + StandardEncryptionManagerTestAccess::SetTimeShift(*manager, std::chrono::hours{2}); ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); EXPECT_EQ(kms->unwraps, 1); - StandardEncryptionManagerTestAccess::SetTimeShift(*manager, -ttl); - StandardEncryptionManagerTestAccess::AdvanceCacheAge(*manager, ttl); + // The hit at 59 minutes does not extend the original entry's lifetime. + StandardEncryptionManagerTestAccess::AdvanceCacheAge(*manager, std::chrono::minutes{2}); + StandardEncryptionManagerTestAccess::SetTimeShift(*manager, -std::chrono::hours{2}); ASSERT_THAT(manager->DecryptManifestListKeyMetadata(key_id), IsOk()); EXPECT_EQ(kms->unwraps, 2); } @@ -355,15 +356,12 @@ TEST_F(StandardEncryptionManagerFileTest, ReadsStreamWithRegisteredManifestListK ASSERT_NE(native, nullptr); const auto& key_metadata = native->key_metadata(); - EXPECT_EQ(key_metadata.encryption_key().size(), 16u); const auto aad_prefix = key_metadata.aad_prefix(); ASSERT_TRUE(aad_prefix.has_value()); - EXPECT_EQ(aad_prefix->size(), - static_cast(StandardEncryptionManager::kAadPrefixLength)); + EXPECT_EQ(aad_prefix->size(), 16u); ICEBERG_UNWRAP_OR_FAIL(auto initial_length, key_metadata.file_length()); EXPECT_FALSE(initial_length.has_value()); - // Stream path: the OutputFile methods write an AGS1 stream. EXPECT_EQ(native->location(), path); ICEBERG_UNWRAP_OR_FAIL(auto stream, native->CreateOrOverwrite()); ASSERT_THAT(stream->Write(std::as_bytes(std::span(plain))), IsOk()); @@ -372,7 +370,16 @@ TEST_F(StandardEncryptionManagerFileTest, ReadsStreamWithRegisteredManifestListK EXPECT_GT(stored, static_cast(plain.size())); EXPECT_EQ(stored, static_cast(std::filesystem::file_size(path))); - // The writer records the stored length on a copy that keeps the same key and AAD. + // Reading a valid AGS1 file still requires its length in trusted key metadata. + ICEBERG_UNWRAP_OR_FAIL(auto raw_without_length, io_->NewInputFile(path)); + ICEBERG_UNWRAP_OR_FAIL( + auto input_without_length, + EncryptedFiles::EncryptedInput(std::move(raw_without_length), key_metadata.Copy())); + ICEBERG_UNWRAP_OR_FAIL(auto without_length, + manager_->Decrypt(std::move(input_without_length))); + EXPECT_THAT(without_length->Size(), IsError(ErrorKind::kInvalid)); + EXPECT_THAT(without_length->Open(), IsError(ErrorKind::kInvalid)); + ICEBERG_UNWRAP_OR_FAIL(auto with_length, key_metadata.CopyWithLength(stored)); EXPECT_TRUE( std::ranges::equal(with_length->encryption_key(), key_metadata.encryption_key())); @@ -454,8 +461,6 @@ TEST_F(StandardEncryptionManagerFileTest, NativeFilesExposeRawBytesWithoutFileLe const auto actual_aad_prefix = native->key_metadata().aad_prefix(); ASSERT_TRUE(actual_aad_prefix.has_value()); EXPECT_TRUE(std::ranges::equal(*actual_aad_prefix, *aad_prefix)); - EXPECT_THAT(native->Size(), IsError(ErrorKind::kInvalid)); - EXPECT_THAT(native->Open(), IsError(ErrorKind::kInvalid)); decrypted.release(); ICEBERG_UNWRAP_OR_FAIL( auto second, manager_->Decrypt(std::unique_ptr(native))); diff --git a/src/iceberg/test/standard_key_metadata_test.cc b/src/iceberg/test/standard_key_metadata_test.cc index 3df6ff9653..09a12bdded 100644 --- a/src/iceberg/test/standard_key_metadata_test.cc +++ b/src/iceberg/test/standard_key_metadata_test.cc @@ -83,6 +83,7 @@ TEST(StandardKeyMetadataTest, RoundTrip) { ICEBERG_UNWRAP_OR_FAIL(auto metadata, StandardKeyMetadata::Make(TestBytes(32, 7))); ICEBERG_UNWRAP_OR_FAIL(auto parsed, StandardKeyMetadata::Parse(metadata.Serialize())); EXPECT_EQ(parsed, metadata); + EXPECT_FALSE(parsed.aad_prefix().has_value()); // Zig-zag varint boundaries, including a ten-byte encoding. for (int64_t length : {int64_t{0}, int64_t{63}, int64_t{64}, int64_t{1} << 40, @@ -90,7 +91,8 @@ TEST(StandardKeyMetadataTest, RoundTrip) { ICEBERG_UNWRAP_OR_FAIL(auto with_length, metadata.WithFileLength(length)); ICEBERG_UNWRAP_OR_FAIL(auto round_trip, StandardKeyMetadata::Parse(with_length.Serialize())); - EXPECT_EQ(round_trip, with_length); + ICEBERG_UNWRAP_OR_FAIL(auto parsed_length, round_trip.file_length()); + EXPECT_EQ(parsed_length, length); } // Avro accepts signed lengths. Preserve their encoding when reading existing metadata. @@ -117,9 +119,6 @@ TEST(StandardKeyMetadataTest, RoundTrip) { StandardKeyMetadata::Parse(empty_aad.Serialize())); ASSERT_TRUE(parsed_empty.aad_prefix().has_value()); EXPECT_TRUE(parsed_empty.aad_prefix()->empty()); - ICEBERG_UNWRAP_OR_FAIL(auto parsed_null, - StandardKeyMetadata::Parse(metadata.Serialize())); - EXPECT_FALSE(parsed_null.aad_prefix().has_value()); } TEST(StandardKeyMetadataTest, InvalidInput) { From fcfe747aa572c80a72bec567a8d57b0da3a372eb Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 2 Dec 2026 14:57:44 +0800 Subject: [PATCH 9/9] test(encryption): use std::array for DEK length cases --- src/iceberg/test/standard_encryption_manager_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/iceberg/test/standard_encryption_manager_test.cc b/src/iceberg/test/standard_encryption_manager_test.cc index 3c0b50bd87..1453051a24 100644 --- a/src/iceberg/test/standard_encryption_manager_test.cc +++ b/src/iceberg/test/standard_encryption_manager_test.cc @@ -20,6 +20,7 @@ #include "iceberg/encryption/standard_encryption_manager.h" #include +#include #include #include #include @@ -535,8 +536,8 @@ TEST(StandardEncryptionManagerTest, FactoryUsesTableProperties) { auto io = arrow::MakeLocalFileIO(); auto properties = TableProperties::FromMap({{"encryption.key-id", "keyA"}}); const auto& dek_length = TableProperties::kEncryptionDekLength.key(); - const std::pair lengths[] = { - {nullptr, 16}, {"16", 16}, {"24", 24}, {"32", 32}}; + constexpr std::array, 4> lengths = { + {{nullptr, 16}, {"16", 16}, {"24", 24}, {"32", 32}}}; for (const auto& [configured, expected] : lengths) { if (configured) { properties.mutable_configs()[dek_length] = configured;