Skip to content

Commit a6b6167

Browse files
matej5Matej Stajduhar
and
Matej Stajduhar
authored
Setting-port-change-option-for-nginx (#1487)
* Setting-port-change-option-for-nginx * Update main.yml * Update nginx.conf.j2 --------- Co-authored-by: Matej Stajduhar <matej.stajduhar@codeenigma.com>
1 parent 5cce045 commit a6b6167

File tree

3 files changed

+80
-35
lines changed

3 files changed

+80
-35
lines changed

roles/aws/acl/defaults/main.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
rate_limit: 200
3+
acl:
4+
name: "dummy_master_acl"
5+
scope: "CLOUDFRONT" # Can be "REGIONAL" for ALBs
6+
region: "us-east-1" # If scope is set to CLOUDFRONT, region must be us-east-1, even though docs say it will be skipped
7+
8+
ip_allow:
9+
name: "Allowed-ips"
10+
list:
11+
- 1.1.1.1/32
12+
- 2.2.2.2/32
13+
- 3.3.3.3/32
14+
15+
ip_block:
16+
name: "Blocked-ips"
17+
list:
18+
- 4.4.4.4/32
19+
- 5.5.5.5/32
20+
- 6.6.6.6/32
21+
22+
cc_block_list:
23+
- BY # Belarus
24+
- CN # China
25+
- IR # Iran
26+
- SA # Saudi Arabia

roles/aws/aws_cloudfront_distribution/tasks/create_acl.yml roles/aws/acl/tasks/main.yml

+51-33
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,58 @@
22
ansible.builtin.set_fact:
33
acl_rules: []
44

5+
- name: Set IP block rule
6+
when: acl.ip_block is defined
7+
block:
8+
- name: Create IP block set for WAF
9+
community.aws.wafv2_ip_set:
10+
name: "{{ acl.ip_block.name }}"
11+
state: present
12+
description: Set of blocked IPs
13+
scope: "{{ acl.scope }}"
14+
region: "{{ acl.region }}"
15+
ip_address_version: IPV4
16+
addresses: "{{ acl.ip_block.list }}"
17+
register: ip_set_info
18+
19+
- name: Create IP block rule
20+
ansible.builtin.set_fact:
21+
ip_block_rule:
22+
- name: "{{ acl.ip_block.name }}"
23+
priority: 0
24+
action:
25+
block: {}
26+
visibility_config:
27+
sampled_requests_enabled: true
28+
cloud_watch_metrics_enabled: true
29+
metric_name: Block_IPs
30+
statement:
31+
ip_set_reference_statement:
32+
arn: "{{ ip_set_info.arn }}"
33+
34+
- name: Add rule to list
35+
ansible.builtin.set_fact:
36+
acl_rules: "{{ acl_rules + ip_block_rule }}"
37+
538
- name: Set IP allow rule
6-
when: cf_acl.ip_allow is defined
39+
when: acl.ip_allow is defined
740
block:
841
- name: Create IP allow set for WAF
942
community.aws.wafv2_ip_set:
10-
name: "{{ cf_acl.ip_allow.name }}"
43+
name: "{{ acl.ip_allow.name }}"
1144
state: present
1245
description: Set of allowed IPs
13-
scope: "{{ cf_acl.scope }}"
14-
region: "{{ cf_acl.region }}"
46+
scope: "{{ acl.scope }}"
47+
region: "{{ acl.region }}"
1548
ip_address_version: IPV4
16-
addresses: "{{ cf_acl.ip_allow.list }}"
49+
addresses: "{{ acl.ip_allow.list }}"
1750
register: ip_set_info
1851

1952
- name: Create IP allow rule
2053
ansible.builtin.set_fact:
2154
ip_allow_rule:
22-
- name: allow_ips
23-
priority: 0
55+
- name: "{{ acl.ip_allow.name }}"
56+
priority: 1
2457
action:
2558
allow: {}
2659
visibility_config:
@@ -35,25 +68,14 @@
3568
ansible.builtin.set_fact:
3669
acl_rules: "{{ acl_rules + ip_allow_rule }}"
3770

38-
- name: Set IP block rule
39-
when: cf_acl.ip_block is defined
71+
- name: Set country block rule
72+
when: acl.cc_block_list is defined
4073
block:
41-
- name: Create IP block set for WAF
42-
community.aws.wafv2_ip_set:
43-
name: "{{ cf_acl.ip_block.name }}"
44-
state: present
45-
description: Set of blocked IPs
46-
scope: "{{ cf_acl.scope }}"
47-
region: "{{ cf_acl.region }}"
48-
ip_address_version: IPV4
49-
addresses: "{{ cf_acl.ip_block.list }}"
50-
register: ip_set_info
51-
52-
- name: Create IP block rule
74+
- name: Create country block rule
5375
ansible.builtin.set_fact:
54-
ip_block_rule:
76+
cc_block_rule:
5577
- name: block_countries
56-
priority: 1
78+
priority: 2
5779
action:
5880
block: {}
5981
visibility_config:
@@ -62,25 +84,21 @@
6284
metric_name: block_countries
6385
statement:
6486
geo_match_statement: # Can't find the actual name, I got this from aws rule JSON formated
65-
country_codes: "{{ cf_acl.cc_block_list }}"
87+
country_codes: "{{ acl.cc_block_list }}"
6688

6789
- name: Add rule to list
6890
ansible.builtin.set_fact:
69-
acl_rules: "{{ acl_rules + ip_block_rule}}"
91+
acl_rules: "{{ acl_rules + cc_block_rule }}"
7092

7193
# Workaround for rate limit rule in ACL (any variable gets interpreted as string instead of int)
7294
- name: Set rate limit variable
7395
when: rate_limit is defined
7496
block:
75-
- name: Define r_limit to avoid issues
76-
ansible.builtin.set_fact:
77-
r_limit: "{{ rate_limit | int }}"
78-
7997
- name: Define rate rule
8098
ansible.builtin.set_fact:
8199
rate_rule:
82100
- name: rate_limit
83-
priority: 2
101+
priority: 3
84102
action:
85103
block: {}
86104
visibility_config:
@@ -98,10 +116,10 @@
98116

99117
- name: Create web acl
100118
community.aws.wafv2_web_acl:
101-
name: "{{ cf_acl.acl_name }}" # Member must satisfy regular expression pattern: ^[\\w\\-]+$
119+
name: "{{ acl.name }}" # Member must satisfy regular expression pattern: ^[\\w\\-]+$
102120
description: "WAF protecting the {{ _domain_name }}"
103-
scope: "{{ cf_acl.scope }}"
104-
region: "{{ cf_acl.region }}"
121+
scope: "{{ acl.scope }}"
122+
region: "{{ acl.region }}"
105123
default_action: Allow # or "Block"
106124
sampled_requests: false
107125
cloudwatch_metrics: true # or "false" to disable metrics

roles/aws/aws_cloudfront_distribution/tasks/main.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
- name: Create web acl if defined
3-
ansible.builtin.include_tasks: create_acl.yml
4-
when: cf_acl is defined
3+
ansible.builtin.include_role:
4+
name: aws/acl
5+
when: acl is defined
56

67
- name: Create a CloudFront distribution.
78
community.aws.cloudfront_distribution:

0 commit comments

Comments
 (0)