From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id A8A4F1FF0A7 for ; Wed, 02 Sep 2026 10:52:09 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1B79D2126F; Wed, 02 Sep 2026 10:52:09 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Sep 2026 10:51:44 +0200 Message-Id: Subject: Re: [PATCH manager v2] fix #6735: api: pci: allow mdevscan access via mapping permissions. From: "Elias Huhsovitz" To: "Dominik Csapak" , X-Mailer: aerc 0.20.0 References: <20260827112525.154445-1-e.huhsovitz@proxmox.com> In-Reply-To: X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788339101036 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.708 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: KH7STIFZ7KFTJ6OLWGJWJZSB24POLUR3 X-Message-ID-Hash: KH7STIFZ7KFTJ6OLWGJWJZSB24POLUR3 X-MailFrom: e.huhsovitz@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: 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.Modi= fy'], 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 =3D ... > my $rpcenv =3D ... > my $authuser =3D ... > > my $has_global_perms =3D ... > my $is_pci_id =3D ... > > > 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:=20 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:=20 if ($is_pci_id) { raise_perm_exc if !$has_global_perms; } else { raise_perm_exc if !$has_global_perms && !check_any(mapping_perms); } =20 # business logic ... # END OF SUBROUTINE Becuase i prefer B. It seems much simpler to me since the permission logic = and=20 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:=20 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.