]> git.proxmox.com Git - proxmox-firewall.git/log
proxmox-firewall.git
7 weeks agobump serde_with to 3 master
Fabian Grünbichler [Thu, 25 Jul 2024 11:00:21 +0000 (13:00 +0200)]
bump serde_with to 3

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
8 weeks agobump version to 0.5.0
Thomas Lamprecht [Mon, 22 Jul 2024 16:06:00 +0000 (18:06 +0200)]
bump version to 0.5.0

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
8 weeks agoguest: match arp packets via meta
Stefan Hanreich [Wed, 3 Jul 2024 09:17:12 +0000 (11:17 +0200)]
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>
8 weeks agoconntrack: arp: move handling to guest chains
Stefan Hanreich [Wed, 3 Jul 2024 09:17:11 +0000 (11:17 +0200)]
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>
8 weeks agocargo: bump proxmox-sys and proxmox-schema dependencies
Stefan Hanreich [Wed, 3 Jul 2024 09:17:10 +0000 (11:17 +0200)]
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>
8 weeks agoservice: flush firewall rules on force disable
Stefan Hanreich [Wed, 17 Jul 2024 13:16:46 +0000 (15:16 +0200)]
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>
2 months agorules: allow vital ICMP(v6) types
Stefan Hanreich [Mon, 10 Jun 2024 12:52:38 +0000 (14:52 +0200)]
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>
2 months agobuild: properly set dh-cargo env variable
Fabian Grünbichler [Thu, 20 Jun 2024 10:32:32 +0000 (12:32 +0200)]
build: properly set dh-cargo env variable

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2 months agomove .cargo/config to .cargo/config.toml
Fabian Grünbichler [Thu, 20 Jun 2024 10:32:19 +0000 (12:32 +0200)]
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>
3 months agobump version to 0.4.2
Thomas Lamprecht [Tue, 21 May 2024 13:44:13 +0000 (15:44 +0200)]
bump version to 0.4.2

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
3 months agoguest out: fix conntrack handling with default block/reject policy
Stefan Hanreich [Wed, 15 May 2024 13:37:19 +0000 (15:37 +0200)]
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>
3 months agoguest out: fix handling ARP traffic with default block/reject policy
Stefan Hanreich [Wed, 15 May 2024 13:37:18 +0000 (15:37 +0200)]
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>
3 months agorules: use proper ICMPv6 type for rejecting IPv6 traffic
Stefan Hanreich [Mon, 13 May 2024 12:14:25 +0000 (14:14 +0200)]
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>
4 months agobump version to 0.4.1
Thomas Lamprecht [Fri, 26 Apr 2024 15:22:05 +0000 (17:22 +0200)]
bump version to 0.4.1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agoservice: add comment for disable flag
Thomas Lamprecht [Fri, 26 Apr 2024 15:16:23 +0000 (17:16 +0200)]
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>
4 months agoservice: add flag file to force-disable nftables
Thomas Lamprecht [Fri, 26 Apr 2024 14:02:38 +0000 (16:02 +0200)]
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>
4 months agobump version to 0.4.0
Thomas Lamprecht [Thu, 25 Apr 2024 17:29:50 +0000 (19:29 +0200)]
bump version to 0.4.0

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agofirewall: improve error handling of firewall
Stefan Hanreich [Thu, 25 Apr 2024 17:23:07 +0000 (19:23 +0200)]
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>
4 months agoconfig: nftables: add support for icmp-type any
Stefan Hanreich [Thu, 25 Apr 2024 17:16:08 +0000 (19:16 +0200)]
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>
4 months agoconfig: macros: add SPICEproxy macro
Stefan Hanreich [Thu, 25 Apr 2024 17:16:01 +0000 (19:16 +0200)]
config: macros: add SPICEproxy macro

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
4 months agobump version to 0.3.1
Thomas Lamprecht [Wed, 24 Apr 2024 17:40:43 +0000 (19:40 +0200)]
bump version to 0.3.1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agofix #5410: config: fix naming scheme for names in firewall config
Stefan Hanreich [Wed, 24 Apr 2024 16:15:20 +0000 (18:15 +0200)]
fix #5410: config: fix naming scheme for names in firewall config

This should bring the allowed names on par with the pve-firewall
naming scheme, allowing also underscores together with minus, as long
it isn't the first character [1].

[1] https://git.proxmox.com/?p=pve-firewall.git;a=blob;f=src/PVE/Firewall.pm;h=0abfeccffc94cec940760e69a894e392dc33f151;hb=29b48c381d14bf425232dc65c9c0d18f95c8f222#l51

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
 [ TL: expand commit message slightly ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agobump version to 0.3.0
Thomas Lamprecht [Tue, 23 Apr 2024 16:34:29 +0000 (18:34 +0200)]
bump version to 0.3.0

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agofirewall: properly handle REJECT rules
Stefan Hanreich [Tue, 23 Apr 2024 16:02:53 +0000 (18:02 +0200)]
firewall: properly handle REJECT rules

Currently we generated DROP statements for all rules involving REJECT.
We only need to generate DROP when in the postrouting chain of tables
with type bridge, since REJECT is disallowed there. Otherwise we jump
into the do-reject chain which properly handles rejects for different
protocol types.

Reported-By: Stefan Sterz <s.sterz@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
4 months agobump version to 0.2.1
Thomas Lamprecht [Tue, 23 Apr 2024 11:20:19 +0000 (13:20 +0200)]
bump version to 0.2.1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agofirewall: properly cleanup tables when firewall is inactive
Stefan Hanreich [Tue, 23 Apr 2024 09:21:39 +0000 (11:21 +0200)]
firewall: properly cleanup tables when firewall is inactive

When executing multiple nft commands they are transactional, either
all get applied or none. When only the host or guest firewall is
active, only one table exists and this causes the delete commands to
fail. To fix this we need to send the delete commands separately.

It might make sense to support running multiple separate batches in
the NftClient in the future in order to avoid having to call nft
twice.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
4 months agobump version to 0.2.0
Thomas Lamprecht [Fri, 19 Apr 2024 17:42:30 +0000 (19:42 +0200)]
bump version to 0.2.0

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
4 months agofirewall: improve systemd unit file
Stefan Hanreich [Fri, 19 Apr 2024 13:00:26 +0000 (15:00 +0200)]
firewall: improve systemd unit file

Explicitly mark the service as simple and remove the PIDFile
attribute, which doesn't do anything with simple services.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
4 months agofirewall: wait for nft process
Stefan Hanreich [Fri, 19 Apr 2024 13:00:25 +0000 (15:00 +0200)]
firewall: wait for nft process

NftClient never waits for the child process to terminate leading to
defunct leftover processes.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
5 months agobuildsys: add upload target
Thomas Lamprecht [Thu, 18 Apr 2024 20:02:26 +0000 (22:02 +0200)]
buildsys: add upload target

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agobuildsys: drop bogus DEB variables
Thomas Lamprecht [Thu, 18 Apr 2024 20:02:08 +0000 (22:02 +0200)]
buildsys: drop bogus DEB variables

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agofirewall: add integration test
Stefan Hanreich [Tue, 16 Apr 2024 17:00:15 +0000 (19:00 +0200)]
firewall: add integration test

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agofirewall: add files for debian packaging
Stefan Hanreich [Fri, 29 Mar 2024 09:53:08 +0000 (10:53 +0100)]
firewall: add files for debian packaging

Suggested-By: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
 [ TL: squash in various fixes and clean-ups ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agofirewall: add proxmox-firewall binary and move existing code into lib
Stefan Hanreich [Fri, 29 Mar 2024 14:29:15 +0000 (15:29 +0100)]
firewall: add proxmox-firewall binary and move existing code into lib

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agofirewall: add ruleset generation logic
Stefan Hanreich [Fri, 29 Mar 2024 14:29:05 +0000 (15:29 +0100)]
firewall: add ruleset generation logic

We create the rules from the firewall config by utilizing the
ToNftRules and ToNftObjects traits to convert the firewall config
structs to nftables objects/chains/rules.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agofirewall: add object generation logic
Stefan Hanreich [Fri, 29 Mar 2024 09:50:20 +0000 (10:50 +0100)]
firewall: add object generation logic

ToNftObjects is basically a conversion trait that converts firewall
config structs into nftables objects. It returns a list of commands
that create the respective nftables objects.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agofirewall: add rule generation logic
Stefan Hanreich [Fri, 29 Mar 2024 15:37:58 +0000 (16:37 +0100)]
firewall: add rule generation logic

ToNftRules is basically a conversion trait for firewall config structs
to convert them into the respective nftables statements.

We are passing a list of rules to the method, which then modifies the
list of rules such that all relevant rules in the list have statements
appended that apply the configured constraints from the firewall
config.

This is particularly relevant for the rule generation logic for
ipsets. Due to how sets work in nftables we need to generate two rules
for every ipset: a rule for the v4 ipset and a rule for the v6 ipset.
This is because sets can only contain either v4 or v6 addresses. By
passing a list of all generated rules we can duplicate all rules and
then add a statement for the v4 or v6 set respectively.

This also enables us to start with multiple rules, which is required
for using log statements in conjunction with limit statements.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agofirewall: add config loader
Stefan Hanreich [Fri, 29 Mar 2024 09:48:30 +0000 (10:48 +0100)]
firewall: add config loader

We load the firewall configuration from the default paths, as well as
only the guest configurations that are local to the node itself. In
the future we could change this to use pmxcfs directly instead.

We also load information from nftables directly about dynamically
created chains (mostly chains for the guest firewall).

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agofirewall: add base ruleset
Stefan Hanreich [Fri, 29 Mar 2024 09:51:54 +0000 (10:51 +0100)]
firewall: add base ruleset

This is the skeleton for the firewall that contains all the base
chains required for the firewall.

The file applies atomically, which means that it flushes all objects
and recreates them - except for the cluster/host/guest chain. This
means that it can be run at any point in time, since it only updates
the chains that are not managed by the firewall itself.

This also means that when we change the rules in the chains (e.g.
during an update) we can always just re-run the nft-file and the
firewall should use the new chains while still retaining the
configuration generated by the firewall daemon.

This also means that when re-creating the firewall rules, the
cluster/host/guest chains need to be flushed manually before creating
new rules.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
5 months agofirewall: add firewall crate
Stefan Hanreich [Fri, 29 Mar 2024 09:47:10 +0000 (10:47 +0100)]
firewall: add firewall crate

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: add nft client
Stefan Hanreich [Fri, 29 Mar 2024 09:45:58 +0000 (10:45 +0100)]
nftables: add nft client

Add a thin wrapper around nft, which can be used to run commands
defined by the rust types.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: types: add conversion traits
Stefan Hanreich [Fri, 29 Mar 2024 15:52:06 +0000 (16:52 +0100)]
nftables: types: add conversion traits

Some parts of the firewall config map directly to nftables objects, so
we introduce conversion traits for convenient conversion into the
respective nftables objects / types.

They are guarded behind a feature, so the nftables crate can be used
standalone without depending on the proxmox-ve-config crate.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: commands: add types
Stefan Hanreich [Wed, 17 Apr 2024 12:55:35 +0000 (14:55 +0200)]
nftables: commands: add types

Add rust types for most of the nftables commands as defined by
libnftables-json [1].

Different commands require different keys to be set for the same type
of object. E.g. deleting an object usually only requires a name +
name of the container (table/chain/rule). Creating an object usually
requires a few more keys, depending on the type of object created.

In order to be able to model the different objects for the different
commands, I've created specific models for a command where necessary.
Parts that are common across multiple commands (e.g. names) have been
moved to their own structs, so they can be reused.

[1] https://manpages.debian.org/bookworm/libnftables1/libnftables-json.5.en.html#COMMAND_OBJECTS

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
5 months agonftables: statement: add conversion traits for config types
Stefan Hanreich [Wed, 17 Apr 2024 12:54:45 +0000 (14:54 +0200)]
nftables: statement: add conversion traits for config types

Some types from the firewall configuration map directly onto nftables
statements. For those we implement conversion traits so we can
conveniently convert between the configuration types and the
respective nftables types.

As with the expressions, those are guarded behind a feature so the
nftables crate can be used standalone without having to pull in the
proxmox-ve-config crate.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: statement: add types
Stefan Hanreich [Fri, 29 Mar 2024 15:47:21 +0000 (16:47 +0100)]
nftables: statement: add types

Adds an enum containing most of the statements defined in the
nftables-json schema [1].

[1] https://manpages.debian.org/bookworm/libnftables1/libnftables-json.5.en.html#STATEMENTS

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: expression: implement conversion traits for firewall config
Stefan Hanreich [Fri, 29 Mar 2024 13:36:44 +0000 (14:36 +0100)]
nftables: expression: implement conversion traits for firewall config

Some types from the firewall configuration map directly onto nftables
expressions. For those we implement conversion traits so we can
conveniently convert between the configuration types and the
respective nftables types.

Those are guarded behind a feature so the nftables crate can be used
standalone without having to pull in the proxmox-ve-config crate.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: expression: add types
Stefan Hanreich [Fri, 29 Mar 2024 13:12:59 +0000 (14:12 +0100)]
nftables: expression: add types

Adds an enum containing most of the expressions defined in the
nftables-json schema [1].

[1] https://manpages.debian.org/bookworm/libnftables1/libnftables-json.5.en.html#EXPRESSIONS

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agonftables: add helpers
Stefan Hanreich [Fri, 29 Mar 2024 09:34:25 +0000 (10:34 +0100)]
nftables: add helpers

Several objects, statements and expressions in nftables-json require
null values, for instance:

    { "flush": { "ruleset": null }}

For this purpose we define our own Null type, which we can then easily
use for defining types that accept Null as value.

Several keys accept as value either a singular element (string or
object) if there is only one object, but an array if there are
multiple objects. For instance when adding a single element to a set:

           { "element": {
       ...
       "elem": "element1"
           }}

but when adding multiple elements:

           { "element": {
       ...
       "elem": ["element1", "element2"]
           }}

NfVec<T> is a wrapper for Vec<T> that serializes into T iff Vec
contains one element, otherwise it serializes like a Vec would
normally do.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agonftables: add crate for libnftables bindings
Stefan Hanreich [Fri, 29 Mar 2024 09:30:32 +0000 (10:30 +0100)]
nftables: add crate for libnftables bindings

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agoconfig: firewall: add conntrack helper types
Stefan Hanreich [Fri, 29 Mar 2024 09:27:17 +0000 (10:27 +0100)]
config: firewall: add conntrack helper types

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
5 months agoconfig: firewall: add firewall macros
Stefan Hanreich [Fri, 29 Mar 2024 09:26:39 +0000 (10:26 +0100)]
config: firewall: add firewall macros

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add guest-specific config + option types
Stefan Hanreich [Fri, 29 Mar 2024 09:25:08 +0000 (10:25 +0100)]
config: firewall: add guest-specific config + option types

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add host specific config + option types
Stefan Hanreich [Fri, 29 Mar 2024 09:23:36 +0000 (10:23 +0100)]
config: firewall: add host specific config + option types

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add cluster-specific config + option types
Stefan Hanreich [Fri, 29 Mar 2024 09:21:04 +0000 (10:21 +0100)]
config: firewall: add cluster-specific config + option types

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add generic parser for firewall configs
Stefan Hanreich [Fri, 29 Mar 2024 09:19:03 +0000 (10:19 +0100)]
config: firewall: add generic parser for firewall configs

Since the basic format of cluster, host and guest firewall
configurations is the same, we create a generic parser that can handle
the common config format. The main difference is in the available
options, which can be passed via a generic parameter.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for security groups
Stefan Hanreich [Fri, 29 Mar 2024 09:15:33 +0000 (10:15 +0100)]
config: firewall: add types for security groups

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for rules
Stefan Hanreich [Fri, 29 Mar 2024 09:14:05 +0000 (10:14 +0100)]
config: firewall: add types for rules

Additionally we implement FromStr for all rule types and parts, which
can be used for parsing firewall config rules. Initial rule parsing
works by parsing the different options into a HashMap and only then
de-serializing a struct from the parsed options.

This intermediate step makes rule parsing a lot easier, since we can
reuse the deserialization logic from serde. Also, we can split the
parsing/deserialization logic from the validation logic.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for ipsets
Stefan Hanreich [Fri, 29 Mar 2024 09:07:58 +0000 (10:07 +0100)]
config: firewall: add types for ipsets

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: guest: add helpers for parsing guest network config
Stefan Hanreich [Fri, 29 Mar 2024 09:04:38 +0000 (10:04 +0100)]
config: guest: add helpers for parsing guest network config

Currently this is parsing the config files via the filesystem. In the
future we could also get this information from pmxcfs directly via
IPC which should be more performant, particularly for a large number
of VMs.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: host: add helpers for host network configuration
Stefan Hanreich [Fri, 29 Mar 2024 09:01:14 +0000 (10:01 +0100)]
config: host: add helpers for host network configuration

Currently the helpers for obtaining the host network configuration
panic on error, which could be avoided by the use of
OnceLock::get_or_init, but this method is currently only available in
nightly versions.

Generally, if there is a problem with obtaining the network config for
the node I would deem it acceptable for now, since that would usually
mean something is amiss with the network configuration and a firewall
won't really do anything then anyway.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for aliases
Stefan Hanreich [Fri, 29 Mar 2024 08:55:33 +0000 (09:55 +0100)]
config: firewall: add types for aliases

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for log level and rate limit
Stefan Hanreich [Fri, 29 Mar 2024 08:52:37 +0000 (09:52 +0100)]
config: firewall: add types for log level and rate limit

Adds types for log and (log-)rate-limiting firewall config options as
well as FromStr implementations for parsing them from the config.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for ports
Stefan Hanreich [Fri, 29 Mar 2024 08:48:50 +0000 (09:48 +0100)]
config: firewall: add types for ports

Adds types for all kinds of port-related values in the firewall config
as well as FromStr implementations for parsing them from the config.

Also adds a helper for parsing the named ports from `/etc/services`.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: firewall: add types for ip addresses
Stefan Hanreich [Tue, 2 Apr 2024 11:33:33 +0000 (13:33 +0200)]
config: firewall: add types for ip addresses

Includes types for all kinds of IP values that can occur in the
firewall config. Additionally, FromStr implementations are available
for parsing from the config files.

Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
5 months agoconfig: add proxmox-ve-config crate
Stefan Hanreich [Fri, 29 Mar 2024 08:41:50 +0000 (09:41 +0100)]
config: add proxmox-ve-config crate

Co-authored-by: Wolfgang Bumiller<w.bumiller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>