forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
First implementation for ExternalEncryptionConfiguration #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
330fb6e
First implementation for ExternalEncryptionConfiguration
3d25c34
Code review
cristekdatum c5486e4
Revert white space
cristekdatum 94ec906
Code review
cristekdatum 72294fc
code review
cristekdatum 770dfe9
Code review
cristekdatum 3e7d115
Code review
cristekdatum be7398a
Code review
cristekdatum 2bf1975
Code review
cristekdatum 0e69beb
Code review
cristekdatum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
python/pyarrow/tests/parquet/test_external_encryption.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
|
cristekdatum marked this conversation as resolved.
|
||
| # 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. | ||
| import pytest | ||
| from datetime import timedelta | ||
| import pyarrow.parquet as pq | ||
| import pyarrow.parquet.encryption as pe | ||
|
|
||
| def test_encryption_configuration_properties(tempdir): | ||
| """Test the standard EncryptionConfiguration properties to avoid regressions.""" | ||
|
|
||
| config = pe.EncryptionConfiguration( | ||
| footer_key="footer-key-name", | ||
| column_keys={ | ||
| "col-key-id": ["a", "b"], | ||
| }, | ||
| encryption_algorithm="AES_GCM_V1", | ||
| plaintext_footer=True, | ||
| double_wrapping=True, | ||
| cache_lifetime=timedelta(minutes=5.0), | ||
| internal_key_material=True, | ||
| data_key_length_bits=256 | ||
| ) | ||
|
|
||
| assert isinstance(config, pe.EncryptionConfiguration) | ||
|
|
||
| assert config.footer_key == "footer-key-name" | ||
| assert config.column_keys == { | ||
| "col-key-id": ["a", "b"] | ||
| } | ||
| assert config.encryption_algorithm == "AES_GCM_V1" | ||
| assert config.plaintext_footer is True | ||
| assert config.double_wrapping is True | ||
| assert config.cache_lifetime == timedelta(minutes=5.0) | ||
| assert config.internal_key_material is True | ||
| assert config.data_key_length_bits == 256 | ||
|
|
||
| def test_external_encryption_configuration_properties(tempdir): | ||
| """Test the ExternalEncryptionConfiguration properties including external-specific fields.""" | ||
|
|
||
| config_external = pe.ExternalEncryptionConfiguration( | ||
| footer_key="footer-key-name", | ||
| column_keys={ | ||
| "col-key-id": ["a", "b"], | ||
| }, | ||
| encryption_algorithm="AES_GCM_V1", | ||
| plaintext_footer=True, | ||
| double_wrapping=True, | ||
| cache_lifetime=timedelta(minutes=5.0), | ||
| internal_key_material=True, | ||
| data_key_length_bits=256, | ||
| per_column_encryption={ | ||
| "a": { | ||
| "encryption_algorithm": "AES_GCM_V1", | ||
|
cristekdatum marked this conversation as resolved.
|
||
| "encryption_key": "key_1" | ||
| }, | ||
| "b": { | ||
| "encryption_algorithm": "AES_GCM_CTR_V1", | ||
| "encryption_key": "key_n" | ||
| } | ||
| }, | ||
| app_context={ | ||
| "user_id": "Picard1701", | ||
| "location": "Presidio" | ||
| }, | ||
| connection_config={ | ||
| "config_file": "path/to/config/file", | ||
| "config_file_decryption_key": "some_key" | ||
| } | ||
| ) | ||
|
|
||
| assert isinstance(config_external, pe.ExternalEncryptionConfiguration) | ||
|
|
||
| assert config_external.footer_key == "footer-key-name" | ||
| assert config_external.column_keys == { | ||
| "col-key-id": ["a", "b"] | ||
| } | ||
| assert config_external.encryption_algorithm == "AES_GCM_V1" | ||
| assert config_external.plaintext_footer is True | ||
| assert config_external.double_wrapping is True | ||
| assert config_external.cache_lifetime == timedelta(minutes=5.0) | ||
| assert config_external.internal_key_material is True | ||
| assert config_external.data_key_length_bits == 256 | ||
|
|
||
| assert config_external.app_context == { | ||
| "user_id": "Picard1701", | ||
| "location": "Presidio" | ||
| } | ||
|
|
||
| assert config_external.connection_config == { | ||
| "config_file": "path/to/config/file", | ||
| "config_file_decryption_key": "some_key" | ||
| } | ||
|
|
||
| assert config_external.per_column_encryption == { | ||
| "a": { | ||
| "encryption_algorithm": "AES_GCM_V1", | ||
| "encryption_key": "key_1" | ||
| }, | ||
| "b": { | ||
| "encryption_algorithm": "AES_GCM_CTR_V1", | ||
| "encryption_key": "key_n" | ||
| } | ||
| } | ||
|
|
||
| def test_external_encryption_app_context_invalid_json(): | ||
| """Ensure app_context raises TypeError for non-JSON-serializable input.""" | ||
| with pytest.raises(TypeError, match="Failed to serialize app_context: {'invalid': {1, 2, 3}}"): | ||
| pe.ExternalEncryptionConfiguration( | ||
| footer_key="key", | ||
| app_context={"invalid": set([1, 2, 3])} # sets are not JSON-serializable | ||
| ) | ||
|
|
||
| def test_external_encryption_per_column_encryption_invalid_algorithm(): | ||
| """Ensure invalid encryption_algorithm raises a ValueError or is rejected.""" | ||
|
|
||
| with pytest.raises(ValueError, match="Invalid cipher name: 'INVALID'"): | ||
| pe.ExternalEncryptionConfiguration( | ||
| footer_key="key", | ||
| per_column_encryption={ | ||
| "a": { | ||
| "encryption_algorithm": "INVALID", | ||
| "encryption_key": "some_key" | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| def test_external_encryption_connection_config_invalid_types(): | ||
| """Ensure connection_config rejects non-string keys or values.""" | ||
| with pytest.raises(TypeError, match="Connection config key must be str, got int"): | ||
| config=pe.ExternalEncryptionConfiguration( | ||
| footer_key="key" | ||
| ) | ||
| config.connection_config={ | ||
| "config_file": "path/to/file", | ||
| 123: "should-fail" # Invalid: key is not a string | ||
| } | ||
|
|
||
| with pytest.raises(TypeError, match="Connection config value must be str, got list"): | ||
| config = pe.ExternalEncryptionConfiguration( | ||
| footer_key="key" | ||
| ) | ||
| config.connection_config={ | ||
| "config_file": ["not", "a", "string"] # Invalid: value is not a string | ||
| } | ||
|
|
||
| def test_external_encryption_rejects_none_values(): | ||
| config = pe.ExternalEncryptionConfiguration(footer_key="key") | ||
|
|
||
| # per_column_encryption: expect ValueError | ||
| with pytest.raises(TypeError, match="per_column_encryption cannot be None"): | ||
| config.per_column_encryption = None | ||
|
|
||
| # app_context: expect ValueError due to None not being JSON-serializable | ||
| with pytest.raises(ValueError, match="app_context must be JSON-serializable"): | ||
| config.app_context = None | ||
|
|
||
| # connection_config: expect ValueError due to None not being iterable | ||
| with pytest.raises(ValueError, match="Connection config value cannot be None"): | ||
| config.connection_config = None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.