From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH access-control] api: role: remove role references from acl rules on role deletion
Date: Wed, 4 Dec 2024 16:11:23 +0100 [thread overview]
Message-ID: <20241204151123.447107-1-d.kral@proxmox.com> (raw)
Let the API endpoint `DELETE /access/roles/{roleid}` or command
`pveum role delete <roleid>` remove any ACL rules in the user
configuration, which reference the removed role.
Before this change, the removal of a role has caused the role to remain
in existing ACL rules, which referenced the removed role. Therefore, on
each parse of the user configuration, a warning was be displayed:
user config - ignore invalid acl role '<role>'
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
src/PVE/API2/Role.pm | 2 +-
src/PVE/AccessControl.pm | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/Role.pm b/src/PVE/API2/Role.pm
index a924018..6e75a3c 100644
--- a/src/PVE/API2/Role.pm
+++ b/src/PVE/API2/Role.pm
@@ -212,7 +212,7 @@ __PACKAGE__->register_method ({
delete ($usercfg->{roles}->{$role});
- # fixme: delete role from acl?
+ PVE::AccessControl::delete_role_acl($role, $usercfg);
cfs_write_file("user.cfg", $usercfg);
}, "delete role failed");
diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm
index 47f2d38..4bbbe80 100644
--- a/src/PVE/AccessControl.pm
+++ b/src/PVE/AccessControl.pm
@@ -1022,6 +1022,29 @@ sub delete_group_acl {
iterate_acl_tree("/", $usercfg->{acl_root}, $code);
}
+sub delete_role_acl_for_each {
+ my ($role, $acl_subjects) = @_;
+
+ for my $subject (sort keys %$acl_subjects) {
+ delete ($acl_subjects->{$subject}->{$role})
+ if $acl_subjects->{$subject}->{$role};
+ }
+}
+
+sub delete_role_acl {
+ my ($role, $usercfg) = @_;
+
+ my $code = sub {
+ my ($path, $acl_node) = @_;
+
+ delete_role_acl_for_each($role, $acl_node->{groups});
+ delete_role_acl_for_each($role, $acl_node->{users});
+ delete_role_acl_for_each($role, $acl_node->{tokens});
+ };
+
+ iterate_acl_tree("/", $usercfg->{acl_root}, $code);
+}
+
sub delete_pool_acl {
my ($pool, $usercfg) = @_;
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
reply other threads:[~2024-12-04 15:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241204151123.447107-1-d.kral@proxmox.com \
--to=d.kral@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox