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);
9 use PVE
::JSONSchema
qw(get_standard_option register_standard_option);
15 use base
qw(PVE::RESTHandler);
17 register_standard_option
('acl-propagate', {
18 description
=> "Allow to propagate (inherit) permissions.",
23 register_standard_option
('acl-path', {
24 description
=> "Access control path",
28 __PACKAGE__-
>register_method ({
32 description
=> "Get Access Control List (ACLs).",
34 description
=> "The returned list is restricted to objects where you have rights to modify permissions.",
38 additionalProperties
=> 0,
45 additionalProperties
=> 0,
47 propagate
=> get_standard_option
('acl-propagate'),
48 path
=> get_standard_option
('acl-path'),
49 type
=> { type
=> 'string', enum
=> ['user', 'group'] },
50 ugid
=> { type
=> 'string' },
51 roleid
=> { type
=> 'string' },
58 my $rpcenv = PVE
::RPCEnvironment
::get
();
59 my $authuser = $rpcenv->get_user();
62 my $usercfg = $rpcenv->{user_cfg
};
63 if (!$usercfg || !$usercfg->{acl
}) {
67 my $audit = $rpcenv->check($authuser, '/access', ['Sys.Audit'], 1);
69 my $acl = $usercfg->{acl
};
70 foreach my $path (keys %$acl) {
71 foreach my $type (qw(users groups)) {
72 my $d = $acl->{$path}->{$type};
74 next if !($audit || $rpcenv->check_perm_modify($authuser, $path, 1));
75 foreach my $id (keys %$d) {
76 foreach my $role (keys %{$d->{$id}}) {
77 my $propagate = $d->{$id}->{$role};
80 type
=> $type eq 'groups' ?
'group' : 'user',
83 propagate
=> $propagate,
93 __PACKAGE__-
>register_method ({
99 check
=> ['perm-modify', '{path}'],
101 description
=> "Update Access Control List (add or remove permissions).",
103 additionalProperties
=> 0,
105 propagate
=> get_standard_option
('acl-propagate'),
106 path
=> get_standard_option
('acl-path'),
108 description
=> "List of users.",
109 type
=> 'string', format
=> 'pve-userid-list',
113 description
=> "List of groups.",
114 type
=> 'string', format
=> 'pve-groupid-list',
118 description
=> "List of roles.",
119 type
=> 'string', format
=> 'pve-roleid-list',
122 description
=> "Remove permissions (instead of adding it).",
128 returns
=> { type
=> 'null' },
132 if (!($param->{users
} || $param->{groups
})) {
134 users
=> "either 'users' or 'groups' is required.",
135 groups
=> "either 'users' or 'groups' is required." });
138 my $path = PVE
::AccessControl
::normalize_path
($param->{path
});
139 raise_param_exc
({ path
=> "invalid ACL path '$param->{path}'" }) if !$path;
141 PVE
::AccessControl
::lock_user_config
(
144 my $cfg = cfs_read_file
("user.cfg");
148 if (defined($param->{propagate
})) {
149 $propagate = $param->{propagate
} ?
1 : 0;
152 foreach my $role (split_list
($param->{roles
})) {
153 die "role '$role' does not exist\n"
154 if !$cfg->{roles
}->{$role};
156 foreach my $group (split_list
($param->{groups
})) {
158 die "group '$group' does not exist\n"
159 if !$cfg->{groups
}->{$group};
161 if ($param->{delete}) {
162 delete($cfg->{acl
}->{$path}->{groups
}->{$group}->{$role});
164 $cfg->{acl
}->{$path}->{groups
}->{$group}->{$role} = $propagate;
168 foreach my $userid (split_list
($param->{users
})) {
169 my $username = PVE
::AccessControl
::verify_username
($userid);
171 die "user '$username' does not exist\n"
172 if !$cfg->{users
}->{$username};
174 if ($param->{delete}) {
175 delete($cfg->{acl
}->{$path}->{users
}->{$username}->{$role});
177 $cfg->{acl
}->{$path}->{users
}->{$username}->{$role} = $propagate;
182 cfs_write_file
("user.cfg", $cfg);
183 }, "ACL update failed");