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 0ADFE1FF16B for ; Fri, 10 Oct 2025 13:12:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 192E6125BA; Fri, 10 Oct 2025 13:12:09 +0200 (CEST) Mime-Version: 1.0 Date: Fri, 10 Oct 2025 13:11:35 +0200 Message-Id: To: "Shan Shaji" X-Mailer: aerc 0.20.0 References: <20251010105518.18543-1-s.shaji@proxmox.com> In-Reply-To: <20251010105518.18543-1-s.shaji@proxmox.com> From: "Shannon Sterz" X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760094662683 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.054 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 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [resources.rs] Subject: Re: [pdm-devel] [PATCH datacenter-manager v3] fix #6794: api: allow non-root users to view stats on dashboard 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 Cc: 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" On Fri Oct 10, 2025 at 12:55 PM CEST, Shan Shaji wrote: > When a non-root user logged into PDM, the Top Entities section was > not visible, even though the required privileges had been assigned. > > To fix it allow all authenticated users to access the `/top-entities` > endpoint. The returned top entities will be filtered by the user's > permission on what resources they have access to. > > Signed-off-by: Shan Shaji > --- > changes since v2: Thanks @Shannon Sterz > - changed PRIV_RESOURCE_AUDIT to Resource.Audit in the access > description. > > changes since v1: Thanks @Shannon Sterz > - Updated commit message. > - Added access description. > - Replaced `UNAUTHORIZED` with `FORBIDDEN`. > - Removed "FIXME" comment. > > server/src/api/resources.rs | 27 +++++++++++++++++--- > server/src/metric_collection/top_entities.rs | 5 ++++ > 2 files changed, 29 insertions(+), 3 deletions(-) > > diff --git a/server/src/api/resources.rs b/server/src/api/resources.rs > index a7c3881..f4f56bc 100644 > --- a/server/src/api/resources.rs > +++ b/server/src/api/resources.rs > @@ -480,7 +480,6 @@ pub async fn get_subscription_status( > } > > // FIXME: make timeframe and count parameters? > -// FIXME: permissions? > #[api( > input: { > properties: { > @@ -490,13 +489,35 @@ pub async fn get_subscription_status( > } > } > }, > + access: { > + permission: &Permission::Anybody, > + description: "The user needs to have at least `Resource.Audit` on one resources under `/resource`. > + Only resources for which the user has `Resource.Audit` on `/resource/{remote_name}` will be > + considered when calculating the top entities." > + }, > )] > /// Returns the top X entities regarding the chosen type > -async fn get_top_entities(timeframe: Option) -> Result { > +async fn get_top_entities( > + timeframe: Option, > + rpcenv: &mut dyn RpcEnvironment, > +) -> Result { > + 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.any_privs_below(&auth_id, &["resource"], PRIV_RESOURCE_AUDIT)? { > + http_bail!(FORBIDDEN, "user has no access to resources"); > + } > + > let (remotes_config, _) = pdm_config::remotes::config()?; > + let check_remote_privs = |remote_name: &str| { > + user_info.lookup_privs(&auth_id, &["resource", remote_name]) & PRIV_RESOURCE_AUDIT != 0 > + }; > > let timeframe = timeframe.unwrap_or(RrdTimeframe::Day); > - let res = top_entities::calculate_top(&remotes_config, timeframe, 10); > + let res = top_entities::calculate_top(&remotes_config, timeframe, 10, check_remote_privs); > Ok(res) > } > > diff --git a/server/src/metric_collection/top_entities.rs b/server/src/metric_collection/top_entities.rs > index 47fda24..990189a 100644 > --- a/server/src/metric_collection/top_entities.rs > +++ b/server/src/metric_collection/top_entities.rs > @@ -36,12 +36,17 @@ pub fn calculate_top( > remotes: &HashMap, > timeframe: proxmox_rrd_api_types::RrdTimeframe, > num: usize, > + check_remote_privs: impl Fn(&str) -> bool > ) -> TopEntities { > let mut guest_cpu = Vec::new(); > let mut node_cpu = Vec::new(); > let mut node_memory = Vec::new(); > > for remote_name in remotes.keys() { > + if !check_remote_privs(remote_name) { > + continue; > + } > + > if let Some(data) = > crate::api::resources::get_cached_resources(remote_name, i64::MAX as u64) > { alright, thanks for incorporating my last notes there. looks good now, consider this: Reviewed-by: Shannon Sterz _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel