Skip to content

Commit

Permalink
Merge pull request #5 from Samseppiol/master
Browse files Browse the repository at this point in the history
Add bucket encryption and bucket access logging
  • Loading branch information
Samseppiol authored Mar 29, 2021
2 parents 50b804a + 55abb1a commit 416442a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions s3-cloudfront.cfhighlander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
ComponentParam 'EnvironmentName', 'dev', isGlobal: true
ComponentParam 'EnvironmentType', 'development', allowedValues: ['development','production'], isGlobal: true
ComponentParam 'DnsDomain', isGlobal: true
if enable_s3_logging
ComponentParam 'LogFilePrefix', ''
ComponentParam 'AccessLogsBucket'
end
end

Component name: cloudfront_component_name, template: 'cloudfront@master.snapshot', render: Inline, config: @config do
Expand Down
10 changes: 10 additions & 0 deletions s3-cloudfront.cfndsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@
end


bucket_encryption = external_parameters.fetch(:bucket_encryption, nil)
enable_s3_logging = external_parameters[:enable_s3_logging]

Condition(:SetLogFilePrefix, FnNot(FnEquals(Ref(:LogFilePrefix), ''))) if enable_s3_logging

S3_Bucket('Bucket') do
BucketName FnSub(external_parameters[:bucket_name])
LoggingConfiguration ({
DestinationBucketName: Ref(:AccessLogsBucket),
LogFilePrefix: FnIf(:SetLogFilePrefix, Ref(:LogFilePrefix), Ref('AWS::NoValue'))
}) if enable_s3_logging
BucketEncryption bucket_encryption unless bucket_encryption.nil?
end

S3_BucketPolicy("BucketPolicy") do
Expand Down
1 change: 1 addition & 0 deletions s3-cloudfront.config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bucket_name: frontend.${EnvironmentName}.${DnsDomain}
enable_s3_logging: false
cloudfront_component_name: cloudfront
# bucket_policy:
# OpsAccount:
Expand Down
13 changes: 13 additions & 0 deletions tests/bucket_encryption.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_metadata:
type: config
name: Bucket and encryption
description: Create bucket with encryption

bucket_name: frontend.${EnvironmentName}.${DnsDomain}
enable_s3_logging: true

bucket_encryption:
ServerSideEncryptionConfiguration:
-
ServerSideEncryptionByDefault:
SSEAlgorithm: AES256

0 comments on commit 416442a

Please sign in to comment.