From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 583821FF0B7 for ; Fri, 13 Nov 2026 10:06:46 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 8D88321827; Fri, 13 Nov 2026 10:06:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stuttgart.de; s=s1022; t=1794560285; bh=G4OoXR3fkexXT0bhE42iALNahpwflSzz2lqyDV8pYJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iZxymRFwTBjBWP9SNeDw62xKNSAgpz+7x9uRusPEFqjyx9aGOhHp46M+hpycw57Gn L9o0sNuDG0DWuFTJ4xVq8w5cDf+Lt9WL8OGli+dxIHTztgF5uBrA/tLdDoB1vT+7fX dnkDWirWlLjiz9QWmc/58yPfgHWR+fnNhmRTnHTtF3q5xaQ5oI93z8s7ZujHZoRDg1 awU9wMW1B/8DaBFVlsZvSkrKvUMZ4JdZ808KxCwLLdj0Nur8Wtk/1nbOcnE6pNDX0U cte5nvxlNgQCqKPDBb+wT8YCq8vKIBEoExNqr/bi3gmOLu99gUePyJvKvw+O+TqUHQ Ror01OFGB61RA== From: Jakob-Tobias Winter To: pbs-devel@lists.proxmox.com Subject: [RFC PATCH proxmox-backup 04/12] fix #7452: api: datastore: add endpoints for snapshot attributes Date: Fri, 13 Nov 2026 09:56:31 +0100 Message-ID: <20261113085637.57360-7-tobias@stuttgart.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113085637.57360-3-tobias@stuttgart.de> References: <20261113085637.57360-3-tobias@stuttgart.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.129 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_PASS -0.001 SPF: HELO matches SPF record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: AQAVMEZL3ZTGWDUKZ7V4Q5EUMV6V4IOW X-Message-ID-Hash: AQAVMEZL3ZTGWDUKZ7V4Q5EUMV6V4IOW X-MailFrom: prvs=d19b210678=tobias@stuttgart.de 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: Jakob-Tobias Winter 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: The attributes of a snapshot can be read and set next to its notes and its protection flag, with the privileges required for the notes. A client which may set the notes of its backups can therefore set the attributes after a backup without further permissions. Attributes are passed as a list of 'KEY=VALUE' entries, with one entry for each value of a key. Setting them replaces all attributes of the snapshot. An empty list is stored as well, so that a snapshot without attributes can be told from one whose client never set any. Signed-off-by: Jakob-Tobias Winter --- src/api2/admin/datastore.rs | 128 +++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 3ba25934f..6b907da32 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -43,8 +43,9 @@ use pbs_api_types::{ IGNORE_VERIFIED_BACKUPS_SCHEMA, JobScheduleStatus, KeepOptions, MAX_NAMESPACE_DEPTH, MaintenanceMode, MaintenanceType, NS_MAX_DEPTH_SCHEMA, Operation, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_MODIFY, PRIV_DATASTORE_PRUNE, PRIV_DATASTORE_READ, - PRIV_DATASTORE_VERIFY, PRIV_SYS_MODIFY, PruneJobOptions, SnapshotListItem, SyncJobConfig, UPID, - UPID_SCHEMA, VERIFICATION_OUTDATED_AFTER_SCHEMA, VERIFY_JOB_READ_THREADS_SCHEMA, + PRIV_DATASTORE_VERIFY, PRIV_SYS_MODIFY, PruneJobOptions, SNAPSHOT_ATTRIBUTE_LIST_SCHEMA, + SnapshotAttributes, SnapshotListItem, SyncJobConfig, UPID, UPID_SCHEMA, + VERIFICATION_OUTDATED_AFTER_SCHEMA, VERIFY_JOB_READ_THREADS_SCHEMA, VERIFY_JOB_VERIFY_THREADS_SCHEMA, print_ns_and_snapshot, print_store_and_ns, }; use pbs_client::pxar::{create_tar, create_zip}; @@ -2223,6 +2224,123 @@ pub fn set_notes( Ok(()) } +#[api( + input: { + properties: { + store: { schema: DATASTORE_SCHEMA }, + ns: { + type: BackupNamespace, + optional: true, + }, + backup_dir: { + type: pbs_api_types::BackupDir, + flatten: true, + }, + }, + }, + returns: { + schema: SNAPSHOT_ATTRIBUTE_LIST_SCHEMA, + }, + access: { + permission: &Permission::Anybody, + description: "Requires on /datastore/{store}[/{namespace}] either DATASTORE_AUDIT for any \ + or DATASTORE_BACKUP and being the owner of the group", + }, +)] +/// Get the attributes of a specific backup +pub fn get_attributes( + store: String, + ns: Option, + backup_dir: pbs_api_types::BackupDir, + rpcenv: &mut dyn RpcEnvironment, +) -> Result, Error> { + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + let ns = ns.unwrap_or_default(); + + let datastore = check_privs_and_load_store( + &store, + &ns, + &auth_id, + PRIV_DATASTORE_AUDIT, + PRIV_DATASTORE_BACKUP, + Operation::Read, + &backup_dir.group, + )?; + + let backup_dir = datastore.backup_dir(ns, backup_dir)?; + + let (manifest, _) = backup_dir.load_manifest()?; + + let attributes = manifest.attributes().unwrap_or_default(); + + Ok(attributes + .iter() + .flat_map(|(key, values)| values.iter().map(move |value| format!("{key}={value}"))) + .collect()) +} + +#[api( + input: { + properties: { + store: { schema: DATASTORE_SCHEMA }, + ns: { + type: BackupNamespace, + optional: true, + }, + backup_dir: { + type: pbs_api_types::BackupDir, + flatten: true, + }, + attributes: { + schema: SNAPSHOT_ATTRIBUTE_LIST_SCHEMA, + optional: true, + }, + }, + }, + access: { + permission: &Permission::Anybody, + description: "Requires on /datastore/{store}[/{namespace}] either DATASTORE_MODIFY for any \ + or DATASTORE_BACKUP and being the owner of the group", + }, +)] +/// Set the attributes of a specific backup, replacing the existing ones +pub fn set_attributes( + store: String, + ns: Option, + backup_dir: pbs_api_types::BackupDir, + attributes: Option>, + rpcenv: &mut dyn RpcEnvironment, +) -> Result<(), Error> { + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + let ns = ns.unwrap_or_default(); + + let datastore = check_privs_and_load_store( + &store, + &ns, + &auth_id, + PRIV_DATASTORE_MODIFY, + PRIV_DATASTORE_BACKUP, + Operation::Write, + &backup_dir.group, + )?; + + let mut attribute_map = SnapshotAttributes::new(); + for attribute in attributes.unwrap_or_default() { + // the format is ensured by the schema + if let Some((key, value)) = attribute.split_once('=') { + attribute_map + .entry(key.to_string()) + .or_default() + .insert(value.to_string()); + } + } + + let backup_dir = datastore.backup_dir(ns, backup_dir)?; + datastore.set_attributes(attribute_map, backup_dir)?; + + Ok(()) +} + #[api( input: { properties: { @@ -2930,6 +3048,12 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ "active-operations", &Router::new().get(&API_METHOD_GET_ACTIVE_OPERATIONS), ), + ( + "attributes", + &Router::new() + .get(&API_METHOD_GET_ATTRIBUTES) + .put(&API_METHOD_SET_ATTRIBUTES), + ), ("catalog", &Router::new().get(&API_METHOD_CATALOG)), ( "change-owner", -- 2.53.0