mirror of
https://git.proxmox.com/git/pve-access-control
synced 2025-06-04 09:34:36 +00:00

this information is already available, but not exposed. we need it for dumping an effective permission tree of a given user/token. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
40 lines
892 B
Perl
Executable File
40 lines
892 B
Perl
Executable File
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use PVE::Tools;
|
|
use PVE::AccessControl;
|
|
use PVE::RPCEnvironment;
|
|
use Getopt::Long;
|
|
|
|
my $rpcenv = PVE::RPCEnvironment->init('cli');
|
|
|
|
my $cfgfn = "test2.cfg";
|
|
$rpcenv->init_request(userconfig => $cfgfn);
|
|
|
|
sub check_roles {
|
|
my ($user, $path, $expected_result) = @_;
|
|
|
|
my $roles = PVE::AccessControl::roles($rpcenv->{user_cfg}, $user, $path);
|
|
my $res = join(',', sort keys %$roles);
|
|
|
|
die "unexpected result\nneed '${expected_result}'\ngot '$res'\n"
|
|
if $res ne $expected_result;
|
|
|
|
print "ROLES:$path:$user:$res\n";
|
|
}
|
|
|
|
# inherit multiple group permissions
|
|
|
|
check_roles('User1@pve', '/', '');
|
|
check_roles('User2@pve', '/', '');
|
|
|
|
check_roles('User1@pve', '/vms', 'Role1,Role2');
|
|
check_roles('User2@pve', '/vms', '');
|
|
|
|
check_roles('User1@pve', '/vms/100', 'Role1,Role2');
|
|
check_roles('User2@pve', '/vms', '');
|
|
|
|
print "all tests passed\n";
|
|
|
|
exit (0);
|