public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Fabian Ebner <f.ebner@proxmox.com>
Subject: Re: [pve-devel] [PATCH v3 manager 2/4] api: vzdump: add call to get currently configured vzdump defaults
Date: Thu, 1 Apr 2021 15:40:49 +0200	[thread overview]
Message-ID: <b10d9b28-e755-0996-e09b-79d239ad89cd@proxmox.com> (raw)
In-Reply-To: <20210311092208.27221-2-f.ebner@proxmox.com>

On 11.03.21 10:22, Fabian Ebner wrote:
> on a given node (and storage).
> 
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
> 
> New in v3
> 
>  PVE/API2/VZDump.pm | 89 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 89 insertions(+)
> 
> diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
> index 44376106..109e178b 100644
> --- a/PVE/API2/VZDump.pm
> +++ b/PVE/API2/VZDump.pm
> @@ -146,6 +146,95 @@ __PACKAGE__->register_method ({
>  	return $rpcenv->fork_worker('vzdump', $taskid, $user, $worker);
>     }});
>  
> +__PACKAGE__->register_method ({
> +    name => 'defaults',
> +    path => 'defaults',
> +    method => 'GET',
> +    description => "Get the currently configured vzdump defaults.",
> +    permissions => {
> +	description => "The user needs 'Datastore.Audit' or " .
> +	    "'Datastore.AllocateSpace' permissions for the specified storage " .
> +	    "(or default storage if none specified). Some properties are only " .
> +	    "returned when the user has 'Sys.Audit' permissions for the node.",

style nit: you can go up to 100 character columns here, also we 

> +	user => 'all',
> +    },
> +    proxyto => 'node',
> +    parameters => {
> +	additionalProperties => 0,
> +	properties => {
> +	    node => get_standard_option('pve-node'),
> +	    storage => get_standard_option('pve-storage-id', { optional => 1 }),
> +	},
> +    },
> +    returns => {
> +	type => 'object',
> +	additionalProperties => 0,
> +	properties => PVE::VZDump::Common::json_config_properties(),

above may suggest that all those properties are returned, but we delete some
out flat, so even if one would access this as root@pam they won't get all of
those and may get confused due to API schema/return value mismatch.

Maybe we could derive a hash from above list at module scope, and delete those
keys that never will be returned. That list could also be reused below for
filtering out those unwanted keys too then.

> +    },
> +    code => sub {
> +	my ($param) = @_;
> +
> +	my $node = extract_param($param, 'node');
> +	my $storage = extract_param($param, 'storage');
> +
> +	my $rpcenv = PVE::RPCEnvironment::get();
> +	my $authuser = $rpcenv->get_user();
> +
> +	my $res = PVE::VZDump::read_vzdump_defaults();
> +
> +	$res->{storage} = $storage if defined($storage);
> +
> +	if (!defined($res->{dumpdir}) && !defined($res->{storage})) {
> +	    $res->{storage} = 'local';
> +	}
> +
> +	if (defined($res->{storage})) {
> +	    $rpcenv->check_any(
> +		$authuser,
> +		"/storage/$res->{storage}",
> +		['Datastore.Audit', 'Datastore.AllocateSpace'],
> +	    );
> +
> +	    my $info = PVE::VZDump::storage_info($res->{storage});
> +	    foreach my $key (qw(dumpdir prune-backups)) {

style nit, for new code use `for`, `foreach` has no additional value/functionality
over `for` since a long time (if ever, actually not too sure from top of my head).

> +		$res->{$key} = $info->{$key} if defined($info->{$key});
> +	    }
> +	}
> +
> +	if (defined($res->{'prune-backups'})) {
> +	    $res->{'prune-backups'} = PVE::JSONSchema::print_property_string(
> +		$res->{'prune-backups'},
> +		'prune-backups',
> +	    );
> +	}
> +
> +	$res->{mailto} = join(",", @{$res->{mailto}})
> +	    if defined($res->{mailto});
> +
> +	$res->{'exclude-path'} = join(",", @{$res->{'exclude-path'}})
> +	    if defined($res->{'exclude-path'});
> +
> +	# normal backup users don't need to know these
> +	if (!$rpcenv->check($authuser, "/nodes/$node", ['Sys.Audit'], 1)) {
> +	    delete $res->{mailto};
> +	    delete $res->{tmpdir};
> +	    delete $res->{dumpdir};
> +	    delete $res->{script};
> +	    delete $res->{bwlimit};

The bwlimit could be exposed though, similarly to how we do already on backup restore.
For not so privileged user we may want to do something like getting the
min($api_bwlimit, $storage_or_dc_options_bwlimit) to ensure an user cannot weasel
themself out of admin imposed restrictions... Also, this does not needs to be in
that series, just a general idea...

> +	    delete $res->{ionice};
> +	}
> +
> +	my $pool = $res->{pool};
> +	if (defined($pool) &&
> +	    !$rpcenv->check($authuser, "/pool/$pool", ['Pool.Allocate'], 1)) {
> +	    delete $res->{pool};
> +	}
> +
> +	delete $res->{size}; # deprecated, to be dropped with PVE 7.0
> +
> +	return $res;
> +    }});
> +
>  __PACKAGE__->register_method ({
>      name => 'extractconfig',
>      path => 'extractconfig',
> 





  reply	other threads:[~2021-04-01 13:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  9:22 [pve-devel] [PATCH v3 manager 1/4] vzdump: storage info: move out activate storage call Fabian Ebner
2021-03-11  9:22 ` [pve-devel] [PATCH v3 manager 2/4] api: vzdump: add call to get currently configured vzdump defaults Fabian Ebner
2021-04-01 13:40   ` Thomas Lamprecht [this message]
2021-04-02 12:27     ` Fabian Ebner
2021-04-02 12:58       ` Thomas Lamprecht
2021-03-11  9:22 ` [pve-devel] [PATCH v3 manager 3/4] ui: backup: fill in some of the " Fabian Ebner
2021-03-11  9:22 ` [pve-devel] [PATCH v3 manager 4/4] fix #2745: ui: backup: allow specifying remove parameter for manual backup Fabian Ebner
2021-04-01 13:25 ` [pve-devel] applied: [PATCH v3 manager 1/4] vzdump: storage info: move out activate storage call Thomas Lamprecht

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=b10d9b28-e755-0996-e09b-79d239ad89cd@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=f.ebner@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