public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup-qemu v2 4/8] commands: extend stricter type checks for guest config archive names
Date: Wed, 16 Sep 2026 16:48:39 +0200	[thread overview]
Message-ID: <20260916144843.567913-5-c.ebner@proxmox.com> (raw)
In-Reply-To: <20260916144843.567913-1-c.ebner@proxmox.com>

Further extends the stricter BackupArchiveName type as introduced in
[0] to also apply to internal add_config() helper for guest config.

Due to the stricter checks, add_config() now allows the server side
extensions as defined in the type for blobs and auto-expands the
server side `.blob` extension when required, the archive type
is explicitley checked instead.

While at it, make sure to always use the latest stricter check by
depending on version 1.0.20, which is not strictly required here but
the submodule already depends on it as well and it protects against
building future versions with the still more relaxed archive name
parsing.

The api type changes affect internal API's only, public API's types
remain unchanged.

[0] https://git.proxmox.com/?p=proxmox-backup.git;a=commit;h=b57274a5a64791e7245bc0655ce0f133668db145

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 Cargo.toml      |  2 +-
 src/backup.rs   |  3 ++-
 src/commands.rs | 18 ++++++++++++------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index c50a0a2..d73324f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,7 +37,7 @@ proxmox-schema = { version = "5", features = [ "api-macro" ] }
 proxmox-sortable-macro = "1"
 proxmox-sys = "1"
 
-pbs-api-types  = { version = "1" }
+pbs-api-types  = { version = "1.0.20" }
 
 pbs-client     = { path = "submodules/proxmox-backup/pbs-client" }
 pbs-datastore  = { path = "submodules/proxmox-backup/pbs-datastore" }
diff --git a/src/backup.rs b/src/backup.rs
index 61ebcfb..3a591ea 100644
--- a/src/backup.rs
+++ b/src/backup.rs
@@ -10,7 +10,7 @@ use tokio::runtime::Runtime;
 use proxmox_async::runtime::get_runtime_with_builder;
 use proxmox_sys::fs::file_get_contents;
 
-use pbs_api_types::{BackupType, CryptMode};
+use pbs_api_types::{BackupArchiveName, BackupType, CryptMode};
 use pbs_client::{BackupWriter, BackupWriterOptions, HttpClient, HttpClientOptions};
 use pbs_datastore::BackupManifest;
 use pbs_key_config::{load_and_decrypt_key, rsa_encrypt_key_config, KeyConfig};
@@ -186,6 +186,7 @@ impl BackupTask {
 
     pub async fn add_config(&self, name: String, data: Vec<u8>) -> Result<c_int, Error> {
         self.check_aborted()?;
+        let name: BackupArchiveName = name.parse()?;
 
         let command_future = add_config(
             self.need_writer()?,
diff --git a/src/commands.rs b/src/commands.rs
index d482fd5..1b009d5 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -6,7 +6,9 @@ use std::sync::{Arc, Mutex};
 use futures::future::{Future, TryFutureExt};
 use serde_json::json;
 
-use pbs_api_types::{BackupArchiveName, CryptMode, ENCRYPTED_KEY_BLOB_NAME, MANIFEST_BLOB_NAME};
+use pbs_api_types::{
+    ArchiveType, BackupArchiveName, CryptMode, ENCRYPTED_KEY_BLOB_NAME, MANIFEST_BLOB_NAME,
+};
 use pbs_client::{BackupWriter, H2Client, UploadOptions};
 use pbs_datastore::data_blob::DataChunkBuilder;
 use pbs_datastore::index::IndexFile;
@@ -94,14 +96,19 @@ async fn register_zero_chunk(
 pub(crate) async fn add_config(
     client: Arc<BackupWriter>,
     manifest: Arc<Mutex<BackupManifest>>,
-    name: String,
+    config_blob_name: BackupArchiveName,
     data: Vec<u8>,
     compress: bool,
     crypt_mode: CryptMode,
 ) -> Result<c_int, Error> {
     //println!("add config {} size {}", name, size);
 
-    let blob_name = format!("{}.blob", name);
+    if config_blob_name.archive_type() != ArchiveType::Blob {
+        bail!(
+            "cannot add '{}' as config blob.",
+            config_blob_name.to_string()
+        );
+    }
 
     let options = UploadOptions {
         compress,
@@ -109,13 +116,12 @@ pub(crate) async fn add_config(
         ..UploadOptions::default()
     };
 
-    let blob_name: BackupArchiveName = blob_name.parse()?;
     let stats = client
-        .upload_blob_from_data(data, &blob_name, options)
+        .upload_blob_from_data(data, &config_blob_name, options)
         .await?;
 
     let mut guard = manifest.lock().unwrap();
-    guard.add_file(&blob_name, stats.size, stats.csum, crypt_mode)?;
+    guard.add_file(&config_blob_name, stats.size, stats.csum, crypt_mode)?;
 
     Ok(0)
 }
-- 
2.47.3





  parent reply	other threads:[~2026-09-16 14:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 14:48 [PATCH many v2 0/8] fix #7530: Implement download bandwidth and restore limits for pbs-restore Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox v2 1/8] pbs-api-types: expose ClientRateLimitConfig fields as pub Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 2/8] commands/restore: fix useless borrow clippy warnings for archive names Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 3/8] commands: fix clippy error for reimplementing Result::ok() Christian Ebner
2026-09-16 14:48 ` Christian Ebner [this message]
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 5/8] restore: implement `bw-limit` parameter imposing download rate limits Christian Ebner
2026-09-16 14:48 ` [PATCH proxmox-backup-qemu v2 6/8] restore: implement `rate-limit` imposing chunk data stream limits Christian Ebner
2026-09-16 14:48 ` [PATCH pve-qemu v2 7/8] fix #7530: pbs-restore: expose optional rate limit parameters Christian Ebner
2026-09-16 14:48 ` [PATCH qemu-server v2 8/8] pbs-restore: set restore bandwidth limit for volumes Christian Ebner

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=20260916144843.567913-5-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pve-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