Skip to content

Commit

Permalink
allow CloudFront logging to access KMS key
Browse files Browse the repository at this point in the history
CloudFront doesn't appear to (currently) set SSE/KMS parameters on its
access log write requests to S3, so a deny policy prevents logs from being
written, even though encryption would happen regardless.
  • Loading branch information
ab77 committed Feb 27, 2024
1 parent f8d787f commit 98d016b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions security/kms-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Parameters:
- workspaces
- dnssec-route53 # Deprecated since v13. Will be removed in v15. Use ROUTE53_DNSSEC instead.
- cloudtrail
- cloudfront-logs
Default: ALL_SERVICES
KeySpec:
Description: 'Specify the type of the CMK.'
Expand Down Expand Up @@ -89,6 +90,7 @@ Conditions:
HasServiceS3PublicAccess: !Equals [!Ref Service, 'S3_PUBLIC_ACCESS']
HasServiceRoute53Dnssec: !Or [!Equals [!Ref Service, 'ROUTE53_DNSSEC'], !Equals [!Ref Service, 'dnssec-route53']]
HasServiceCloudFront: !Equals [!Ref Service, 'CLOUDFRONT']
HasServiceCloudFrontLogs: !Equals [!Ref Service, 'cloudfront-logs']
HasServiceCloudTrail: !Equals [!Ref Service, 'CLOUDTRAIL']
HasService: !Not [!Or [!Condition HasServiceAllServices, !Condition HasServiceS3PublicAccess, !Condition HasServiceRoute53Dnssec, !Condition HasServiceCloudFront, !Condition HasServiceCloudTrail]]
HasSymmetricKey: !Equals [!Ref KeySpec, 'SYMMETRIC_DEFAULT']
Expand Down Expand Up @@ -205,6 +207,16 @@ Resources:
StringLike:
'aws:SourceArn': !Sub 'arn:aws:cloudfront::${AWS::AccountId}:distribution/*'
- !Ref 'AWS::NoValue'
- !If
- HasServiceCloudFrontLogs
- Effect: Allow # https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#AccessLogsKMSPermissions
Principal:
Service: 'delivery.logs.amazonaws.com'
Action:
- 'kms:GenerateDataKey*'
- 'kms:Decrypt'
Resource: '*'
- !Ref 'AWS::NoValue'
KeyAlias:
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Expand Down

0 comments on commit 98d016b

Please sign in to comment.