]> git.proxmox.com Git - pve-docs.git/blob - pve-firewall.adoc
925ce161596505268cf6861069db79ac2b842439
[pve-docs.git] / pve-firewall.adoc
1 ifdef::manvolnum[]
2 PVE({manvolnum})
3 ================
4 include::attributes.txt[]
5
6 NAME
7 ----
8
9 pve-firewall - The PVE Firewall Daemon
10
11
12 SYNOPSYS
13 --------
14
15 include::pve-firewall.8-synopsis.adoc[]
16
17
18 DESCRIPTION
19 -----------
20 endif::manvolnum[]
21
22 ifndef::manvolnum[]
23 {pve} Firewall
24 ==============
25 include::attributes.txt[]
26 endif::manvolnum[]
27
28 // Copied from pve wiki: Revision as of 08:45, 9 November 2015
29
30 Proxmox VE Firewall provides an easy way to protect your IT
31 infrastructure. You can easily setup firewall rules for all hosts
32 inside a cluster, or define rules for virtual machines and
33 containers. Features like firewall macros, security groups, IP sets
34 and aliases help making that task easier.
35
36 While all configuration is stored on the cluster file system, the
37 iptables based firewall runs on each cluster node, and thus provides
38 full isolation between virtual machines. The distributed nature of
39 this system also provides much higher bandwidth than a central
40 firewall solution.
41
42 NOTE: If you enable the firewall, all traffic is blocked by default,
43 except WebGUI(8006) and ssh(22) from your local network.
44
45 The firewall has full support for IPv4 and IPv6. IPv6 support is fully
46 transparent, and we filter traffic for both protocols by default. So
47 there is no need to maintain a different set of rules for IPv6.
48
49
50 Zones
51 -----
52
53 The Proxmox VE firewall groups the network into the following logical zones:
54
55 Host::
56
57 Traffic from/to a cluster node
58
59 VM::
60
61 Traffic from/to a specific VM
62
63 For each zone, you can define firewall rules for incoming and/or
64 outgoing traffic.
65
66
67 Ports used by Proxmox VE
68 ------------------------
69
70 * Web interface: 8006
71 * VNC Web console: 5900-5999
72 * SPICE proxy: 3128
73 * sshd (used for cluster actions): 22
74 * rpcbind: 111
75 * corosync multicast (if you run a cluster): 5404, 5405 UDP
76
77
78 Configuration
79 -------------
80
81 All firewall related configuration is stored on the proxmox cluster
82 file system. So those files are automatically distributed to all
83 cluster nodes, and the 'pve-firewall' service updates the underlying
84 iptables rules automatically on any change. Any configuration can be
85 done using the GUI (i.e. Datacenter -> Firewall -> Options tab (tabs
86 at the bottom of the page), or on a Node -> Firewall), so the
87 following configuration file snippets are just for completeness.
88
89 Cluster wide configuration is stored at:
90
91 /etc/pve/firewall/cluster.fw
92
93 The firewall is completely disabled by default, so you need to set the
94 enable option here:
95
96 ----
97 [OPTIONS]
98 # enable firewall (cluster wide setting, default is disabled)
99 enable: 1
100 ----
101
102 The cluster wide configuration can contain the following data:
103
104 * IP set definitions
105 * Alias definitions
106 * Security group definitions
107 * Cluster wide firewall rules for all nodes
108
109 VM firewall configuration is read from:
110
111 /etc/pve/firewall/<VMID>.fw
112
113 and contains the following data:
114
115 * IP set definitions
116 * Alias definitions
117 * Firewall rules for this VM
118 * VM specific options
119
120 And finally, any host related configuration is read from:
121
122 /etc/pve/nodes/<nodename>/host.fw
123
124 This is useful if you want to overwrite rules from 'cluster.fw'
125 config. You can also increase log verbosity, and set netfilter related
126 options.
127
128 Enabling the Firewall for VMs and Containers
129 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
131 You need to enable the firewall on the virtual network interface configuration
132 in addition to the general 'Enable Firewall' option in the 'Options' tab.
133
134 Firewall Rules
135 ~~~~~~~~~~~~~~
136
137 Firewall rules consists of a direction (`IN` or `OUT`) and an
138 action (`ACCEPT`, `DENY`, `REJECT`). You can also specify a macro
139 name. Macros contain predifined sets of rules and options. Rules can be disabled by prefixing them with '|'.
140
141 .Firewall rules syntax
142 ----
143 [RULES]
144
145 DIRECTION ACTION [OPTIONS]
146 |DIRECTION ACTION [OPTIONS] # disabled rule
147
148 DIRECTION MACRO(ACTION) [OPTIONS] # use predefined macro
149 ----
150
151 The following options can be used to refine rule matches.
152
153 include::pve-firewall-rules-opts.adoc[]
154
155 Here are some examples:
156
157 ----
158 [RULES]
159 IN SSH(ACCEPT) -i net0
160 IN SSH(ACCEPT) -i net0 # a comment
161 IN SSH(ACCEPT) -i net0 -source 192.168.2.192 # only allow SSH from 192.168.2.192
162 IN SSH(ACCEPT) -i net0 -source 10.0.0.1-10.0.0.10 # accept SSH for ip range
163 IN SSH(ACCEPT) -i net0 -source 10.0.0.1,10.0.0.2,10.0.0.3 #accept ssh for ip list
164 IN SSH(ACCEPT) -i net0 -source +mynetgroup # accept ssh for ipset mynetgroup
165 IN SSH(ACCEPT) -i net0 -source myserveralias #accept ssh for alias myserveralias
166
167 |IN SSH(ACCEPT) -i net0 # disabled rule
168
169 IN DROP # drop all incoming packages
170 OUT ACCEPT # accept all outgoing packages
171 ----
172
173 Security Groups
174 ~~~~~~~~~~~~~~~
175
176 A security group is a collection of rules, defined at cluster level, which
177 can be used in all VMs' rules. For example you can define a group named
178 `webserver` with rules to open the http and https ports.
179
180 ----
181 # /etc/pve/firewall/cluster.fw
182
183 [group webserver]
184 IN ACCEPT -p tcp -dport 80
185 IN ACCEPT -p tcp -dport 443
186 ----
187
188 Then, you can add this group to a VM's firewall
189
190 ----
191 # /etc/pve/firewall/<VMID>.fw
192
193 [RULES]
194 GROUP webserver
195 ----
196
197
198 IP Aliases
199 ~~~~~~~~~~
200
201 IP Aliases allow you to associate IP addresses of networks with a
202 name. You can then refer to those names:
203
204 * inside IP set definitions
205 * in `source` and `dest` properties of firewall rules
206
207 Standard IP alias `local_network`
208 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209
210 This alias is automatically defined. Please use the following command
211 to see assigned values:
212
213 ----
214 # pve-firewall localnet
215 local hostname: example
216 local IP address: 192.168.2.100
217 network auto detect: 192.168.0.0/20
218 using detected local_network: 192.168.0.0/20
219 ----
220
221 The firewall automatically sets up rules to allow everything needed
222 for cluster communication (corosync, API, SSH) using this alias.
223
224 The user can overwrite these values in the cluster.fw alias
225 section. If you use a single host on a public network, it is better to
226 explicitly assign the local IP address
227
228 ----
229 # /etc/pve/firewall/cluster.fw
230 [ALIASES]
231 local_network 1.2.3.4 # use the single ip address
232 ----
233
234 IP Sets
235 ~~~~~~~
236
237 IP sets can be used to define groups of networks and hosts. You can
238 refer to them with `+name` in the firewall rules' `source` and `dest`
239 properties.
240
241 The following example allows HTTP traffic from the `management` IP
242 set.
243
244 IN HTTP(ACCEPT) -source +management
245
246 Standard IP set `management`
247 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248
249 This IP set applies only to host firewalls (not VM firewalls). Those
250 ips are allowed to do normal management tasks (PVE GUI, VNC, SPICE,
251 SSH).
252
253 The local cluster network is automatically added to this IP set (alias
254 `cluster_network`), to enable inter-host cluster
255 communication. (multicast,ssh,...)
256
257 ----
258 # /etc/pve/firewall/cluster.fw
259
260 [IPSET management]
261 192.168.2.10
262 192.168.2.10/24
263 ----
264
265 Standard IP set 'blacklist'
266 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
267
268 Traffic from these ips is dropped by every host's and VM's firewall.
269
270 ----
271 # /etc/pve/firewall/cluster.fw
272
273 [IPSET blacklist]
274 77.240.159.182
275 213.87.123.0/24
276 ----
277
278 [[ipfilter-section]]
279 Standard IP set 'ipfilter-net*'
280 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
281
282 These filters belong to a VM's network interface and are mainly used to prevent
283 IP spoofing. If such a set exists for an interface then any outgoing traffic
284 with a source IP not matching its interface's corresponding ipfilter set will
285 be dropped.
286
287 For containers with configured IP addresses these sets, if they exist (or are
288 activated via the general `IP Filter` option in the VM's firewall's 'options'
289 tab), implicitly contain the associated IP addresses.
290
291 For both virtual machines and containers they also implicitly contain the
292 standard MAC-derived IPv6 link-local address in order to allow the neighbor
293 discovery protocol to work.
294
295 ----
296 /etc/pve/firewall/<VMID>.fw
297
298 [IPSET ipfilter-net0] # only allow specified IPs on net0
299 192.168.2.10
300 ----
301
302 Services and Commands
303 ~~~~~~~~~~~~~~~~~~~~~
304
305 The firewall runs two service daemons on each node:
306
307 * pvefw-logger: NFLOG daemon (ulogd replacement).
308 * pve-firewall: updates iptables rules
309
310 There is also a CLI command named 'pve-firewall', which can be used to
311 start and stop the firewall service:
312
313 # pve-firewall start
314 # pve-firewall stop
315
316 To get the status use:
317
318 # pve-firewall status
319
320 The above command reads and compiles all firewall rules, so you will
321 see warnings if your firewall configuration contains any errors.
322
323 If you want to see the generated iptables rules you can use:
324
325 # iptables-save
326
327 Tips and Tricks
328 ~~~~~~~~~~~~~~~
329
330 How to allow FTP
331 ^^^^^^^^^^^^^^^^
332
333 FTP is an old style protocol which uses port 21 and several other dynamic ports. So you
334 need a rule to accept port 21. In addition, you need to load the 'ip_conntrack_ftp' module.
335 So please run:
336
337 modprobe ip_conntrack_ftp
338
339 and add `ip_conntrack_ftp` to '/etc/modules' (so that it works after a reboot) .
340
341 Suricata IPS integration
342 ^^^^^^^^^^^^^^^^^^^^^^^^
343
344 If you want to use the http://suricata-ids.org/[Suricata IPS]
345 (Intrusion Prevention System), it's possible.
346
347 Packets will be forwarded to the IPS only after the firewall ACCEPTed
348 them.
349
350 Rejected/Dropped firewall packets don't go to the IPS.
351
352 Install suricata on proxmox host:
353
354 ----
355 # apt-get install suricata
356 # modprobe nfnetlink_queue
357 ----
358
359 Don't forget to add `nfnetlink_queue` to '/etc/modules' for next reboot.
360
361 Then, enable IPS for a specific VM with:
362
363 ----
364 # /etc/pve/firewall/<VMID>.fw
365
366 [OPTIONS]
367 ips: 1
368 ips_queues: 0
369 ----
370
371 `ips_queues` will bind a specific cpu queue for this VM.
372
373 Available queues are defined in
374
375 ----
376 # /etc/default/suricata
377 NFQUEUE=0
378 ----
379
380 Notes on IPv6
381 ^^^^^^^^^^^^^
382
383 The firewall contains a few IPv6 specific options. One thing to note is that
384 IPv6 does not use the ARP protocol anymore, and instead uses NDP (Neighbor
385 Discovery Protocol) which works on IP level and thus needs IP addresses to
386 succeed. For this purpose link-local addresses derived from the interface's MAC
387 address are used. By default the 'NDP' option is enabled on both host and VM
388 level to allow neighbor discovery (NDP) packets to be sent and received.
389
390 Beside neighbor discovery NDP is also used for a couple of other things, like
391 autoconfiguration and advertising routers.
392
393 By default VMs are allowed to send out router solicitation messages (to query
394 for a router), and to receive router advetisement packets. This allows them to
395 use stateless auto configuration. On the other hand VMs cannot advertise
396 themselves as routers unless the 'Allow Router Advertisement' (`radv: 1`) option
397 is set.
398
399 As for the link local addresses required for NDP, there's also an 'IP Filter'
400 (`ipfilter: 1`) option which can be enabled which has the same effect as adding
401 an `ipfilter-net*` ipset for each of the VM's network interfaces containing the
402 corresponding link local addresses. (See the
403 <<ipfilter-section,Standard IP set 'ipfilter-net*'>> section for details.)
404
405 Avoiding link-local addresses on tap and veth devices
406 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
407
408 With IPv6 enabled by default every interface gets a MAC-derived link local
409 address. However, most devices on a typical {pve} setup are connected to a
410 bridge and so the bridge is the only interface which really needs one.
411
412 To disable a link local address on an interface you can set the interface's
413 `disable_ipv6` sysconf variable. Despite the name, this does not prevent IPv6
414 traffic from passing through the interface when routing or bridging, so the
415 only noticeable effect will be the removal of the link local address.
416
417 The easiest method of achieving this setting for all newly started VMs is to
418 set it for the `default` interface configuration and enabling it explicitly on
419 the interfaces which need it. This is also the case for other settings such as
420 `forwarding`, `accept_ra` or `autoconf`.
421
422 Here's a possible setup:
423 ----
424 # /etc/sysconf.d/90-ipv6.conf
425
426 net.ipv6.conf.default.forwarding = 0
427 net.ipv6.conf.default.proxy_ndp = 0
428 net.ipv6.conf.default.autoconf = 0
429 net.ipv6.conf.default.disable_ipv6 = 1
430 net.ipv6.conf.default.accept_ra = 0
431
432 net.ipv6.conf.lo.disable_ipv6 = 0
433 ----
434
435 ----
436 # /etc/network/interfaces
437 (...)
438 iface vmbr0 inet6 static
439 address fc00::31
440 netmask 16
441 gateway fc00::1
442 accept_ra 0
443 pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/disable_ipv6
444 (...)
445 ----
446
447
448 ifdef::manvolnum[]
449
450 Macro Definitions
451 -----------------
452
453 include::pve-firewall-macros.adoc[]
454
455
456 include::pve-copyright.adoc[]
457
458 endif::manvolnum[]