1 package PVE
::API2
::ACL
;
5 use PVE
::Cluster qw
(cfs_read_file cfs_write_file
);
6 use PVE
::Tools
qw(split_list);
7 use PVE
::AccessControl
;
8 use PVE
::Exception
qw(raise_param_exc);
14 use base
qw(PVE::RESTHandler);
16 __PACKAGE__-
>register_method ({
20 description
=> "Get Access Control List (ACLs).",
22 description
=> "The returned list is restricted to objects where you have rights to modify permissions.",
26 additionalProperties
=> 0,
33 additionalProperties
=> 0,
35 path
=> { type
=> 'string' },
36 type
=> { type
=> 'string', enum
=> ['user', 'group'] },
37 ugid
=> { type
=> 'string' },
38 roleid
=> { type
=> 'string' },
39 propagate
=> { type
=> 'boolean' },
46 my $rpcenv = PVE
::RPCEnvironment
::get
();
47 my $authuser = $rpcenv->get_user();
50 my $usercfg = $rpcenv->{user_cfg
};
51 if (!$usercfg || !$usercfg->{acl
}) {
55 my $audit = $rpcenv->check($authuser, '/access', ['Sys.Audit'], 1);
57 my $acl = $usercfg->{acl
};
58 foreach my $path (keys %$acl) {
59 foreach my $type (qw(users groups)) {
60 my $d = $acl->{$path}->{$type};
62 next if !($audit || $rpcenv->check_perm_modify($authuser, $path, 1));
63 foreach my $id (keys %$d) {
64 foreach my $role (keys %{$d->{$id}}) {
65 my $propagate = $d->{$id}->{$role};
68 type
=> $type eq 'groups' ?
'group' : 'user',
71 propagate
=> $propagate,
81 __PACKAGE__-
>register_method ({
87 check
=> ['perm-modify', '{path}'],
89 description
=> "Update Access Control List (add or remove permissions).",
91 additionalProperties
=> 0,
94 description
=> "Access control path",
98 description
=> "List of users.",
99 type
=> 'string', format
=> 'pve-userid-list',
103 description
=> "List of groups.",
104 type
=> 'string', format
=> 'pve-groupid-list',
108 description
=> "List of roles.",
109 type
=> 'string', format
=> 'pve-roleid-list',
112 description
=> "Allow to propagate (inherit) permissions.",
118 description
=> "Remove permissions (instead of adding it).",
124 returns
=> { type
=> 'null' },
128 if (!($param->{users
} || $param->{groups
})) {
130 users
=> "either 'users' or 'groups' is required.",
131 groups
=> "either 'users' or 'groups' is required." });
134 my $path = PVE
::AccessControl
::normalize_path
($param->{path
});
135 raise_param_exc
({ path
=> "invalid ACL path '$param->{path}'" }) if !$path;
137 PVE
::AccessControl
::lock_user_config
(
140 my $cfg = cfs_read_file
("user.cfg");
144 if (defined($param->{propagate
})) {
145 $propagate = $param->{propagate
} ?
1 : 0;
148 foreach my $role (split_list
($param->{roles
})) {
149 die "role '$role' does not exist\n"
150 if !$cfg->{roles
}->{$role};
152 foreach my $group (split_list
($param->{groups
})) {
154 die "group '$group' does not exist\n"
155 if !$cfg->{groups
}->{$group};
157 if ($param->{delete}) {
158 delete($cfg->{acl
}->{$path}->{groups
}->{$group}->{$role});
160 $cfg->{acl
}->{$path}->{groups
}->{$group}->{$role} = $propagate;
164 foreach my $userid (split_list
($param->{users
})) {
165 my $username = PVE
::AccessControl
::verify_username
($userid);
167 die "user '$username' does not exist\n"
168 if !$cfg->{users
}->{$username};
170 if ($param->{delete}) {
171 delete($cfg->{acl
}->{$path}->{users
}->{$username}->{$role});
173 $cfg->{acl
}->{$path}->{users
}->{$username}->{$role} = $propagate;
178 cfs_write_file
("user.cfg", $cfg);
179 }, "ACL update failed");