public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
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	[thread overview]
Message-ID: <20261201091111.940190-4-dietmar@proxmox.com> (raw)
In-Reply-To: <20261201091111.940190-1-dietmar@proxmox.com>

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 <dietmar@proxmox.com>
---
 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<PxarPrevRef>,
     /// Maximum number of lookahead cache entries
     pub max_cache_size: Option<usize>,
+    /// 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<Box<dyn FnMut(&Path) + Send>>,
 }
 
 pub type MetadataArchiveReader = Arc<dyn ReadAt + Send + Sync + 'static>;
@@ -195,6 +198,7 @@ struct Archiver {
     last_reusable_offset: Option<u64>,
     reuse_stats: ReuseStats,
     split_archive: bool,
+    on_access_denied: Option<Box<dyn FnMut(&Path) + Send>>,
 }
 
 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<Vec<PathBuf>, Error> {
+        let denied: Arc<Mutex<Vec<PathBuf>>> = 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::<PathBuf>(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




  parent reply	other threads:[~2026-12-01  9:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:11 [PATCH proxmox-backup 0/5] client: report or fail on files left out for lack of permission Dietmar Maurer
2026-12-01  9:11 ` [PATCH proxmox-backup 1/5] client: pxar: handle open errors at the call sites Dietmar Maurer
2026-12-01  9:11 ` [PATCH proxmox-backup 2/5] client: pxar: name the directory of an unreadable .pxarexclude Dietmar Maurer
2026-12-01  9:11 ` Dietmar Maurer [this message]
2026-12-01  9:11 ` [PATCH proxmox-backup 4/5] client: pxar: optionally fail on entries left out for lack of permission Dietmar Maurer
2026-12-01  9:11 ` [PATCH proxmox-backup 5/5] client: backup: add option to fail on files that cannot be read Dietmar Maurer

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=20261201091111.940190-4-dietmar@proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=pbs-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal