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

fix(s3): buckets with SSE-KMS silently fail to receive logs #23385

Merged
merged 2 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,17 @@ export class Bucket extends BucketBase {
if (!props.serverAccessLogsBucket && !props.serverAccessLogsPrefix) {
return undefined;
}
if (
// The current bucket is being used and is configured for default SSE-KMS
!props.serverAccessLogsBucket && (
props.encryptionKey ||
props.encryption === BucketEncryption.KMS ||
props.encryption === BucketEncryption.KMS_MANAGED) ||
// Another bucket is being used that is configured for default SSE-KMS
props.serverAccessLogsBucket?.encryptionKey
) {
throw new Error('SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets');
}

return {
destinationBucketName: props.serverAccessLogsBucket?.bucketName,
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-s3/test/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@ describe('bucket', () => {

});

test('throws error if using KMS-Managed key and server access logging to self', () => {
const stack = new cdk.Stack();
expect(() => {
new s3.Bucket(stack, 'MyBucket', { encryption: s3.BucketEncryption.KMS_MANAGED, serverAccessLogsPrefix: 'test' });
}).toThrow('SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets');
});
test('throws error if using KMS CMK and server access logging to self', () => {
const stack = new cdk.Stack();
const key = new kms.Key(stack, 'TestKey');
expect(() => {
new s3.Bucket(stack, 'MyBucket', { encryptionKey: key, serverAccessLogsPrefix: 'test' });
}).toThrow('SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets');
});
test('throws error if enabling server access logging to bucket with SSE-KMS', () => {
const stack = new cdk.Stack();
const key = new kms.Key(stack, 'TestKey');
const targetBucket = new s3.Bucket(stack, 'TargetBucket', { encryptionKey: key } );
expect(() => {
new s3.Bucket(stack, 'MyBucket', { serverAccessLogsBucket: targetBucket });
}).toThrow('SSE-S3 is the only supported default bucket encryption for Server Access Logging target buckets');
});

test('bucket with versioning turned on', () => {
const stack = new cdk.Stack();
new s3.Bucket(stack, 'MyBucket', {
Expand Down