-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Core: Add StandardEncryptionManager #9277
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ef53c2d
initial commit
ggershinsky 20fa8cd
Update and add factory
ggershinsky 94ab0cc
Encryption properties class
ggershinsky c2907f8
add plaintext mng instance
ggershinsky ee70332
post-review changes
ggershinsky 4c6fb3a
address review comments
ggershinsky a9e4271
no encryption in format 1
ggershinsky aa3e562
null keymetadata
ggershinsky 7e38396
address review comments
ggershinsky 87ba3ec
cleanup
ggershinsky 925c73a
enable SEMFactory only if kms type is set
ggershinsky 726e568
address review comments
ggershinsky 06fbac6
add changes in EncryptedOutputFile
ggershinsky 86d7e17
Review fixes.
rdblue 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 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 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 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 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
107 changes: 107 additions & 0 deletions
107
core/src/main/java/org/apache/iceberg/encryption/EncryptionUtil.java
This file contains 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,107 @@ | ||
/* | ||
* 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.iceberg.encryption; | ||
|
||
import java.util.Map; | ||
import org.apache.iceberg.CatalogProperties; | ||
import org.apache.iceberg.FileFormat; | ||
import org.apache.iceberg.TableProperties; | ||
import org.apache.iceberg.common.DynConstructors; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
import org.apache.iceberg.util.PropertyUtil; | ||
|
||
public class EncryptionUtil { | ||
|
||
private EncryptionUtil() {} | ||
|
||
public static KeyManagementClient createKmsClient(Map<String, String> catalogProperties) { | ||
String kmsType = catalogProperties.get(CatalogProperties.ENCRYPTION_KMS_TYPE); | ||
String kmsImpl = catalogProperties.get(CatalogProperties.ENCRYPTION_KMS_IMPL); | ||
|
||
Preconditions.checkArgument( | ||
kmsType == null || kmsImpl == null, | ||
"Cannot set both KMS type (%s) and KMS impl (%s)", | ||
kmsType, | ||
kmsImpl); | ||
|
||
// TODO: Add KMS implementations | ||
Preconditions.checkArgument(kmsType == null, "Unsupported KMS type: %s", kmsType); | ||
|
||
KeyManagementClient kmsClient; | ||
DynConstructors.Ctor<KeyManagementClient> ctor; | ||
try { | ||
ctor = DynConstructors.builder(KeyManagementClient.class).impl(kmsImpl).buildChecked(); | ||
} catch (NoSuchMethodException e) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Cannot initialize KeyManagementClient, missing no-arg constructor for class %s", | ||
kmsImpl), | ||
e); | ||
} | ||
|
||
try { | ||
kmsClient = ctor.newInstance(); | ||
} catch (ClassCastException e) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Cannot initialize kms client, %s does not implement KeyManagementClient interface", | ||
kmsImpl), | ||
e); | ||
} | ||
|
||
kmsClient.initialize(catalogProperties); | ||
|
||
return kmsClient; | ||
} | ||
|
||
public static EncryptionManager createEncryptionManager( | ||
Map<String, String> tableProperties, KeyManagementClient kmsClient) { | ||
Preconditions.checkArgument(kmsClient != null, "Invalid KMS client: null"); | ||
String tableKeyId = tableProperties.get(TableProperties.ENCRYPTION_TABLE_KEY); | ||
|
||
if (null == tableKeyId) { | ||
// Unencrypted table | ||
return PlaintextEncryptionManager.instance(); | ||
} | ||
|
||
String fileFormat = | ||
PropertyUtil.propertyAsString( | ||
tableProperties, | ||
TableProperties.DEFAULT_FILE_FORMAT, | ||
TableProperties.DEFAULT_FILE_FORMAT_DEFAULT); | ||
|
||
if (FileFormat.fromString(fileFormat) != FileFormat.PARQUET) { | ||
throw new UnsupportedOperationException( | ||
"Iceberg encryption currently supports only parquet format for data files"); | ||
} | ||
|
||
int dataKeyLength = | ||
PropertyUtil.propertyAsInt( | ||
tableProperties, | ||
TableProperties.ENCRYPTION_DEK_LENGTH, | ||
TableProperties.ENCRYPTION_DEK_LENGTH_DEFAULT); | ||
|
||
Preconditions.checkState( | ||
dataKeyLength == 16 || dataKeyLength == 24 || dataKeyLength == 32, | ||
"Invalid data key length: %s (must be 16, 24, or 32)", | ||
dataKeyLength); | ||
|
||
return new StandardEncryptionManager(tableKeyId, dataKeyLength, kmsClient); | ||
} | ||
} |
This file contains 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Maybe, "Iceberg encryption for data files currently only supports parquet, default file format of $format is set as $DEFAULT_FILE_FORMAT""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to remove this anyway in the next PR since it doesn't actually prevent writing Avro or ORC files with encryption turned on.