From f8d787f6b475d519867372d9b2625143a858ab9f Mon Sep 17 00:00:00 2001 From: Anton Belodedenko <2033996+ab77@users.noreply.github.com> Date: Tue, 13 Feb 2024 03:45:49 -0800 Subject: [PATCH] [Improvement] state/s3 - Add Access type ElbAccessLogWriteEncrypted for encrypted ELB logs (#737) --- state/s3.yaml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/state/s3.yaml b/state/s3.yaml index 58a6fd710..1c93212ca 100644 --- a/state/s3.yaml +++ b/state/s3.yaml @@ -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 @@ -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] @@ -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 @@ -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