Skip to content

Commit ad54e15

Browse files
committed
Set default bucket encryption during bucket creation
All S3 buckets have encryption configured by default, and objects are automatically encrypted by using server side encryption. When we do get-bucker-encryption on any bucket we get the the default encryption configuration. With this patch we set default encryption on bucket while creating the bucket and follow the behavior of S3 bucket Signed-off-by: Vinayakswami Hariharmath <[email protected]>
1 parent 259adab commit ad54e15

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/endpoint/s3/ops/s3_put_bucket.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ async function put_bucket(req, res) {
99
const lock_enabled = config.WORM_ENABLED ? req.headers['x-amz-bucket-object-lock-enabled'] &&
1010
req.headers['x-amz-bucket-object-lock-enabled'].toUpperCase() === 'TRUE' : undefined;
1111
await req.object_sdk.create_bucket({ name: req.params.bucket, lock_enabled: lock_enabled });
12+
13+
// Set default server side bucket encryption
14+
// More details: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-encryption.html
15+
await req.object_sdk.put_bucket_encryption({
16+
name: req.params.bucket,
17+
encryption: {
18+
"algorithm": "AES256",
19+
}
20+
});
1221
res.setHeader('Location', '/' + req.params.bucket);
1322
}
1423

src/test/system_tests/ceph_s3_tests/s3-tests-lists/s3_tests_pending_list.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ s3tests_boto3/functional/test_s3.py::test_lifecycle_expiration_size_lt
144144
s3tests_boto3/functional/test_s3.py::test_object_lock_delete_multipart_object_with_retention
145145
s3tests_boto3/functional/test_s3.py::test_object_lock_delete_multipart_object_with_legal_hold_on
146146
s3tests_boto3/functional/test_s3.py::test_get_undefined_public_block
147-
s3tests_boto3/functional/test_s3.py::test_get_public_block_deny_bucket_policy
147+
s3tests_boto3/functional/test_s3.py::test_get_public_block_deny_bucket_policy
148+
s3tests_boto3/functional/test_s3.py::test_get_bucket_encryption_s3
149+
s3tests_boto3/functional/test_s3.py::test_get_bucket_encryption_kms

src/test/unit_tests/test_s3_encryption.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ mocha.describe('Bucket Encryption Operations', async () => {
7171
await local_s3.createBucket({ Bucket: BKT });
7272
});
7373

74-
mocha.it('should get bucket encryption error without encryption configured', async () => {
74+
mocha.it('getBucketEncryption should return the default server side encryption configuration', async () => {
7575
try {
7676
const res = await local_s3.getBucketEncryption({ Bucket: BKT });
77-
throw new Error(`Expected to get error with unconfigured bucket encryption ${res}`);
77+
const expected_response = {
78+
ServerSideEncryptionConfiguration: {
79+
Rules: [{
80+
ApplyServerSideEncryptionByDefault: {
81+
SSEAlgorithm: 'AES256'
82+
}
83+
}]
84+
}
85+
};
86+
const res_without_metadata = _.omit(res, '$metadata');
87+
assert.deepEqual(res_without_metadata, expected_response);
7888
} catch (error) {
79-
assert(error.message === 'The server side encryption configuration was not found.', `Error message does not match got: ${error.message}`);
80-
assert(error.Code === 'ServerSideEncryptionConfigurationNotFoundError', `Error code does not match got: ${error.Code}`);
81-
assert(error.$metadata.httpStatusCode === 404, `Error status code does not match got: ${error.$metadata.httpStatusCode}`);
89+
throw new Error(`The server side encryption configuration was not found ${error.message}`);
8290
}
8391
});
8492

0 commit comments

Comments
 (0)