X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=blobdiff_plain;f=PVE%2FAccessControl.pm;h=47b010f98eb0b00bfe5c89bc76c4ac92ff7f4a0b;hp=310a3f1dedf76d68790207ea98337beac6f71c4a;hb=c0fead8c981e6891799f28ed4cff87f50d6d3f7a;hpb=12683df7c4ee7dd10257a35189998ebe2bde5597 diff --git a/PVE/AccessControl.pm b/PVE/AccessControl.pm index 310a3f1..47b010f 100644 --- a/PVE/AccessControl.pm +++ b/PVE/AccessControl.pm @@ -514,8 +514,8 @@ sub delete_user_acl { delete ($usercfg->{acl}->{$acl}->{users}->{$username}) if $usercfg->{acl}->{$acl}->{users}->{$username}; } - } + sub delete_group_acl { my ($group, $usercfg) = @_; @@ -525,7 +525,18 @@ sub delete_group_acl { delete ($usercfg->{acl}->{$acl}->{groups}->{$group}) if $usercfg->{acl}->{$acl}->{groups}->{$group}; } +} + +sub delete_pool_acl { + my ($pool, $usercfg) = @_; + + my $path = "/pool/$pool"; + + foreach my $aclpath (keys %{$usercfg->{acl}}) { + delete ($usercfg->{acl}->{$aclpath}) + if $usercfg->{acl}->{$aclpath} eq 'path'; + } } # we automatically create some predefined roles by splitting privs @@ -537,17 +548,23 @@ my $privgroups = { VM => { root => [], admin => [ - 'VM.Modify', + 'VM.Config.Disk', + 'VM.Config.CDROM', + 'VM.Config.CPU', + 'VM.Config.Memory', + 'VM.Config.Network', + 'VM.Config.HWType', + 'VM.Config.Options', # covers all other things 'VM.Allocate', 'VM.Migrate', - 'Permissions.Modify', + 'VM.Monitor', ], user => [ 'VM.Console', 'VM.PowerMgmt', ], audit => [ - 'VM.Audit' + 'VM.Audit', ], }, Sys => { @@ -556,6 +573,7 @@ my $privgroups = { 'Sys.Modify', # edit/change node settings ], admin => [ + 'Permissions.Modify', 'Sys.Console', 'Sys.Syslog', ], @@ -565,11 +583,10 @@ my $privgroups = { ], }, Datastore => { - root => [ + root => [], + admin => [ 'Datastore.Allocate', - 'Permissions.Modify', ], - admin => [], user => [ 'Datastore.AllocateSpace', ], @@ -579,13 +596,21 @@ my $privgroups = { }, User => { root => [ - - ], + 'Realm.Allocate', + ], admin => [ 'User.Modify', - 'User.Add', - 'User.Delete', - ], + 'Group.Allocate', # edit/change group settings + 'Realm.AllocateUser', + ], + user => [], + audit => [], + }, + Pool => { + root => [], + admin => [ + 'Pool.Allocate', # create/delete pools + ], user => [], audit => [], }, @@ -663,12 +688,14 @@ sub add_role_privs { sub normalize_path { my $path = shift; - $path =~ s|/+|/|; + $path =~ s|/+|/|g; $path =~ s|/$||; $path = '/' if !$path; + $path = "/$path" if $path !~ m|^/|; + return undef if $path !~ m|^[[:alnum:]\-\_\/]+$|; return $path; @@ -751,6 +778,20 @@ sub verify_rolename { return $rolename; } +PVE::JSONSchema::register_format('pve-poolid', \&verify_groupname); +sub verify_poolname { + my ($poolname, $noerr) = @_; + + if ($poolname !~ m/^[A-Za-z0-9\.\-_]+$/) { + + die "pool name '$poolname' contains invalid characters\n" if !$noerr; + + return undef; + } + + return $poolname; +} + PVE::JSONSchema::register_format('pve-priv', \&verify_privname); sub verify_privname { my ($priv, $noerr) = @_; @@ -916,6 +957,44 @@ sub parse_user_config { } else { warn "user config - ignore invalid path in acl '$pathtxt'\n"; } + } elsif ($et eq 'pool') { + my ($pool, $comment, $vmlist, $storelist) = @data; + + if (!verify_poolname($pool, 1)) { + warn "user config - ignore pool '$pool' - invalid characters in pool name\n"; + next; + } + + # make sure to add the pool (even if there are no members) + $cfg->{pools}->{$pool} = { vms => {}, storage => {} } if !$cfg->{pools}->{$pool}; + + $cfg->{pools}->{$pool}->{comment} = PVE::Tools::decode_text($comment) if $comment; + + foreach my $vmid (split_list($vmlist)) { + if ($vmid !~ m/^\d+$/) { + warn "user config - ignore invalid vmid '$vmid' in pool '$pool'\n"; + next; + } + $vmid = int($vmid); + + if ($cfg->{vms}->{$vmid}) { + warn "user config - ignore duplicate vmid '$vmid' in pool '$pool'\n"; + next; + } + + $cfg->{pools}->{$pool}->{vms}->{$vmid} = 1; + + # record vmid ==> pool relation + $cfg->{vms}->{$vmid} = $pool; + } + + foreach my $storeid (split_list($storelist)) { + if ($storeid !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) { + warn "user config - ignore invalid storage '$storeid' in pool '$pool'\n"; + next; + } + $cfg->{pools}->{$pool}->{storage}->{$storeid} = 1; + } } else { warn "user config - ignore config line: $line\n"; } @@ -1138,6 +1217,16 @@ sub write_user_config { $data .= "\n"; + foreach my $pool (keys %{$cfg->{pools}}) { + my $d = $cfg->{pools}->{$pool}; + my $vmlist = join (',', keys %{$d->{vms}}); + my $storelist = join (',', keys %{$d->{storage}}); + my $comment = $d->{comment} ? PVE::Tools::encode_text($d->{comment}) : ''; + $data .= "pool:$pool:$comment:$vmlist:$storelist:\n"; + } + + $data .= "\n"; + foreach my $role (keys %{$cfg->{roles}}) { next if $special_roles->{$role}; @@ -1206,6 +1295,9 @@ sub write_user_config { sub roles { my ($cfg, $user, $path) = @_; + # NOTE: we do not consider pools here. + # You need to use $rpcenv->roles() instead if you want that. + return 'Administrator' if $user eq 'root@pam'; # root can do anything my $perm = {}; @@ -1254,18 +1346,14 @@ sub roles { $perm = $new; # overwrite previous settings next; } - - #die "what herea?"; } - my $res = {}; - if (!defined ($perm->{NoAccess})) { - $res = $perm; - } + return ('NoAccess') if defined ($perm->{NoAccess}); + #return () if defined ($perm->{NoAccess}); #print "permission $user $path = " . Dumper ($perm); - my @ra = keys %$res; + my @ra = keys %$perm; #print "roles $user $path = " . join (',', @ra) . "\n";