Skip to content
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

Set default bucket encryption during bucket creation #8478

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/endpoint/s3/ops/s3_put_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ async function put_bucket(req, res) {
const lock_enabled = config.WORM_ENABLED ? req.headers['x-amz-bucket-object-lock-enabled'] &&
req.headers['x-amz-bucket-object-lock-enabled'].toUpperCase() === 'TRUE' : undefined;
await req.object_sdk.create_bucket({ name: req.params.bucket, lock_enabled: lock_enabled });

// Set default server side bucket encryption
// More details: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-encryption.html
await req.object_sdk.put_bucket_encryption({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be set for any bucket, even namespace buckets (S3, blob)? It's worth checking the current support for bucket encryption in NS buckets and mapping the gaps. I think that if there are any gaps, we should at least make sure we are not setting a configuration that might conflict with the target configuration (e.g. S3 bucket)

name: req.params.bucket,
encryption: {
"algorithm": "AES256",
}
});
res.setHeader('Location', '/' + req.params.bucket);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,6 @@ s3tests_boto3/functional/test_s3.py::test_lifecycle_expiration_size_lt
s3tests_boto3/functional/test_s3.py::test_object_lock_delete_multipart_object_with_retention
s3tests_boto3/functional/test_s3.py::test_object_lock_delete_multipart_object_with_legal_hold_on
s3tests_boto3/functional/test_s3.py::test_get_undefined_public_block
s3tests_boto3/functional/test_s3.py::test_get_public_block_deny_bucket_policy
s3tests_boto3/functional/test_s3.py::test_get_public_block_deny_bucket_policy
s3tests_boto3/functional/test_s3.py::test_get_bucket_encryption_s3
s3tests_boto3/functional/test_s3.py::test_get_bucket_encryption_kms
18 changes: 13 additions & 5 deletions src/test/unit_tests/test_s3_encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,22 @@ mocha.describe('Bucket Encryption Operations', async () => {
await local_s3.createBucket({ Bucket: BKT });
});

mocha.it('should get bucket encryption error without encryption configured', async () => {
mocha.it('getBucketEncryption should return the default server side encryption configuration', async () => {
try {
const res = await local_s3.getBucketEncryption({ Bucket: BKT });
throw new Error(`Expected to get error with unconfigured bucket encryption ${res}`);
const expected_response = {
ServerSideEncryptionConfiguration: {
Rules: [{
ApplyServerSideEncryptionByDefault: {
SSEAlgorithm: 'AES256'
}
}]
}
};
const res_without_metadata = _.omit(res, '$metadata');
assert.deepEqual(res_without_metadata, expected_response);
} catch (error) {
assert(error.message === 'The server side encryption configuration was not found.', `Error message does not match got: ${error.message}`);
assert(error.Code === 'ServerSideEncryptionConfigurationNotFoundError', `Error code does not match got: ${error.Code}`);
assert(error.$metadata.httpStatusCode === 404, `Error status code does not match got: ${error.$metadata.httpStatusCode}`);
throw new Error(`The server side encryption configuration was not found ${error.message}`);
}
});

Expand Down