diff --git a/backend/windmill-common/src/min_job_isolation.rs b/backend/windmill-common/src/min_job_isolation.rs index cb3cfa6b72..53afae8c6b 100644 --- a/backend/windmill-common/src/min_job_isolation.rs +++ b/backend/windmill-common/src/min_job_isolation.rs @@ -198,20 +198,17 @@ pub fn worker_allowed_tags(wc: &WorkerConfig, tags: &[String]) -> Vec { /// Why this worker must not run a job with `tag`, if it must not. Pulls already leave refused /// tags out; this catches the jobs handed to a worker directly, like a same-worker flow's steps, -/// which cannot be left for another worker and so fail. A job that runs `in_process` (a native -/// language, a `//native` Bun script) gets no sandbox on any worker, so it counts as `None`. -pub fn worker_refusal(wc: &WorkerConfig, tag: &str, in_process: bool) -> Option { - let mins = MIN_JOB_ISOLATION_BY_TAG.load(); - let min = min_for_tag(tag, &mins)?; - if in_process { - return (min > IsolationLevel::None).then(|| { - format!( - "Tag {tag} requires job isolation {} but this job runs inside the worker process, without isolation", - min.as_str() - ) - }); - } - let own = worker_job_isolation(wc); +/// which cannot be left for another worker and so fail. +pub fn worker_refusal(wc: &WorkerConfig, tag: &str) -> Option { + refusal( + tag, + worker_job_isolation(wc), + &MIN_JOB_ISOLATION_BY_TAG.load(), + ) +} + +fn refusal(tag: &str, own: IsolationLevel, mins: &MinJobIsolationByTag) -> Option { + let min = min_for_tag(tag, mins)?; (min > own).then(|| { format!( "Tag {tag} requires job isolation {} but this worker's isolation is {}", @@ -303,6 +300,14 @@ mod tests { assert_eq!(min("bashx"), None); assert_eq!(min("python3"), None); assert!(parse_min_job_isolation_by_tag(Some(serde_json::json!(["bash"]))).is_empty()); + assert_eq!(refusal("bash-dev", IsolationLevel::Unshare, &mins), None); + assert_eq!( + refusal("bash-ws1", IsolationLevel::Unshare, &mins).as_deref(), + Some( + "Tag bash-ws1 requires job isolation nsjail but this worker's isolation is unshare" + ) + ); + assert_eq!(refusal("python3", IsolationLevel::None, &mins), None); } #[test] diff --git a/backend/windmill-worker/src/bun_executor.rs b/backend/windmill-worker/src/bun_executor.rs index 50dfa14a5c..6da968e422 100644 --- a/backend/windmill-worker/src/bun_executor.rs +++ b/backend/windmill-worker/src/bun_executor.rs @@ -2318,16 +2318,6 @@ pub async fn handle_bun_job( None }; - if annotation.native { - if let Some(refusal) = windmill_common::min_job_isolation::worker_refusal( - &windmill_common::worker::WORKER_CONFIG.load(), - &job.tag, - true, - ) { - return Err(error::Error::ExecutionErr(refusal)); - } - } - if annotation.sandbox && NSJAIL_AVAILABLE.is_none() { return Err(error::Error::ExecutionErr( "Script has //sandbox annotation but nsjail is not available on this worker. \ diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index ddd1869580..1c78869769 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -3846,8 +3846,14 @@ pub async fn run_worker( // A job carrying a pre-run error never runs its code: it only has to be // pulled so `handle_queued_job` can fail it. Both hand-off paths below // dispatch by path and return before that check, so a job sent down them - // would run with whatever arguments survived the failure. - let fails_before_running = job.pre_run_error.is_some(); + // would run with whatever arguments survived the failure. The same holds for + // a job whose tag this worker refuses, handed to it without a pull. + let fails_before_running = job.pre_run_error.is_some() + || windmill_common::min_job_isolation::worker_refusal( + &WORKER_CONFIG.load(), + &job.tag, + ) + .is_some(); // A dedicated worker or flow runner runs every job it gets with its own // unscoped worker token, so a job with a restricted token runs here, with the // token minted for it, whichever tag brought it. @@ -4864,11 +4870,9 @@ pub async fn handle_queued_job( } } - if let Some(refusal) = windmill_common::min_job_isolation::worker_refusal( - &WORKER_CONFIG.load(), - &job.tag, - job.script_lang.is_some_and(|lang| lang.is_native()), - ) { + if let Some(refusal) = + windmill_common::min_job_isolation::worker_refusal(&WORKER_CONFIG.load(), &job.tag) + { return Err(Error::ExecutionErr(refusal)); } diff --git a/frontend/src/lib/components/instanceSettings.ts b/frontend/src/lib/components/instanceSettings.ts index bc97b7ea6d..fbe23a5944 100644 --- a/frontend/src/lib/components/instanceSettings.ts +++ b/frontend/src/lib/components/instanceSettings.ts @@ -441,7 +441,7 @@ export const settings: Record = { key: 'min_job_isolation_by_tag', fieldType: 'min_job_isolation_by_tag', description: - 'Require a minimum isolation for the jobs of a tag (none < unshare < nsjail). A worker whose isolation is below a tag\'s minimum pulls no jobs for that tag: they stay queued until a sufficiently isolated worker picks them up. A minimum also covers the tags derived from it (per-workspace, fork and dev workspace tags): any tag starting with the tag followed by -. Native-mode and dedicated workers count as none, and jobs that run inside the worker process (native languages, //native Bun scripts) fail on a tag with a minimum.This guards against a misconfigured worker group, not against a tampered worker. Learn more', + 'Require a minimum isolation for the jobs of a tag (none < unshare < nsjail). A worker whose isolation is below a tag\'s minimum pulls no jobs for that tag: they stay queued until a sufficiently isolated worker picks them up. A minimum also covers the tags derived from it (per-workspace, fork and dev workspace tags): any tag starting with the tag followed by -. Native-mode and dedicated workers count as none. The minimum decides which workers may run a tag\'s jobs, not how a job runs: native languages, //native Bun scripts and squashed loops run outside the sandbox on any worker. This guards against a misconfigured worker group, not against a tampered worker. Learn more', storage: 'setting' }, {