ggershinsky commented on code in PR #3471: URL: https://github.com/apache/iceberg/pull/3471#discussion_r902436072
########## core/src/main/java/org/apache/iceberg/encryption/EnvelopeEncryptionManager.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.nio.ByteBuffer; +import java.security.SecureRandom; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +/** + * Encryption manager which in conjunction with a KMS can encrypt {@link OutputFile} and decrypt + * {@link InputFile}. Envelope encryption uses a key wrapping strategy, where a Key Encryption Key (KEK) is used to + * wrap or unwrap a Data Encryption Key DEK which is used to encrypt the underlying files. + * + * When generating new DEKs for OutputFiles, this class will first attempt to have the KMS generate a new key. If the + * KMS does not support key generation a new key will be produced by pulling bytes from a {@link SecureRandom} on the + * JVM writing the file. + */ +public class EnvelopeEncryptionManager implements EncryptionManager { + private final EnvelopeConfiguration dataEncryptionConfig; + private final boolean nativeFormatEncryption; + private final KmsClient kmsClient; + private final int dataKeyLength; + private final boolean kmsGeneratedKeys; + + private transient volatile SecureRandom workerRNG = null; + + public static final String encryptionConfigMismatchMessagePrefix = Review Comment: - If table properties are kept only in metadata.json file, they can be modified by an attacker with r/w storage rights. For example, removing the table encryption key property - which makes future writes unencrypted. In the long run, we will protect against this attack by signing the metadata.json contents. But this will require Iceberg spec additions. For now, verifying the table properties via client-side properties. - Readers are basically not affected by this attack - If table properties are stored in and fetched from a Catalog service, writers are also not affected by this attack https://github.com/apache/iceberg/issues/5103 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
