-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal-cloudfront-waf-acl.yaml
101 lines (100 loc) · 2.93 KB
/
global-cloudfront-waf-acl.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
AWSTemplateFormatVersion: 2010-09-09
Transform: "AWS::Serverless-2016-10-31"
Description: An AWS Serverless Specification template for a serverless application.
Parameters:
FrontendBucketDomainName:
Type: String
Description: The regional domain name of the S3 bucket
FrontendBucketOAI:
Type: String
Description: The CloudFront Origin Access Identity
AllowedIP:
Type: String
Description: IP address CIDR allowed to access CloudFront distribution.
Default: "0.0.0.0/32"
Resources:
CloudFrontDistribution:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
WebACLId: !GetAtt WafACL.Arn
Origins:
- DomainName: !Ref FrontendBucketDomainName
Id: Frontend
S3OriginConfig:
OriginAccessIdentity: !Join
- ""
- - origin-access-identity/cloudfront/
- !Ref FrontendBucketOAI
Enabled: true
DefaultRootObject: index.html
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
TargetOriginId: Frontend
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
WafACL:
Type: "AWS::WAFv2::WebACL"
Properties:
DefaultAction:
Block: {}
Name: WafAclName
Scope: CLOUDFRONT
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: WafAclMetric
Rules:
- Name: AllowSpecificIP
Priority: 0
Statement:
RuleGroupReferenceStatement:
Arn: !GetAtt WafRule.Arn
OverrideAction:
None: {}
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: AllowSpecificIP
WafIPSet:
Type: "AWS::WAFv2::IPSet"
Properties:
Name: GlobalWafIPSet
IPAddressVersion: IPV4
Scope: CLOUDFRONT
Addresses:
- !Ref AllowedIP
WafRule:
Type: "AWS::WAFv2::RuleGroup"
Properties:
Name: GlobalWafRule
Scope: CLOUDFRONT
Capacity: 100
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: WafRuleMetric
Rules:
- Name: AllowSpecificIP
Priority: 0
Action:
Allow: {}
Statement:
IPSetReferenceStatement:
Arn: !GetAtt WafIPSet.Arn
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: AllowSpecificIP
Outputs:
CloudFrontDistributionUrl:
Description: The CloudFront Distribution URL
Value: !Sub "https://${CloudFrontDistribution.DomainName}"
CloudFrontDistributionID:
Description: The CloudFront Distribution ID
Value: !Ref CloudFrontDistribution