]> git.proxmox.com Git - pve-access-control.git/blobdiff - PVE/API2/User.pm
remove_storage_access: cleanup of access permissions for removed storage
[pve-access-control.git] / PVE / API2 / User.pm
index 6f4aff1c84b19baa9c6218d0bb7e926f3c95a7fb..6208ad5bdfa94e65e374937d926ef1eae34ef37f 100644 (file)
@@ -21,7 +21,7 @@ my $extract_user_data = sub {
 
     my $res = {};
 
-    foreach my $prop (qw(enable expire firstname lastname email comment)) {
+    foreach my $prop (qw(enable expire firstname lastname email comment keys)) {
        $res->{$prop} = $data->{$prop} if defined($data->{$prop});
     }
 
@@ -38,7 +38,7 @@ __PACKAGE__->register_method ({
     method => 'GET',
     description => "User index.",
     permissions => { 
-       description => "The returned list is restricted to users where you have 'User.Modify' or 'User.Allocate' permissions on '/access' or on a group the user belongs too. But it always includes the current (authenticated) user.",
+       description => "The returned list is restricted to users where you have 'User.Modify' or 'Sys.Audit' permissions on '/access/groups' or on a group the user belongs too. But it always includes the current (authenticated) user.",
        user => 'all',
     },
     parameters => {
@@ -70,9 +70,8 @@ __PACKAGE__->register_method ({
 
        my $res = [];
 
-       my $privs = [ 'User.Modify', 'User.Allocate' ];
-
-       my $canUserMod = $rpcenv->check_any($authuser, "/access", $privs, 1);
+       my $privs = [ 'User.Modify', 'Sys.Audit' ];
+       my $canUserMod = $rpcenv->check_any($authuser, "/access/groups", $privs, 1);
        my $groups = $rpcenv->filter_groups($authuser, $privs, 1);
        my $allowed_users = $rpcenv->group_member_join([keys %$groups]);      
 
@@ -102,8 +101,11 @@ __PACKAGE__->register_method ({
     path => '', 
     method => 'POST',
     permissions => { 
-       description => "You need 'User.Allocate' permissions to '/access/groups/<group>' for any group specified, or 'User.Allocate' on '/access' if you pass no groups.",
-       check => ['userid-group', ['User.Allocate'], groups_param => 1],
+       description => "You need 'Realm.AllocateUser' on '/access/realm/<realm>' on the realm of user <userid>, and 'User.Modify' permissions to '/access/groups/<group>' for any group specified (or 'User.Modify' on '/access/groups' if you pass no groups.",
+       check => [ 'and',
+                  [ 'userid-param', 'Realm.AllocateUser'],
+                  [ 'userid-group', ['User.Modify'], groups_param => 1],
+           ],
     },
     description => "Create new user.",
     parameters => {
@@ -122,6 +124,11 @@ __PACKAGE__->register_method ({
            lastname => { type => 'string', optional => 1 },
            email => { type => 'string', optional => 1, format => 'email-opt' },
            comment => { type => 'string', optional => 1 },
+           keys => {
+               description => "Keys for two factor auth (yubico).",
+               type => 'string', 
+               optional => 1,
+           },
            expire => { 
                description => "Account expiration date (seconds since epoch). '0' means no expiration date.",
                type => 'integer', 
@@ -171,6 +178,7 @@ __PACKAGE__->register_method ({
                $usercfg->{users}->{$username}->{lastname} = $param->{lastname} if $param->{lastname};
                $usercfg->{users}->{$username}->{email} = $param->{email} if $param->{email};
                $usercfg->{users}->{$username}->{comment} = $param->{comment} if $param->{comment};
+               $usercfg->{users}->{$username}->{keys} = $param->{keys} if $param->{keys};
 
                cfs_write_file("user.cfg", $usercfg);
            }, "create user failed");
@@ -184,7 +192,7 @@ __PACKAGE__->register_method ({
     method => 'GET',
     description => "Get user configuration.",
     permissions => { 
-       check => ['userid-group', ['User.Modify']],
+       check => ['userid-group', ['User.Modify', 'Sys.Audit']],
     },
     parameters => {
        additionalProperties => 0,
@@ -201,6 +209,7 @@ __PACKAGE__->register_method ({
            lastname => { type => 'string', optional => 1 },
            email => { type => 'string', optional => 1 },
            comment => { type => 'string', optional => 1 },    
+           keys => { type => 'string', optional => 1 },    
            groups => { type => 'array' },
        }
     },
@@ -245,6 +254,11 @@ __PACKAGE__->register_method ({
            lastname => { type => 'string', optional => 1 },
            email => { type => 'string', optional => 1, format => 'email-opt' },
            comment => { type => 'string', optional => 1 },
+           keys => {
+               description => "Keys for two factor auth (yubico).",
+               type => 'string', 
+               optional => 1,
+           },
            expire => { 
                description => "Account expiration date (seconds since epoch). '0' means no expiration date.",
                type => 'integer', 
@@ -288,6 +302,7 @@ __PACKAGE__->register_method ({
                $usercfg->{users}->{$username}->{lastname} = $param->{lastname} if defined($param->{lastname});
                $usercfg->{users}->{$username}->{email} = $param->{email} if defined($param->{email});
                $usercfg->{users}->{$username}->{comment} = $param->{comment} if defined($param->{comment});
+               $usercfg->{users}->{$username}->{keys} = $param->{keys} if defined($param->{keys});
 
                cfs_write_file("user.cfg", $usercfg);
            }, "update user failed");
@@ -302,7 +317,10 @@ __PACKAGE__->register_method ({
     method => 'DELETE',
     description => "Delete user.",
     permissions => { 
-       check => ['userid-group', ['User.Allocate']],
+       check => [ 'and',
+                  [ 'userid-param', 'Realm.AllocateUser'],
+                  [ 'userid-group', ['User.Modify']],
+           ],
     },
     parameters => {
        additionalProperties => 0,
@@ -325,9 +343,13 @@ __PACKAGE__->register_method ({
 
                my $usercfg = cfs_read_file("user.cfg");
 
-               delete ($usercfg->{users}->{$userid});
+               my $domain_cfg = cfs_read_file('domains.cfg');
+               if (my $cfg = $domain_cfg->{ids}->{$realm}) {
+                   my $plugin = PVE::Auth::Plugin->lookup($cfg->{type});
+                   $plugin->delete_user($cfg, $realm, $ruid);
+               }
 
-               PVE::AccessControl::delete_shadow_password($ruid) if $realm eq 'pve';
+               delete $usercfg->{users}->{$userid};
 
                PVE::AccessControl::delete_user_group($userid, $usercfg);
                PVE::AccessControl::delete_user_acl($userid, $usercfg);