ggershinsky commented on code in PR #7387:
URL: https://github.com/apache/arrow-rs/pull/7387#discussion_r2030521777


##########
parquet/src/encryption/key_management/crypto_factory.rs:
##########
@@ -0,0 +1,833 @@
+// 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.
+
+//! The key-management tools API for building file encryption and decryption 
properties
+//! that work with a Key Management Server.
+
+use crate::encryption::decrypt::FileDecryptionProperties;
+use crate::encryption::encrypt::FileEncryptionProperties;
+use crate::encryption::key_management::key_unwrapper::KeyUnwrapper;
+use crate::encryption::key_management::key_wrapper::KeyWrapper;
+use crate::encryption::key_management::kms::{KmsClientFactory, 
KmsConnectionConfig};
+use crate::encryption::key_management::kms_manager::KmsManager;
+use crate::errors::{ParquetError, Result};
+use ring::rand::{SecureRandom, SystemRandom};
+use std::collections::HashMap;
+use std::sync::Arc;
+use std::time::Duration;
+
+/// Configuration for encrypting a Parquet file using a KMS
+#[derive(Debug)]
+pub struct EncryptionConfiguration {
+    footer_key: String,
+    column_keys: HashMap<String, Vec<String>>,

Review Comment:
   this was a bit confusing, initially I thought these are the encryption keys. 
Of course, we are keeping the IDs of the master keys here. Maybe some renaming 
can make this clearer?



##########
parquet/src/encryption/key_management/crypto_factory.rs:
##########
@@ -0,0 +1,833 @@
+// 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.
+
+//! The key-management tools API for building file encryption and decryption 
properties
+//! that work with a Key Management Server.
+
+use crate::encryption::decrypt::FileDecryptionProperties;
+use crate::encryption::encrypt::FileEncryptionProperties;
+use crate::encryption::key_management::key_unwrapper::KeyUnwrapper;
+use crate::encryption::key_management::key_wrapper::KeyWrapper;
+use crate::encryption::key_management::kms::{KmsClientFactory, 
KmsConnectionConfig};
+use crate::encryption::key_management::kms_manager::KmsManager;
+use crate::errors::{ParquetError, Result};
+use ring::rand::{SecureRandom, SystemRandom};
+use std::collections::HashMap;
+use std::sync::Arc;
+use std::time::Duration;
+
+/// Configuration for encrypting a Parquet file using a KMS
+#[derive(Debug)]
+pub struct EncryptionConfiguration {
+    footer_key: String,
+    column_keys: HashMap<String, Vec<String>>,
+    plaintext_footer: bool,
+    double_wrapping: bool,
+    cache_lifetime: Option<Duration>,
+    internal_key_material: bool,
+    data_key_length_bits: u32,
+}
+
+impl EncryptionConfiguration {
+    /// Create a new builder for an [`EncryptionConfiguration`]
+    pub fn builder(footer_key: String) -> EncryptionConfigurationBuilder {
+        EncryptionConfigurationBuilder::new(footer_key)
+    }
+
+    /// Master key identifier for footer key encryption or signing
+    pub fn footer_key(&self) -> &str {
+        &self.footer_key
+    }
+
+    /// Map from master key identifiers to the column paths encrypted with a 
column
+    pub fn column_keys(&self) -> &HashMap<String, Vec<String>> {
+        &self.column_keys
+    }
+
+    /// Whether to write the footer in plaintext.
+    pub fn plaintext_footer(&self) -> bool {
+        self.plaintext_footer
+    }
+
+    /// Whether to use double wrapping, where data encryption keys (DEKs) are 
wrapped
+    /// with key encryption keys (KEKs), which are then wrapped with the KMS.
+    /// This allows reducing interactions with the KMS.
+    pub fn double_wrapping(&self) -> bool {
+        self.double_wrapping
+    }
+
+    /// How long to cache objects for, including decrypted key encryption keys
+    /// and KMS clients. When None, clients are cached indefinitely.
+    pub fn cache_lifetime(&self) -> Option<Duration> {
+        self.cache_lifetime
+    }
+
+    /// Whether to store encryption key material inside Parquet file metadata,
+    /// rather than in external JSON files.
+    /// Using external key material allows for rotation of master keys.

Review Comment:
   with time, we've started to use the term "rotation" only for in-KMS key 
rotation. Here, it could be something like "Using external key material allows 
for re-wrapping of data keys after rotation of master keys in KMS."



##########
parquet/src/encryption/key_management/crypto_factory.rs:
##########
@@ -0,0 +1,833 @@
+// 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.
+
+//! The key-management tools API for building file encryption and decryption 
properties
+//! that work with a Key Management Server.
+
+use crate::encryption::decrypt::FileDecryptionProperties;
+use crate::encryption::encrypt::FileEncryptionProperties;
+use crate::encryption::key_management::key_unwrapper::KeyUnwrapper;
+use crate::encryption::key_management::key_wrapper::KeyWrapper;
+use crate::encryption::key_management::kms::{KmsClientFactory, 
KmsConnectionConfig};
+use crate::encryption::key_management::kms_manager::KmsManager;
+use crate::errors::{ParquetError, Result};
+use ring::rand::{SecureRandom, SystemRandom};
+use std::collections::HashMap;
+use std::sync::Arc;
+use std::time::Duration;
+
+/// Configuration for encrypting a Parquet file using a KMS
+#[derive(Debug)]
+pub struct EncryptionConfiguration {
+    footer_key: String,
+    column_keys: HashMap<String, Vec<String>>,
+    plaintext_footer: bool,
+    double_wrapping: bool,
+    cache_lifetime: Option<Duration>,
+    internal_key_material: bool,
+    data_key_length_bits: u32,
+}
+
+impl EncryptionConfiguration {
+    /// Create a new builder for an [`EncryptionConfiguration`]
+    pub fn builder(footer_key: String) -> EncryptionConfigurationBuilder {
+        EncryptionConfigurationBuilder::new(footer_key)
+    }
+
+    /// Master key identifier for footer key encryption or signing
+    pub fn footer_key(&self) -> &str {
+        &self.footer_key
+    }
+
+    /// Map from master key identifiers to the column paths encrypted with a 
column
+    pub fn column_keys(&self) -> &HashMap<String, Vec<String>> {
+        &self.column_keys
+    }
+
+    /// Whether to write the footer in plaintext.
+    pub fn plaintext_footer(&self) -> bool {
+        self.plaintext_footer
+    }
+
+    /// Whether to use double wrapping, where data encryption keys (DEKs) are 
wrapped
+    /// with key encryption keys (KEKs), which are then wrapped with the KMS.
+    /// This allows reducing interactions with the KMS.
+    pub fn double_wrapping(&self) -> bool {
+        self.double_wrapping
+    }
+
+    /// How long to cache objects for, including decrypted key encryption keys
+    /// and KMS clients. When None, clients are cached indefinitely.
+    pub fn cache_lifetime(&self) -> Option<Duration> {
+        self.cache_lifetime
+    }
+
+    /// Whether to store encryption key material inside Parquet file metadata,
+    /// rather than in external JSON files.
+    /// Using external key material allows for rotation of master keys.
+    /// Currently only internal key material is implemented.
+    pub fn internal_key_material(&self) -> bool {
+        self.internal_key_material
+    }
+
+    /// Number of bits for randomly generated data encryption keys.
+    /// Currently only 128-bit keys are implemented.
+    pub fn data_key_length_bits(&self) -> u32 {
+        self.data_key_length_bits
+    }
+}
+
+/// Builder for a Parquet [`EncryptionConfiguration`].
+pub struct EncryptionConfigurationBuilder {
+    footer_key: String,
+    column_keys: HashMap<String, Vec<String>>,
+    plaintext_footer: bool,
+    double_wrapping: bool,
+    cache_lifetime: Option<Duration>,
+    internal_key_material: bool,
+    data_key_length_bits: u32,
+}
+
+impl EncryptionConfigurationBuilder {
+    /// Create a new [`EncryptionConfigurationBuilder`] with default options
+    pub fn new(footer_key: String) -> Self {
+        Self {
+            footer_key,
+            column_keys: Default::default(),
+            plaintext_footer: false,
+            double_wrapping: true,
+            cache_lifetime: Some(Duration::from_secs(600)),
+            internal_key_material: true,
+            data_key_length_bits: 128,
+        }
+    }
+
+    /// Finalizes the encryption configuration to be used
+    pub fn build(self) -> EncryptionConfiguration {
+        EncryptionConfiguration {
+            footer_key: self.footer_key,
+            column_keys: self.column_keys,
+            plaintext_footer: self.plaintext_footer,
+            double_wrapping: self.double_wrapping,
+            cache_lifetime: self.cache_lifetime,
+            internal_key_material: self.internal_key_material,
+            data_key_length_bits: self.data_key_length_bits,
+        }
+    }
+
+    /// Specify a column master key identifier and the column names to be 
encrypted with this key.
+    /// Note that if no column keys are specified, uniform encryption is used 
where all columns
+    /// are encrypted with the footer key.
+    pub fn add_column_key(mut self, master_key: String, column_paths: 
Vec<String>) -> Self {
+        self.column_keys
+            .entry(master_key)
+            .or_default()
+            .extend(column_paths);
+        self
+    }
+
+    /// Set whether to write the footer in plaintext.
+    /// Defaults to false.
+    pub fn set_plaintext_footer(mut self, plaintext_footer: bool) -> Self {
+        self.plaintext_footer = plaintext_footer;
+        self
+    }
+
+    /// Set whether to use double wrapping, where data encryption keys (DEKs) 
are wrapped
+    /// with key encryption keys (KEKs), which are then wrapped with the KMS.
+    /// This allows reducing interactions with the KMS.
+    /// Defaults to True.
+    pub fn set_double_wrapping(mut self, double_wrapping: bool) -> Self {
+        self.double_wrapping = double_wrapping;
+        self
+    }
+
+    /// Set how long to cache objects for, including decrypted key encryption 
keys
+    /// and KMS clients. When None, clients are cached indefinitely.
+    /// Defaults to 10 minutes.

Review Comment:
   10 minutes might be too aggressive. Recently, we found a NIST spec that 
allows for a significant increase in the lifetime. I'll send a PR for this to 
parquet-java, lets see if it triggers a discussion.



##########
parquet/src/encryption/key_management/crypto_factory.rs:
##########
@@ -0,0 +1,833 @@
+// 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.
+
+//! The key-management tools API for building file encryption and decryption 
properties
+//! that work with a Key Management Server.
+
+use crate::encryption::decrypt::FileDecryptionProperties;
+use crate::encryption::encrypt::FileEncryptionProperties;
+use crate::encryption::key_management::key_unwrapper::KeyUnwrapper;
+use crate::encryption::key_management::key_wrapper::KeyWrapper;
+use crate::encryption::key_management::kms::{KmsClientFactory, 
KmsConnectionConfig};
+use crate::encryption::key_management::kms_manager::KmsManager;
+use crate::errors::{ParquetError, Result};
+use ring::rand::{SecureRandom, SystemRandom};
+use std::collections::HashMap;
+use std::sync::Arc;
+use std::time::Duration;
+
+/// Configuration for encrypting a Parquet file using a KMS
+#[derive(Debug)]
+pub struct EncryptionConfiguration {
+    footer_key: String,
+    column_keys: HashMap<String, Vec<String>>,
+    plaintext_footer: bool,
+    double_wrapping: bool,
+    cache_lifetime: Option<Duration>,
+    internal_key_material: bool,
+    data_key_length_bits: u32,
+}
+
+impl EncryptionConfiguration {
+    /// Create a new builder for an [`EncryptionConfiguration`]
+    pub fn builder(footer_key: String) -> EncryptionConfigurationBuilder {
+        EncryptionConfigurationBuilder::new(footer_key)
+    }
+
+    /// Master key identifier for footer key encryption or signing
+    pub fn footer_key(&self) -> &str {
+        &self.footer_key
+    }
+
+    /// Map from master key identifiers to the column paths encrypted with a 
column

Review Comment:
   -> something like "column paths encrypted with the key"?



-- 
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]

Reply via email to