From: "Thomas Ellmenreich" <t.ellmenreich@proxmox.com>
To: "Arthur Bied-Charreton" <a.bied-charreton@proxmox.com>,
<pve-devel@lists.proxmox.com>
Subject: Re: [PATCH proxmox-firewall 11/13] firewall: dump config to local directory after apply
Date: Fri, 11 Sep 2026 11:10:30 +0200 [thread overview]
Message-ID: <DLCDC8WT99KZ.37TB1PCCLIWT8@proxmox.com> (raw)
In-Reply-To: <20260721135407.372150-12-a.bied-charreton@proxmox.com>
On Tue Jul 21, 2026 at 3:54 PM CEST, Arthur Bied-Charreton wrote:
> The firewall configuration files are stored on pmxcfs, which is only
> available when pve-cluster is up. To be able to restore firewall rules
> before the network comes up and close the boot-time window in which the
> PVE host is unprotected, dump the required configuration files to a
> local directory after every apply.
>
> The last dumped version is cached for each file, the daemon only
> actually writes to disk if there has been a change since the last write
> or the dump file does not exist.
>
> Ownership of the dumps is keyed on the nftables option in the host
> config. When the firewall is disabled, the dumps are only removed if
> nftables is enabled - otherwise that responsibility is on pve-firewall.
>
> Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
[snip]
> diff --git a/proxmox-firewall/src/bin/proxmox-firewall.rs b/proxmox-firewall/src/bin/proxmox-firewall.rs
> index 27fd67d..5b20ca0 100644
> --- a/proxmox-firewall/src/bin/proxmox-firewall.rs
> +++ b/proxmox-firewall/src/bin/proxmox-firewall.rs
[snip]
> @@ -42,14 +48,58 @@ fn remove_firewall() -> Result<(), std::io::Error> {
> Ok(())
> }
>
> +fn dump_config(cfg: &FirewallConfig, cache: &mut HashMap<&str, Vec<u8>>) {
> + let dump_dir = Path::new(DUMP_DIR);
> + if !dump_dir.exists()
> + && let Err(e) = fs::create_path(dump_dir, None, None)
> + {
> + log::warn!("could not create {DUMP_DIR}: {e} - config will not be dumped");
^
Should this `warn` maybe be an `error` since not dumping the config
means having no firewall during startup which could be quite grave for
certain usecases? But just a thought, maybe I'm missing something.
> + return;
> + }
> +
> + if let Err(e) = std::fs::set_permissions(dump_dir, std::fs::Permissions::from_mode(0o700)) {
> + log::warn!("could not set permissions on {DUMP_DIR}: {e}");
> + }
> +
> + for (bytes, name) in [
> + (cfg.cluster_raw(), "cluster.fw"),
> + (cfg.host_raw(), "host.fw"),
> + (cfg.sdn_raw(), "sdn.json"),
> + ] {
> + let out = dump_dir.join(name);
> + match bytes {
> + Some(b) if !out.exists() || b != cache.get(name).map(Vec::as_slice).unwrap_or(&[]) => {
> + match fs::replace_file(&out, b, fs::CreateOptions::new(), true) {
> + Err(e) => log::warn!("could not dump {name} to {out:?}: {e}"),
^
same with this `warn`?
> + Ok(()) => {
> + log::info!("successfully dumped {out:?}");
> + cache.insert(name, b.to_vec());
> + }
> + }
> + }
> + Some(_) => log::info!("no changes to {name} since last dump to {out:?}"),
> + None => {
> + log::info!("nothing to dump for {name}");
^
This could maybe be removed or downgraded to `debug` or `trace`
as it doesn't provide vital information and thus clutters the
log in most cases.
> + cache.remove(name);
> + _ = std::fs::remove_file(&out);
> + }
> + }
> + }
> +}
[snip]
next prev parent reply other threads:[~2026-09-11 9:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 13:53 [RFC firewall/manager/proxmox{,-firewall} 00/13] fix #5759: keep firewall rules up across boot and shutdown Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-manager 01/13] network interface pinning: write new firewall config to local dir Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 02/13] firewall: config: sort OPTIONS when serializing Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 03/13] d/control: bump libpve-common-perl Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 04/13] firewall: dump configs locally after applying Arthur Bied-Charreton
2026-07-21 13:53 ` [PATCH pve-firewall 05/13] fix #5759: firewall: do not remove chains when host is shutting down Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH pve-firewall 06/13] firewall: add restore command Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH pve-firewall 07/13] fix #5759: firewall: restore from dumped config before network-pre Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox 08/13] systemd: systemctl: add is-system-running helper Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 09/13] firewall: fix clippy warnings Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 10/13] fix #5759: firewall: do not clear rules on system shutdown Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 11/13] firewall: dump config to local directory after apply Arthur Bied-Charreton
2026-09-11 9:10 ` Thomas Ellmenreich [this message]
2026-09-11 9:28 ` Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 12/13] firewall: add restore command Arthur Bied-Charreton
2026-09-11 9:14 ` Thomas Ellmenreich
2026-09-11 9:37 ` Arthur Bied-Charreton
2026-09-11 9:54 ` Arthur Bied-Charreton
2026-07-21 13:54 ` [PATCH proxmox-firewall 13/13] fix #5759: firewall: restore from dumped config before network-pre Arthur Bied-Charreton
2026-09-11 12:26 ` [RFC firewall/manager/proxmox{,-firewall} 00/13] fix #5759: keep firewall rules up across boot and shutdown Thomas Ellmenreich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DLCDC8WT99KZ.37TB1PCCLIWT8@proxmox.com \
--to=t.ellmenreich@proxmox.com \
--cc=a.bied-charreton@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox