all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: Jakob-Tobias Winter <tobias@stuttgart.de>, pbs-devel@lists.proxmox.com
Subject: Re: [RFC PATCH proxmox-backup 04/12] fix #7452: api: datastore: add endpoints for snapshot attributes
Date: Mon, 16 Nov 2026 15:57:55 +0100	[thread overview]
Message-ID: <60ed22a6-5074-4de2-8109-efd6afe45ced@proxmox.com> (raw)
In-Reply-To: <20261113085637.57360-7-tobias@stuttgart.de>

On 11/13/26 10:06 AM, Jakob-Tobias Winter wrote:
> 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.

I think it would be better if the client cannot modify attributes of a 
snapshot, and modification can only be done by a highly privileged user 
on the PBS side (e.g. root@pam only)

It would be better if the client provides the list of attributes it 
wants to set for the to-be backed up snapshot as optional params during 
the backup session initialization, during the protocol upgrade in [0]. 
These should then be checked against the ones which a client may upload 
as part of the manifest, and reject if they do not match. The latter 
must be checked in [1].

This is especially of interest since attributes might be used for other 
jobs as well, e.g. pruning, where we do not want a client to overwrite 
the state again.


[0] 
https://git.proxmox.com/?p=proxmox-backup.git;a=blob;f=src/api2/backup/mod.rs;h=a9b1ca5c268016978d292ebc03aaa1a7d3afcaaa;hb=HEAD#l74
[1] 
https://git.proxmox.com/?p=proxmox-backup.git;a=blob;f=src/api2/backup/environment.rs;h=be70d74f828e33b0020d4b7b5825cf98af77901d;hb=HEAD#l798

> 
> 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 <tobias@stuttgart.de>
> ---
>   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<BackupNamespace>,
> +    backup_dir: pbs_api_types::BackupDir,
> +    rpcenv: &mut dyn RpcEnvironment,
> +) -> Result<Vec<String>, 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}")))

comment: The formatting here is better defined as helper on the api 
type, that is an implementation detail. Further, given that the result 
here is a Vec<String>, it would make sense to define the AttributeItem 
as dedicated API type instead? This introduces basically a second type 
of serialization next to the json one.

> +        .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<BackupNamespace>,
> +    backup_dir: pbs_api_types::BackupDir,
> +    attributes: Option<Vec<String>>,

same as for others, this would be better defined as dedicated type, 
which also holds the deserialization logic ...

> +    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());

... so this would live on the type in pbs-api-types instead, as this is 
an implementation detail thereof.

> +        }
> +    }
> +
> +    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",





  reply	other threads:[~2026-11-16 14:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  8:56 [RFC PATCH many 00/12] snapshot attributes for tags and pools of PVE guests, tape job filter Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH proxmox 01/12] pbs-api-types: add types and schemas for snapshot attributes Jakob-Tobias Winter
2026-11-16 14:57   ` Christian Ebner
2026-11-18 12:54   ` Samuel Rufinatscha
2026-11-13  8:56 ` [RFC PATCH proxmox 02/12] pbs-api-types: tape: add attribute filter to backup jobs Jakob-Tobias Winter
2026-11-16 14:57   ` Christian Ebner
2026-11-13  8:56 ` [RFC PATCH proxmox-backup 03/12] datastore: add attributes to backup snapshots Jakob-Tobias Winter
2026-11-16 14:57   ` Christian Ebner
2026-11-18 12:55   ` Samuel Rufinatscha
2026-11-13  8:56 ` [RFC PATCH proxmox-backup 04/12] fix #7452: api: datastore: add endpoints for snapshot attributes Jakob-Tobias Winter
2026-11-16 14:57   ` Christian Ebner [this message]
2026-11-13  8:56 ` [RFC PATCH proxmox-backup 05/12] tape: backup job: allow selecting groups by " Jakob-Tobias Winter
2026-11-18 13:06   ` Samuel Rufinatscha
2026-11-18 15:19     ` Christian Ebner
2026-11-13  8:56 ` [RFC PATCH proxmox-backup 06/12] ui: tape backup job: add attribute filter Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH proxmox-backup 07/12] docs: describe snapshot attributes and the tape job " Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH storage 08/12] pbs: add helper to set the attributes of a backup snapshot Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH guest-common 09/12] vzdump: add pbs-snapshot-attributes option Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH manager 10/12] vzdump: store guest tags and pool as snapshot attributes on PBS Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH manager 11/12] ui: backup job: add selector for PBS snapshot attributes Jakob-Tobias Winter
2026-11-13  8:56 ` [RFC PATCH docs 12/12] vzdump: describe snapshot attributes on Proxmox Backup Server Jakob-Tobias Winter
2026-11-16 14:57 ` [RFC PATCH many 00/12] snapshot attributes for tags and pools of PVE guests, tape job filter Christian Ebner
2026-11-18 13:07   ` Samuel Rufinatscha
2026-11-18 14:22 ` Samuel Rufinatscha
2026-11-19 11:58   ` Jakob-Tobias Winter

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=60ed22a6-5074-4de2-8109-efd6afe45ced@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=tobias@stuttgart.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal