This is an automated email from the ASF dual-hosted git repository.
adamreeve pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 17765780676 GH-51351: [C++][Parquet] Use default KMS connection values
(#53996)
17765780676 is described below
commit 1776578067602ed059db9bd8c3e4fc126c4597f3
Author: Dricmoy Bhattacharjee <[email protected]>
AuthorDate: Tue Oct 20 16:03:46 2026 -0600
GH-51351: [C++][Parquet] Use default KMS connection values (#53996)
### Rationale for this change
`FileKeyWrapper` calls `SetDefaultIfEmpty()` on its stored configuration,
but passes the original, unmodified configuration to `GetKmsClient`. This
allows the KMS client factory to receive empty instance ID and URL values even
though Arrow has already filled in defaults on its internal copy.
### What changes are included in this PR?
- Pass the defaulted `kms_connection_config_` member to `GetKmsClient`.
- Update C++ and Python key-rotation tests to expect Arrow's existing
default values for empty fields.
- Separate the writer and reader crypto factories in the dataset encryption
tests.
The dataset tests give the writer all keys and the reader only some. With a
shared factory, the reader can reuse the writer's cached client, which already
has all the keys. Separate factories ensure the reader uses its own keys, so
the missing-key checks work correctly. The write-path fix exposes this because
writing and reading now use the same default instance ID, where empty and
`"DEFAULT"` IDs previously selected separate cache entries.
### Are these changes tested?
- Local C++ encryption key-management suite: 24 tests passed.
- Both local Python encryption test files: 62 passed, 1 skipped. The
skipped case requires a build without encryption support.
- C++ and Python formatting and lint, and `git diff --check`, passed.
- Fork CI for `537e296384`:
[Python](https://github.com/Dricmoy/arrow/actions/runs/38923806919),
[Dev](https://github.com/Dricmoy/arrow/actions/runs/38923806888), and
[Docs](https://github.com/Dricmoy/arrow/actions/runs/38923806885) passed. The
[C++ workflow](https://github.com/Dricmoy/arrow/actions/runs/38852310915)
passed for the preceding commit; the follow-up commit changes only Python tests.
### Are there any user-facing changes?
KMS client factories receive Arrow's `"DEFAULT"` markers instead of empty
strings for omitted instance ID and URL values. Explicit non-empty values are
preserved. These markers are interpreted by the KMS implementation; they are
not automatically resolved server addresses.
I reviewed the compatibility tradeoff: custom factories that special-case
empty strings may need updating. Defaulting the instance ID can also change
client reuse because the cache is indexed by access token and instance ID.
Requests with the same token and resolved ID can now share a client where empty
and `"DEFAULT"` IDs previously selected separate entries. This makes client
creation consistent with Arrow's existing defaulting logic and stored key
metadata, but changes behavior for [...]
Closes #51351. Follow-up to #53949.
### Was AI used for this PR?
AI assisted with the implementation, tests, validation, and this
description. I reviewed the configuration flow, the default-value test
expectations, the reader/writer cache separation, and the compatibility
tradeoff described above. The PR overall is fairly small consistent expectation
change, had some tests changed to fit the updated expectations.
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [x] AI
- [ ] Not reviewed
* GitHub Issue: #51351
Authored-by: Dricmoy <[email protected]>
Signed-off-by: Adam Reeve <[email protected]>
---
cpp/src/parquet/encryption/file_key_wrapper.cc | 2 +-
cpp/src/parquet/encryption/key_management_test.cc | 12 ++++++------
python/pyarrow/tests/parquet/test_encryption.py | 10 ++++++----
python/pyarrow/tests/test_dataset_encryption.py | 10 ++++++----
4 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/cpp/src/parquet/encryption/file_key_wrapper.cc
b/cpp/src/parquet/encryption/file_key_wrapper.cc
index fd870ed1f3b..50fe197c48d 100644
--- a/cpp/src/parquet/encryption/file_key_wrapper.cc
+++ b/cpp/src/parquet/encryption/file_key_wrapper.cc
@@ -40,7 +40,7 @@ FileKeyWrapper::FileKeyWrapper(KeyToolkit* key_toolkit,
key_toolkit->kms_client_cache_per_token().CheckCacheForExpiredTokens(
cache_entry_lifetime_seconds_);
kms_client_ =
- key_toolkit->GetKmsClient(kms_connection_config,
cache_entry_lifetime_seconds_);
+ key_toolkit->GetKmsClient(kms_connection_config_,
cache_entry_lifetime_seconds_);
if (double_wrapping) {
key_toolkit->kek_write_cache_per_token().CheckCacheForExpiredTokens(
diff --git a/cpp/src/parquet/encryption/key_management_test.cc
b/cpp/src/parquet/encryption/key_management_test.cc
index 80ef28b766b..2a65a177def 100644
--- a/cpp/src/parquet/encryption/key_management_test.cc
+++ b/cpp/src/parquet/encryption/key_management_test.cc
@@ -566,9 +566,9 @@ TEST_F(TestEncryptionKeyManagement,
ReadKmsUrlFromFileDuringKeyRotation) {
ASSERT_EQ(requests.size(), 2);
// The first KMS creation request is for wrapping new keys.
- // This uses the empty config provided.
- EXPECT_EQ(requests[0].kms_instance_id, "");
- EXPECT_EQ(requests[0].kms_instance_url, "");
+ // Empty values in the provided config are replaced with defaults.
+ EXPECT_EQ(requests[0].kms_instance_id, KmsClient::kKmsInstanceIdDefault);
+ EXPECT_EQ(requests[0].kms_instance_url, KmsClient::kKmsInstanceUrlDefault);
// The KMS client used to unwrap the previous keys should be configured
// with the instance ID and url provided at write time.
EXPECT_EQ(requests[1].kms_instance_id, "123");
@@ -582,9 +582,9 @@ TEST_F(TestEncryptionKeyManagement,
KeyRotationWithoutReadingKmsUrl) {
ASSERT_EQ(requests.size(), 2);
// The first KMS creation request is for wrapping new keys.
- // This uses the empty config provided.
- EXPECT_EQ(requests[0].kms_instance_id, "");
- EXPECT_EQ(requests[0].kms_instance_url, "");
+ // Empty values in the provided config are replaced with defaults.
+ EXPECT_EQ(requests[0].kms_instance_id, KmsClient::kKmsInstanceIdDefault);
+ EXPECT_EQ(requests[0].kms_instance_url, KmsClient::kKmsInstanceUrlDefault);
// When unwrapping the existing keys, the URL in the key material is
// ignored and the default used.
EXPECT_EQ(requests[1].kms_instance_id, "123");
diff --git a/python/pyarrow/tests/parquet/test_encryption.py
b/python/pyarrow/tests/parquet/test_encryption.py
index 5185bf6a301..b80d5c2b778 100644
--- a/python/pyarrow/tests/parquet/test_encryption.py
+++ b/python/pyarrow/tests/parquet/test_encryption.py
@@ -763,12 +763,14 @@ def
test_key_rotation_reads_kms_url_from_file(reusable_tempdir, data_table,
rotation_config, path, read_kms_url=read_kms_url)
if read_kms_url:
- # The empty config provided is used to wrap new keys,
- # and the config from the file was used to unwrap the original keys.
- assert created_configs == [("", ""), (KMS_INSTANCE_ID,
KMS_INSTANCE_URL)]
+ # Defaults are used to wrap new keys, and the config from the file
+ # is used to unwrap the original keys.
+ assert created_configs == [
+ ("DEFAULT", "DEFAULT"), (KMS_INSTANCE_ID, KMS_INSTANCE_URL)]
else:
# The default URL is used when unwrapping the original keys.
- assert created_configs == [("", ""), (KMS_INSTANCE_ID, "DEFAULT")]
+ assert created_configs == [
+ ("DEFAULT", "DEFAULT"), (KMS_INSTANCE_ID, "DEFAULT")]
# New key material always uses the provided KMS connection configuration
rotated_keys = read_external_keys_to_dict(path)
diff --git a/python/pyarrow/tests/test_dataset_encryption.py
b/python/pyarrow/tests/test_dataset_encryption.py
index ceb75ca603b..a913707ad05 100644
--- a/python/pyarrow/tests/test_dataset_encryption.py
+++ b/python/pyarrow/tests/test_dataset_encryption.py
@@ -133,12 +133,14 @@ def do_test_dataset_encryption_decryption(table,
extra_column_path=None):
encrypt_kms_connection_config =
create_kms_connection_config(write_keys)
decrypt_kms_connection_config = create_kms_connection_config(read_keys)
- crypto_factory = pe.CryptoFactory(kms_factory)
+ encrypt_crypto_factory = pe.CryptoFactory(kms_factory)
+ # Keep the writer's cached keys out of the reader's configuration.
+ decrypt_crypto_factory = pe.CryptoFactory(kms_factory)
parquet_encryption_cfg = ds.ParquetEncryptionConfig(
- crypto_factory, encrypt_kms_connection_config, encryption_config
+ encrypt_crypto_factory, encrypt_kms_connection_config,
encryption_config
)
parquet_decryption_cfg = ds.ParquetDecryptionConfig(
- crypto_factory, decrypt_kms_connection_config, decryption_config
+ decrypt_crypto_factory, decrypt_kms_connection_config,
decryption_config
)
# create write_options with dataset encryption config
@@ -176,7 +178,7 @@ def do_test_dataset_encryption_decryption(table,
extra_column_path=None):
assert
table.select(read_columns).equals(dataset.to_table(read_columns))
# set decryption properties for parquet fragment scan options
- decryption_properties = crypto_factory.file_decryption_properties(
+ decryption_properties =
decrypt_crypto_factory.file_decryption_properties(
decrypt_kms_connection_config, decryption_config)
pq_scan_opts = ds.ParquetFragmentScanOptions(
decryption_properties=decryption_properties