-
Notifications
You must be signed in to change notification settings - Fork 1
/
firewall.yml
129 lines (107 loc) · 3.58 KB
/
firewall.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
- hosts: all
name: configure firewalld
become: true
vars_files:
- ./vars.yml
tasks:
- name: Install firewall and SELinux related stuff on Red Hat and Fedora
yum:
name:
- python3-policycoreutils
- ipset
- firewalld
- git
state: installed
when: ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora'
- name: Install firewall related stuff on Debian and Ubuntu
apt:
pkg:
- ipset
- firewalld
- git
state: present
when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
- name: Open public reachable ports
firewalld:
port: "{{ item }}"
state: enabled
permanent: true
loop: "{{ public_ports }}"
- name: Add trusted networks and IPs
firewalld:
source: "{{ item }}"
zone: trusted
state: enabled
permanent: true
loop: "{{ trusted_networks }}"
- name: Ensure Firewalld is running
service:
name: firewalld
state: started
enabled: true
- name: Download git repo for RIPE subnets
ansible.builtin.git:
repo: "https://github.com/mivk/ip-country.git"
dest: /root/ip-country
single_branch: yes
version: master
when: fck_ptn
- name: Update RIPE Subnet list of ptn-country
shell: /root/ip-country/get-ripe-ips -o /root/ -c ru
when: fck_ptn
- name: Delete blacklist IPv4
shell: firewall-cmd --delete-ipset=blacklist --permanent
when: fck_ptn
ignore_errors: true
- name: Delete blacklist for IPv6
shell: firewall-cmd --delete-ipset=blacklist6 --permanent
when: fck_ptn
ignore_errors: true
- name: Add blacklist for IPv4
shell: firewall-cmd --permanent --new-ipset=blacklist --type=hash:net --option=family=inet --option=hashsize=4096 --option=maxelem=200000
when: fck_ptn
- name: Add blacklist for IPv6
shell: firewall-cmd --permanent --new-ipset=blacklist6 --type=hash:net --option=family=inet6 --option=hashsize=4096 --option=maxelem=200000
when: fck_ptn
- name: Load entries from ptn blacklisted IPv4 subnets from RIPE
shell: firewall-cmd --permanent --ipset=blacklist --add-entries-from-file=/root/ipv4_ru
when: fck_ptn
- name: Load entries from ptn blacklisted IPv6 prefixes from RIPE
shell: firewall-cmd --permanent --ipset=blacklist6 --add-entries-from-file=/root/ipv6_ru
when: fck_ptn
- name: Activate ptn Blacklist for IPv4
shell: firewall-cmd --permanent --zone=drop --add-source=ipset:blacklist
when: fck_ptn
- name: Activate ptn Blacklist for IPv6
shell: firewall-cmd --permanent --zone=drop --add-source=ipset:blacklist6
when: fck_ptn
- name: Make sure firewalld is up and running
systemd:
name: firewalld
state: restarted
enabled: true
- name: Configure SELinux to allow SSHD to bind to port 2222
seport:
ports: 2222
proto: tcp
setype: ssh_port_t
state: present
when: ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora'
- name: Ensure SELinux is in enforcing mode
selinux:
policy: targeted
state: enforcing
when: ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora'
- name: Ensure rpcbind is disabled
service:
name: rpcbind.service
state: stopped
enabled: false
when: ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora'
- name: Ensure rpcbind socket is disabled
service:
name: rpcbind.socket
state: stopped
enabled: false
when: ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora'