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