Complete customer transfers on first authenticated inventory
Rust development slice / linux (push) Failing after 8s

This commit is contained in:
2026-11-18 22:57:05 +01:00
parent 65d84a19c0
commit 480e3749a6
13 changed files with 234 additions and 76 deletions
+26 -2
View File
@@ -128,6 +128,7 @@ pub async fn list(
"device-fleet:{}",
rmm_domain::jobs::hash(binding.to_string().as_bytes())
);
let first_page = q.cursor.is_none();
let mut page = Cursor::parse(
s,
&p,
@@ -143,10 +144,15 @@ pub async fn list(
let mut last = None;
let mut truncated = false;
let mut authorized = false;
let mut principals = Vec::new();
for customer in tenants {
if page.last_tenant.is_some_and(|after| customer < after) {
continue;
}
if customer == p.tenant {
principals.push(p.clone());
continue;
}
let mut headers = h.clone();
headers.insert(
"x-rmm-tenant",
@@ -155,7 +161,25 @@ pub async fn list(
);
let current = crate::jobs::principal(s, &headers, false).await?;
crate::jobs::scope(&current, customer, false)?;
let mut tx = rmm_persistence::tenant_tx(&s.pool, customer).await?;
principals.push(current);
}
// Read all customers from the same snapshot so a transfer cannot appear
// under both customers if its cutover commits while listing the fleet.
let mut tx = s.pool.begin().await?;
sqlx::query("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY")
.execute(&mut *tx)
.await?;
if first_page {
page.as_of = sqlx::query_scalar("SELECT clock_timestamp()")
.fetch_one(&mut *tx)
.await?;
}
for current in principals {
let customer = current.tenant;
sqlx::query("SELECT set_config('app.tenant_id',$1,true)")
.bind(customer.to_string())
.execute(&mut *tx)
.await?;
match crate::permissions::require_principal(&mut tx, &current, "inventory:read").await {
Err(Error(StatusCode::FORBIDDEN, _)) if tenant.is_none() => continue,
other => other?,
@@ -179,7 +203,6 @@ pub async fn list(
.rows(&mut tx)
.await?;
let hosts = assigned_hosts(&mut tx, customer, page.as_of, &rows).await?;
tx.commit().await?;
for row in rows {
if items.len() == capacity {
truncated = true;
@@ -192,6 +215,7 @@ pub async fn list(
break;
}
}
tx.commit().await?;
if !authorized {
return Err(Error(StatusCode::FORBIDDEN, "FORBIDDEN"));
}