-
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 5 commits
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 |
|---|---|---|
|
|
@@ -101,6 +101,52 @@ export AWS_SERVER_SIDE_ENCRYPTION=aws:kms:dsse | |
| cargo test --features aws | ||
| ``` | ||
|
|
||
| #### SSE-C Encryption tests | ||
|
|
||
| Unfortunately, localstack does not support SSE-C encryption (https://github.com/localstack/localstack/issues/11356). | ||
|
|
||
| We will use [MinIO](https://min.io/docs/minio/container/operations/server-side-encryption.html) to test SSE-C encryption. | ||
|
|
||
| First, create a self-signed certificate to enable HTTPS for MinIO, as SSE-C requires HTTPS. | ||
|
|
||
| ```shell | ||
| mkdir ~/certs | ||
| cd ~/certs | ||
| openssl genpkey -algorithm RSA -out private.key | ||
| openssl req -new -key private.key -out request.csr -subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=example.com/[email protected]" | ||
| openssl x509 -req -days 365 -in request.csr -signkey private.key -out public.crt | ||
| rm request.csr | ||
| ``` | ||
|
|
||
| Second, start MinIO with the self-signed certificate. | ||
|
|
||
| ```shell | ||
| docker run -d \ | ||
| -p 9000:9000 \ | ||
| --name minio \ | ||
| -v ${HOME}/certs:/root/.minio/certs \ | ||
| -e "MINIO_ROOT_USER=minio" \ | ||
| -e "MINIO_ROOT_PASSWORD=minio123" \ | ||
| minio/minio server /data | ||
| ``` | ||
|
|
||
| Create a test bucket. | ||
|
|
||
| ```shell | ||
| export AWS_ACCESS_KEY_ID=minio | ||
| export AWS_SECRET_ACCESS_KEY=minio123 | ||
| aws s3 mb s3://test-bucket --endpoint-url=https://localhost:9000 --no-verify-ssl | ||
| ``` | ||
|
|
||
| Run the tests. The real test is `test_s3_ssec_encryption_with_minio()` | ||
|
|
||
| ```shell | ||
| export TEST_S3_SSEC_ENCRYPTION=1 | ||
| cargo test --features aws --package object_store --lib aws::tests::test_s3_ssec_encryption_with_minio -- --exact --nocapture | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ### Azure | ||
|
|
||
| To test the Azure integration | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,7 +26,10 @@ 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}; | ||||||||||||||
|
|
@@ -73,7 +76,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 +169,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 +399,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 +519,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 +577,9 @@ impl AmazonS3Builder { | |||||||||||||
| .encryption_bucket_key_enabled | ||||||||||||||
| .as_ref() | ||||||||||||||
| .map(ToString::to_string), | ||||||||||||||
| S3EncryptionConfigKey::CustomerEncryptionKey => { | ||||||||||||||
| self.encryption_customer_key_base64.clone() | ||||||||||||||
| } | ||||||||||||||
| }, | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -813,6 +827,16 @@ impl AmazonS3Builder { | |||||||||||||
| self | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// Use SSE-C for server side encryption. | ||||||||||||||
|
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. Should probably say whether it should already be base64 encoded.
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. Added a comment |
||||||||||||||
| 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.

Uh oh!
There was an error while loading. Please reload this page.