xanderbailey commented on code in PR #2466: URL: https://github.com/apache/iceberg-rust/pull/2466#discussion_r3268460719
########## crates/iceberg/src/encryption/kms/aws_kms.rs: ########## @@ -0,0 +1,240 @@ +// 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. + +use async_trait::async_trait; +use aws_config::BehaviorVersion; +use aws_config::meta::region::RegionProviderChain; +use aws_sdk_kms::Client; +use aws_sdk_kms::primitives::Blob; +use aws_sdk_kms::types::DataKeySpec; + +use crate::encryption::{AesKeySize, GeneratedKey, KeyManagementClient, SensitiveBytes}; +use crate::{Error, ErrorKind}; + +/// AWS KMS implementation of [`KeyManagementClient`]. +/// +/// ```no_run +/// use iceberg::encryption::KeyManagementClient; +/// use iceberg::encryption::kms::AwsKeyManagementClient; +/// +/// async fn example() -> iceberg::Result<()> { +/// let kms = AwsKeyManagementClient::new().await; +/// let dek = vec![0u8; 32]; +/// const KMS_KEY_ID: &str = +/// "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; +/// let wrapped = kms.wrap_key(&dek, KMS_KEY_ID).await?; +/// let unwrapped = kms.unwrap_key(&wrapped, KMS_KEY_ID).await?; +/// assert_eq!(dek.as_slice(), unwrapped.as_bytes()); +/// Ok(()) +/// } +/// ``` +#[derive(Clone, Debug)] +pub struct AwsKeyManagementClient { + kms_client: Client, +} + +impl AwsKeyManagementClient { + /// Creates an `AwsKeyManagementClient` using AWS SDK default credential + /// and region resolution. + /// + /// AWS SDK config resolution (env vars, profiles, IMDS) runs once on construction; + /// callers should reuse a single instance rather than building per request. + pub async fn new() -> Self { + let region_provider = RegionProviderChain::default_provider(); + + let config = aws_config::defaults(BehaviorVersion::v2026_01_12()) + .region(region_provider) + .load() + .await; + + Self { + kms_client: Client::new(&config), + } + } + + /// Creates an `AwsKeyManagementClient` from a pre-configured AWS KMS client. + pub fn new_with_client(kms_client: Client) -> Self { Review Comment: I wonder if we should introduce the factory first to get an idea for what the right way to construct the KMS is? -- 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]
