mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-04 08:09:16 +00:00
feat(nsjail): make rlimit_fsize configurable per worker (NSJAIL_RLIMIT_FSIZE_MB) (#12609)
python3, ansible and dbt nsjail run configs hard-code rlimit_fsize: 1000, so a jailed job cannot write any single file larger than 1000 MiB, even with a disk-backed /tmp (nsjail_tmp_backing=disk) and plenty of worker disk. Jobs that download multi-GB files (e.g. a 1.75 GB CSV) fail, while the same job works under unshare. Add NSJAIL_RLIMIT_FSIZE_MB (worker env, read at startup): MiB, or unlimited/none/inf/0 for rlimit_fsize_type: INF. Unset keeps 1000 MiB. Reuses the rlimit_as renderer, now generic over the field name. Total space stays bounded by the /tmp tmpfs size or, when disk-backed, the worker's disk. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1fb70c4fab
commit
e6d9ff8f95
@@ -7,7 +7,7 @@ time_limit: {TIMEOUT}
|
||||
|
||||
{RLIMIT_AS}
|
||||
rlimit_cpu: 1000
|
||||
rlimit_fsize: 1000
|
||||
{RLIMIT_FSIZE}
|
||||
rlimit_nofile: 10000
|
||||
|
||||
cwd: "/tmp"
|
||||
|
||||
@@ -7,7 +7,7 @@ time_limit: {TIMEOUT}
|
||||
|
||||
{RLIMIT_AS}
|
||||
rlimit_cpu: 1000
|
||||
rlimit_fsize: 1000
|
||||
{RLIMIT_FSIZE}
|
||||
rlimit_nofile: 10000
|
||||
|
||||
cwd: "{PROJECT_DIR}"
|
||||
|
||||
@@ -7,7 +7,7 @@ time_limit: {TIMEOUT}
|
||||
|
||||
{RLIMIT_AS}
|
||||
rlimit_cpu: 1000
|
||||
rlimit_fsize: 1000
|
||||
{RLIMIT_FSIZE}
|
||||
rlimit_nofile: 10000
|
||||
|
||||
cwd: "/tmp"
|
||||
|
||||
@@ -35,14 +35,14 @@ use crate::{
|
||||
common::{
|
||||
build_command_with_isolation, check_executor_binary_exists, get_reserved_variables,
|
||||
interpolate_template, read_and_check_result, render_nsjail_rlimit_as,
|
||||
resolve_nsjail_timeout, resolve_nsjail_tmp_mount_block, start_child_process,
|
||||
transform_json, validate_relative_path, OccupancyMetrics,
|
||||
render_nsjail_rlimit_fsize, resolve_nsjail_timeout, resolve_nsjail_tmp_mount_block,
|
||||
start_child_process, transform_json, validate_relative_path, OccupancyMetrics,
|
||||
},
|
||||
handle_child::{handle_child, run_future_with_polling_update_job_poller},
|
||||
is_sandboxing_enabled,
|
||||
python_executor::{create_dependencies_dir, handle_python_reqs, uv_pip_compile},
|
||||
PyV, DISABLE_NUSER, GIT_PATH, HOME_ENV, NSJAIL_ANSIBLE_RLIMIT_AS_MB, NSJAIL_PATH, PATH_ENV,
|
||||
PROXY_ENVS, PY_INSTALL_DIR, TZ_ENV,
|
||||
PyV, DISABLE_NUSER, GIT_PATH, HOME_ENV, NSJAIL_ANSIBLE_RLIMIT_AS_MB, NSJAIL_PATH,
|
||||
NSJAIL_RLIMIT_FSIZE_MB, PATH_ENV, PROXY_ENVS, PY_INSTALL_DIR, TZ_ENV,
|
||||
};
|
||||
use windmill_common::client::AuthedClient;
|
||||
|
||||
@@ -2163,6 +2163,10 @@ mount {{
|
||||
"{RLIMIT_AS}",
|
||||
&render_nsjail_rlimit_as(NSJAIL_ANSIBLE_RLIMIT_AS_MB.as_deref(), 4096),
|
||||
)
|
||||
.replace(
|
||||
"{RLIMIT_FSIZE}",
|
||||
&render_nsjail_rlimit_fsize(NSJAIL_RLIMIT_FSIZE_MB.as_deref(), 1000),
|
||||
)
|
||||
.replace("{PY_INSTALL_DIR}", &*PY_INSTALL_DIR)
|
||||
.replace("{JOB_DIR}", job_dir)
|
||||
.replace("{CLONE_NEWUSER}", &(!*DISABLE_NUSER).to_string())
|
||||
|
||||
@@ -1457,23 +1457,37 @@ pub async fn resolve_nsjail_timeout(
|
||||
/// - `unlimited`/`none`/`inf`/`0` -> `rlimit_as_type: INF` (address space uncapped)
|
||||
/// - a positive integer (MiB) -> `rlimit_as: {n}`
|
||||
pub fn render_nsjail_rlimit_as(env_override: Option<&str>, default_mb: u32) -> String {
|
||||
render_nsjail_rlimit("rlimit_as", env_override, default_mb)
|
||||
}
|
||||
|
||||
/// Render the `rlimit_fsize` line (largest single file a jailed job may write, in
|
||||
/// MiB) for the nsjail run configs that set one (python3, ansible, dbt), honoring
|
||||
/// the `NSJAIL_RLIMIT_FSIZE_MB` env var. Same value grammar as
|
||||
/// [`render_nsjail_rlimit_as`]. The total space a job can fill is bounded
|
||||
/// separately by its `/tmp` (tmpfs size or, when disk-backed, the worker's disk),
|
||||
/// so operators who move `/tmp` to disk usually want to raise or lift this too.
|
||||
pub fn render_nsjail_rlimit_fsize(env_override: Option<&str>, default_mb: u32) -> String {
|
||||
render_nsjail_rlimit("rlimit_fsize", env_override, default_mb)
|
||||
}
|
||||
|
||||
fn render_nsjail_rlimit(field: &str, env_override: Option<&str>, default_mb: u32) -> String {
|
||||
match env_override.map(str::trim) {
|
||||
None | Some("") => format!("rlimit_as: {default_mb}"),
|
||||
None | Some("") => format!("{field}: {default_mb}"),
|
||||
Some(v)
|
||||
if v.eq_ignore_ascii_case("unlimited")
|
||||
|| v.eq_ignore_ascii_case("none")
|
||||
|| v.eq_ignore_ascii_case("inf")
|
||||
|| v == "0" =>
|
||||
{
|
||||
"rlimit_as_type: INF".to_string()
|
||||
format!("{field}_type: INF")
|
||||
}
|
||||
Some(v) => match v.parse::<u32>() {
|
||||
Ok(mb) => format!("rlimit_as: {mb}"),
|
||||
Ok(mb) => format!("{field}: {mb}"),
|
||||
Err(_) => {
|
||||
tracing::warn!(
|
||||
"Invalid nsjail rlimit_as override {v:?}, using default {default_mb}MiB"
|
||||
"Invalid nsjail {field} override {v:?}, using default {default_mb}MiB"
|
||||
);
|
||||
format!("rlimit_as: {default_mb}")
|
||||
format!("{field}: {default_mb}")
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -1668,7 +1682,7 @@ pub(crate) async fn resolve_nsjail_tmp_mount_block(job_dir: &str) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod nsjail_rlimit_as_tests {
|
||||
use super::render_nsjail_rlimit_as;
|
||||
use super::{render_nsjail_rlimit_as, render_nsjail_rlimit_fsize};
|
||||
|
||||
#[test]
|
||||
fn unset_uses_default() {
|
||||
@@ -1707,6 +1721,23 @@ mod nsjail_rlimit_as_tests {
|
||||
);
|
||||
assert_eq!(render_nsjail_rlimit_as(Some("-1"), 4096), "rlimit_as: 4096");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fsize_uses_its_own_field() {
|
||||
assert_eq!(render_nsjail_rlimit_fsize(None, 1000), "rlimit_fsize: 1000");
|
||||
assert_eq!(
|
||||
render_nsjail_rlimit_fsize(Some("20000"), 1000),
|
||||
"rlimit_fsize: 20000"
|
||||
);
|
||||
assert_eq!(
|
||||
render_nsjail_rlimit_fsize(Some("unlimited"), 1000),
|
||||
"rlimit_fsize_type: INF"
|
||||
);
|
||||
assert_eq!(
|
||||
render_nsjail_rlimit_fsize(Some("abc"), 1000),
|
||||
"rlimit_fsize: 1000"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -31,7 +31,8 @@ use windmill_parser_yaml::{
|
||||
use windmill_queue::{append_logs, CanceledBy, MiniPulledJob};
|
||||
|
||||
use crate::common::{
|
||||
render_envars, render_nsjail_rlimit_as, resolve_nsjail_timeout, resolve_nsjail_tmp_mount_block,
|
||||
render_envars, render_nsjail_rlimit_as, render_nsjail_rlimit_fsize, resolve_nsjail_timeout,
|
||||
resolve_nsjail_tmp_mount_block,
|
||||
};
|
||||
use crate::common::{start_child_process, OccupancyMetrics};
|
||||
use crate::dbt_engine::{provision_engine, ProvisionedEngine, DBT_CACHE_DIR};
|
||||
@@ -46,8 +47,8 @@ use crate::handle_child::{
|
||||
};
|
||||
use crate::worker::write_module_files;
|
||||
use crate::{
|
||||
is_sandboxing_enabled, GIT_PATH, NSJAIL_DBT_RLIMIT_AS_MB, NSJAIL_PATH, PATH_ENV, PROXY_ENVS,
|
||||
TZ_ENV,
|
||||
is_sandboxing_enabled, GIT_PATH, NSJAIL_DBT_RLIMIT_AS_MB, NSJAIL_PATH, NSJAIL_RLIMIT_FSIZE_MB,
|
||||
PATH_ENV, PROXY_ENVS, TZ_ENV,
|
||||
};
|
||||
|
||||
/// The profile name Windmill renders into `profiles.yml`. dbt takes the profile
|
||||
@@ -1372,6 +1373,10 @@ pub(crate) async fn prepare_project(
|
||||
"{RLIMIT_AS}",
|
||||
&render_nsjail_rlimit_as(NSJAIL_DBT_RLIMIT_AS_MB.as_deref(), 4096),
|
||||
)
|
||||
.replace(
|
||||
"{RLIMIT_FSIZE}",
|
||||
&render_nsjail_rlimit_fsize(NSJAIL_RLIMIT_FSIZE_MB.as_deref(), 1000),
|
||||
)
|
||||
.replace("{JOB_DIR}", &escape_textproto(job_dir))
|
||||
.replace(
|
||||
"{PROJECT_DIR}",
|
||||
|
||||
@@ -153,18 +153,18 @@ use windmill_object_store::get_cache_object_store;
|
||||
use crate::{
|
||||
check_no_network_jailed,
|
||||
common::{
|
||||
build_command_with_isolation, create_args_and_out_file, get_reserved_variables, read_file,
|
||||
read_result, render_nsjail_rlimit_as, resolve_nsjail_timeout,
|
||||
proto_str, resolve_nsjail_tmp_mount_block, start_child_process, OccupancyMetrics,
|
||||
StreamNotifier, DEV_CONF_NSJAIL,
|
||||
build_command_with_isolation, create_args_and_out_file, get_reserved_variables, proto_str,
|
||||
read_file, read_result, render_nsjail_rlimit_as, render_nsjail_rlimit_fsize,
|
||||
resolve_nsjail_timeout, resolve_nsjail_tmp_mount_block, start_child_process,
|
||||
OccupancyMetrics, StreamNotifier, DEV_CONF_NSJAIL,
|
||||
},
|
||||
get_proxy_envs_for_lang, get_run_proxy_envs,
|
||||
handle_child::handle_child,
|
||||
is_sandboxing_enabled, nsjail_clone_newnet, read_ee_registry,
|
||||
worker_utils::ping_job_status,
|
||||
PyV, DISABLE_NUSER, HOME_ENV, INDEX_CERT, NATIVE_CERT, NSJAIL_AVAILABLE, NSJAIL_PATH,
|
||||
NSJAIL_PY_RLIMIT_AS_MB, PATH_ENV, PIP_EXTRA_INDEX_URL, PIP_INDEX_URL, PROXY_ENVS,
|
||||
PY_INSTALL_DIR, TRACING_PROXY_CA_CERT_PATH, TRUSTED_HOST, TZ_ENV, UV_CACHE_DIR,
|
||||
NSJAIL_PY_RLIMIT_AS_MB, NSJAIL_RLIMIT_FSIZE_MB, PATH_ENV, PIP_EXTRA_INDEX_URL, PIP_INDEX_URL,
|
||||
PROXY_ENVS, PY_INSTALL_DIR, TRACING_PROXY_CA_CERT_PATH, TRUSTED_HOST, TZ_ENV, UV_CACHE_DIR,
|
||||
UV_EXCLUDE_NEWER, UV_HTTP_TIMEOUT, UV_INDEX_STRATEGY, UV_PYTHON_INSTALL_MIRROR,
|
||||
};
|
||||
use windmill_common::client::AuthedClient;
|
||||
@@ -1173,6 +1173,10 @@ mount {{
|
||||
"{RLIMIT_AS}",
|
||||
&render_nsjail_rlimit_as(NSJAIL_PY_RLIMIT_AS_MB.as_deref(), 4096),
|
||||
)
|
||||
.replace(
|
||||
"{RLIMIT_FSIZE}",
|
||||
&render_nsjail_rlimit_fsize(NSJAIL_RLIMIT_FSIZE_MB.as_deref(), 1000),
|
||||
)
|
||||
.replace("{JOB_DIR}", job_dir)
|
||||
.replace("{PY_INSTALL_DIR}", &*PY_INSTALL_DIR)
|
||||
.replace("{CLONE_NEWUSER}", &(!*DISABLE_NUSER).to_string())
|
||||
|
||||
@@ -397,6 +397,12 @@ lazy_static::lazy_static! {
|
||||
pub static ref NSJAIL_DBT_RLIMIT_AS_MB: Option<String> =
|
||||
std::env::var("NSJAIL_DBT_RLIMIT_AS_MB").ok();
|
||||
|
||||
/// Override for the nsjail `rlimit_fsize` cap (largest single file a jailed
|
||||
/// python3/ansible/dbt job may write). MiB, or `unlimited`/`none`/`inf`/`0` to
|
||||
/// uncap. Unset keeps the historical 1000 MiB. See `render_nsjail_rlimit_fsize`.
|
||||
pub static ref NSJAIL_RLIMIT_FSIZE_MB: Option<String> =
|
||||
std::env::var("NSJAIL_RLIMIT_FSIZE_MB").ok();
|
||||
|
||||
// pub static ref DISABLE_NSJAIL: bool = false;
|
||||
pub static ref DISABLE_NSJAIL: bool = std::env::var("DISABLE_NSJAIL")
|
||||
.ok()
|
||||
|
||||
@@ -480,7 +480,7 @@ export const settings: Record<string, Setting[]> = {
|
||||
key: 'nsjail_tmp_backing',
|
||||
fieldType: 'select',
|
||||
description:
|
||||
'How <code>/tmp</code> is backed inside the nsjail sandbox. <strong>RAM (tmpfs)</strong> is the default — fast, with a hard size cap from <em>Nsjail tmpfs size</em>, but consumes worker memory. <strong>Disk (bind mount)</strong> uses a per-job directory on the worker disk — no RAM cost, but the only remaining per-file ceiling is <code>rlimit_fsize</code> (~1GB for python/ansible, unbounded for most other languages because they set <code>disable_rl: true</code>); pair with host disk monitoring or quotas.',
|
||||
'How <code>/tmp</code> is backed inside the nsjail sandbox. <strong>RAM (tmpfs)</strong> is the default — fast, with a hard size cap from <em>Nsjail tmpfs size</em>, but consumes worker memory. <strong>Disk (bind mount)</strong> uses a per-job directory on the worker disk — no RAM cost, but the only remaining per-file ceiling is <code>rlimit_fsize</code> (1000 MiB for python/ansible/dbt, raise it per worker group with the <code>NSJAIL_RLIMIT_FSIZE_MB</code> env var; unbounded for most other languages because they set <code>disable_rl: true</code>); pair with host disk monitoring or quotas.',
|
||||
storage: 'setting',
|
||||
placeholder: 'tmpfs',
|
||||
defaultValue: () => 'tmpfs',
|
||||
|
||||
Reference in New Issue
Block a user