From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 49A171FF0A7 for ; Wed, 02 Sep 2026 12:56:18 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 22E78212EB; Wed, 02 Sep 2026 12:56:17 +0200 (CEST) Message-ID: Date: Wed, 2 Sep 2026 12:56:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH manager v2] fix #6735: api: pci: allow mdevscan access via mapping permissions. To: Elias Huhsovitz , pve-devel@lists.proxmox.com References: <20260827112525.154445-1-e.huhsovitz@proxmox.com> Content-Language: en-US From: Dominik Csapak In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788346568842 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.569 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: LYKTW5EOEHC2THZBO2VIN4DXSCTET4TU X-Message-ID-Hash: LYKTW5EOEHC2THZBO2VIN4DXSCTET4TU X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 9/2/26 10:51 AM, Elias Huhsovitz wrote: > Thanks for the feedback! Just one small stylistic question below. > > On Tue Sep 1, 2026 at 2:27 PM CEST, Dominik Csapak wrote: >> some comments inline >> > > [...] >>> + >>> + return PVE::QemuServer::PCI::Mdev::get_mdev_types($id) if ($is_pci_id); >>> + >>> + if (!$rpcenv->check_any($authuser, '/', ['Sys.Audit', 'Sys.Modify'], 1)) { >> >> isn't this just $has_global_perms again? > > Sorry, these shouldn't have been here, i formatted the wrong branch by > mistake. The check is indeeed redundant. > >>> + $rpcenv->check_any( >>> + $authuser, >>> + "/mapping/pci/$id", >>> + ['Mapping.Use', 'Mapping.Modify', 'Mapping.Audit'], >>> + ); >> >> this was also already checked? >> >> >> IMO these happen because the code flow is not very obvious. Instead >> of having a bunch of postif clauses, I'd prefer a simpler approach: >> >> >> my $id = ... >> my $rpcenv = ... >> my $authuser = ... >> >> my $has_global_perms = ... >> my $is_pci_id = ... >> >> >> if ($is_pci_id) { >> raise_perm_exc if !$has_global_perms; >> ... >> } else { >> raise_perm_exc if !$has_global_perms && !check_any(mapping_perms); >> ... >> } >> >> with such code, the existing flow and indentation stays the same, >> and it's clear which branch takes which permissions >> >> does that make sense? > > > I just have a small question here: > > Do you propse A or B: > > A: > > if ($is_pci_id) { > raise_perm_exc if !$has_global_perms; > # business logic .... > } else { > raise_perm_exc if !$has_global_perms && !check_any(mapping_perms); > # business logic ... > } > > # END OF SUBROUTINE > > B: > > if ($is_pci_id) { > raise_perm_exc if !$has_global_perms; > } else { > raise_perm_exc if !$has_global_perms && !check_any(mapping_perms); > } > > # business logic ... > > # END OF SUBROUTINE > > Becuase i prefer B. It seems much simpler to me since the permission logic and > business logic aren't intertwined. I would even like to go as far as > factoring the logic into its own subroutine, since the business logic > should be completely separate from the authorization. > > C: > > check_custom_perm($is_pci_id); > > # business logic ... > > # END OF SUBROUTINE > > > This also doesnt change the business logic, and i can keep the if-else > statement if you prefer. Actually i would prefer A, because the two branches are by definition very different (aside from one permission check), so having it split up early makes sense to me. With B and C, we at least have to duplicate one if/else (namely on the 'is it a pci id or not' and that has a good chance to diverge in the future (e.g. imagine we introduce a 3rd branch that needs again different permissions, with A this is more or less automatic since each branch needs it's own check. with B and C two different parts of the code have to argue about the same branching.