refactor: say who chose the path wherever a job is built from one (#12358)

* refactor: say who chose the path wherever a job is built from one

* refactor: rename SavedItem to Deployed, checked when saved

* refactor: trigger pushes are deployed, test connection named by the tester

* chore: update ee-repo-ref to bf04cefe64776cb7262f041105b6ceca2953d5f4

This commit updates the EE repository reference after PR #976 was merged in windmill-ee-private.

Previous ee-repo-ref: 2276bc7f7f711d6ef33a5133ca87e78ae0fa345a

New ee-repo-ref: bf04cefe64776cb7262f041105b6ceca2953d5f4

Automated by sync-ee-ref workflow.

---------

Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
This commit is contained in:
AlexRV12
2026-11-12 07:16:25 +01:00
committed by GitHub
co-authored by windmill-internal-app[bot]
parent 1583207af7
commit d78bc9b026
18 changed files with 127 additions and 28 deletions
+1 -1
View File
@@ -1 +1 @@
3ad072124c3682e282829dd7213e42a6e28cf1fa
bf04cefe64776cb7262f041105b6ceca2953d5f4
+1
View File
@@ -125,6 +125,7 @@ async fn trigger_args_lose_every_reserved_control_key(db: Pool<Postgres>) -> any
None,
None,
trigger_authed(),
windmill_common::jobs::ChosenBy::Deployed,
"test-workspace",
&windmill_common::runnable_ref::RunnableRef::from_path(SCRIPT_PATH, false)?,
args,
+1
View File
@@ -53,6 +53,7 @@ async fn hub_target_with_retry_runs_its_preprocessor(db: Pool<Postgres>) -> anyh
is_admin: true,
..Default::default()
},
windmill_common::jobs::ChosenBy::Deployed,
"test-workspace",
&windmill_common::runnable_ref::RunnableRef::from_path(
&format!("hub/{version}/test/pre"),
+3 -1
View File
@@ -37,7 +37,7 @@ use windmill_common::{
get_latest_flow_version_info_for_path,
jobs::{
check_tag_available_for_workspace_internal, format_result, script_path_to_payload,
JobPayload,
ChosenBy, JobPayload,
},
runnable_ref::RunnableRef,
triggers::TriggerMetadata,
@@ -1242,6 +1242,7 @@ pub async fn push_flow_job_by_path_into_queue<'c>(
pub async fn push_script_job_by_path_into_queue<'c>(
authed: ApiAuthed,
chosen_by: ChosenBy,
db: DB,
tx_o: Option<sqlx::Transaction<'c, sqlx::Postgres>>,
user_db: UserDB,
@@ -1267,6 +1268,7 @@ pub async fn push_script_job_by_path_into_queue<'c>(
let (job_payload, tag, delete_after_use, delete_after_secs, timeout, on_behalf_of) =
script_path_to_payload(
script,
chosen_by.origin(authed.to_authed_ref()),
Some(userdb_authed),
db.clone(),
&w_id,
+20 -2
View File
@@ -68,6 +68,7 @@ use windmill_common::{
jobs::{
normalize_nul_in_args, resolve_delete_after_secs, runnable_ref_to_payload,
sanitize_untrusted_args, schedule_job_deletion, JobPayload, JobTriggerKind, RawCode,
RunOrigin,
},
runnable_ref::RunnableRef,
scripts::ScriptLang,
@@ -4659,6 +4660,9 @@ async fn execute_component(
// tag from the deployed policy and ignore the request body.
let is_preview = payload.force_viewer_static_fields.is_some();
let is_inline = payload.raw_code.is_some();
// Whether the caller, rather than the deployed app, chose `payload.path`: always in preview,
// and in run mode when a Viewer app falls back to a runnable its policy does not declare.
let mut caller_named_path = is_preview;
// Preview mode runs request-supplied code as a `Viewer`-mode job (the
// app-editor equivalent of `/jobs/run/preview`), so it enforces the same
@@ -4926,7 +4930,10 @@ async fn execute_component(
triggerables_v2.get(&format!("{}:{p}", payload.component))
})
})
.or(Some(&policy_triggerables_default)),
.or_else(|| {
caller_named_path = true;
Some(&policy_triggerables_default)
}),
_ => None,
})
.ok_or_else(|| Error::BadRequest(format!("Path {path} forbidden by policy")))?;
@@ -5161,7 +5168,18 @@ async fn execute_component(
)
}
// flow or script:
(Some(runnable), None, None) => runnable_ref_to_payload(&runnable, &db, &w_id).await?,
(Some(runnable), None, None) => {
let origin = match opt_authed.as_ref() {
Some(viewer) if caller_named_path => RunOrigin::NamedBy(viewer.to_authed_ref()),
None if caller_named_path => {
return Err(Error::NotAuthorized(
"Required to be authed in viewer mode".to_string(),
))
}
_ => RunOrigin::Deployed,
};
runnable_ref_to_payload(&runnable, origin, &db, &w_id).await?
}
// inline script: "preview" mode, or run mode without an entry in the
// `app_script` table (legacy `rawscript/<sha>`-keyed triggerables).
(None, Some(raw_code), None) => {
+9 -1
View File
@@ -117,7 +117,8 @@ use windmill_common::{
Suspend,
},
jobs::{
script_path_to_payload, CompletedJob, JobKind, JobPayload, OnBehalfOf, QueuedJob, RawCode,
script_path_to_payload, ChosenBy, CompletedJob, JobKind, JobPayload, OnBehalfOf, QueuedJob,
RawCode, RunOrigin,
},
oauth2::HmacSha256,
query_builders,
@@ -7138,6 +7139,7 @@ async fn batch_rerun_handle_job(
match RunnableRef::from_path(&job.script_path, false) {
Ok(script) => push_script_job_by_path_into_queue(
authed.clone(),
ChosenBy::Caller,
db.clone(),
None,
user_db.clone(),
@@ -7725,6 +7727,7 @@ pub async fn run_script_by_path(
let (uuid, _, _) = push_script_job_by_path_into_queue(
authed,
ChosenBy::Caller,
db,
None,
user_db,
@@ -7940,6 +7943,7 @@ pub async fn run_workflow_as_code(
let script = RunnableRef::from_path(job.script_path(), false)?;
script_path_to_payload(
&script,
RunOrigin::Deployed,
Some(userdb_authed),
db.clone(),
&w_id,
@@ -8273,6 +8277,7 @@ pub async fn run_wait_result_job_by_path_get(
let (job_payload, tag, delete_after_use, delete_after_secs, timeout, on_behalf_authed) =
script_path_to_payload(
&script,
RunOrigin::NamedBy(authed.to_authed_ref()),
Some(user_db_with_authed),
db.clone(),
&w_id,
@@ -8425,6 +8430,7 @@ pub async fn run_wait_result_script_by_path_internal(
let (job_payload, tag, delete_after_use, delete_after_secs, timeout, on_behalf_of) =
script_path_to_payload(
script,
RunOrigin::NamedBy(authed.to_authed_ref()),
Some(db_authed),
db.clone(),
&w_id,
@@ -8790,6 +8796,7 @@ pub async fn stream_job(
RunnableId::ScriptId(ScriptId::ScriptPath(script)) | RunnableId::HubScript(script) => {
let (uuid, _, _) = push_script_job_by_path_into_queue(
authed.clone(),
ChosenBy::Caller,
db.clone(),
None,
user_db,
@@ -10639,6 +10646,7 @@ async fn run_dynamic_select(
let (uuid, _, _) = push_script_job_by_path_into_queue(
authed.clone(),
ChosenBy::Caller,
db.clone(),
None,
user_db.clone(),
@@ -26,7 +26,7 @@ use windmill_common::{
db::UserDB,
error::{Error, Result},
global_settings::HTTP_ROUTE_DEFAULT_ALLOWED_ORIGINS,
jobs::JobTriggerKind,
jobs::{ChosenBy, JobTriggerKind},
runnable_ref::RunnableRef,
triggers::{TriggerKind, TriggerMetadata},
utils::{not_found_if_none, StripPath},
@@ -773,6 +773,7 @@ async fn route_job(
&db,
Some(user_db),
authed,
ChosenBy::Deployed,
&trigger.workspace_id,
&runnable,
args,
@@ -806,6 +807,7 @@ async fn route_job(
None,
Some(user_db.clone()),
authed.clone(),
ChosenBy::Deployed,
&trigger.workspace_id,
&runnable,
args,
@@ -868,6 +870,7 @@ async fn route_job(
&db,
Some(user_db),
authed,
ChosenBy::Deployed,
&trigger.workspace_id,
&runnable,
args,
@@ -885,6 +888,7 @@ async fn route_job(
&db,
Some(user_db),
authed,
ChosenBy::Deployed,
&trigger.workspace_id,
&runnable,
args,
+32 -1
View File
@@ -148,8 +148,38 @@ pub fn resolve_delete_after_secs(
}
}
/// Who chose the path a job is resolved from. Deliberately has no default: every caller must say
/// which it is.
pub enum RunOrigin<'a> {
/// The person who chose the path, whose rights it is held to; usually, not always, the
/// identity the job runs as (a preview on behalf of another user, a run-as script).
NamedBy(AuthedRef<'a>),
/// The path is read from a row whose write was checked when it was saved, so it is not
/// re-checked here. Choose it only when that save-time check exists.
Deployed,
}
/// [`RunOrigin`] for a function that is handed the identity of the person who would have named
/// the path: `Caller` resolves to `NamedBy` that identity. Never pass `Caller` with an identity
/// other than that person's (a trigger's run-as user).
#[derive(Clone, Copy)]
pub enum ChosenBy {
Caller,
Deployed,
}
impl ChosenBy {
pub fn origin<'a>(self, caller: AuthedRef<'a>) -> RunOrigin<'a> {
match self {
ChosenBy::Caller => RunOrigin::NamedBy(caller),
ChosenBy::Deployed => RunOrigin::Deployed,
}
}
}
pub async fn script_path_to_payload<'e>(
script: &RunnableRef,
_origin: RunOrigin<'_>,
db_authed: Option<UserDbWithAuthed<'e, AuthedRef<'e>>>,
db: DB,
w_id: &str,
@@ -247,11 +277,12 @@ pub async fn script_path_to_payload<'e>(
pub async fn runnable_ref_to_payload(
runnable: &RunnableRef,
origin: RunOrigin<'_>,
db: &DB,
w_id: &str,
) -> Result<(JobPayload, Option<String>, Option<OnBehalfOf>), Error> {
let (payload, tag, _, _, _, on_behalf_of) = if !runnable.is_flow() {
script_path_to_payload(runnable, None, db.clone(), w_id, Some(true)).await?
script_path_to_payload(runnable, origin, None, db.clone(), w_id, Some(true)).await?
} else {
let path = runnable.path().to_string();
if let Some(hub_id) = runnable.hub_id() {
+5 -4
View File
@@ -75,7 +75,7 @@ use windmill_common::{
add_virtual_items_if_necessary, FlowModule, FlowModuleValue, FlowValue, InputTransform,
Retry, StopAfterIf,
},
jobs::{runnable_ref_to_payload, JobKind, JobPayload, RawCode},
jobs::{runnable_ref_to_payload, JobKind, JobPayload, RawCode, RunOrigin},
min_version::{MIN_VERSION_IS_AT_LEAST_1_432, MIN_VERSION_IS_AT_LEAST_1_440},
runnable_ref::RunnableRef,
schedule::Schedule,
@@ -798,7 +798,7 @@ async fn restart_perpetual_runs_at_path(
// run, below.
let script = RunnableRef::from_path(script_path, false)?;
let (mut payload, tag, _, _, timeout, on_behalf_of) =
script_path_to_payload(&script, None, db.clone(), w_id, None).await?;
script_path_to_payload(&script, RunOrigin::Deployed, None, db.clone(), w_id, None).await?;
// A replacement continues a loop rather than answering a trigger, and every perpetual restart
// is pushed without debouncing for that reason. Deployed settings here would debounce the
// loops at this path against each other and collapse those that share arguments into one.
@@ -3572,7 +3572,7 @@ pub async fn push_error_handler<'a, 'c, T: Serialize + Send + Sync>(
w_id
};
let (payload, tag, on_behalf_of) =
runnable_ref_to_payload(on_failure, db, handler_w_id).await?;
runnable_ref_to_payload(on_failure, RunOrigin::Deployed, db, handler_w_id).await?;
let mut extra = HashMap::new();
if let Some(schedule_path) = schedule_path {
@@ -3766,7 +3766,8 @@ pub async fn push_success_handler<'a, 'c, T: Serialize + Send + Sync>(
email: &str,
priority: Option<i16>,
) -> windmill_common::error::Result<Uuid> {
let (payload, tag, on_behalf_of) = runnable_ref_to_payload(on_success, db, w_id).await?;
let (payload, tag, on_behalf_of) =
runnable_ref_to_payload(on_success, RunOrigin::Deployed, db, w_id).await?;
let mut extra = HashMap::new();
if let Some(schedule_path) = schedule_path {
@@ -12,7 +12,7 @@ use std::collections::{HashMap, HashSet};
use serde_json::value::RawValue;
use sqlx::types::Json;
use windmill_common::jobs::runnable_ref_to_payload;
use windmill_common::jobs::{runnable_ref_to_payload, RunOrigin};
use windmill_common::runnable_ref::RunnableRef;
use windmill_common::utils::{report_critical_error, report_recovered_critical_error};
use windmill_common::DB;
@@ -123,15 +123,17 @@ async fn dispatch_expiring_variables_inner(db: &DB) {
) {
(Some(error), _) => Err(error.clone()),
(None, Err(e)) => Err(format!("{e:#}")),
(None, Ok(handler)) => runnable_ref_to_payload(&handler, db, &row.workspace_id)
.await
.map_err(|e| {
let error = format!("{e:#}");
if handler.path().starts_with("hub/") {
failed_hub_handlers.insert(row.handler_path.clone(), error.clone());
}
error
}),
(None, Ok(handler)) => {
runnable_ref_to_payload(&handler, RunOrigin::Deployed, db, &row.workspace_id)
.await
.map_err(|e| {
let error = format!("{e:#}");
if handler.path().starts_with("hub/") {
failed_hub_handlers.insert(row.handler_path.clone(), error.clone());
}
error
})
}
};
let handler = match handler {
Ok(handler) => handler,
@@ -9,6 +9,7 @@ use windmill_common::DB;
use windmill_common::{
db::UserDB,
error::{Error, Result},
jobs::ChosenBy,
runnable_ref::RunnableRef,
worker::to_raw_value,
};
@@ -318,6 +319,7 @@ impl TriggerCrud for WebsocketTrigger {
&runnable?,
&db,
authed.clone(),
ChosenBy::Caller,
config.url_runnable_args.as_ref().map(to_raw_value).as_ref(),
&workspace_id,
)
@@ -6,7 +6,7 @@ use sqlx::{types::Json as SqlxJson, FromRow};
use windmill_api_auth::ApiAuthed;
use windmill_common::{
error::{Error, Result},
jobs::JobTriggerKind,
jobs::{ChosenBy, JobTriggerKind},
runnable_ref::RunnableRef,
triggers::{TriggerKind, TriggerMetadata},
worker::to_raw_value,
@@ -195,6 +195,7 @@ pub async fn get_url_from_runnable_value(
runnable: &RunnableRef,
db: &DB,
authed: ApiAuthed,
chosen_by: ChosenBy,
args: Option<&Box<RawValue>>,
workspace_id: &str,
) -> Result<String> {
@@ -210,6 +211,7 @@ pub async fn get_url_from_runnable_value(
db,
None,
authed,
chosen_by,
workspace_id,
runnable,
PushArgsOwned { args, extra: None },
@@ -19,7 +19,7 @@ use tokio_tungstenite::{tungstenite, tungstenite::Message, MaybeTlsStream, WebSo
use windmill_common::ssrf::SsrfValidationError;
use windmill_common::{
error::{to_anyhow, Error, Result},
jobs::JobTriggerKind,
jobs::{ChosenBy, JobTriggerKind},
runnable_ref::RunnableRef,
triggers::TriggerMetadata,
utils::report_critical_error,
@@ -103,6 +103,7 @@ async fn connect_once(
&runnable,
db,
authed,
ChosenBy::Deployed,
args,
&listening_trigger.workspace_id,
)
@@ -246,6 +247,7 @@ async fn send_initial_messages(
db,
None,
authed.clone(),
ChosenBy::Deployed,
&listening_trigger.workspace_id,
&RunnableRef::from_path(&path, is_flow)?,
PushArgsOwned { args, extra: None },
@@ -561,6 +563,7 @@ impl Listener for WebsocketTrigger {
db,
None,
authed,
ChosenBy::Deployed,
&workspace_id,
&runnable,
args,
@@ -591,6 +594,7 @@ impl Listener for WebsocketTrigger {
&db_,
None,
authed,
ChosenBy::Deployed,
&w_id,
&runnable,
args,
@@ -15,7 +15,7 @@ use windmill_common::{
db::{UserDB, DB},
error::{self, Error, Result},
feature_usage::log_feature_usage,
jobs::{delete_jobs, JobTriggerKind},
jobs::{delete_jobs, ChosenBy, JobTriggerKind},
triggers::TriggerMetadata,
};
@@ -220,6 +220,7 @@ pub async fn resume_suspended_trigger_jobs(
Some(tx),
Some(user_db.clone()),
authed.clone(),
ChosenBy::Deployed,
&w_id,
&windmill_common::runnable_ref::RunnableRef::from_path(
&trigger.script_path,
+2 -1
View File
@@ -18,7 +18,7 @@ use tokio::sync::RwLock;
use windmill_api_auth::ApiAuthed;
use windmill_common::{
error::{Error, Result},
jobs::JobTriggerKind,
jobs::{ChosenBy, JobTriggerKind},
runnable_ref::RunnableRef,
triggers::{TriggerKind, TriggerMetadata},
utils::{report_critical_error, report_recovered_critical_error},
@@ -566,6 +566,7 @@ pub trait Listener: TriggerCrud + TriggerJobArgs {
db,
None,
authed,
ChosenBy::Deployed,
&listening_trigger.workspace_id,
&runnable,
args,
@@ -12,7 +12,9 @@ use windmill_common::{
error::Result,
flows::{FlowModuleValue, Retry},
get_latest_deployed_hash_for_path, get_latest_flow_version_info_for_path,
jobs::{get_has_preprocessor_from_content_and_lang, script_path_to_payload, JobPayload},
jobs::{
get_has_preprocessor_from_content_and_lang, script_path_to_payload, ChosenBy, JobPayload,
},
runnable_ref::RunnableRef,
scripts::{get_full_hub_script_by_id, ScriptHash, ScriptLang},
triggers::{
@@ -507,6 +509,7 @@ pub async fn trigger_runnable_inner<'c>(
tx_o: Option<sqlx::Transaction<'c, sqlx::Postgres>>,
user_db: Option<UserDB>,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
runnable: &RunnableRef,
mut args: PushArgsOwned,
@@ -569,6 +572,7 @@ pub async fn trigger_runnable_inner<'c>(
tx_o,
user_db,
authed,
chosen_by,
workspace_id,
runnable,
args,
@@ -598,6 +602,7 @@ pub async fn trigger_runnable(
db: &DB,
user_db: Option<UserDB>,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
runnable: &RunnableRef,
args: PushArgsOwned,
@@ -614,6 +619,7 @@ pub async fn trigger_runnable(
None,
user_db,
authed,
chosen_by,
workspace_id,
runnable,
args,
@@ -635,6 +641,7 @@ pub async fn trigger_runnable_and_wait_for_result(
db: &DB,
user_db: Option<UserDB>,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
runnable: &RunnableRef,
args: PushArgsOwned,
@@ -650,6 +657,7 @@ pub async fn trigger_runnable_and_wait_for_result(
None,
user_db,
authed,
chosen_by,
workspace_id,
runnable,
args,
@@ -686,6 +694,7 @@ pub async fn trigger_runnable_and_wait_for_raw_result(
db: &DB,
user_db: Option<UserDB>,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
runnable: &RunnableRef,
args: PushArgsOwned,
@@ -699,6 +708,7 @@ pub async fn trigger_runnable_and_wait_for_raw_result(
db,
user_db,
authed,
chosen_by,
workspace_id,
runnable,
args,
@@ -716,6 +726,7 @@ async fn trigger_runnable_and_wait_for_job(
db: &DB,
user_db: Option<UserDB>,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
runnable: &RunnableRef,
args: PushArgsOwned,
@@ -731,6 +742,7 @@ async fn trigger_runnable_and_wait_for_job(
None,
user_db,
authed,
chosen_by,
workspace_id,
runnable,
args,
@@ -775,6 +787,7 @@ pub async fn trigger_runnable_and_wait_for_raw_result_with_error_ctx(
db: &DB,
user_db: Option<UserDB>,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
runnable: &RunnableRef,
args: PushArgsOwned,
@@ -788,6 +801,7 @@ pub async fn trigger_runnable_and_wait_for_raw_result_with_error_ctx(
db,
user_db,
authed,
chosen_by,
workspace_id,
runnable,
args,
@@ -816,6 +830,7 @@ async fn trigger_script_internal<'c>(
tx_o: Option<sqlx::Transaction<'c, sqlx::Postgres>>,
user_db: UserDB,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
script: &RunnableRef,
args: PushArgsOwned,
@@ -835,6 +850,7 @@ async fn trigger_script_internal<'c>(
let run_query = RunJobQuery { job_id, suspended_mode, ..Default::default() };
let (uuid, resolved_delete_secs, tx_out) = push_script_job_by_path_into_queue(
authed,
chosen_by,
db.clone(),
tx_o,
user_db,
@@ -852,6 +868,7 @@ async fn trigger_script_internal<'c>(
tx_o,
user_db,
authed,
chosen_by,
workspace_id,
script,
args,
@@ -873,6 +890,7 @@ async fn trigger_script_with_retry_and_error_handler<'c>(
tx_o: Option<sqlx::Transaction<'c, sqlx::Postgres>>,
user_db: UserDB,
authed: ApiAuthed,
chosen_by: ChosenBy,
workspace_id: &str,
script: &RunnableRef,
args: PushArgsOwned,
@@ -904,6 +922,7 @@ async fn trigger_script_with_retry_and_error_handler<'c>(
let db_authed = UserDbWithAuthed { db: user_db.clone(), authed: &authed.to_authed_ref() };
script_path_to_payload(
script,
chosen_by.origin(authed.to_authed_ref()),
Some(db_authed),
db.clone(),
&workspace_id,
+2 -1
View File
@@ -3516,7 +3516,7 @@ pub async fn handle_wac_v2_output(
};
use serde_json::Value;
use windmill_common::get_latest_flow_version_info_for_path;
use windmill_common::jobs::{script_path_to_payload, JobKind, JobPayload, RawCode};
use windmill_common::jobs::{script_path_to_payload, JobKind, JobPayload, RawCode, RunOrigin};
use windmill_common::runnable_ref::RunnableRef;
use windmill_common::runnable_settings::{
ConcurrencySettings, ConcurrencySettingsWithCustom, DebouncingSettings,
@@ -3797,6 +3797,7 @@ pub async fn handle_wac_v2_output(
// Resolve script path to job payload (handles hash, lang, etc.)
let (payload, _, _, _, _, on_behalf_of) = script_path_to_payload(
&script,
RunOrigin::Deployed,
None, // no authed db for background workers
db.clone(),
&job.workspace_id,
+2 -1
View File
@@ -44,7 +44,7 @@ use windmill_common::flow_status::{
};
use windmill_common::flows::{add_virtual_items_if_necessary, Branch, FlowNodeId, StopAfterIf};
use windmill_common::jobs::{
script_path_to_payload, JobKind, JobPayload, OnBehalfOf, RawCode, TriggerKindLabel,
script_path_to_payload, JobKind, JobPayload, OnBehalfOf, RawCode, RunOrigin, TriggerKindLabel,
ENTRYPOINT_OVERRIDE,
};
use windmill_common::runnable_ref::RunnableRef;
@@ -7005,6 +7005,7 @@ pub async fn script_to_payload(
let (jp, tag, delete_after_use, delete_after_secs, script_timeout, on_behalf_of) =
script_path_to_payload(
&script,
RunOrigin::Deployed,
None,
db.clone(),
&flow_job.workspace_id,