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