From d4172c05b600c1c876734e038414ea3a7cf3f0cf Mon Sep 17 00:00:00 2001 From: balatoth Date: Wed, 14 Oct 2026 14:09:07 +0200 Subject: [PATCH 1/4] fix linux sandbox identity execution Co-authored-by: Cursor --- crates/axis-sandbox/src/linux/identity.rs | 51 ++++++++++++++++++++++- crates/axis-sandbox/src/linux/mod.rs | 15 +++---- crates/axis-sandbox/src/linux/mxc.rs | 18 ++++---- crates/axis-sandbox/src/linux/seccomp.rs | 2 + 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/crates/axis-sandbox/src/linux/identity.rs b/crates/axis-sandbox/src/linux/identity.rs index cf65a70..8530ebf 100644 --- a/crates/axis-sandbox/src/linux/identity.rs +++ b/crates/axis-sandbox/src/linux/identity.rs @@ -10,6 +10,12 @@ use std::os::unix::io::RawFd; use std::path::{Component, Path, PathBuf}; const SANDBOX_TMPDIR_NAME: &str = ".axis-tmp"; +const CAP_SETGID: u32 = 6; +const CAP_SETUID: u32 = 7; + +const fn identity_switch_capabilities() -> u64 { + (1_u64 << CAP_SETGID) | (1_u64 << CAP_SETUID) +} #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct ResolvedIdentity { @@ -61,6 +67,7 @@ struct ProcessIds { real_gid: u32, effective_gid: u32, saved_gid: u32, + effective_capabilities: u64, } impl ProcessIds { @@ -105,7 +112,10 @@ fn resolve_run_as_user_with_process_ids( )); } - if process_ids.effective_uid != 0 { + let required_capabilities = identity_switch_capabilities(); + if process_ids.effective_uid != 0 + && process_ids.effective_capabilities & required_capabilities != required_capabilities + { return Err(format!( "run_as_user '{username}' requires root or equivalent setuid capability; current effective UID is {}", process_ids.effective_uid @@ -152,6 +162,17 @@ fn current_process_ids() -> Result { std::io::Error::last_os_error() )); } + let status = std::fs::read_to_string("/proc/self/status") + .map_err(|error| format!("cannot inspect process capabilities: {error}"))?; + let effective_capabilities = status + .lines() + .find_map(|line| line.strip_prefix("CapEff:")) + .map(str::trim) + .ok_or_else(|| "cannot inspect process capabilities: CapEff is missing".to_string()) + .and_then(|value| { + u64::from_str_radix(value, 16) + .map_err(|error| format!("cannot inspect process capabilities: {error}")) + })?; Ok(ProcessIds { real_uid, @@ -160,6 +181,7 @@ fn current_process_ids() -> Result { real_gid, effective_gid, saved_gid, + effective_capabilities, }) } @@ -451,6 +473,7 @@ mod tests { real_gid: 0, effective_gid: 0, saved_gid: 0, + effective_capabilities: 0, } } @@ -462,6 +485,7 @@ mod tests { real_gid, effective_gid: 0, saved_gid: 0, + effective_capabilities: 0, } } @@ -514,6 +538,7 @@ mod tests { real_gid: 1000, effective_gid: 1000, saved_gid: 1000, + effective_capabilities: 0, }, ) .unwrap_err(); @@ -534,6 +559,7 @@ mod tests { real_gid: 2000, effective_gid: 0, saved_gid: 3000, + effective_capabilities: 0, }, "caller UID state", ), @@ -546,6 +572,7 @@ mod tests { real_gid: 2000, effective_gid: 0, saved_gid: 3000, + effective_capabilities: 0, }, "caller UID state", ), @@ -558,6 +585,7 @@ mod tests { real_gid: 2000, effective_gid: 1000, saved_gid: 3000, + effective_capabilities: 0, }, "caller GID state", ), @@ -570,6 +598,7 @@ mod tests { real_gid: 2000, effective_gid: 0, saved_gid: 1000, + effective_capabilities: 0, }, "caller GID state", ), @@ -595,6 +624,26 @@ mod tests { assert_eq!(resolved.username, "sandbox-user"); } + #[test] + fn resolve_run_as_user_accepts_non_root_parent_with_setuid_and_setgid_capabilities() { + let lookup = fake_lookup(&[("sandbox-user", 2000, 2000)]); + let process_ids = ProcessIds { + real_uid: 1000, + effective_uid: 1000, + saved_uid: 1000, + real_gid: 1000, + effective_gid: 1000, + saved_gid: 1000, + effective_capabilities: identity_switch_capabilities(), + }; + + let resolved = + resolve_run_as_user_with_process_ids("sandbox-user", &lookup, process_ids).unwrap(); + + assert_eq!(resolved.uid, 2000); + assert_eq!(resolved.gid, 2000); + } + #[test] fn prepare_workspace_rejects_symlink_workspace() { let temp = tempfile::tempdir().unwrap(); diff --git a/crates/axis-sandbox/src/linux/mod.rs b/crates/axis-sandbox/src/linux/mod.rs index 61e08bd..c3e590c 100644 --- a/crates/axis-sandbox/src/linux/mod.rs +++ b/crates/axis-sandbox/src/linux/mod.rs @@ -1708,6 +1708,13 @@ impl SandboxImpl for LinuxSandbox { })?; let tmpdir_required = landlock::policy_uses_tmpdir(&self.config.policy.filesystem); if let Some(identity) = &resolved_identity { + if tmpdir_required { + crate::sandbox::record_startup_result(&trace, "support_files.tmpdir", || { + identity::create_tmpdir_for_identity(&self.config.workspace_dir, identity) + .map_err(|e| SandboxError::IsolationFailed(format!("run_as_user: {e}"))) + })?; + self.tmpdir_active = true; + } crate::sandbox::record_startup_result( &trace, "support_files.run_as_user_workspace", @@ -1719,13 +1726,7 @@ impl SandboxImpl for LinuxSandbox { } let prepared_landlock = crate::sandbox::record_startup_result(&trace, "filesystem_setup.landlock", || { - if let (Some(identity), true) = (&resolved_identity, tmpdir_required) { - if let Err(e) = - identity::create_tmpdir_for_identity(&self.config.workspace_dir, identity) - { - return Err(SandboxError::IsolationFailed(format!("run_as_user: {e}"))); - } - self.tmpdir_active = true; + if resolved_identity.is_some() && tmpdir_required { landlock::prepare_landlock_with_tmpdir_setup( &self.config.policy.filesystem, &self.config.workspace_dir, diff --git a/crates/axis-sandbox/src/linux/mxc.rs b/crates/axis-sandbox/src/linux/mxc.rs index e950903..203eab3 100644 --- a/crates/axis-sandbox/src/linux/mxc.rs +++ b/crates/axis-sandbox/src/linux/mxc.rs @@ -959,6 +959,15 @@ impl MxcLinuxSandbox { let mut tmpdir_active = false; let tmpdir_required = super::landlock::policy_uses_tmpdir(&config.policy.filesystem); if let Some(identity) = &resolved_identity { + if tmpdir_required { + crate::sandbox::record_startup_result(&trace, "support_files.tmpdir", || { + super::identity::create_tmpdir_for_identity(&config.workspace_dir, identity) + .map_err(|err| { + SandboxError::IsolationFailed(format!("MXC run_as_user: {err}")) + }) + })?; + tmpdir_active = true; + } crate::sandbox::record_startup_result( &trace, "support_files.run_as_user_workspace", @@ -969,15 +978,6 @@ impl MxcLinuxSandbox { }) }, )?; - if tmpdir_required { - crate::sandbox::record_startup_result(&trace, "support_files.tmpdir", || { - super::identity::create_tmpdir_for_identity(&config.workspace_dir, identity) - .map_err(|err| { - SandboxError::IsolationFailed(format!("MXC run_as_user: {err}")) - }) - })?; - tmpdir_active = true; - } } else if tmpdir_required { crate::sandbox::record_startup_result(&trace, "support_files.tmpdir", || { super::landlock::create_tmpdir(&config.workspace_dir) diff --git a/crates/axis-sandbox/src/linux/seccomp.rs b/crates/axis-sandbox/src/linux/seccomp.rs index bd1783e..a50a01c 100644 --- a/crates/axis-sandbox/src/linux/seccomp.rs +++ b/crates/axis-sandbox/src/linux/seccomp.rs @@ -159,6 +159,7 @@ const WHITELIST: &[(u32, &str)] = &[ (110, "getppid"), (111, "getpgrp"), (124, "getsid"), + (125, "capget"), // read-only capability introspection for verifying privilege drop (131, "sigaltstack"), (137, "statfs"), (138, "fstatfs"), @@ -907,6 +908,7 @@ mod tests { assert!(nrs.contains(&0), "read missing"); assert!(nrs.contains(&1), "write missing"); assert!(nrs.contains(&59), "execve missing"); + assert!(nrs.contains(&125), "capget missing"); assert!(nrs.contains(&231), "exit_group missing"); assert!(nrs.contains(&9), "mmap missing"); assert!(nrs.contains(&56), "clone missing"); From d100f47036f45b0ee966bc871615ab9cb94f4d7c Mon Sep 17 00:00:00 2001 From: Balazs Toth Date: Fri, 13 Nov 2026 19:35:50 +0100 Subject: [PATCH 2/4] require every identity switch capability for non-root run_as_user A non-root caller now needs CAP_CHOWN, CAP_FOWNER and CAP_DAC_OVERRIDE besides CAP_SETUID and CAP_SETGID, because AXIS assigns the workspace and tmpdir to the target and reopens them. Checking all five up front fails early with a clear message instead of EPERM at launch. Docs updated. Co-authored-by: Cursor --- crates/axis-sandbox/src/linux/identity.rs | 71 +++++++++++++++++++---- docs/axis-isolation-contract.md | 4 +- docs/linux-setup.md | 2 +- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/crates/axis-sandbox/src/linux/identity.rs b/crates/axis-sandbox/src/linux/identity.rs index 8530ebf..4f29dac 100644 --- a/crates/axis-sandbox/src/linux/identity.rs +++ b/crates/axis-sandbox/src/linux/identity.rs @@ -10,11 +10,20 @@ use std::os::unix::io::RawFd; use std::path::{Component, Path, PathBuf}; const SANDBOX_TMPDIR_NAME: &str = ".axis-tmp"; +const CAP_CHOWN: u32 = 0; +const CAP_DAC_OVERRIDE: u32 = 1; +const CAP_FOWNER: u32 = 3; const CAP_SETGID: u32 = 6; const CAP_SETUID: u32 = 7; +// run_as_user chowns and chmods the workspace and tmpdir to the target +// identity, then reopens them; a non-root caller needs all five. const fn identity_switch_capabilities() -> u64 { - (1_u64 << CAP_SETGID) | (1_u64 << CAP_SETUID) + (1_u64 << CAP_CHOWN) + | (1_u64 << CAP_DAC_OVERRIDE) + | (1_u64 << CAP_FOWNER) + | (1_u64 << CAP_SETGID) + | (1_u64 << CAP_SETUID) } #[derive(Debug, Clone, PartialEq, Eq)] @@ -117,7 +126,7 @@ fn resolve_run_as_user_with_process_ids( && process_ids.effective_capabilities & required_capabilities != required_capabilities { return Err(format!( - "run_as_user '{username}' requires root or equivalent setuid capability; current effective UID is {}", + "run_as_user '{username}' requires root, or CAP_SETUID, CAP_SETGID, CAP_CHOWN, CAP_FOWNER and CAP_DAC_OVERRIDE; current effective UID is {}", process_ids.effective_uid )); } @@ -625,17 +634,9 @@ mod tests { } #[test] - fn resolve_run_as_user_accepts_non_root_parent_with_setuid_and_setgid_capabilities() { + fn resolve_run_as_user_accepts_non_root_parent_with_identity_switch_capabilities() { let lookup = fake_lookup(&[("sandbox-user", 2000, 2000)]); - let process_ids = ProcessIds { - real_uid: 1000, - effective_uid: 1000, - saved_uid: 1000, - real_gid: 1000, - effective_gid: 1000, - saved_gid: 1000, - effective_capabilities: identity_switch_capabilities(), - }; + let process_ids = non_root_process_ids(identity_switch_capabilities()); let resolved = resolve_run_as_user_with_process_ids("sandbox-user", &lookup, process_ids).unwrap(); @@ -644,6 +645,52 @@ mod tests { assert_eq!(resolved.gid, 2000); } + #[test] + fn resolve_run_as_user_rejects_non_root_parent_with_only_setuid_and_setgid() { + let lookup = fake_lookup(&[("sandbox-user", 2000, 2000)]); + let process_ids = non_root_process_ids((1_u64 << CAP_SETUID) | (1_u64 << CAP_SETGID)); + + let err = + resolve_run_as_user_with_process_ids("sandbox-user", &lookup, process_ids).unwrap_err(); + + assert!( + err.contains("CAP_CHOWN, CAP_FOWNER and CAP_DAC_OVERRIDE"), + "{err}" + ); + } + + #[test] + fn resolve_run_as_user_rejects_non_root_parent_missing_any_identity_switch_capability() { + let lookup = fake_lookup(&[("sandbox-user", 2000, 2000)]); + for cap in [ + CAP_CHOWN, + CAP_DAC_OVERRIDE, + CAP_FOWNER, + CAP_SETGID, + CAP_SETUID, + ] { + let process_ids = + non_root_process_ids(identity_switch_capabilities() & !(1_u64 << cap)); + + let err = resolve_run_as_user_with_process_ids("sandbox-user", &lookup, process_ids) + .unwrap_err(); + + assert!(err.contains("requires root"), "capability {cap}: {err}"); + } + } + + fn non_root_process_ids(effective_capabilities: u64) -> ProcessIds { + ProcessIds { + real_uid: 1000, + effective_uid: 1000, + saved_uid: 1000, + real_gid: 1000, + effective_gid: 1000, + saved_gid: 1000, + effective_capabilities, + } + } + #[test] fn prepare_workspace_rejects_symlink_workspace() { let temp = tempfile::tempdir().unwrap(); diff --git a/docs/axis-isolation-contract.md b/docs/axis-isolation-contract.md index 7984558..8acb38a 100644 --- a/docs/axis-isolation-contract.md +++ b/docs/axis-isolation-contract.md @@ -138,7 +138,9 @@ Required behavior: - Environment filtering must remove inherited provider secrets and inherited proxy credentials unless AXIS intentionally adds sanitized values. - `run_as_user` must not run as root and must fail if the requested identity - cannot be prepared safely. + cannot be prepared safely. A non-root caller may request it only when it + holds `CAP_SETUID`, `CAP_SETGID`, `CAP_CHOWN`, `CAP_FOWNER` and + `CAP_DAC_OVERRIDE`; AXIS clears every capability set before exec. - `identity: isolated` is portable intent for a backend-owned isolated token or account. It must not be implemented by guessing a host username. Windows MXC maps it to the actual least-privilege ProcessContainer token; legacy diff --git a/docs/linux-setup.md b/docs/linux-setup.md index 5e77f38..df16ab6 100644 --- a/docs/linux-setup.md +++ b/docs/linux-setup.md @@ -59,7 +59,7 @@ is unavailable for the default provider, AXIS fails before running the command. | `network.mode: allow` | Uses host networking while still applying filesystem, seccomp, identity, timeout, and requested resource policy. | No endpoint policies may be configured. Requested resource limits still need enforcement support. | | `network.mode: proxy` | Starts an AXIS CONNECT proxy behind a netns boundary that rejects direct egress. | `ip`, `iptables`, and either native `CAP_NET_ADMIN` or the optional AXIS netns helper. Kernel-log audit evidence additionally needs readable `/dev/kmsg`. | | Resource limits | `max_processes`, `max_memory_mb`, and `cpu_rate_percent` are enforced through cgroups v2 when available. | Writable cgroups v2. Memory-only rlimit fallback is documented; process-count rlimit fallback requires a dedicated `run_as_user`; CPU quota has no rlimit fallback. | -| `run_as_user` | Drops to a configured non-root user and prepares writable workspace state for that user. | The target user must already exist, must not be root, and must be usable by the current caller. | +| `run_as_user` | Drops to a configured non-root user and prepares writable workspace state for that user. Every capability is dropped before exec. | The target user must already exist, must not be root, and must not share the caller's UID or GID. The caller must be root, or hold `CAP_SETUID`, `CAP_SETGID`, `CAP_CHOWN`, `CAP_FOWNER` and `CAP_DAC_OVERRIDE` in its effective set, because AXIS assigns the workspace and tmpdir to the target user. | | Bubblewrap fallback | Can provide block-mode fallback when Landlock is unavailable. | A safe root-owned system `bwrap` executable. It is not a proxy-mode fallback unless proxy reachability is also implemented. | `0` for `max_processes`, `max_memory_mb`, or `cpu_rate_percent` means that From 7efc59da1d4cd9ad8f093a7d92ac20d5f1759d2f Mon Sep 17 00:00:00 2001 From: Balazs Toth Date: Fri, 13 Nov 2026 20:14:47 +0100 Subject: [PATCH 3/4] keep usernames and uids out of run_as_user test assertion messages Co-authored-by: Cursor --- crates/axis-sandbox/src/linux/identity.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/axis-sandbox/src/linux/identity.rs b/crates/axis-sandbox/src/linux/identity.rs index 4f29dac..b09a462 100644 --- a/crates/axis-sandbox/src/linux/identity.rs +++ b/crates/axis-sandbox/src/linux/identity.rs @@ -653,10 +653,7 @@ mod tests { let err = resolve_run_as_user_with_process_ids("sandbox-user", &lookup, process_ids).unwrap_err(); - assert!( - err.contains("CAP_CHOWN, CAP_FOWNER and CAP_DAC_OVERRIDE"), - "{err}" - ); + assert!(err.contains("CAP_CHOWN, CAP_FOWNER and CAP_DAC_OVERRIDE")); } #[test] @@ -675,7 +672,10 @@ mod tests { let err = resolve_run_as_user_with_process_ids("sandbox-user", &lookup, process_ids) .unwrap_err(); - assert!(err.contains("requires root"), "capability {cap}: {err}"); + assert!( + err.contains("requires root"), + "capability {cap} was not required" + ); } } From 05b4b7c0d26571ff62ec84b77fe1d166e294703c Mon Sep 17 00:00:00 2001 From: Balazs Toth Date: Sat, 14 Nov 2026 13:25:32 +0100 Subject: [PATCH 4/4] bump quinn-udp to 0.5.16 and rustix to 1.1.6 for RUSTSEC-2026-0538 and RUSTSEC-2026-0486 Only the two lockfile entries change; every other package, including the windows-sys versions, stays as locked. cargo deny check advisories licenses sources passes for the workspace and gui/linux. Co-authored-by: Cursor --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4f0347..eb34e2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1923,9 +1923,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.14" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016" dependencies = [ "cfg_aliases", "libc", @@ -2183,9 +2183,9 @@ checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags", "errno",