mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-29 08:06:46 +00:00
fix: exempt admin hash runs and read the pause id under the lock
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c0831b2b93
commit
8aa436ea23
@@ -135,7 +135,8 @@ async fn pause_holds_and_resume_releases(db: Pool<Postgres>) -> anyhow::Result<(
|
||||
}))
|
||||
.send()
|
||||
.await?;
|
||||
assert_eq!(resp.status(), 201, "{}", resp.text().await?);
|
||||
assert_eq!(resp.status(), 201);
|
||||
let obo_hash = resp.text().await?;
|
||||
let admin_obo = job_id(
|
||||
post(format!("{ws}/jobs/run/p/u/test-user/obo_member"), ADMIN)
|
||||
.json(&json!({}))
|
||||
@@ -144,6 +145,14 @@ async fn pause_holds_and_resume_releases(db: Pool<Postgres>) -> anyhow::Result<(
|
||||
)
|
||||
.await;
|
||||
assert_eq!(kind_and_due(&db, admin_obo).await.0, "script");
|
||||
let admin_obo_hash = job_id(
|
||||
post(format!("{ws}/jobs/run/h/{obo_hash}"), ADMIN)
|
||||
.json(&json!({}))
|
||||
.send()
|
||||
.await?,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(kind_and_due(&db, admin_obo_hash).await.0, "script");
|
||||
|
||||
// A caller waiting for the result is refused rather than left waiting.
|
||||
let resp = post(
|
||||
|
||||
@@ -42,7 +42,10 @@ struct JobsPaused {
|
||||
pause_id: Uuid,
|
||||
}
|
||||
|
||||
async fn read_pause(db: &DB, w_id: &str) -> windmill_common::error::Result<Option<JobsPaused>> {
|
||||
async fn read_pause<'c, E: sqlx::PgExecutor<'c>>(
|
||||
db: E,
|
||||
w_id: &str,
|
||||
) -> windmill_common::error::Result<Option<JobsPaused>> {
|
||||
Ok(sqlx::query_as!(
|
||||
JobsPaused,
|
||||
r#"SELECT paused_until, paused_by, paused_at, reason, pause_id,
|
||||
@@ -140,6 +143,8 @@ async fn pause_jobs(
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
// Read before the commit releases the lock: a later pause would hand this one its `pause_id`.
|
||||
let pause = read_pause(&mut *tx, &w_id).await?;
|
||||
tx.commit().await?;
|
||||
job_pause::evict(&w_id);
|
||||
|
||||
@@ -149,7 +154,7 @@ async fn pause_jobs(
|
||||
};
|
||||
log_feature_usage("workspace_job_pause", "paused", source);
|
||||
|
||||
Ok(Json(read_pause(&db, &w_id).await?))
|
||||
Ok(Json(pause))
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
|
||||
@@ -10856,37 +10856,42 @@ pub async fn run_job_by_hash_inner(
|
||||
|
||||
let end_user_email = run_end_user_email(&db, &w_id, &authed, trigger.as_ref()).await?;
|
||||
let scope_ceiling = windmill_api_auth::caller_scope_ceiling(&db, &authed).await?;
|
||||
let (uuid, tx) = push(
|
||||
&db,
|
||||
tx,
|
||||
&w_id,
|
||||
job_payload,
|
||||
push_args,
|
||||
authed.display_username(),
|
||||
email,
|
||||
permissioned_as,
|
||||
authed.token_prefix.as_deref(),
|
||||
authed.username_override.as_deref(),
|
||||
scheduled_for,
|
||||
None,
|
||||
run_query.parent_job,
|
||||
None,
|
||||
run_query.root_job,
|
||||
run_query.job_id,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
!run_query.invisible_to_owner.unwrap_or(false),
|
||||
tag,
|
||||
timeout,
|
||||
None,
|
||||
None,
|
||||
push_authed.as_ref(),
|
||||
false,
|
||||
end_user_email,
|
||||
authed.trigger_or_fallback(trigger),
|
||||
run_query.suspended_mode,
|
||||
scope_ceiling.as_deref(),
|
||||
// `push` gets no `authed` for an on-behalf-of run, so it cannot see an admin started it.
|
||||
let admin_direct_obo = push_authed.is_none() && authed.is_admin && trigger.is_none();
|
||||
let (uuid, tx) = windmill_common::job_pause::exempt_if(
|
||||
admin_direct_obo,
|
||||
push(
|
||||
&db,
|
||||
tx,
|
||||
&w_id,
|
||||
job_payload,
|
||||
push_args,
|
||||
authed.display_username(),
|
||||
email,
|
||||
permissioned_as,
|
||||
authed.token_prefix.as_deref(),
|
||||
authed.username_override.as_deref(),
|
||||
scheduled_for,
|
||||
None,
|
||||
run_query.parent_job,
|
||||
None,
|
||||
run_query.root_job,
|
||||
run_query.job_id,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
!run_query.invisible_to_owner.unwrap_or(false),
|
||||
tag,
|
||||
timeout,
|
||||
None,
|
||||
None,
|
||||
push_authed.as_ref(),
|
||||
false,
|
||||
end_user_email,
|
||||
authed.trigger_or_fallback(trigger),
|
||||
run_query.suspended_mode,
|
||||
scope_ceiling.as_deref(),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
|
||||
Reference in New Issue
Block a user