-
Notifications
You must be signed in to change notification settings - Fork 258
feat: Parquet Modular Encryption with Spark KMS for native readers #2447
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 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
dcc882b
Parquet Modular Encryption support for native readers using KMS on Sp…
mbutrovich 8bac76a
Fix unused import.
mbutrovich 40935df
Fix encryptionEnabled check in NativeBatchReader.java, and guard encr…
mbutrovich 7cbfb1b
Fix NPE when checking encryptedEnabled.
mbutrovich 1e1fa2f
Merge branch 'main' into decryption
mbutrovich 090497b
Minor refactor for encryptionEnabled.
mbutrovich 992a4e1
Merge branch 'main' into decryption
mbutrovich c9dfdd5
More tests.
mbutrovich bf0bec4
Cleanup Seq loop that wasn't doing anything.
mbutrovich a0e2d9a
Merge branch 'main' into decryption
mbutrovich 271e940
Docs.
mbutrovich 571c881
Docs.
mbutrovich 4dde7fb
Refactor out of parquet_exec.rs.
mbutrovich ac566f5
Merge branch 'main' into decryption
mbutrovich 9bc24fd
Add uniform encryption test.
mbutrovich 1dfb252
Merge branch 'main' into decryption
mbutrovich bf6ad03
Address PR feedback.
mbutrovich 7d1bf39
Add benchmark.
mbutrovich 8ba2680
Address PR feedback related to number of hadoopConfs in a Comet plan …
mbutrovich e9fcca7
Adjust error handling.
mbutrovich e8c23ab
Add test with UNION.
mbutrovich a53aa2f
Add docs to reflect UNION discussion in PR feedback.
mbutrovich fbe2c96
Address PR feedback.
mbutrovich d266184
Merge branch 'main' into decryption
mbutrovich 257f163
Fix after merge conflicts with main.
mbutrovich 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
common/src/main/java/org/apache/comet/parquet/CometFileKeyUnwrapper.java
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,88 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.comet.parquet; | ||
|
|
||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.parquet.crypto.DecryptionKeyRetriever; | ||
| import org.apache.parquet.crypto.DecryptionPropertiesFactory; | ||
| import org.apache.parquet.crypto.FileDecryptionProperties; | ||
| import org.apache.parquet.crypto.ParquetCryptoRuntimeException; | ||
|
|
||
| /** | ||
| * Helper class to access DecryptionKeyRetriever.getKey from native code via JNI. This class handles | ||
| * the complexity of getting the proper Hadoop Configuration from the current Spark context and | ||
| * creating properly configured DecryptionKeyRetriever instances using DecryptionPropertiesFactory. | ||
| */ | ||
| public class CometFileKeyUnwrapper { | ||
|
|
||
| // Each file path gets a unique DecryptionKeyRetriever | ||
| private final ConcurrentHashMap<String, DecryptionKeyRetriever> retrieverCache = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| // Each hadoopConf yields a unique DecryptionPropertiesFactory. While it's unlikely that | ||
| // this plan contains more than one hadoopConf, we don't want to assume that. So we'll | ||
| // provide the ability to cache more than one Factory with a map. | ||
| private final ConcurrentHashMap<Configuration, DecryptionPropertiesFactory> factoryCache = | ||
mbutrovich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new ConcurrentHashMap<>(); | ||
|
|
||
| /** | ||
| * Creates and stores a DecryptionKeyRetriever instance for the given file path. | ||
| * | ||
| * @param filePath The path to the Parquet file | ||
| * @param hadoopConf The Hadoop Configuration to use for this file path | ||
| */ | ||
| public void storeDecryptionKeyRetriever(final String filePath, final Configuration hadoopConf) { | ||
| // Use DecryptionPropertiesFactory.loadFactory to get the factory and then call | ||
| // getFileDecryptionProperties | ||
| DecryptionPropertiesFactory factory = factoryCache.get(hadoopConf); | ||
parthchandra marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (factory == null) { | ||
| factory = DecryptionPropertiesFactory.loadFactory(hadoopConf); | ||
| factoryCache.put(hadoopConf, factory); | ||
mbutrovich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Path path = new Path(filePath); | ||
| FileDecryptionProperties decryptionProperties = | ||
| factory.getFileDecryptionProperties(hadoopConf, path); | ||
|
|
||
| DecryptionKeyRetriever keyRetriever = decryptionProperties.getKeyRetriever(); | ||
| retrieverCache.put(filePath, keyRetriever); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the decryption key for the given key metadata using the cached DecryptionKeyRetriever for | ||
| * the specified file path. | ||
| * | ||
| * @param filePath The path to the Parquet file | ||
| * @param keyMetadata The key metadata bytes from the Parquet file | ||
| * @return The decrypted key bytes | ||
| * @throws ParquetCryptoRuntimeException if key unwrapping fails | ||
| */ | ||
| public byte[] getKey(final String filePath, final byte[] keyMetadata) | ||
| throws ParquetCryptoRuntimeException { | ||
| DecryptionKeyRetriever keyRetriever = retrieverCache.get(filePath); | ||
| if (keyRetriever == null) { | ||
| throw new ParquetCryptoRuntimeException( | ||
| "Failed to find DecryptionKeyRetriever for path: " + filePath); | ||
| } | ||
| return keyRetriever.getKey(keyMetadata); | ||
| } | ||
| } | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
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.