From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id ECFDD1FF142 for ; Fri, 22 May 2026 15:30:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C8CF7C059; Fri, 22 May 2026 15:30:42 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 22 May 2026 15:30:38 +0200 Subject: Re: [PATCH datacenter-manager v3 2/6] lib/api: add 'location-info' api call with cached information To: "Dominik Csapak" , Message-Id: X-Mailer: aerc 0.20.0 References: <20260522083412.1223719-1-d.csapak@proxmox.com> <20260522083412.1223719-8-d.csapak@proxmox.com> In-Reply-To: <20260522083412.1223719-8-d.csapak@proxmox.com> From: "Shannon Sterz" X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1779456619647 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.113 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 Message-ID-Hash: CLKD4PAND6CTIZXHYWOBXOMCQP4ZE5M5 X-Message-ID-Hash: CLKD4PAND6CTIZXHYWOBXOMCQP4ZE5M5 X-MailFrom: s.sterz@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 Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri May 22, 2026 at 10:34 AM CEST, Dominik Csapak wrote: > PVE and PBS remotes can have a location configured, and we want to query > that, so add a cache for this location info and an API call to query it. > > Modeled after the other resource api calls (status/subscription) but > lets the location info be optional since this is a relatively new > feature. > > The biggest difference is that we try to get a location at all costs, so > if there is no new enough location in the cache we try to update it. > > If that fails (e.g. because the remote is offline) we retry the cache > with unlimited 'max-age'. Otherwise there could be a situation where the > location info is so old that offline remotes won't be shown. > > Refactor some permission checks from the subscription api call so we can > reuse that. > > Signed-off-by: Dominik Csapak > --- > lib/pdm-api-types/src/lib.rs | 34 ++++++++ > server/src/api/resources.rs | 120 +++++++++++++++++++++----- > server/src/lib.rs | 1 + > server/src/location_cache.rs | 160 +++++++++++++++++++++++++++++++++++ > 4 files changed, 294 insertions(+), 21 deletions(-) > create mode 100644 server/src/location_cache.rs -->8 snip 8<-- > diff --git a/server/src/api/resources.rs b/server/src/api/resources.rs > index 1a6a23d9..9ec1ce89 100644 > --- a/server/src/api/resources.rs > +++ b/server/src/api/resources.rs > @@ -18,7 +18,7 @@ use pdm_api_types::resource::{ > use pdm_api_types::subscription::{ > NodeSubscriptionInfo, RemoteSubscriptionState, RemoteSubscriptions, = SubscriptionLevel, > }; > -use pdm_api_types::{Authid, PRIV_RESOURCE_AUDIT, VIEW_ID_SCHEMA}; > +use pdm_api_types::{Authid, CachedLocationInfo, PRIV_RESOURCE_AUDIT, VIE= W_ID_SCHEMA}; > use pdm_search::{Search, SearchTerm}; > use proxmox_access_control::CachedUserInfo; > use proxmox_router::{ > @@ -41,6 +41,10 @@ pub const ROUTER: Router =3D Router::new() > #[sortable] > const SUBDIRS: SubdirMap =3D &sorted!([ > ("list", &Router::new().get(&API_METHOD_GET_RESOURCES)), > + ( > + "location-info", > + &Router::new().get(&API_METHOD_GET_LOCATION_INFO) > + ), > ("status", &Router::new().get(&API_METHOD_GET_STATUS)), > ( > "top-entities", > @@ -214,6 +218,29 @@ impl From for RemoteResources { > } > } > > +fn check_remote_priv(user_info: &CachedUserInfo, auth_id: &Authid, remot= e: &str) -> bool { > + user_info > + .check_privs(auth_id, &["resource", remote], PRIV_RESOURCE_AUDIT= , false) > + .is_ok() > +} > + > +/// When returning true, all remotes are allowed and no per-remote permi= ssion check should be > +/// necessary > +fn check_all_remotes_allowed( > + user_info: &CachedUserInfo, > + auth_id: &Authid, > + view: Option<&str>, > +) -> Result { > + Ok(if let Some(view) =3D view { > + user_info.check_privs(auth_id, &["view", view], PRIV_RESOURCE_AU= DIT, false)?; > + false > + } else { > + user_info > + .check_privs(auth_id, &["resource"], PRIV_RESOURCE_AUDIT, fa= lse) > + .is_ok() > + }) > +} > + i wonder if these two sould eventually also take a `privilege` parameter and maybe be moved to a more central place, but nothing that needs to be done with this series. maybe even a helper that combines the `if` statements below as well, as they are almost identical. > #[api( > // FIXME:: see list-like API calls in resource routers, we probably = want more fine-grained > // checks.. > @@ -641,34 +668,16 @@ pub async fn get_subscription_status( > .parse()?; > let user_info =3D CachedUserInfo::new()?; > > - let allow_all =3D if let Some(view) =3D &view { > - user_info.check_privs(&auth_id, &["view", view], PRIV_RESOURCE_A= UDIT, false)?; > - false > - } else { > - user_info > - .check_privs(&auth_id, &["resource"], PRIV_RESOURCE_AUDIT, f= alse) > - .is_ok() > - }; > + let allow_all =3D check_all_remotes_allowed(&user_info, &auth_id, vi= ew.as_deref())?; > > let view =3D views::get_optional_view(view.as_deref())?; > > - let check_priv =3D |remote_name: &str| -> bool { > - user_info > - .check_privs( > - &auth_id, > - &["resource", remote_name], > - PRIV_RESOURCE_AUDIT, > - false, > - ) > - .is_ok() > - }; > - > for (remote_name, remote) in remotes_config { > if let Some(view) =3D &view { > if view.can_skip_remote(&remote_name) { > continue; > } > - } else if !allow_all && !check_priv(&remote_name) { > + } else if !allow_all && !check_remote_priv(&user_info, &auth_id,= &remote_name) { > continue; > } ^ these if statements here -->8 snip 8<--