From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id A685F1FF0B3 for ; Fri, 11 Sep 2026 11:28:59 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 86CAC21575; Fri, 11 Sep 2026 11:28:56 +0200 (CEST) Date: Fri, 11 Sep 2026 11:28:49 +0200 From: Arthur Bied-Charreton To: Thomas Ellmenreich Subject: Re: [PATCH proxmox-firewall 11/13] firewall: dump config to local directory after apply Message-ID: References: <20260721135407.372150-1-a.bied-charreton@proxmox.com> <20260721135407.372150-12-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1789118920574 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.611 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: 6YD7GF7YKUWKSUTGRMMVFITGXMH6ASOJ X-Message-ID-Hash: 6YD7GF7YKUWKSUTGRMMVFITGXMH6ASOJ X-MailFrom: a.bied-charreton@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 CC: pve-devel@lists.proxmox.com 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 Fri, Sep 11, 2026 at 11:10:30AM +0200, Thomas Ellmenreich wrote: > 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-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>) { > > + 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. > You're right, error might be more suitable here. I originally opted for warn since I felt that error should be kept for cases that actually break the firewall's intended functionality, but I guess one could argue that that is the case here. > > + 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`? Ack, see above > > > + 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. > The default logging level for the proxmox-firewall is WARN, so this is not shown unless one actively changes it. I do agree that debug makes more sense though, will change that, thanks! > > + cache.remove(name); > > + _ = std::fs::remove_file(&out); > > + } > > + } > > + } > > +} > > [snip]