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 BA9C71FF09F for ; Tue, 01 Dec 2026 10:11:24 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5A25D216CB; Tue, 01 Dec 2026 10:11:18 +0100 (CET) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup 3/5] client: pxar: let callers see entries left out for lack of permission Date: Tue, 1 Dec 2026 10:11:09 +0100 Message-ID: <20261201091111.940190-4-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.453 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: QRLRZLGWZAOLPPABZL3GIE4CRKTRHUJ3 X-Message-ID-Hash: QRLRZLGWZAOLPPABZL3GIE4CRKTRHUJ3 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: Entries that cannot be opened or stat'ed for lack of permission are left out of the archive with a warning in the log, and the backup succeeds. A caller that reports on a backup, such as a graphical client showing its result, cannot tell such a run from a complete one without parsing the log. An optional callback now gets the archive-relative path of each entry left out this way. The warnings stay as they were, and existing callers pass no callback, so their behavior is unchanged. An unreadable .pxarexclude is reported when its directory's patterns are read, as they are not applied then, which can include much more data than intended. It is not reported again when opened as an entry, nor missed when a pattern excludes it as such. Signed-off-by: Dietmar Maurer --- pbs-client/src/pxar/create.rs | 90 +++++++++++++++++++ proxmox-backup-client/src/main.rs | 1 + .../src/proxmox_restore_daemon/api.rs | 1 + pxar-bin/src/main.rs | 1 + 4 files changed, 93 insertions(+) diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs index e21d73f69..47ae4b01c 100644 --- a/pbs-client/src/pxar/create.rs +++ b/pbs-client/src/pxar/create.rs @@ -59,6 +59,9 @@ pub struct PxarCreateOptions { pub previous_ref: Option, /// Maximum number of lookahead cache entries pub max_cache_size: Option, + /// 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>, } pub type MetadataArchiveReader = Arc; @@ -195,6 +198,7 @@ struct Archiver { last_reusable_offset: Option, reuse_stats: ReuseStats, split_archive: bool, + on_access_denied: Option>, } type Encoder<'a, T> = pxar::encoder::aio::Encoder<'a, T>; @@ -306,6 +310,7 @@ where last_reusable_offset: None, reuse_stats: ReuseStats::default(), split_archive, + on_access_denied: options.on_access_denied, }; archiver @@ -504,6 +509,9 @@ impl Archiver { Err(Errno::EACCES) => { let path = self.path.join(".pxarexclude"); 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)); return Ok(()); } Err(Errno::ESTALE) => { @@ -688,6 +696,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)); continue; } Err(Errno::ESTALE) => { @@ -724,6 +733,13 @@ impl Archiver { warn!("warning: stale file handle encountered while reading: {path:?}"); } + fn report_access_denied(&mut self, path: Option<&PathBuf>) { + let path = path.unwrap_or(&self.path); + if let Some(callback) = self.on_access_denied.as_mut() { + callback(path); + } + } + fn report_vanished_file(&self) { warn!("warning: file vanished while reading: {:?}", self.path); } @@ -766,6 +782,10 @@ impl Archiver { } Err(Errno::EACCES) => { 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); + } return Ok(()); } Err(Errno::ESTALE) => { @@ -1989,6 +2009,75 @@ 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> { + let denied: Arc>> = Arc::default(); + let collect = Arc::clone(&denied); + let options = PxarCreateOptions { + entries_max: crate::pxar::ENCODER_MAX_ENTRIES, + on_access_denied: Some(Box::new(move |path| { + collect.lock().unwrap().push(path.to_path_buf()) + })), + ..Default::default() + }; + let source_dir = Dir::open(dir, OFlag::O_DIRECTORY, Mode::empty())?; + let writer = pxar::PxarVariant::Unified(DummyWriter::new::(None)?); + let rt = tokio::runtime::Runtime::new()?; + rt.block_on(create_archive( + source_dir, + PxarWriters::new(writer, None), + Flags::DEFAULT, + |_| Ok(()), + options, + None, + None, + ))?; + let mut denied = std::mem::take(&mut *denied.lock().unwrap()); + denied.sort(); + Ok(denied) + } + + #[test] + fn test_access_denied() -> Result<(), Error> { + use std::os::unix::fs::PermissionsExt; + + if unsafe { libc::geteuid() } == 0 { + // skip test, root can read everything + return Ok(()); + } + + let testdir = create_testdir("test_access_denied")?; + std::fs::create_dir_all(testdir.join("locked"))?; + std::fs::create_dir_all(testdir.join("sub"))?; + std::fs::write(testdir.join("secret"), "data")?; + std::fs::write(testdir.join("sub/a.tmp"), "data")?; + std::fs::write(testdir.join("sub/.pxarexclude"), "*.tmp\n")?; + let chmod = |path: &str, mode| { + std::fs::set_permissions(testdir.join(path), std::fs::Permissions::from_mode(mode)) + }; + for path in ["locked", "secret", "sub/.pxarexclude"] { + chmod(path, 0o000)?; + } + + let expected = [ + PathBuf::from("locked"), + PathBuf::from("secret"), + PathBuf::from("sub/.pxarexclude"), + ]; + // the unreadable .pxarexclude only once, though it is also opened as an entry + let reported = archive_access_denied(&testdir); + // also when a pattern excludes it as an entry + std::fs::write(testdir.join(".pxarexclude"), ".pxarexclude\n")?; + let excluded = archive_access_denied(&testdir); + + for path in ["locked", "secret", "sub/.pxarexclude"] { + chmod(path, 0o755)?; + } + assert_eq!(reported?, expected); + assert_eq!(excluded?, expected); + Ok(()) + } + #[test] fn test_create_archive_with_reference() -> Result<(), Error> { let euid = unsafe { libc::geteuid() }; @@ -2064,6 +2153,7 @@ mod tests { last_reusable_offset: None, reuse_stats: ReuseStats::default(), split_archive: true, + on_access_denied: None, }; 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 5238a75ea..ef1b1575b 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -1242,6 +1242,7 @@ async fn create_backup( skip_e2big_xattr, previous_ref, max_cache_size, + on_access_denied: None, }; 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 e6ea29093..aac46592b 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs @@ -370,6 +370,7 @@ fn extract( skip_e2big_xattr: false, previous_ref: None, max_cache_size: None, + on_access_denied: None, }; let pxar_writer = pxar::PxarVariant::Unified(TokioWriter::new(writer)); diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 4b14507ca..6511c1b17 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -383,6 +383,7 @@ async fn create_archive( skip_e2big_xattr: false, previous_ref: None, max_cache_size: None, + on_access_denied: None, }; let source = PathBuf::from(source); -- 2.47.3