X-Git-Url: https://git.proxmox.com/?p=pve-access-control.git;a=blobdiff_plain;f=PVE%2FAccessControl.pm;h=2b7974dd6245fd44d92a9d3902c0f9cfe07c4bea;hp=331823e3b5130aa77b01d4187fad8e920070d441;hb=dd2cfee072b8ebe8280595b250dafdb2786297af;hpb=2e376c5849d8717b5d8b8f4a779ea03490625c58 diff --git a/PVE/AccessControl.pm b/PVE/AccessControl.pm index 331823e..2b7974d 100644 --- a/PVE/AccessControl.pm +++ b/PVE/AccessControl.pm @@ -156,14 +156,15 @@ sub verify_ticket { my $rsa_pub = get_pubkey(); if ($rsa_pub->verify($plain, decode_base64($sig))) { - if ($plain =~ m/^PVE:(([A-Za-z0-9\.\-_]+)(\@([A-Za-z0-9\.\-_]+))?):([A-Z0-9]{8})$/) { + if ($plain =~ m/^PVE:(\S+):([A-Z0-9]{8})$/) { my $username = $1; - my $timestamp = $5; + my $timestamp = $2; my $ttime = hex($timestamp); my $age = time() - $ttime; - if (($age > -300) && ($age < $ticket_lifetime)) { + if (verify_username($username, 1) && + ($age > -300) && ($age < $ticket_lifetime)) { return wantarray ? ($username, $age) : $username; } } @@ -463,14 +464,14 @@ sub encrypt_pw { sub store_pam_password { my ($userid, $password) = @_; - my $cmd = ['/usr/sbin/usermod']; + my $cmd = ['usermod']; my $epw = encrypt_pw($password); push @$cmd, '-p', $epw; push @$cmd, $userid; - run_command($cmd); + run_command($cmd, errmsg => 'change password failed'); } sub domain_set_password { @@ -514,8 +515,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 +526,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,16 +549,24 @@ my $privgroups = { VM => { root => [], admin => [ - 'VM.Modify', + 'VM.Config.Disk', + 'VM.Config.CPU', + 'VM.Config.Memory', + 'VM.Config.Network', + 'VM.Config.HWType', + 'VM.Config.Options', # covers all other things 'VM.Allocate', 'VM.Migrate', + 'VM.Monitor', ], user => [ + 'VM.Config.CDROM', # change CDROM media 'VM.Console', + 'VM.Backup', 'VM.PowerMgmt', ], audit => [ - 'VM.Audit' + 'VM.Audit', ], }, Sys => { @@ -568,6 +588,7 @@ my $privgroups = { root => [], admin => [ 'Datastore.Allocate', + 'Datastore.AllocateTemplate', ], user => [ 'Datastore.AllocateSpace', @@ -577,10 +598,21 @@ my $privgroups = { ], }, User => { - root => [], + root => [ + 'Realm.Allocate', + ], admin => [ 'User.Modify', - 'User.Allocate', + 'Group.Allocate', # edit/change group settings + 'Realm.AllocateUser', + ], + user => [], + audit => [], + }, + Pool => { + root => [], + admin => [ + 'Pool.Allocate', # create/delete pools ], user => [], audit => [], @@ -632,7 +664,7 @@ my $valid_attributes = { ldap => { server1 => '[\w\d]+(.[\w\d]+)*', server2 => '[\w\d]+(.[\w\d]+)*', - base_dn => '\w+=[\w\s]+(,\s*\w+=[\w\s]+)*', + base_dn => '\w+=[^,]+(,\s*\w+=[^,]+)*', user_attr => '\S{2,}', secure => '', port => '\d+', @@ -674,6 +706,7 @@ sub normalize_path { my $realm_regex = qr/[A-Za-z][A-Za-z0-9\.\-_]+/; +PVE::JSONSchema::register_format('pve-realm', \&pve_verify_realm); sub pve_verify_realm { my ($realm, $noerr) = @_; @@ -717,7 +750,7 @@ PVE::JSONSchema::register_standard_option('userid', { PVE::JSONSchema::register_standard_option('realm', { description => "Authentication domain ID", - type => 'string', format => 'pve-configid', + type => 'string', format => 'pve-realm', maxLength => 32, }); @@ -749,6 +782,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) = @_; @@ -893,7 +940,7 @@ sub parse_user_config { } foreach my $ug (split_list($uglist)) { - if ($ug =~ m/^@(\w+)$/) { + if ($ug =~ m/^@(\S+)$/) { my $group = $1; if ($cfg->{groups}->{$group}) { # group exists $cfg->{acl}->{$path}->{groups}->{$group}->{$role} = $propagate; @@ -915,42 +962,42 @@ sub parse_user_config { warn "user config - ignore invalid path in acl '$pathtxt'\n"; } } elsif ($et eq 'pool') { - my ($pathtxt, $comment, $vmlist, $storelist) = @data; + my ($pool, $comment, $vmlist, $storelist) = @data; - if (my $path = normalize_path($pathtxt)) { - # make sure to add the pool (even if there are no members) - $cfg->{pools}->{$path} = { vms => {}, storage => {} } if !$cfg->{pools}->{$path}; + if (!verify_poolname($pool, 1)) { + warn "user config - ignore pool '$pool' - invalid characters in pool name\n"; + next; + } - $cfg->{pools}->{$path}->{comment} = PVE::Tools::decode_text($comment) if $comment; + # make sure to add the pool (even if there are no members) + $cfg->{pools}->{$pool} = { vms => {}, storage => {} } if !$cfg->{pools}->{$pool}; - foreach my $vmid (split_list($vmlist)) { - if ($vmid !~ m/^\d+$/) { - warn "user config - ignore invalid vmid '$vmid' in pool '$path'\n"; - next; - } - $vmid = int($vmid); + $cfg->{pools}->{$pool}->{comment} = PVE::Tools::decode_text($comment) if $comment; - if ($cfg->{vms}->{$vmid}) { - warn "user config - ignore duplicate vmid '$vmid' in pool '$path'\n"; - next; - } - - $cfg->{pools}->{$path}->{vms}->{$vmid} = 1; - - # record vmid ==> pool relation - $cfg->{vms}->{$vmid} = $path; + 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); - 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 '$path'\n"; - next; - } - $cfg->{pools}->{$path}->{storage}->{$storeid} = 1; + if ($cfg->{vms}->{$vmid}) { + warn "user config - ignore duplicate vmid '$vmid' in pool '$pool'\n"; + next; } - } else { - warn "user config - ignore invalid path in pool'$pathtxt'\n"; + $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"; @@ -1174,12 +1221,12 @@ sub write_user_config { $data .= "\n"; - foreach my $path (keys %{$cfg->{pools}}) { - my $d = $cfg->{pools}->{$path}; + 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:$path:$comment:$vmlist:$storelist:\n"; + $data .= "pool:$pool:$comment:$vmlist:$storelist:\n"; } $data .= "\n";