|
2 | 2 | ansible.builtin.set_fact:
|
3 | 3 | acl_rules: []
|
4 | 4 |
|
| 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 | + |
5 | 38 | - name: Set IP allow rule
|
6 |
| - when: cf_acl.ip_allow is defined |
| 39 | + when: acl.ip_allow is defined |
7 | 40 | block:
|
8 | 41 | - name: Create IP allow set for WAF
|
9 | 42 | community.aws.wafv2_ip_set:
|
10 |
| - name: "{{ cf_acl.ip_allow.name }}" |
| 43 | + name: "{{ acl.ip_allow.name }}" |
11 | 44 | state: present
|
12 | 45 | description: Set of allowed IPs
|
13 |
| - scope: "{{ cf_acl.scope }}" |
14 |
| - region: "{{ cf_acl.region }}" |
| 46 | + scope: "{{ acl.scope }}" |
| 47 | + region: "{{ acl.region }}" |
15 | 48 | ip_address_version: IPV4
|
16 |
| - addresses: "{{ cf_acl.ip_allow.list }}" |
| 49 | + addresses: "{{ acl.ip_allow.list }}" |
17 | 50 | register: ip_set_info
|
18 | 51 |
|
19 | 52 | - name: Create IP allow rule
|
20 | 53 | ansible.builtin.set_fact:
|
21 | 54 | ip_allow_rule:
|
22 |
| - - name: allow_ips |
23 |
| - priority: 0 |
| 55 | + - name: "{{ acl.ip_allow.name }}" |
| 56 | + priority: 1 |
24 | 57 | action:
|
25 | 58 | allow: {}
|
26 | 59 | visibility_config:
|
|
35 | 68 | ansible.builtin.set_fact:
|
36 | 69 | acl_rules: "{{ acl_rules + ip_allow_rule }}"
|
37 | 70 |
|
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 |
40 | 73 | 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 |
53 | 75 | ansible.builtin.set_fact:
|
54 |
| - ip_block_rule: |
| 76 | + cc_block_rule: |
55 | 77 | - name: block_countries
|
56 |
| - priority: 1 |
| 78 | + priority: 2 |
57 | 79 | action:
|
58 | 80 | block: {}
|
59 | 81 | visibility_config:
|
|
62 | 84 | metric_name: block_countries
|
63 | 85 | statement:
|
64 | 86 | 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 }}" |
66 | 88 |
|
67 | 89 | - name: Add rule to list
|
68 | 90 | ansible.builtin.set_fact:
|
69 |
| - acl_rules: "{{ acl_rules + ip_block_rule}}" |
| 91 | + acl_rules: "{{ acl_rules + cc_block_rule }}" |
70 | 92 |
|
71 | 93 | # Workaround for rate limit rule in ACL (any variable gets interpreted as string instead of int)
|
72 | 94 | - name: Set rate limit variable
|
73 | 95 | when: rate_limit is defined
|
74 | 96 | block:
|
75 |
| - - name: Define r_limit to avoid issues |
76 |
| - ansible.builtin.set_fact: |
77 |
| - r_limit: "{{ rate_limit | int }}" |
78 |
| - |
79 | 97 | - name: Define rate rule
|
80 | 98 | ansible.builtin.set_fact:
|
81 | 99 | rate_rule:
|
82 | 100 | - name: rate_limit
|
83 |
| - priority: 2 |
| 101 | + priority: 3 |
84 | 102 | action:
|
85 | 103 | block: {}
|
86 | 104 | visibility_config:
|
|
98 | 116 |
|
99 | 117 | - name: Create web acl
|
100 | 118 | 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\\-]+$ |
102 | 120 | description: "WAF protecting the {{ _domain_name }}"
|
103 |
| - scope: "{{ cf_acl.scope }}" |
104 |
| - region: "{{ cf_acl.region }}" |
| 121 | + scope: "{{ acl.scope }}" |
| 122 | + region: "{{ acl.region }}" |
105 | 123 | default_action: Allow # or "Block"
|
106 | 124 | sampled_requests: false
|
107 | 125 | cloudwatch_metrics: true # or "false" to disable metrics
|
|
0 commit comments