-
Notifications
You must be signed in to change notification settings - Fork 449
feat(encryption) [3/N] Support encryption: KMS #2339
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
Open
xanderbailey
wants to merge
8
commits into
apache:main
Choose a base branch
from
xanderbailey:xb/kms_em
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
22e97ea
feat(encryption) [3/N] Support encryption: KMS
xanderbailey aaa46f2
fmt
xanderbailey 60989d2
comment
xanderbailey 4d97a3e
remove default
xanderbailey 0399bb0
renames
xanderbailey 1b2777f
default key length
xanderbailey 48f08cb
private fields
xanderbailey 011da81
fmt
xanderbailey 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // 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. | ||
|
|
||
| //! Key management client trait for encryption key operations. | ||
| //! | ||
| //! Mirrors the Java `KeyManagementClient` interface from the Apache Iceberg spec. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use async_trait::async_trait; | ||
|
|
||
| use crate::Result; | ||
| use crate::encryption::SensitiveBytes; | ||
|
|
||
| /// Result of a server-side key generation operation. | ||
| /// | ||
| /// Returned by [`KeyManagementClient::generate_key`] when the KMS supports | ||
| /// atomic key generation and wrapping. | ||
| pub struct GeneratedKey { | ||
| key: SensitiveBytes, | ||
| wrapped_key: Vec<u8>, | ||
| } | ||
|
|
||
| impl GeneratedKey { | ||
| /// Creates a new `GeneratedKey` from plaintext key bytes and wrapped key bytes. | ||
| pub fn new(key: SensitiveBytes, wrapped_key: Vec<u8>) -> Self { | ||
| Self { key, wrapped_key } | ||
| } | ||
|
|
||
| /// Returns the plaintext key bytes. Zeroized on drop, redacted in Debug. | ||
| pub fn key(&self) -> &SensitiveBytes { | ||
| &self.key | ||
| } | ||
|
|
||
| /// Returns the wrapped (encrypted) key bytes. | ||
| pub fn wrapped_key(&self) -> &[u8] { | ||
| &self.wrapped_key | ||
| } | ||
| } | ||
|
|
||
| /// Pluggable interface for key management systems (AWS KMS, Azure Key Vault, etc.). | ||
| #[async_trait] | ||
| pub trait KeyManagementClient: Send + Sync + std::fmt::Debug { | ||
| /// Wrap (encrypt) a key using a wrapping key managed by the KMS. | ||
| async fn wrap_key(&self, key: &[u8], wrapping_key_id: &str) -> Result<Vec<u8>>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wrapped key is cipher text so I think this is fine. |
||
|
|
||
| /// Unwrap (decrypt) a previously wrapped key. | ||
| async fn unwrap_key(&self, wrapped_key: &[u8], wrapping_key_id: &str) | ||
| -> Result<SensitiveBytes>; | ||
|
|
||
| /// Whether this KMS supports server-side key generation. | ||
| /// | ||
| /// If `true`, callers can use [`generate_key`](Self::generate_key) for atomic | ||
| /// key generation and wrapping, which is more secure than generating a key | ||
| /// locally and then wrapping it. | ||
| fn supports_key_generation(&self) -> bool; | ||
|
|
||
| /// Generate a new key and wrap it atomically on the server side. | ||
| /// | ||
| /// This is only supported when [`supports_key_generation`](Self::supports_key_generation) | ||
| /// returns `true`. | ||
| async fn generate_key(&self, wrapping_key_id: &str) -> Result<GeneratedKey>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl KeyManagementClient for Arc<dyn KeyManagementClient> { | ||
| async fn wrap_key(&self, key: &[u8], wrapping_key_id: &str) -> Result<Vec<u8>> { | ||
| self.as_ref().wrap_key(key, wrapping_key_id).await | ||
| } | ||
|
|
||
| async fn unwrap_key( | ||
| &self, | ||
| wrapped_key: &[u8], | ||
| wrapping_key_id: &str, | ||
| ) -> Result<SensitiveBytes> { | ||
| self.as_ref().unwrap_key(wrapped_key, wrapping_key_id).await | ||
| } | ||
|
|
||
| fn supports_key_generation(&self) -> bool { | ||
| self.as_ref().supports_key_generation() | ||
| } | ||
|
|
||
| async fn generate_key(&self, wrapping_key_id: &str) -> Result<GeneratedKey> { | ||
| self.as_ref().generate_key(wrapping_key_id).await | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
We should avoid pub field pattern.
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.
48f08cb