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 74F031FF09F for ; Tue, 01 Dec 2026 10:11:18 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7D41020998; Tue, 01 Dec 2026 10:11:17 +0100 (CET) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup 4/5] client: pxar: optionally fail on entries left out for lack of permission Date: Tue, 1 Dec 2026 10:11:10 +0100 Message-ID: <20261201091111.940190-5-dietmar@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201091111.940190-1-dietmar@proxmox.com> References: <20261201091111.940190-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.460 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) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: 3G2SJIXA2TQOPXKEV5AOGJW7PIOSVJA3 X-Message-ID-Hash: 3G2SJIXA2TQOPXKEV5AOGJW7PIOSVJA3 X-MailFrom: dietmar@zilli.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 Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Leaving out entries that cannot be read lets a backup succeed while it misses data, which retention may then use to replace complete snapshots. A caller that needs all data, for example because it backs up folders it expects to own, cannot rely on such a backup. A new option fails the archive at the first such entry instead. This includes a .pxarexclude that cannot be read, also one excluded as an entry, as ignoring its patterns may add much more data than intended. It is off by default, so existing callers keep leaving entries out. Signed-off-by: Dietmar Maurer --- pbs-client/src/pxar/create.rs | 39 +++++++++++++++---- proxmox-backup-client/src/main.rs | 1 + .../src/proxmox_restore_daemon/api.rs | 1 + pxar-bin/src/main.rs | 1 + 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index 47ae4b01c..c6d4b8b41 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -62,6 +62,9 @@ pub struct PxarCreateOptions { /// Called with the archive-relative path of each entry left out for lack of permission. For /// a `.pxarexclude` file, this also means that its patterns were not applied. pub on_access_denied: Option>, + /// Fail on the first entry that cannot be read for lack of permission, instead of leaving it + /// out + pub fail_on_access_denied: bool, } pub type MetadataArchiveReader = Arc; @@ -199,6 +202,7 @@ struct Archiver { reuse_stats: ReuseStats, split_archive: bool, on_access_denied: Option>, + fail_on_access_denied: bool, } type Encoder<'a, T> = pxar::encoder::aio::Encoder<'a, T>; @@ -311,6 +315,7 @@ where reuse_stats: ReuseStats::default(), split_archive, on_access_denied: options.on_access_denied, + fail_on_access_denied: options.fail_on_access_denied, }; archiver @@ -511,7 +516,7 @@ impl Archiver { warn!("failed to open file: {path:?}: access denied"); // reported here rather than as an entry, as its patterns are not applied, also // when a pattern excludes it as an entry - self.report_access_denied(Some(&path)); + self.report_access_denied(Some(&path))?; return Ok(()); } Err(Errno::ESTALE) => { @@ -696,7 +701,7 @@ impl Archiver { Err(Errno::EACCES) => { // may happen for fuse mountpoints without allow_other or allow_root warn!("warning: failed to stat file: {full_path:?}: access denied"); - self.report_access_denied(Some(&full_path)); + self.report_access_denied(Some(&full_path))?; continue; } Err(Errno::ESTALE) => { @@ -733,11 +738,15 @@ impl Archiver { warn!("warning: stale file handle encountered while reading: {path:?}"); } - fn report_access_denied(&mut self, path: Option<&PathBuf>) { + fn report_access_denied(&mut self, path: Option<&PathBuf>) -> Result<(), Error> { let path = path.unwrap_or(&self.path); if let Some(callback) = self.on_access_denied.as_mut() { callback(path); } + if self.fail_on_access_denied { + bail!("unable to back up {path:?}: access denied"); + } + Ok(()) } fn report_vanished_file(&self) { @@ -784,7 +793,7 @@ impl Archiver { warn!("failed to open file: {c_file_name:?}: access denied"); // reported when its directory's patterns were read, which comes first if c_file_name != c".pxarexclude" { - self.report_access_denied(None); + self.report_access_denied(None)?; } return Ok(()); } @@ -2009,8 +2018,9 @@ mod tests { Ok(testdir) } - /// Archives `dir` and returns the entries reported as left out for lack of permission. - fn archive_access_denied(dir: &Path) -> Result, Error> { + /// Archives `dir` and returns the entries reported as left out for lack of permission, or + /// with `fail`, fails at the first of them. + fn archive_access_denied(dir: &Path, fail: bool) -> Result, Error> { let denied: Arc>> = Arc::default(); let collect = Arc::clone(&denied); let options = PxarCreateOptions { @@ -2018,6 +2028,7 @@ mod tests { on_access_denied: Some(Box::new(move |path| { collect.lock().unwrap().push(path.to_path_buf()) })), + fail_on_access_denied: fail, ..Default::default() }; let source_dir = Dir::open(dir, OFlag::O_DIRECTORY, Mode::empty())?; @@ -2065,16 +2076,27 @@ mod tests { PathBuf::from("sub/.pxarexclude"), ]; // the unreadable .pxarexclude only once, though it is also opened as an entry - let reported = archive_access_denied(&testdir); + let reported = archive_access_denied(&testdir, false); + let failed = archive_access_denied(&testdir, true); // also when a pattern excludes it as an entry std::fs::write(testdir.join(".pxarexclude"), ".pxarexclude\n")?; - let excluded = archive_access_denied(&testdir); + let excluded = archive_access_denied(&testdir, false); + std::fs::write( + testdir.join(".pxarexclude"), + "locked\nsecret\n.pxarexclude\n", + )?; + let excluded_failed = archive_access_denied(&testdir, true); for path in ["locked", "secret", "sub/.pxarexclude"] { chmod(path, 0o755)?; } assert_eq!(reported?, expected); assert_eq!(excluded?, expected); + assert!(failed.is_err()); + // only the .pxarexclude is left, which is excluded as an entry, but whose patterns would + // have been ignored + let err = format!("{:#}", excluded_failed.unwrap_err()); + assert!(err.contains("sub/.pxarexclude"), "{err}"); Ok(()) } @@ -2154,6 +2176,7 @@ mod tests { reuse_stats: ReuseStats::default(), split_archive: true, on_access_denied: None, + fail_on_access_denied: false, }; let accessor = Accessor::new(pxar::PxarVariant::Unified(reader), metadata_size) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index ef1b1575b..e71677633 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -1243,6 +1243,7 @@ async fn create_backup( previous_ref, max_cache_size, on_access_denied: None, + fail_on_access_denied: false, }; let upload_options = UploadOptions { diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs index aac46592b..c3ca6b807 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs @@ -371,6 +371,7 @@ fn extract( previous_ref: None, max_cache_size: None, on_access_denied: None, + fail_on_access_denied: false, }; let pxar_writer = pxar::PxarVariant::Unified(TokioWriter::new(writer)); diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 6511c1b17..05358fa52 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -384,6 +384,7 @@ async fn create_archive( previous_ref: None, max_cache_size: None, on_access_denied: None, + fail_on_access_denied: false, }; let source = PathBuf::from(source); -- 2.47.3