From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 6F2BB1FF16E
	for <inbox@lore.proxmox.com>; Mon,  3 Feb 2025 12:49:12 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6ACB72E5B8;
	Mon,  3 Feb 2025 12:49:10 +0100 (CET)
Message-ID: <64c46c18-1e31-45d7-88ba-12010bea2539@proxmox.com>
Date: Mon, 3 Feb 2025 12:49:06 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Daniel Kral <d.kral@proxmox.com>
References: <20241204151123.447107-1-d.kral@proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <20241204151123.447107-1-d.kral@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.198 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 POISEN_SPAM_PILL          0.1 Meta: its spam
 POISEN_SPAM_PILL_1        0.1 random spam to be learned in bayes
 POISEN_SPAM_PILL_3        0.1 random spam to be learned in bayes
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH access-control] api: role: remove role
 references from acl rules on role deletion
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Am 04.12.24 um 16:11 schrieb Daniel Kral:
> 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>'
> 

Might be good to note that the next modification of the configuration
would drop the unknown role (even if a role with the same name is
re-added right away).

> Signed-off-by: Daniel Kral <d.kral@proxmox.com>

Just a minor nit below, otherwise:

Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
Tested-by: Fiona Ebner <f.ebner@proxmox.com>

What would be really nice is to have some tests for various
add/modify/delete sequences touching user.cfg :) I don't think current
tests cover that yet.

> ---
>  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 {

Nit: could be a private "my sub"

> +    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) = @_;
>  



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel