-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(object_store): add support for server-side encryption with customer-provided keys (SSE-C) #6230
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
feat(object_store): add support for server-side encryption with customer-provided keys (SSE-C) #6230
Changes from 1 commit
f30b0e0
4b852e1
a45e559
52fbdeb
8137c31
839ef03
6e6f354
d3747fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,10 +26,14 @@ use crate::aws::{ | |||||||||||||
| use crate::client::TokenCredentialProvider; | ||||||||||||||
| use crate::config::ConfigValue; | ||||||||||||||
| use crate::{ClientConfigKey, ClientOptions, Result, RetryConfig, StaticCredentialProvider}; | ||||||||||||||
| use base64::prelude::BASE64_STANDARD; | ||||||||||||||
| use base64::Engine; | ||||||||||||||
| use itertools::Itertools; | ||||||||||||||
| use md5::{Digest, Md5}; | ||||||||||||||
| use reqwest::header::{HeaderMap, HeaderValue}; | ||||||||||||||
| use serde::{Deserialize, Serialize}; | ||||||||||||||
| use snafu::{OptionExt, ResultExt, Snafu}; | ||||||||||||||
| use std::error; | ||||||||||||||
| use std::str::FromStr; | ||||||||||||||
| use std::sync::Arc; | ||||||||||||||
| use std::time::Duration; | ||||||||||||||
|
|
@@ -73,7 +77,7 @@ enum Error { | |||||||||||||
| #[snafu(display("Invalid Zone suffix for bucket '{bucket}'"))] | ||||||||||||||
| ZoneSuffix { bucket: String }, | ||||||||||||||
|
|
||||||||||||||
| #[snafu(display("Invalid encryption type: {}. Valid values are \"AES256\", \"sse:kms\", and \"sse:kms:dsse\".", passed))] | ||||||||||||||
| #[snafu(display("Invalid encryption type: {}. Valid values are \"AES256\", \"sse:kms\", \"sse:kms:dsse\" and \"sse-c\".", passed))] | ||||||||||||||
| InvalidEncryptionType { passed: String }, | ||||||||||||||
|
|
||||||||||||||
| #[snafu(display( | ||||||||||||||
|
|
@@ -166,6 +170,8 @@ pub struct AmazonS3Builder { | |||||||||||||
| encryption_type: Option<ConfigValue<S3EncryptionType>>, | ||||||||||||||
| encryption_kms_key_id: Option<String>, | ||||||||||||||
| encryption_bucket_key_enabled: Option<ConfigValue<bool>>, | ||||||||||||||
| /// base64-encoded 256-bit customer encryption key for SSE-C. | ||||||||||||||
| encryption_customer_key_base64: Option<String>, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// Configuration keys for [`AmazonS3Builder`] | ||||||||||||||
|
|
@@ -394,6 +400,9 @@ impl FromStr for AmazonS3ConfigKey { | |||||||||||||
| "aws_sse_bucket_key_enabled" => { | ||||||||||||||
| Ok(Self::Encryption(S3EncryptionConfigKey::BucketKeyEnabled)) | ||||||||||||||
| } | ||||||||||||||
| "aws_sse_customer_key_base64" => Ok(Self::Encryption( | ||||||||||||||
| S3EncryptionConfigKey::CustomerEncryptionKey, | ||||||||||||||
| )), | ||||||||||||||
| _ => match s.parse() { | ||||||||||||||
| Ok(key) => Ok(Self::Client(key)), | ||||||||||||||
| Err(_) => Err(Error::UnknownConfigurationKey { key: s.into() }.into()), | ||||||||||||||
|
|
@@ -511,6 +520,9 @@ impl AmazonS3Builder { | |||||||||||||
| S3EncryptionConfigKey::BucketKeyEnabled => { | ||||||||||||||
| self.encryption_bucket_key_enabled = Some(ConfigValue::Deferred(value.into())) | ||||||||||||||
| } | ||||||||||||||
| S3EncryptionConfigKey::CustomerEncryptionKey => { | ||||||||||||||
| self.encryption_customer_key_base64 = Some(value.into()) | ||||||||||||||
| } | ||||||||||||||
| }, | ||||||||||||||
| }; | ||||||||||||||
| self | ||||||||||||||
|
|
@@ -566,6 +578,9 @@ impl AmazonS3Builder { | |||||||||||||
| .encryption_bucket_key_enabled | ||||||||||||||
| .as_ref() | ||||||||||||||
| .map(ToString::to_string), | ||||||||||||||
| S3EncryptionConfigKey::CustomerEncryptionKey => { | ||||||||||||||
| self.encryption_customer_key_base64.clone() | ||||||||||||||
| } | ||||||||||||||
| }, | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -813,6 +828,16 @@ impl AmazonS3Builder { | |||||||||||||
| self | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// Use SSE-C for server side encryption. | ||||||||||||||
| pub fn with_ssec_encryption(mut self, customer_key_base64: impl Into<String>) -> Self { | ||||||||||||||
|
Member
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. I'm confused, should this parameter already be base64 encoded? I ask because internally it looks like you are encoding it?
Suggested change
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. Good catch. My intention is to make this API takes an already base64 encoded key. The reason is because I checked the AWS SDK examples in
So now I removed the base64 encoding inside this method, and changed the test to encode first. |
||||||||||||||
| self.encryption_type = Some(ConfigValue::Parsed(S3EncryptionType::SseC)); | ||||||||||||||
| if let Some(customer_key_64) = customer_key_base64.into().into() { | ||||||||||||||
| self.encryption_customer_key_base64 = | ||||||||||||||
| Some(BASE64_STANDARD.encode(customer_key_64.clone())); | ||||||||||||||
| } | ||||||||||||||
|
||||||||||||||
| if let Some(customer_key_64) = customer_key_base64.into().into() { | |
| self.encryption_customer_key_base64 = | |
| Some(BASE64_STANDARD.encode(customer_key_64.clone())); | |
| } | |
| self.encryption_customer_key_base64 = | |
| Some(BASE64_STANDARD.encode(customer_key.into())); |
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.
I added the if mainly following other examples in this file like with_dsse_kms_encryption.
I've now removed the if. Still not sure why the other places need the if though.

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.
Should probably say whether it should already be base64 encoded.
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.
Added a comment