-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2370] Supports data encryption #3614
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
Closed
Closed
Changes from 36 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
5456ff2
HUDI-2370
liujinhui1994 926c941
exclude other parquet
liujinhui1994 ea401bc
Merge branch 'master' into HUDI-2370
liujinhui1994 6697169
update spark.sql.parquet.enableVectorizedReader=true
liujinhui1994 4fb2b5a
Merge branch 'master' into HUDI-2370
liujinhui1994 dd1bc3d
TEST ci
liujinhui1994 8328d5b
Merge branch 'master' into HUDI-2370
liujinhui1994 b9cbda1
test ci
liujinhui1994 b4d1f3c
Merge branch 'master' into HUDI-2370
liujinhui1994 6357b3e
Merge remote-tracking branch 'origin/HUDI-2370' into HUDI-2370
liujinhui1994 30f5c98
HUDI-2370
liujinhui1994 9637ae9
Merge remote-tracking branch 'origin/HUDI-2370' into HUDI-2370
liujinhui1994 5e0672f
HUDI-2370
liujinhui1994 9207f2c
HUDI-2370
liujinhui1994 917d5ea
Merge branch 'master' into HUDI-2370
liujinhui1994 115d606
HUDI-2370
liujinhui1994 cb2d4c6
HUDI-2370
liujinhui1994 f6d9204
HUDI-2370
liujinhui1994 c665b68
HUDI-2370
liujinhui1994 1e344f7
HUDI-2370
liujinhui1994 3352417
HUDI-2370
liujinhui1994 03c5308
HUDI-2370
liujinhui1994 c17ca61
HUDI-2370
liujinhui1994 db2bd88
Merge branch 'master' into HUDI-2370
liujinhui1994 61156c4
HUDI-2370
liujinhui1994 a3677e6
HUDI-2370
liujinhui1994 624c64a
HUDI-2370
liujinhui1994 429f7a6
test class exception
liujinhui1994 ce26ca8
test class exception
liujinhui1994 8bd01e8
test class exception
liujinhui1994 7c7ffa1
test class exception
liujinhui1994 491b4ea
test class exception
liujinhui1994 4548198
test class exception
liujinhui1994 c646ab9
test class exception
liujinhui1994 f8efb1f
test class exception
liujinhui1994 661c2d4
test class exception
liujinhui1994 303a3f3
Merge branch 'master' into HUDI-2370
liujinhui1994 4ca8852
HUDI-2370
liujinhui1994 f85aeac
HUDI-2370
liujinhui1994 8babbfa
HUDI-2370
liujinhui1994 a4688a9
HUDI-2370
liujinhui1994 1981bf7
HUDI-2370
liujinhui1994 c9e4ff7
Merge branch 'master' into HUDI-2370
liujinhui1994 26c72bc
HUDI-2370
liujinhui1994 ff998e2
Merge branch 'master' into HUDI-2370
liujinhui1994 cce3365
HUDI-2370
liujinhui1994 f74353d
HUDI-2370
liujinhui1994 c36dc87
HUDI-2370
liujinhui1994 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
70 changes: 70 additions & 0 deletions
70
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/storage/SystemUtils.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,70 @@ | ||
| /* | ||
| * 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.hudi.io.storage; | ||
|
|
||
| import java.io.File; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
| import java.security.CodeSource; | ||
| import java.security.ProtectionDomain; | ||
|
|
||
| /** | ||
| * system util. | ||
| */ | ||
| public class SystemUtils { | ||
|
|
||
| public static URL getClassLocation(final Class<?> cls) { | ||
liujinhui1994 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (cls == null) { | ||
| throw new IllegalArgumentException("null input: cls"); | ||
| } | ||
|
|
||
| URL result = null; | ||
| final String clsAsResource = cls.getName().replace('.', '/').concat(".class"); | ||
|
|
||
| final ProtectionDomain pd = cls.getProtectionDomain(); | ||
|
|
||
| if (pd != null) { | ||
| final CodeSource cs = pd.getCodeSource(); | ||
| if (cs != null) { | ||
| result = cs.getLocation(); | ||
| } | ||
|
|
||
| if (result != null) { | ||
| if ("file".equals(result.getProtocol())) { | ||
| try { | ||
| if (result.toExternalForm().endsWith(".jar") || result.toExternalForm().endsWith(".zip")) { | ||
| result = new URL("jar:".concat(result.toExternalForm()).concat("!/").concat(clsAsResource)); | ||
| } else if (new File(result.getFile()).isDirectory()) { | ||
| result = new URL(result, clsAsResource); | ||
| } | ||
| } catch (MalformedURLException ignore) { | ||
| System.out.println("-W"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (result == null) { | ||
| final ClassLoader clsLoader = cls.getClassLoader(); | ||
| result = clsLoader != null ? clsLoader.getResource(clsAsResource) : ClassLoader.getSystemResource(clsAsResource); | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
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
104 changes: 104 additions & 0 deletions
104
hudi-common/src/main/java/org/apache/hudi/crypot/kms/InMemoryKMS.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,104 @@ | ||
| /* | ||
| * 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.hudi.crypot.kms; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hudi.common.config.ConfigProperty; | ||
| import org.apache.parquet.crypto.KeyAccessDeniedException; | ||
| import org.apache.parquet.crypto.ParquetCryptoRuntimeException; | ||
| import org.apache.parquet.crypto.keytools.KeyToolkit; | ||
| import org.apache.parquet.crypto.keytools.KmsClient; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Base64; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * This is a mock class, built for testing only. Don't use it as an example of KmsClient implementation. | ||
| * (org.apache.parquet.crypto.keytools.samples.VaultClient is the sample implementation). | ||
| */ | ||
| public class InMemoryKMS implements KmsClient { | ||
liujinhui1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static final Logger LOG = LoggerFactory.getLogger(InMemoryKMS.class); | ||
|
|
||
| private static final ConfigProperty<String> KEY_LIST_PROPERTY_NAME = ConfigProperty | ||
| .key("hoodie.parquet.encryption.key.list") | ||
| .noDefaultValue() | ||
| .withDocumentation("hudi parquet encryption key list, example: keyName_1:value_1, keyName_2:value_2"); | ||
|
|
||
| private static Map<String,byte[]> masterKeyMap; | ||
|
|
||
| @Override | ||
| public synchronized void initialize(Configuration configuration, String kmsInstanceID, String kmsInstanceURL, String accessToken) { | ||
| // Parse master keys | ||
| String[] masterKeys = configuration.getTrimmedStrings(KEY_LIST_PROPERTY_NAME.key()); | ||
| if (null == masterKeys || masterKeys.length == 0) { | ||
| throw new ParquetCryptoRuntimeException("No encryption key list"); | ||
| } | ||
| masterKeyMap = parseKeyList(masterKeys); | ||
| } | ||
|
|
||
| private static Map<String, byte[]> parseKeyList(String[] masterKeys) { | ||
|
|
||
| Map<String,byte[]> keyMap = new HashMap<>(); | ||
|
|
||
| int nKeys = masterKeys.length; | ||
| for (int i = 0; i < nKeys; i++) { | ||
| String[] parts = masterKeys[i].split(":"); | ||
| String keyName = parts[0].trim(); | ||
| if (parts.length != 2) { | ||
| throw new IllegalArgumentException("Key '" + keyName + "' is not formatted correctly"); | ||
| } | ||
| String key = parts[1].trim(); | ||
| try { | ||
| byte[] keyBytes = Base64.getDecoder().decode(key); | ||
| keyMap.put(keyName, keyBytes); | ||
| } catch (IllegalArgumentException e) { | ||
| LOG.warn("Could not decode key '" + keyName + "'!"); | ||
| throw e; | ||
| } | ||
| } | ||
| return keyMap; | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized String wrapKey(byte[] keyBytes, String masterKeyIdentifier) | ||
| throws KeyAccessDeniedException, UnsupportedOperationException { | ||
|
|
||
| byte[] masterKey = masterKeyMap.get(masterKeyIdentifier); | ||
| if (null == masterKey) { | ||
| throw new ParquetCryptoRuntimeException("Key not found: " + masterKeyIdentifier); | ||
| } | ||
| byte[] add = masterKeyIdentifier.getBytes(StandardCharsets.UTF_8); | ||
| return KeyToolkit.encryptKeyLocally(keyBytes, masterKey, add); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized byte[] unwrapKey(String wrappedKey, String masterKeyIdentifier) | ||
| throws KeyAccessDeniedException, UnsupportedOperationException { | ||
| byte[] masterKey = masterKeyMap.get(masterKeyIdentifier); | ||
| if (null == masterKey) { | ||
| throw new ParquetCryptoRuntimeException("Key not found: " + masterKeyIdentifier); | ||
| } | ||
| byte[] add = masterKeyIdentifier.getBytes(StandardCharsets.UTF_8); | ||
| return KeyToolkit.decryptKeyLocally(wrappedKey, masterKey, add); | ||
| } | ||
| } | ||
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.
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.