From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 2D3301FF0B3 for ; Fri, 11 Sep 2026 11:10:38 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 877DC21537; Fri, 11 Sep 2026 11:10:37 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 11 Sep 2026 11:10:30 +0200 Message-Id: Subject: Re: [PATCH proxmox-firewall 11/13] firewall: dump config to local directory after apply From: "Thomas Ellmenreich" To: "Arthur Bied-Charreton" , X-Mailer: aerc 0.20.0 References: <20260721135407.372150-1-a.bied-charreton@proxmox.com> <20260721135407.372150-12-a.bied-charreton@proxmox.com> In-Reply-To: <20260721135407.372150-12-a.bied-charreton@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1789117820752 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.622 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: WAYVB4XR4XC6K4A5UQMEGX5EPMIMQ2OR X-Message-ID-Hash: WAYVB4XR4XC6K4A5UQMEGX5EPMIMQ2OR X-MailFrom: t.ellmenreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 [snip] > diff --git a/proxmox-firewall/src/bin/proxmox-firewall.rs b/proxmox-firew= all/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(()) > } > =20 > +fn dump_config(cfg: &FirewallConfig, cache: &mut HashMap<&str, Vec>)= { > + let dump_dir =3D Path::new(DUMP_DIR); > + if !dump_dir.exists() > + && let Err(e) =3D fs::create_path(dump_dir, None, None) > + { > + log::warn!("could not create {DUMP_DIR}: {e} - config will not b= e 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) =3D std::fs::set_permissions(dump_dir, std::fs::Permis= sions::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 =3D dump_dir.join(name); > + match bytes { > + Some(b) if !out.exists() || b !=3D cache.get(name).map(Vec::= as_slice).unwrap_or(&[]) =3D> { > + match fs::replace_file(&out, b, fs::CreateOptions::new()= , true) { > + Err(e) =3D> log::warn!("could not dump {name} to {ou= t:?}: {e}"), ^ same with this `warn`? > + Ok(()) =3D> { > + log::info!("successfully dumped {out:?}"); > + cache.insert(name, b.to_vec()); > + } > + } > + } > + Some(_) =3D> log::info!("no changes to {name} since last dum= p to {out:?}"), > + None =3D> { > + 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); > + _ =3D std::fs::remove_file(&out); > + } > + } > + } > +} [snip]