From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 445F41FF179 for ; Wed, 12 Nov 2025 14:20:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 19D6733FE; Wed, 12 Nov 2025 14:20:55 +0100 (CET) From: Gabriel Goller To: pdm-devel@lists.proxmox.com Date: Wed, 12 Nov 2025 14:20:25 +0100 Message-ID: <20251112132045.165444-9-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251112132045.165444-1-g.goller@proxmox.com> References: <20251112132045.165444-1-g.goller@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762953625281 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.003 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 8/9] api: add permissions for ip-vrf and mac-vrf endpoints X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" The ip-vrf and mac-vrf endpoints expose EVPN zone and vnet information but currently lack access control. Add permission checks that require Audit privileges on the respective zone or vnet. Signed-off-by: Gabriel Goller --- server/src/api/nodes/sdn.rs | 52 +++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/server/src/api/nodes/sdn.rs b/server/src/api/nodes/sdn.rs index 065ebe07846e..ee857ea9eee9 100644 --- a/server/src/api/nodes/sdn.rs +++ b/server/src/api/nodes/sdn.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Error}; +use anyhow::{anyhow, format_err, Error}; use http::StatusCode; use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, sdn::SDN_ID_SCHEMA, NODE_SCHEMA}; @@ -9,6 +9,10 @@ use pve_api_types::{SdnVnetMacVrf, SdnZoneIpVrf}; use crate::api::pve::{connect, get_remote}; mod zones { + use pdm_api_types::{Authid, PRIV_RESOURCE_AUDIT}; + use proxmox_access_control::CachedUserInfo; + use proxmox_router::{http_bail, Permission, RpcEnvironment}; + use super::*; const ZONE_SUBDIRS: SubdirMap = &[("ip-vrf", &Router::new().get(&API_METHOD_GET_IP_VRF))]; @@ -28,13 +32,33 @@ mod zones { }, }, returns: { type: SdnZoneIpVrf }, + access: { + permission: &Permission::Anybody, + description: "The user needs to have at least the `Resource.Audit` privilege on + `/resource/{remote}/sdn/zone/{zone}`." + } )] /// Get the IP-VRF for an EVPN zone for a node on a given remote async fn get_ip_vrf( remote: String, node: String, zone: String, + rpcenv: &mut dyn RpcEnvironment, ) -> Result, Error> { + let user_info = CachedUserInfo::new()?; + + let auth_id: Authid = rpcenv + .get_auth_id() + .ok_or_else(|| format_err!("no authid available"))? + .parse()?; + + if user_info.lookup_privs(&auth_id, &["resource", &remote, "sdn", "zone", &zone]) + & PRIV_RESOURCE_AUDIT + == 0 + { + http_bail!(FORBIDDEN, "user has no access to {remote}/sdn/zone/{zone}"); + } + let (remote_config, _) = pdm_config::remotes::config()?; let remote = get_remote(&remote_config, &remote)?; let client = connect(remote)?; @@ -52,6 +76,10 @@ mod zones { } mod vnets { + use pdm_api_types::{Authid, PRIV_RESOURCE_AUDIT}; + use proxmox_access_control::CachedUserInfo; + use proxmox_router::{http_bail, Permission, RpcEnvironment}; + use super::*; const VNET_SUBDIRS: SubdirMap = &[("mac-vrf", &Router::new().get(&API_METHOD_GET_MAC_VRF))]; @@ -71,16 +99,36 @@ mod vnets { }, }, returns: { type: SdnVnetMacVrf }, + access: { + permission: &Permission::Anybody, + description: "The user needs to have at least the `Resource.Audit` privilege on + `/resource/{remote}/sdn/vnet/{vnet}`." + } )] /// Get the MAC-VRF for an EVPN vnet for a node on a given remote async fn get_mac_vrf( remote: String, node: String, vnet: String, + rpcenv: &mut dyn RpcEnvironment, ) -> Result, Error> { + let user_info = CachedUserInfo::new()?; + + let auth_id: Authid = rpcenv + .get_auth_id() + .ok_or_else(|| format_err!("no authid available"))? + .parse()?; + + if user_info.lookup_privs(&auth_id, &["resource", &remote, "sdn", "vnet", &vnet]) + & PRIV_RESOURCE_AUDIT + == 0 + { + http_bail!(FORBIDDEN, "user has no access to {remote}/sdn/vnet/{vnet}"); + } + let (remote_config, _) = pdm_config::remotes::config()?; let remote = get_remote(&remote_config, &remote)?; - let client = connect(&remote)?; + let client = connect(remote)?; client .get_vnet_mac_vrf(&node, &vnet) -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel