Commit Graph

95 Commits

Author SHA1 Message Date
Thomas Lamprecht
0a60fbd309 bump version to 0.7.1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-04-08 15:54:22 +02:00
Stefan Hanreich
f16e60bc09 guest: do not try to create map entries if there are no devices
When the firewall was enabled for a guest, but disabled for all
interfaces of a guest, the firewall tried to add an empty list to the
guest map, which is an invalid nftables statement.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Link: https://lore.proxmox.com/20250408134135.242922-1-s.hanreich@proxmox.com
2025-04-08 15:51:12 +02:00
Thomas Lamprecht
5718726aef bump version to 0.7.0
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-04-07 15:08:53 +02:00
Thomas Lamprecht
40bf33c0fa cargo: bump proxmox-ve-config dependency to 0.2.3
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-04-07 13:48:24 +02:00
Stefan Hanreich
2d381630c6 tests: add network device without firewall key
A bug in proxmox-ve-config caused the key to be defaulted to on, if it
didn't exist in the configuration. Add this scenario to the
integration tests, so we can potentially catch problems with the
missing firewall key via the integration tests.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Link: https://lore.proxmox.com/20250313132231.166477-5-s.hanreich@proxmox.com
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Hannes Laimer <h.laimer@proxmox.com>
2025-04-07 13:43:06 +02:00
Stefan Hanreich
4b47d2adac partially fix #6176: do not generate mac filter if firewall disabled
The firewall generated mac filters for outgoing packets even if the
firewall was disabled for a specific interface. This was applicable to
ARP packets as well.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Link: https://lore.proxmox.com/20250313132231.166477-4-s.hanreich@proxmox.com
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Hannes Laimer <h.laimer@proxmox.com>
2025-04-07 13:43:06 +02:00
Stefan Hanreich
0f0e1875ac partially fix #6176: ipfilter: honor firewall setting from guest cfg
ipfilter ipsets and rules were still generated, even if the firewall
was disabled for the network device.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Link: https://lore.proxmox.com/20250313132231.166477-3-s.hanreich@proxmox.com
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Hannes Laimer <h.laimer@proxmox.com>
2025-04-07 13:43:06 +02:00
Stefan Hanreich
1fc3f4ec1a ipsets: remove dereference
The network device configuration doesn't return a reference anymore,
so we do not need to dereference here anymore.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Link: https://lore.proxmox.com/20250313132231.166477-2-s.hanreich@proxmox.com
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
Reviewed-by: Hannes Laimer <h.laimer@proxmox.com>
2025-04-07 13:43:06 +02:00
Stefan Hanreich
75d2c9793c tests: add Ping macro to tests
Rules using the Ping macro were wrongly generated due to the ICMP
macros using the wrong format for specifying ICMP type. The test cases
did not include any macros utilizing the ICMP protocol. Add them to
catch any errors related to ICMP parsing in the future.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
Link: https://lore.proxmox.com/20250204095733.55146-3-s.hanreich@proxmox.com
Reviewed-by: Hannes Laimer <h.laimer@proxmox.com>
2025-04-07 13:42:46 +02:00
Christoph Heiss
ac5206a4b4 tests: integration: silence warning about unused variable
It's just a stub method, so this gets never used.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
2025-03-26 10:39:25 +01:00
Hannes Laimer
ee45277559 firewall: apply nf_conntrack_allow_invalid option to host table
... on all chains that check for ct state. Since we support this option,
we should also use it in our firewall rule generation.

This is a follow-up to
  64dc344b ("firewall: apply `nt_conntrack_allow_invalid` option to guest table")

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
2025-03-13 17:14:25 +01:00
Hannes Laimer
ab2709bf51 fix: firewall: apply nf_conntrack_allow_invalid to all chains
... on the guest table. There is no reason to not respect that option
on those two chains. These two were missed in the referenced commit.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Fixes: 64dc344b ("firewall: apply `nt_conntrack_allow_invalid` option to guest table")
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Stefan Hanreich <s.hanreich@proxmox.com>
2025-03-13 17:13:40 +01:00
Fabian Grünbichler
efef5c53e4 build: bump env_logger to 0.11
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2025-03-13 15:07:46 +01:00
Wolfgang Bumiller
57aac70bbe bump d/control
proxmox-ve-config currently still has a non-standard d/control, so
that one needs manual fixing, but the rest follows the usual
conventions...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2025-03-13 14:16:02 +01:00
Stefan Hanreich
5841bef7f2 tests: add test for security groups in cluster config
There was a bug where rulesets with security groups bound to a
specific interface would cause the firewall to fail to create a new
ruleset. Catch this by adding a security group bound to an interface
to the ruleset.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2025-03-13 13:59:08 +01:00
Stefan Hanreich
b3f3d7209b security groups: skip in forward chain when interface is specified
Security groups can be bound to a specific interface. The notion of
this breaks down when considering the forward direction, since there
are two interfaces involved: incoming and outgoing, which can be
different depending on the kind of traffic.

With the current implementation, the firewall refuses to generate
rulesets with security groups that are bound to specific interfaces.
Check for this case explicitly and skip creating rules in the forward
chain when a security group bound to a specific interface is
encountered.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Tested-by: Hannes Duerr <h.duerr@proxmox.com>
2025-03-13 13:59:08 +01:00
Stefan Hanreich
697da0168e cargo: update proxmox-ve-config
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2025-03-13 13:57:54 +01:00
Christoph Heiss
b0e756d5e2 d/control: drop unused build dependencies
These are simply just of the proxmox-ve-config crate, which was
moved to a separate repository in

  aa7692036 ("add proxmox-ve-rs crate - move proxmox-ve-config there")

and are not used by the other remaining crates.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
2025-01-24 13:48:14 +01:00
Stefan Hanreich
0479539f01 clippy: useless use of format!
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-11-25 21:58:41 +01:00
Thomas Lamprecht
6ef05080c6 bump version to 0.6.0
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-19 16:53:12 +01:00
Thomas Lamprecht
22958811c8 config: fallback to legacy path when reading PVE IPAM state
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 22:24:26 +01:00
Hannes Laimer
64dc344bb8 firewall: apply nt_conntrack_allow_invalid option to guest table
So it behaves the same way the 'old' firewall did. Since currently
ct state invalid are always dropped on the guest table, regardless
of the option. The host behaviour is not changed as it would
require `forward` to match the 'old' behaviour.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
 [ TL: resolve merge conflict due to recent context changes ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-17 13:29:58 +01:00
Stefan Hanreich
8ef2e4e6b5 use std::mem::take over drain()
This is more efficient than draining and collecting the Vec. It also
fixes the respective clippy lint.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-11-17 12:59:43 +01:00
Stefan Hanreich
646fc18d04 sdn: create forward firewall rules
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Tested-by: Hannes Dürr <h.duerr@proxmox.com>
2024-11-17 12:59:43 +01:00
Stefan Hanreich
0c8bd4ad19 sdn: add support for loading vnet-level firewall config
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Tested-by: Hannes Dürr <h.duerr@proxmox.com>
2024-11-17 12:59:43 +01:00
Stefan Hanreich
d6edc73674 nftables: derive additional traits for nftables types
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2024-11-17 12:59:43 +01:00
Stefan Hanreich
6f01ca780b ipsets: autogenerate ipsets for vnets and ipam
They act like virtual ipsets, similar to ipfilter-net, that can be
used for defining firewall rules for sdn objects dynamically.

The changes in proxmox-ve-config also introduced a dedicated struct
for representing ip ranges, so we update the existing code, so that it
uses that struct as well.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Tested-by: Gabriel Goller <g.goller@proxmox.com>
Tested-by: Hannes Dürr <h.duerr@proxmox.com>
2024-11-17 12:59:43 +01:00
Stefan Hanreich
669f99801b config: tests: add support for loading sdn and ipam config
Also add example SDN configuration files that get automatically
loaded, which can be used for future tests.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Tested-by: Gabriel Goller <g.goller@proxmox.com>
Tested-by: Hannes Dürr <h.duerr@proxmox.com>
2024-11-17 12:59:43 +01:00
Stefan Hanreich
aa76920360 add proxmox-ve-rs crate - move proxmox-ve-config there
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
 [ TL: add dependency to d/control and update its version ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-17 12:59:43 +01:00
Fabian Grünbichler
bea3e651b4 firewall: cargo: use new cargo feature resolver
Virtual cargo workspaces (workspaces without a [package] section)
default to the cargo feature resolver "1" – even though this outputs a
warning on every cargo invocation. To remove the warning, explicitly set
the resolver to version "2".

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>

FG: adapted to current Cargo.toml
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-10-31 14:03:31 +01:00
Fabian Grünbichler
ac39ec3c66 bump serde_with to 3
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-07-25 13:00:21 +02:00
Thomas Lamprecht
38c9eab41c bump version to 0.5.0
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-07-22 18:06:00 +02:00
Stefan Hanreich
57f6c9221d guest: match arp packets via meta
When matching via ether type, VLAN packets are not matched. This can
cause ARP packets encapsulated in VLAN frames to be dropped.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-07-22 17:56:51 +02:00
Stefan Hanreich
de75183366 conntrack: arp: move handling to guest chains
In order to make sure we are only affecting VM traffic and no host
interfaces that are bridged, move the rules into a chain that gets
executed inside the guest chain, rather than setting the rules
globally.

Since ether type matches on the respective Ethernet header, it
doesn't work for packets with VLAN header. Matching via meta protocol
ensures that VLAN encapsulated ARP packets are matched as well.
Otherwise ARP traffic inside VLANs gets dropped, due to them having
conntrack state invalid.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-07-22 17:53:54 +02:00
Stefan Hanreich
293a19c213 cargo: bump proxmox-sys and proxmox-schema dependencies
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
 [ TL: update to versions released since this patch was created and
   updated proxmox-sys tree-wide ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-07-22 17:50:11 +02:00
Stefan Hanreich
08b74961cc service: flush firewall rules on force disable
When disabling the nftables firewall again, there is a race condition
where the nftables ruleset never gets flushed and persists after
disabling.

The nftables firewall update loop does a noop when the force disable
file exists. It only flushes the ruleset when nftables is disabled in
the configuration file but the force disable file does not yet exist.

This can lead to the following situation:

* nftables is activated and created its ruleset
* user switches from nftables firewall back to iptables firewall
* pve-firewall runs and creates the force disable file
* proxmox-firewall sees that the file exists and does nothing

Reported-by: Hannes Laimer <h.laimer@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-07-22 17:43:05 +02:00
Stefan Hanreich
1e16cc8827 rules: allow vital ICMP(v6) types
There are certain ICMP messages that should always pass through a
firewall irregardless of any other rules. This is particularly
important for ICMPv6. While we already handled NDP, there are certain
control messages that should always be able to pass through any
firewall, according to RFC 4890.

For ICMP we additionally allow 'Source Quench' as well.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-07-10 14:54:30 +02:00
Fabian Grünbichler
aa9b2e2395 build: properly set dh-cargo env variable
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-06-20 12:32:32 +02:00
Fabian Grünbichler
f39f78150b move .cargo/config to .cargo/config.toml
the old location has been deprecated for a while, and rustc 1.78 will start to warn about it.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-06-20 12:32:19 +02:00
Thomas Lamprecht
7d1a12822d bump version to 0.4.2
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-05-21 15:44:13 +02:00
Stefan Hanreich
67eba1f525 guest out: fix conntrack handling with default block/reject policy
The output chain did not have any connection tracking (conntrack)
rules, which lead to issues when the default output policy is not
accept. Also, move the conntrack rules to the beginning of all chains.

Originally-by: Laurent Guerby <laurent@guerby.net>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-05-21 15:40:27 +02:00
Stefan Hanreich
3500a8d833 guest out: fix handling ARP traffic with default block/reject policy
In order to be able to send outgoing ARP packets when the default
policy is set to drop or reject, we need to explicitly allow ARP
traffic in the outgoing chain of guests. We need to do this in the
guest chain itself in order to be able to filter spoofed packets via
the MAC filter.

Contrary to the out direction we can simply accept all incoming ARP
traffic, since we do not do any MAC filtering for incoming traffic.
Since we create fdb entries for every NIC, guests should only see ARP
traffic for their MAC addresses anyway.

Originally-by: Laurent Guerby <laurent@guerby.net>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-05-21 15:40:27 +02:00
Stefan Hanreich
bc3791c59a rules: use proper ICMPv6 type for rejecting IPv6 traffic
ICMPv6 has different message types for rejecting traffic. With ICMP we
used host-prohibited as rejection type, which doesn't exist in ICMPv6.
Add an additional rule for IPv6, so it uses admin-prohibited.

Additionally, add a terminal drop statement in order to prevent any
traffic that does not get matched from bypassing the reject chain.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-05-21 15:39:48 +02:00
Thomas Lamprecht
019bf8c843 bump version to 0.4.1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-04-26 17:22:28 +02:00
Thomas Lamprecht
97b31ad885 service: add comment for disable flag
this is something that should be roughly covered directly in the code

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-04-26 17:16:24 +02:00
Thomas Lamprecht
7acba538b8 service: add flag file to force-disable nftables
This will be set in the iptables/Perl based pve-firewall service and
ensures that users pulling this service but not enabling it are
"protected" from log-spam due to some pve-firewall config not being
parsed correctly (yet).

We can remove this again once we're sure that all edge cases are
covered, or this service here becomes the default.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-04-26 17:11:41 +02:00
Thomas Lamprecht
d0506dc1a8 bump version to 0.4.0
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-04-25 19:29:50 +02:00
Stefan Hanreich
3b4bc833c1 firewall: improve error handling of firewall
Error handling of the firewall binary should now be much more robust
on configuration errors. Instead of panicking in some cases it should
now log an error.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-04-25 19:25:17 +02:00
Stefan Hanreich
d409750487 config: nftables: add support for icmp-type any
We support any as wildcard for matching all icmp types. Implement
parsing logic for parsing the any value and support converting the any
value into an nftables expression.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-04-25 19:21:50 +02:00
Stefan Hanreich
58ebc5500c config: macros: add SPICEproxy macro
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2024-04-25 19:21:50 +02:00