Skip to content

Commit

Permalink
feat(@aws-cdk/s3): Add support for SSE-S3 encryption
Browse files Browse the repository at this point in the history
This fixes #237
  • Loading branch information
rix0rrr authored Jul 9, 2018
1 parent 4916985 commit cddc949
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
17 changes: 16 additions & 1 deletion packages/@aws-cdk/s3/lib/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ export class Bucket extends BucketRef {
return { encryptionKey, bucketEncryption };
}

if (encryptionType === BucketEncryption.S3Managed) {
const bucketEncryption = {
serverSideEncryptionConfiguration: [
{ serverSideEncryptionByDefault: { sseAlgorithm: 'AES256' } }
]
};

return { bucketEncryption };
}

if (encryptionType === BucketEncryption.KmsManaged) {
const bucketEncryption = {
serverSideEncryptionConfiguration: [
Expand Down Expand Up @@ -406,10 +416,15 @@ export enum BucketEncryption {
Unencrypted = 'NONE',

/**
* Server-side KMS encryption with a master key managed by S3.
* Server-side KMS encryption with a master key managed by KMS.
*/
KmsManaged = 'MANAGED',

/**
* Server-side encryption with a master key managed by S3.
*/
S3Managed = 'S3MANAGED',

/**
* Server-side encryption with a KMS key managed by the user.
* If `encryptionKey` is specified, this key will be used, otherwise, one will be defined.
Expand Down
47 changes: 46 additions & 1 deletion packages/@aws-cdk/s3/test/integ.bucket.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
}
}
},
"MyOtherBucket543F3540": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
}
}
},
"MyUserDC45028B": {
"Type": "AWS::IAM::User"
},
Expand Down Expand Up @@ -144,6 +158,37 @@
"Arn"
]
}
},
{
"Action": [
"s3:GetObject*",
"s3:GetBucket*",
"s3:List*"
],
"Effect": "Allow",
"Resource": [
{
"Fn::GetAtt": [
"MyOtherBucket543F3540",
"Arn"
]
},
{
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"MyOtherBucket543F3540",
"Arn"
]
},
"/",
"*"
]
]
}
]
}
],
"Version": "2012-10-17"
Expand All @@ -157,4 +202,4 @@
}
}
}
}
}
5 changes: 5 additions & 0 deletions packages/@aws-cdk/s3/test/integ.bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const bucket = new Bucket(stack, 'MyBucket', {
encryption: BucketEncryption.Kms
});

const otherwiseEncryptedBucket = new Bucket(stack, 'MyOtherBucket', {
encryption: BucketEncryption.S3Managed
});

const user = new User(stack, 'MyUser');
bucket.grantReadWrite(user);
otherwiseEncryptedBucket.grantRead(user);

process.stdout.write(app.run());

0 comments on commit cddc949

Please sign in to comment.