mirror of
git://git.proxmox.com/git/pve-network.git
synced 2025-05-01 11:36:22 +02:00
fix permissions && use new /sdn/zones/<zone>/<vnet> path
- use new /sdn/zones/zone/<vnet> path for vnet && subnets permissions - fix some permissions on /sdn/zones && /sdn Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
parent
cbf906daae
commit
d7c1620043
|
@ -51,7 +51,7 @@ __PACKAGE__->register_method({
|
||||||
method => 'GET',
|
method => 'GET',
|
||||||
description => "Directory index.",
|
description => "Directory index.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/', [ 'SDN.Audit' ]],
|
check => ['perm', '/sdn', [ 'SDN.Audit' ]],
|
||||||
},
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
|
|
|
@ -33,13 +33,34 @@ my $api_sdn_subnets_config = sub {
|
||||||
return $scfg;
|
return $scfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my $api_sdn_vnets_config = sub {
|
||||||
|
my ($cfg, $id) = @_;
|
||||||
|
|
||||||
|
my $scfg = dclone(PVE::Network::SDN::Vnets::sdn_vnets_config($cfg, $id));
|
||||||
|
$scfg->{vnet} = $id;
|
||||||
|
$scfg->{digest} = $cfg->{digest};
|
||||||
|
|
||||||
|
return $scfg;
|
||||||
|
};
|
||||||
|
|
||||||
|
my $check_vnet_access = sub {
|
||||||
|
my ($vnet, $privs) = @_;
|
||||||
|
|
||||||
|
my $cfg = PVE::Network::SDN::Vnets::config();
|
||||||
|
my $rpcenv = PVE::RPCEnvironment::get();
|
||||||
|
my $authuser = $rpcenv->get_user();
|
||||||
|
my $scfg = &$api_sdn_vnets_config($cfg, $vnet);
|
||||||
|
my $zoneid = $scfg->{zone};
|
||||||
|
$rpcenv->check_any($authuser, "/sdn/zones/$zoneid/$vnet", $privs);
|
||||||
|
};
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
name => 'index',
|
name => 'index',
|
||||||
path => '',
|
path => '',
|
||||||
method => 'GET',
|
method => 'GET',
|
||||||
description => "SDN subnets index.",
|
description => "SDN subnets index.",
|
||||||
permissions => {
|
permissions => {
|
||||||
description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/subnets/<subnet>'",
|
description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
|
||||||
user => 'all',
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
|
@ -69,10 +90,9 @@ __PACKAGE__->register_method ({
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param) = @_;
|
||||||
|
|
||||||
my $rpcenv = PVE::RPCEnvironment::get();
|
my $vnetid = $param->{vnet};
|
||||||
my $authuser = $rpcenv->get_user();
|
my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($vnetid, $privs);
|
||||||
my $vnetid = $param->{vnet};
|
|
||||||
|
|
||||||
my $cfg = {};
|
my $cfg = {};
|
||||||
if($param->{pending}) {
|
if($param->{pending}) {
|
||||||
|
@ -89,9 +109,6 @@ __PACKAGE__->register_method ({
|
||||||
my @sids = PVE::Network::SDN::Subnets::sdn_subnets_ids($cfg);
|
my @sids = PVE::Network::SDN::Subnets::sdn_subnets_ids($cfg);
|
||||||
my $res = [];
|
my $res = [];
|
||||||
foreach my $id (@sids) {
|
foreach my $id (@sids) {
|
||||||
my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
|
|
||||||
next if !$rpcenv->check_any($authuser, "/sdn/vnets/$vnetid/subnets/$id", $privs, 1);
|
|
||||||
|
|
||||||
my $scfg = &$api_sdn_subnets_config($cfg, $id);
|
my $scfg = &$api_sdn_subnets_config($cfg, $id);
|
||||||
next if !$scfg->{vnet} || $scfg->{vnet} ne $vnetid;
|
next if !$scfg->{vnet} || $scfg->{vnet} ne $vnetid;
|
||||||
push @$res, $scfg;
|
push @$res, $scfg;
|
||||||
|
@ -106,9 +123,9 @@ __PACKAGE__->register_method ({
|
||||||
method => 'GET',
|
method => 'GET',
|
||||||
description => "Read sdn subnet configuration.",
|
description => "Read sdn subnet configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets/{vnet}/subnets/{subnet}', ['SDN.Allocate']],
|
description => "Require 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
|
||||||
},
|
user => 'all',
|
||||||
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
properties => {
|
properties => {
|
||||||
|
@ -132,6 +149,10 @@ __PACKAGE__->register_method ({
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param) = @_;
|
||||||
|
|
||||||
|
my $vnet = extract_param($param, 'vnet');
|
||||||
|
my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($vnet, $privs);
|
||||||
|
|
||||||
my $cfg = {};
|
my $cfg = {};
|
||||||
if($param->{pending}) {
|
if($param->{pending}) {
|
||||||
my $running_cfg = PVE::Network::SDN::running_config();
|
my $running_cfg = PVE::Network::SDN::running_config();
|
||||||
|
@ -146,7 +167,7 @@ __PACKAGE__->register_method ({
|
||||||
|
|
||||||
my $scfg = &$api_sdn_subnets_config($cfg, $param->{subnet});
|
my $scfg = &$api_sdn_subnets_config($cfg, $param->{subnet});
|
||||||
|
|
||||||
raise_param_exc({ vnet => "wrong vnet"}) if $param->{vnet} ne $scfg->{vnet};
|
raise_param_exc({ vnet => "wrong vnet"}) if $vnet ne $scfg->{vnet};
|
||||||
|
|
||||||
return $scfg;
|
return $scfg;
|
||||||
}});
|
}});
|
||||||
|
@ -158,7 +179,8 @@ __PACKAGE__->register_method ({
|
||||||
method => 'POST',
|
method => 'POST',
|
||||||
description => "Create a new sdn subnet object.",
|
description => "Create a new sdn subnet object.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets/{vnet}/subnets', ['SDN.Allocate']],
|
description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
|
||||||
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => PVE::Network::SDN::SubnetPlugin->createSchema(),
|
parameters => PVE::Network::SDN::SubnetPlugin->createSchema(),
|
||||||
returns => { type => 'null' },
|
returns => { type => 'null' },
|
||||||
|
@ -168,6 +190,10 @@ __PACKAGE__->register_method ({
|
||||||
my $type = extract_param($param, 'type');
|
my $type = extract_param($param, 'type');
|
||||||
my $cidr = extract_param($param, 'subnet');
|
my $cidr = extract_param($param, 'subnet');
|
||||||
|
|
||||||
|
my $vnet = $param->{vnet};
|
||||||
|
my $privs = [ 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($vnet, $privs);
|
||||||
|
|
||||||
# create /etc/pve/sdn directory
|
# create /etc/pve/sdn directory
|
||||||
PVE::Cluster::check_cfs_quorum();
|
PVE::Cluster::check_cfs_quorum();
|
||||||
mkdir("/etc/pve/sdn") if ! -d '/etc/pve/sdn';
|
mkdir("/etc/pve/sdn") if ! -d '/etc/pve/sdn';
|
||||||
|
@ -210,7 +236,8 @@ __PACKAGE__->register_method ({
|
||||||
method => 'PUT',
|
method => 'PUT',
|
||||||
description => "Update sdn subnet object configuration.",
|
description => "Update sdn subnet object configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets/{vnet}/subnets', ['SDN.Allocate']],
|
description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
|
||||||
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => PVE::Network::SDN::SubnetPlugin->updateSchema(),
|
parameters => PVE::Network::SDN::SubnetPlugin->updateSchema(),
|
||||||
returns => { type => 'null' },
|
returns => { type => 'null' },
|
||||||
|
@ -219,6 +246,10 @@ __PACKAGE__->register_method ({
|
||||||
|
|
||||||
my $id = extract_param($param, 'subnet');
|
my $id = extract_param($param, 'subnet');
|
||||||
my $digest = extract_param($param, 'digest');
|
my $digest = extract_param($param, 'digest');
|
||||||
|
my $vnet = $param->{vnet};
|
||||||
|
|
||||||
|
my $privs = [ 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($vnet, $privs);
|
||||||
|
|
||||||
PVE::Network::SDN::lock_sdn_config(
|
PVE::Network::SDN::lock_sdn_config(
|
||||||
sub {
|
sub {
|
||||||
|
@ -226,7 +257,6 @@ __PACKAGE__->register_method ({
|
||||||
my $cfg = PVE::Network::SDN::Subnets::config();
|
my $cfg = PVE::Network::SDN::Subnets::config();
|
||||||
my $zone_cfg = PVE::Network::SDN::Zones::config();
|
my $zone_cfg = PVE::Network::SDN::Zones::config();
|
||||||
my $vnet_cfg = PVE::Network::SDN::Vnets::config();
|
my $vnet_cfg = PVE::Network::SDN::Vnets::config();
|
||||||
my $vnet = $param->{vnet};
|
|
||||||
my $zoneid = $vnet_cfg->{ids}->{$vnet}->{zone};
|
my $zoneid = $vnet_cfg->{ids}->{$vnet}->{zone};
|
||||||
my $zone = $zone_cfg->{ids}->{$zoneid};
|
my $zone = $zone_cfg->{ids}->{$zoneid};
|
||||||
|
|
||||||
|
@ -256,7 +286,8 @@ __PACKAGE__->register_method ({
|
||||||
method => 'DELETE',
|
method => 'DELETE',
|
||||||
description => "Delete sdn subnet object configuration.",
|
description => "Delete sdn subnet object configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets/{vnet}/subnets', ['SDN.Allocate']],
|
description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
|
||||||
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
|
@ -272,6 +303,9 @@ __PACKAGE__->register_method ({
|
||||||
my ($param) = @_;
|
my ($param) = @_;
|
||||||
|
|
||||||
my $id = extract_param($param, 'subnet');
|
my $id = extract_param($param, 'subnet');
|
||||||
|
my $vnet = extract_param($param, 'vnet');
|
||||||
|
my $privs = [ 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($vnet, $privs);
|
||||||
|
|
||||||
PVE::Network::SDN::lock_sdn_config(
|
PVE::Network::SDN::lock_sdn_config(
|
||||||
sub {
|
sub {
|
||||||
|
@ -284,7 +318,6 @@ __PACKAGE__->register_method ({
|
||||||
PVE::Network::SDN::SubnetPlugin->on_delete_hook($id, $cfg, $vnets_cfg);
|
PVE::Network::SDN::SubnetPlugin->on_delete_hook($id, $cfg, $vnets_cfg);
|
||||||
|
|
||||||
my $zone_cfg = PVE::Network::SDN::Zones::config();
|
my $zone_cfg = PVE::Network::SDN::Zones::config();
|
||||||
my $vnet = $param->{vnet};
|
|
||||||
my $zoneid = $vnets_cfg->{ids}->{$vnet}->{zone};
|
my $zoneid = $vnets_cfg->{ids}->{$vnet}->{zone};
|
||||||
my $zone = $zone_cfg->{ids}->{$zoneid};
|
my $zone = $zone_cfg->{ids}->{$zoneid};
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,17 @@ my $api_sdn_vnets_deleted_config = sub {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my $check_vnet_access = sub {
|
||||||
|
my ($vnet, $privs) = @_;
|
||||||
|
|
||||||
|
my $cfg = PVE::Network::SDN::Vnets::config();
|
||||||
|
my $rpcenv = PVE::RPCEnvironment::get();
|
||||||
|
my $authuser = $rpcenv->get_user();
|
||||||
|
my $scfg = &$api_sdn_vnets_config($cfg, $vnet);
|
||||||
|
my $zoneid = $scfg->{zone};
|
||||||
|
$rpcenv->check_any($authuser, "/sdn/zones/$zoneid/$vnet", $privs);
|
||||||
|
};
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
name => 'index',
|
name => 'index',
|
||||||
path => '',
|
path => '',
|
||||||
|
@ -57,7 +68,7 @@ __PACKAGE__->register_method ({
|
||||||
description => "SDN vnets index.",
|
description => "SDN vnets index.",
|
||||||
permissions => {
|
permissions => {
|
||||||
description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate'"
|
description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate'"
|
||||||
." permissions on '/sdn/vnets/<vnet>'",
|
." permissions on '/sdn/zones/<zone>/<vnet>'",
|
||||||
user => 'all',
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
|
@ -105,9 +116,10 @@ __PACKAGE__->register_method ({
|
||||||
my $res = [];
|
my $res = [];
|
||||||
foreach my $id (@sids) {
|
foreach my $id (@sids) {
|
||||||
my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
|
my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
|
||||||
next if !$rpcenv->check_any($authuser, "/sdn/vnets/$id", $privs, 1);
|
|
||||||
|
|
||||||
my $scfg = &$api_sdn_vnets_config($cfg, $id);
|
my $scfg = &$api_sdn_vnets_config($cfg, $id);
|
||||||
|
my $zoneid = $scfg->{zone};
|
||||||
|
next if !$rpcenv->check_any($authuser, "/sdn/zones/$zoneid/$id", $privs, 1);
|
||||||
|
|
||||||
push @$res, $scfg;
|
push @$res, $scfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +132,9 @@ __PACKAGE__->register_method ({
|
||||||
method => 'GET',
|
method => 'GET',
|
||||||
description => "Read sdn vnet configuration.",
|
description => "Read sdn vnet configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets/{vnet}', ['SDN.Allocate']],
|
description => "Require 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
|
||||||
},
|
user => 'all',
|
||||||
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
properties => {
|
properties => {
|
||||||
|
@ -144,6 +157,11 @@ __PACKAGE__->register_method ({
|
||||||
code => sub {
|
code => sub {
|
||||||
my ($param) = @_;
|
my ($param) = @_;
|
||||||
|
|
||||||
|
my $id = extract_param($param, 'vnet');
|
||||||
|
|
||||||
|
my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($id, $privs);
|
||||||
|
|
||||||
my $cfg = {};
|
my $cfg = {};
|
||||||
if($param->{pending}) {
|
if($param->{pending}) {
|
||||||
my $running_cfg = PVE::Network::SDN::running_config();
|
my $running_cfg = PVE::Network::SDN::running_config();
|
||||||
|
@ -156,7 +174,7 @@ __PACKAGE__->register_method ({
|
||||||
$cfg = PVE::Network::SDN::Vnets::config();
|
$cfg = PVE::Network::SDN::Vnets::config();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $api_sdn_vnets_config->($cfg, $param->{vnet});
|
return $api_sdn_vnets_config->($cfg, $id);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
__PACKAGE__->register_method ({
|
__PACKAGE__->register_method ({
|
||||||
|
@ -166,7 +184,7 @@ __PACKAGE__->register_method ({
|
||||||
method => 'POST',
|
method => 'POST',
|
||||||
description => "Create a new sdn vnet object.",
|
description => "Create a new sdn vnet object.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets', ['SDN.Allocate']],
|
check => ['perm', '/sdn/zones/{zone}', ['SDN.Allocate']],
|
||||||
},
|
},
|
||||||
parameters => PVE::Network::SDN::VnetPlugin->createSchema(),
|
parameters => PVE::Network::SDN::VnetPlugin->createSchema(),
|
||||||
returns => { type => 'null' },
|
returns => { type => 'null' },
|
||||||
|
@ -210,7 +228,8 @@ __PACKAGE__->register_method ({
|
||||||
method => 'PUT',
|
method => 'PUT',
|
||||||
description => "Update sdn vnet object configuration.",
|
description => "Update sdn vnet object configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets', ['SDN.Allocate']],
|
description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
|
||||||
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => PVE::Network::SDN::VnetPlugin->updateSchema(),
|
parameters => PVE::Network::SDN::VnetPlugin->updateSchema(),
|
||||||
returns => { type => 'null' },
|
returns => { type => 'null' },
|
||||||
|
@ -220,12 +239,14 @@ __PACKAGE__->register_method ({
|
||||||
my $id = extract_param($param, 'vnet');
|
my $id = extract_param($param, 'vnet');
|
||||||
my $digest = extract_param($param, 'digest');
|
my $digest = extract_param($param, 'digest');
|
||||||
|
|
||||||
|
my $privs = [ 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($id, $privs);
|
||||||
|
|
||||||
PVE::Network::SDN::lock_sdn_config(sub {
|
PVE::Network::SDN::lock_sdn_config(sub {
|
||||||
my $cfg = PVE::Network::SDN::Vnets::config();
|
my $cfg = PVE::Network::SDN::Vnets::config();
|
||||||
|
|
||||||
PVE::SectionConfig::assert_if_modified($cfg, $digest);
|
PVE::SectionConfig::assert_if_modified($cfg, $digest);
|
||||||
|
|
||||||
|
|
||||||
my $opts = PVE::Network::SDN::VnetPlugin->check_config($id, $param, 0, 1);
|
my $opts = PVE::Network::SDN::VnetPlugin->check_config($id, $param, 0, 1);
|
||||||
raise_param_exc({ zone => "missing zone"}) if !$opts->{zone};
|
raise_param_exc({ zone => "missing zone"}) if !$opts->{zone};
|
||||||
my $subnets = PVE::Network::SDN::Vnets::get_subnets($id);
|
my $subnets = PVE::Network::SDN::Vnets::get_subnets($id);
|
||||||
|
@ -256,7 +277,8 @@ __PACKAGE__->register_method ({
|
||||||
method => 'DELETE',
|
method => 'DELETE',
|
||||||
description => "Delete sdn vnet object configuration.",
|
description => "Delete sdn vnet object configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/vnets', ['SDN.Allocate']],
|
description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
|
||||||
|
user => 'all',
|
||||||
},
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
|
@ -272,6 +294,9 @@ __PACKAGE__->register_method ({
|
||||||
|
|
||||||
my $id = extract_param($param, 'vnet');
|
my $id = extract_param($param, 'vnet');
|
||||||
|
|
||||||
|
my $privs = [ 'SDN.Allocate' ];
|
||||||
|
&$check_vnet_access($id, $privs);
|
||||||
|
|
||||||
PVE::Network::SDN::lock_sdn_config(sub {
|
PVE::Network::SDN::lock_sdn_config(sub {
|
||||||
my $cfg = PVE::Network::SDN::Vnets::config();
|
my $cfg = PVE::Network::SDN::Vnets::config();
|
||||||
my $scfg = PVE::Network::SDN::Vnets::sdn_vnets_config($cfg, $id); # check if exists
|
my $scfg = PVE::Network::SDN::Vnets::sdn_vnets_config($cfg, $id); # check if exists
|
||||||
|
|
|
@ -251,7 +251,7 @@ __PACKAGE__->register_method ({
|
||||||
method => 'PUT',
|
method => 'PUT',
|
||||||
description => "Update sdn zone object configuration.",
|
description => "Update sdn zone object configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/zones', ['SDN.Allocate']],
|
check => ['perm', '/sdn/zones/{zone}', ['SDN.Allocate']],
|
||||||
},
|
},
|
||||||
parameters => PVE::Network::SDN::Zones::Plugin->updateSchema(),
|
parameters => PVE::Network::SDN::Zones::Plugin->updateSchema(),
|
||||||
returns => { type => 'null' },
|
returns => { type => 'null' },
|
||||||
|
@ -315,7 +315,7 @@ __PACKAGE__->register_method ({
|
||||||
method => 'DELETE',
|
method => 'DELETE',
|
||||||
description => "Delete sdn zone object configuration.",
|
description => "Delete sdn zone object configuration.",
|
||||||
permissions => {
|
permissions => {
|
||||||
check => ['perm', '/sdn/zones', ['SDN.Allocate']],
|
check => ['perm', '/sdn/zones/{zone}', ['SDN.Allocate']],
|
||||||
},
|
},
|
||||||
parameters => {
|
parameters => {
|
||||||
additionalProperties => 0,
|
additionalProperties => 0,
|
||||||
|
|
Loading…
Reference in a new issue