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

encrypt *LB access logs if KMS key is specified #737

Merged
merged 1 commit into from
Feb 13, 2024
Merged
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
20 changes: 17 additions & 3 deletions state/s3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Parameters:
Description: 'Access policy of the bucket.'
Type: String
Default: Private
AllowedValues: [Private, PublicRead, PublicWrite, PublicReadAndWrite, CloudFrontRead, CloudFrontAccessLogWrite, ElbAccessLogWrite, S3AccessLogWrite, ConfigWrite, CloudTrailWrite, VpcEndpointRead, FlowLogWrite]
AllowedValues: [Private, PublicRead, PublicWrite, PublicReadAndWrite, CloudFrontRead, CloudFrontAccessLogWrite, ElbAccessLogWrite, ElbAccessLogWriteEncrypted, S3AccessLogWrite, ConfigWrite, CloudTrailWrite, VpcEndpointRead, FlowLogWrite]
Versioning:
Description: 'Enable versioning to keep a backup if objects change.'
Type: String
Expand Down Expand Up @@ -138,7 +138,9 @@ Conditions:
HasPublicWriteAccess: !Or [!Equals [!Ref Access, PublicWrite], !Equals [!Ref Access, PublicReadAndWrite]]
HasCloudFrontReadAccess: !Equals [!Ref Access, CloudFrontRead]
HasCloudFrontAccessLogWrite: !Equals [!Ref Access, CloudFrontAccessLogWrite]
HasElbAccessLogWriteAccess: !Equals [!Ref Access, ElbAccessLogWrite]
HasElbAccessLogWriteAccess: !Or [!Equals [!Ref Access, ElbAccessLogWrite], !Equals [!Ref Access, ElbAccessLogWriteEncrypted]]
# The only server-side encryption option that's supported is Amazon S3-managed keys (SSE-S3).
HasElbAccessLogWriteEncrypted: !Equals [!Ref Access, ElbAccessLogWriteEncrypted]
HasS3AccessLogWrite: !Equals [!Ref Access, S3AccessLogWrite]
HasConfigWriteAccess: !Equals [!Ref Access, ConfigWrite]
HasCloudTrailWriteAccess: !Equals [!Ref Access, CloudTrailWrite]
Expand Down Expand Up @@ -214,7 +216,9 @@ Resources:
Resource: !Sub '${Bucket.Arn}/*'
Condition:
StringNotEquals:
's3:x-amz-server-side-encryption': ''
's3:x-amz-server-side-encryption':
- 'AES256'
- 'aws:kms'
's3:x-amz-server-side-encryption-aws-kms-key-id': {'Fn::ImportValue': !Sub '${ParentKmsKeyStack}-KeyArn'}
- !Ref 'AWS::NoValue'
- !If
Expand Down Expand Up @@ -294,6 +298,16 @@ Resources:
Effect: Allow
Resource: !GetAtt 'Bucket.Arn'
- !Ref 'AWS::NoValue'
- !If
- HasElbAccessLogWriteEncrypted
- Principal: '*'
Action: 's3:PutObject*'
Effect: Deny
Resource: !Sub '${Bucket.Arn}/*'
Condition:
StringNotEquals:
's3:x-amz-server-side-encryption': 'AES256' # https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingServerSideEncryption.html
- !Ref 'AWS::NoValue'
- !If
- HasConfigWriteAccess
- Effect: Allow
Expand Down
Loading