From fd6c008d709c9018bd1307d19f3e7fd3c9b516f3 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Fri, 9 Oct 2026 19:11:09 +0000 Subject: [PATCH 1/4] fix(minimald): name the userns restriction in session spawn errors On a userns-restricted host (stock Ubuntu 24.04+, ApparmorUnconfined or userns Disabled), the session sandbox child dies writing its uid map and the client's attach fails with a bare 'session host exited before its channel could attach'. The daemon's startup probe already diagnosed the restriction and its fix, but only logged them. Thread that diagnosis from the probe into the config the session actors build on, and fold it into the spawn-failed error, so the error a client sees names the restriction and the fix instead of a symptom that explains nothing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- crates/minimald/src/main.rs | 17 ++++++++++++-- crates/minimald/src/server.rs | 14 ++++++++++++ crates/minimald/src/session.rs | 34 +++++++++++++++++++++++++--- crates/minimald/src/session/tests.rs | 28 +++++++++++++++++++++++ crates/minimald/src/sessions.rs | 13 ++++++++++- crates/minimald/src/test_harness.rs | 2 ++ 6 files changed, 102 insertions(+), 6 deletions(-) diff --git a/crates/minimald/src/main.rs b/crates/minimald/src/main.rs index b2a2f9ba7f..42b1b8f7b6 100644 --- a/crates/minimald/src/main.rs +++ b/crates/minimald/src/main.rs @@ -1011,8 +1011,11 @@ async fn async_main() -> Result<(), MainError> { ))); } - // Setup the server config (shared by the UDS and vsock transports). - let config = Config { + // Setup the server config (shared by the UDS and vsock transports). `mut`: + // the Linux userns probe below folds its diagnosis into this config + // before `Server::run` takes it. + #[cfg_attr(not(target_os = "linux"), allow(unused_mut))] + let mut config = Config { host_key: HostKey::OnDisk { path: sub_path!(cli.client_instance_dir(), "ssh_host_ed25519_key") .as_utf8_path() @@ -1052,6 +1055,11 @@ async fn async_main() -> Result<(), MainError> { .egress_deny_all_opt_out, std::env::var(EGRESS_DENY_ALL_OPT_OUT_ENV).ok().as_deref(), ), + // Set by the Linux userns probe below: the diagnosis + fix a spawn + // failure should name, so the attach error a client sees on a + // restricted host explains itself. `None` everywhere else (no probe, + // or none triggered). + userns_spawn_hint: None, }; // Ensure the SSH host key is accessible in a instance-specific known_hosts file. // R1.2: load once and reuse in the vsock beacon so there is no redundant disk read. @@ -1119,6 +1127,11 @@ async fn async_main() -> Result<(), MainError> { "sessions will fail to start: this host refuses the unprivileged user \ namespace every session sandbox needs" ); + // The same diagnosis, carried to the attach error: the warn above + // only reaches this log, while the client whose `min` attach dies + // on the restriction sees the spawn error — fold the reason and + // the fix into it so the error explains itself. + config.userns_spawn_hint = Some(format!("{restriction} — fix: {fix}")); } // Track the host's wall clock, when configured. diff --git a/crates/minimald/src/server.rs b/crates/minimald/src/server.rs index d509cdf3e4..f566add49e 100644 --- a/crates/minimald/src/server.rs +++ b/crates/minimald/src/server.rs @@ -275,6 +275,14 @@ pub struct Config { /// declares its own egress section is unaffected either way. #[serde(default)] pub deny_all_opt_out: bool, + + /// The startup probe's diagnosis of why this host refuses the + /// unprivileged user namespace every session sandbox needs, with the + /// fix to run — `None` when the probe found nothing (or never ran, + /// off-Linux). Threaded to the session actors so a spawn failure names + /// the restriction instead of a bare "host exited" symptom. + #[serde(default)] + pub userns_spawn_hint: Option, } impl Config { @@ -566,6 +574,10 @@ impl ServerState { // task path resolve the same effective egress the daemon // was started with (NET-074/NET-077). config.deny_all_opt_out, + // The startup probe's diagnosis + fix, so a spawn failure on + // a userns-restricted host names the restriction (see + // [`Config::userns_spawn_hint`]). + config.userns_spawn_hint.clone(), ) .await?, config, @@ -2773,6 +2785,8 @@ pub(crate) fn test_config(dir: &std::path::Path) -> Config { // The default every unit-test daemon runs: the rollout phase this // build ships, not opted out. deny_all_opt_out: false, + // No probe ran for a unit-test config, so no diagnosis to name. + userns_spawn_hint: None, } } diff --git a/crates/minimald/src/session.rs b/crates/minimald/src/session.rs index ecf6cc0646..b1a81316b8 100644 --- a/crates/minimald/src/session.rs +++ b/crates/minimald/src/session.rs @@ -38,6 +38,21 @@ mod helpers; pub(crate) use helpers::*; +/// The error a failed host attach surfaces: the bare symptom, plus the +/// startup probe's diagnosis and fix when it has one. A host that dies in +/// the launch-to-attach window on a userns-restricted host (stock Ubuntu +/// 24.04+) otherwise leaves the client with a symptom that names neither +/// the restriction nor the fix — the probe already logged both, so carry +/// them into the error the client actually sees. +fn spawn_failed_error(userns_spawn_hint: Option<&str>) -> std::io::Error { + match userns_spawn_hint { + Some(hint) => std::io::Error::other(format!( + "session host exited before its channel could attach — {hint}" + )), + None => std::io::Error::other("session host exited before its channel could attach"), + } +} + /// An error that occurred when attaching to a running session/its-shell. #[derive(Debug)] pub enum AttachError { @@ -197,6 +212,13 @@ pub(crate) struct SessionConfig { /// it so a diagnostics bundle can name the posture without the daemon's /// flags. pub deny_all_opt_out: bool, + + /// The startup probe's diagnosis of why this host refuses the + /// unprivileged user namespace every sandbox needs, with the fix to + /// run — `None` when the probe found nothing (or never ran, off-Linux). + /// A spawn failure that lands here names the restriction instead of the + /// bare "host exited" symptom. + pub userns_spawn_hint: Option, } /// The egress *section* the gate compiles for a session: the materialized @@ -909,6 +931,12 @@ pub struct Session { /// path reads it through the handle for the same resolution. deny_all_opt_out: bool, + /// The startup probe's diagnosis of why this host refuses the + /// unprivileged user namespace every sandbox needs, with the fix to + /// run — `None` when the probe found nothing. A spawn failure names it + /// (see [`spawn_failed_error`]) so the attach error explains itself. + userns_spawn_hint: Option, + /// The live direct-tcpip forwards opened for this session: one abort /// handle per relay the connection layer spawned. Pruned as relays /// finish; every live one is aborted by [`Session::stop_running`], so a @@ -989,6 +1017,7 @@ impl Session { net_switch, manager, deny_all_opt_out, + userns_spawn_hint, #[cfg(target_os = "linux")] hostnames, #[cfg(target_os = "linux")] @@ -1002,6 +1031,7 @@ impl Session { daemon_ctx, net_switch, deny_all_opt_out, + userns_spawn_hint, tracker: OpTracker::new_root(), inner, workspace_baseline: WorkspaceBaseline::Unarmed, @@ -4650,9 +4680,7 @@ impl Session { ) .await .map_err(|_| { - AttachError::SpawnFailed(std::io::Error::other( - "session host exited before its channel could attach", - )) + AttachError::SpawnFailed(spawn_failed_error(self.userns_spawn_hint.as_deref())) })?; let SessionInner::Active { host, .. } = &mut self.inner else { unreachable!("mint_session_host is only reachable from the Active state"); diff --git a/crates/minimald/src/session/tests.rs b/crates/minimald/src/session/tests.rs index e8665fcc40..04927de55f 100644 --- a/crates/minimald/src/session/tests.rs +++ b/crates/minimald/src/session/tests.rs @@ -164,6 +164,34 @@ fn inherited_session_env_prefix_not_substring() { ); } +/// A spawn failure with no probe diagnosis keeps the bare symptom — the +/// exact message the pre-hint daemon surfaced, so an unrestricted host (or +/// an off-Linux one, where no probe runs) sees no change. +#[test] +fn spawn_failed_error_without_a_hint_keeps_the_bare_symptom() { + assert_eq!( + super::spawn_failed_error(None).to_string(), + "session host exited before its channel could attach" + ); +} + +/// A spawn failure with a probe diagnosis names it: the symptom stays (the +/// host did exit before attaching) and the restriction + fix the startup +/// probe logged follow it, so the error a client sees on a userns- +/// restricted host explains itself. +#[test] +fn spawn_failed_error_with_a_hint_names_the_restriction_and_fix() { + let hint = "kernel.apparmor_restrict_unprivileged_userns=1 and this \ + process is unconfined — fix: install minimald's AppArmor \ + profile (one-time, needs root)"; + let msg = super::spawn_failed_error(Some(hint)).to_string(); + assert!( + msg.starts_with("session host exited before its channel could attach — "), + "the symptom must stay the error's lead: {msg}" + ); + assert!(msg.contains(hint), "the diagnosis must travel whole: {msg}"); +} + /// Reads the session record for `id`, or `None` once it has been deleted. async fn record_exists(client: &mut TestClient, id: SessionId) -> bool { client diff --git a/crates/minimald/src/sessions.rs b/crates/minimald/src/sessions.rs index 82132f5ec1..4630202d21 100644 --- a/crates/minimald/src/sessions.rs +++ b/crates/minimald/src/sessions.rs @@ -265,6 +265,13 @@ pub struct Manager { /// so each one resolves its own effective egress (NET-074) the same way /// the RPC path does. deny_all_opt_out: bool, + + /// The startup probe's diagnosis of why this host refuses the + /// unprivileged user namespace every sandbox needs, with the fix to + /// run — `None` when the probe found nothing. Threaded from the server + /// config into every session actor so a spawn failure names the + /// restriction instead of the bare "host exited" symptom. + userns_spawn_hint: Option, } impl Manager { @@ -276,6 +283,7 @@ impl Manager { daemon_ctx: Arc, net_switch: Arc>, deny_all_opt_out: bool, + userns_spawn_hint: Option, ) -> Result { let store = Store::init(minimal_state_dir.clone()).await?; @@ -582,6 +590,7 @@ impl Manager { #[cfg(target_os = "linux")] loopback, deny_all_opt_out, + userns_spawn_hint, }; tokio::spawn(mngr.mainloop()); @@ -1093,6 +1102,7 @@ impl Manager { net_switch: Arc::clone(&self.net_switch), manager: self.weak_self.clone(), deny_all_opt_out: self.deny_all_opt_out, + userns_spawn_hint: self.userns_spawn_hint.clone(), #[cfg(target_os = "linux")] hostnames: Arc::clone(&self.hostnames), #[cfg(target_os = "linux")] @@ -2075,13 +2085,14 @@ pub(crate) mod tests { .unwrap(); let daemon_ctx = Arc::new(mctx::DaemonContext::init(mctx_config).unwrap()); // `false`: these tests run the default the build ships, not the - // opt-out. + // opt-out. `None`: no startup probe ran, so no diagnosis to name. Manager::init( daemon_abs(&state), daemon_abs(&cache), daemon_ctx, switch, false, + None, ) .await .unwrap() diff --git a/crates/minimald/src/test_harness.rs b/crates/minimald/src/test_harness.rs index 0b39977dfb..3a312c2949 100644 --- a/crates/minimald/src/test_harness.rs +++ b/crates/minimald/src/test_harness.rs @@ -288,6 +288,8 @@ fn config_in(temp: &TempDir, deny_all_opt_out: bool) -> Config { // runtime-dir lock, deriving the octet from the per-start id. daemon_identity_dir: None, deny_all_opt_out, + // No startup probe ran for a harness server, so no diagnosis. + userns_spawn_hint: None, } } From 87d2143bcc3963cb17bf92ed4b5505a4658f9409 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:26:30 -0700 Subject: [PATCH 2/4] fix(minimald): probe the userns restriction when the attach fails The startup probe's verdict went stale once a sysctl changed under a running daemon (the host-setup doc's sysctl -w fix needs no restart), so the attach error could name a lifted restriction or miss a new one. Re-probe at failure time instead, share the fix text with the startup warning through userns_restriction_fix, and drop the Config -> Manager -> Session plumbing the cached hint needed. --- crates/minimald/src/lib.rs | 34 +++++++++++++++++++++ crates/minimald/src/main.rs | 44 ++------------------------- crates/minimald/src/server.rs | 14 --------- crates/minimald/src/session.rs | 46 ++++++++++++++++------------- crates/minimald/src/sessions.rs | 13 +------- crates/minimald/src/test_harness.rs | 2 -- 6 files changed, 63 insertions(+), 90 deletions(-) diff --git a/crates/minimald/src/lib.rs b/crates/minimald/src/lib.rs index b2cb547c72..2102ccc664 100644 --- a/crates/minimald/src/lib.rs +++ b/crates/minimald/src/lib.rs @@ -52,6 +52,40 @@ pub struct ChannelConfig { pub(crate) pty: Option, } +/// The fix to run for a host that refuses the unprivileged user namespace +/// every session sandbox needs. One source for the daemon's startup warning +/// and the spawn-failed attach error, so both name the same remediation. +#[cfg(target_os = "linux")] +#[must_use] +pub fn userns_restriction_fix(restriction: sandbox2::UsernsRestriction) -> String { + match restriction { + sandbox2::UsernsRestriction::ApparmorUnconfined => { + // The loader lands under the installer's `data` prefix, which + // resolves through $XDG_DATA_HOME exactly like + // `paths::minimal_data_dir` — don't hardcode ~/.local/share. + // A daemon at a path outside the profile's tunable (a custom + // MINIMAL_BIN, a dev build) needs the binary attached too. + format!( + "install minimald's AppArmor profile (one-time, needs root): sudo bash \ + {data}/apparmor/install-apparmor-profile.sh --path {bin} (from a checkout: \ + sudo scripts/install-apparmor-profile.sh --path {bin})", + data = paths::minimal_data_dir(), + bin = std::env::current_exe() + .ok() + .and_then(|p| p.to_str().map(str::to_owned)) + .unwrap_or_else(|| "".to_string()), + ) + } + sandbox2::UsernsRestriction::Disabled => { + "re-enable user namespaces, e.g. sudo sysctl -w user.max_user_namespaces=15000" + .to_string() + } + // `UsernsRestriction` is #[non_exhaustive]; future variants get + // the docs pointer until a matching remediation lands here. + _ => "see the linux-host-setup doc".to_string(), + } +} + #[cfg(test)] mod integration_naming_convention { //! Guards the integration-test auto-discovery contract (root variant). The diff --git a/crates/minimald/src/main.rs b/crates/minimald/src/main.rs index 42b1b8f7b6..5660f6979c 100644 --- a/crates/minimald/src/main.rs +++ b/crates/minimald/src/main.rs @@ -1011,11 +1011,8 @@ async fn async_main() -> Result<(), MainError> { ))); } - // Setup the server config (shared by the UDS and vsock transports). `mut`: - // the Linux userns probe below folds its diagnosis into this config - // before `Server::run` takes it. - #[cfg_attr(not(target_os = "linux"), allow(unused_mut))] - let mut config = Config { + // Setup the server config (shared by the UDS and vsock transports). + let config = Config { host_key: HostKey::OnDisk { path: sub_path!(cli.client_instance_dir(), "ssh_host_ed25519_key") .as_utf8_path() @@ -1055,11 +1052,6 @@ async fn async_main() -> Result<(), MainError> { .egress_deny_all_opt_out, std::env::var(EGRESS_DENY_ALL_OPT_OUT_ENV).ok().as_deref(), ), - // Set by the Linux userns probe below: the diagnosis + fix a spawn - // failure should name, so the attach error a client sees on a - // restricted host explains itself. `None` everywhere else (no probe, - // or none triggered). - userns_spawn_hint: None, }; // Ensure the SSH host key is accessible in a instance-specific known_hosts file. // R1.2: load once and reuse in the vsock beacon so there is no redundant disk read. @@ -1094,32 +1086,7 @@ async fn async_main() -> Result<(), MainError> { // silent on the vsock path. #[cfg(target_os = "linux")] if let Some(restriction) = sandbox2::user_namespaces_restriction() { - let fix = match restriction { - sandbox2::UsernsRestriction::ApparmorUnconfined => { - // The loader lands under the installer's `data` prefix, which - // resolves through $XDG_DATA_HOME exactly like - // `paths::minimal_data_dir` — don't hardcode ~/.local/share. - // A daemon at a path outside the profile's tunable (a custom - // MINIMAL_BIN, a dev build) needs the binary attached too. - format!( - "install minimald's AppArmor profile (one-time, needs root): sudo bash \ - {data}/apparmor/install-apparmor-profile.sh --path {bin} (from a checkout: \ - sudo scripts/install-apparmor-profile.sh --path {bin})", - data = paths::minimal_data_dir(), - bin = std::env::current_exe() - .ok() - .and_then(|p| p.to_str().map(str::to_owned)) - .unwrap_or_else(|| "".to_string()), - ) - } - sandbox2::UsernsRestriction::Disabled => { - "re-enable user namespaces, e.g. sudo sysctl -w user.max_user_namespaces=15000" - .to_string() - } - // `UsernsRestriction` is #[non_exhaustive]; future variants get - // the docs pointer until a matching remediation lands here. - _ => "see the linux-host-setup doc".to_string(), - }; + let fix = minimald::userns_restriction_fix(restriction); tracing::warn!( reason = %restriction, fix, @@ -1127,11 +1094,6 @@ async fn async_main() -> Result<(), MainError> { "sessions will fail to start: this host refuses the unprivileged user \ namespace every session sandbox needs" ); - // The same diagnosis, carried to the attach error: the warn above - // only reaches this log, while the client whose `min` attach dies - // on the restriction sees the spawn error — fold the reason and - // the fix into it so the error explains itself. - config.userns_spawn_hint = Some(format!("{restriction} — fix: {fix}")); } // Track the host's wall clock, when configured. diff --git a/crates/minimald/src/server.rs b/crates/minimald/src/server.rs index f566add49e..d509cdf3e4 100644 --- a/crates/minimald/src/server.rs +++ b/crates/minimald/src/server.rs @@ -275,14 +275,6 @@ pub struct Config { /// declares its own egress section is unaffected either way. #[serde(default)] pub deny_all_opt_out: bool, - - /// The startup probe's diagnosis of why this host refuses the - /// unprivileged user namespace every session sandbox needs, with the - /// fix to run — `None` when the probe found nothing (or never ran, - /// off-Linux). Threaded to the session actors so a spawn failure names - /// the restriction instead of a bare "host exited" symptom. - #[serde(default)] - pub userns_spawn_hint: Option, } impl Config { @@ -574,10 +566,6 @@ impl ServerState { // task path resolve the same effective egress the daemon // was started with (NET-074/NET-077). config.deny_all_opt_out, - // The startup probe's diagnosis + fix, so a spawn failure on - // a userns-restricted host names the restriction (see - // [`Config::userns_spawn_hint`]). - config.userns_spawn_hint.clone(), ) .await?, config, @@ -2785,8 +2773,6 @@ pub(crate) fn test_config(dir: &std::path::Path) -> Config { // The default every unit-test daemon runs: the rollout phase this // build ships, not opted out. deny_all_opt_out: false, - // No probe ran for a unit-test config, so no diagnosis to name. - userns_spawn_hint: None, } } diff --git a/crates/minimald/src/session.rs b/crates/minimald/src/session.rs index 3f218853b5..e50995f836 100644 --- a/crates/minimald/src/session.rs +++ b/crates/minimald/src/session.rs @@ -38,12 +38,31 @@ mod helpers; pub(crate) use helpers::*; +/// Why this host refuses the unprivileged user namespace every session +/// sandbox needs, with the fix to run — `None` when nothing is visible. +/// +/// Probed at failure time rather than reused from the daemon's startup +/// probe: the sysctls it reads take effect live (the host-setup doc's +/// `sysctl -w` fix needs no daemon restart), so a startup verdict could +/// name a restriction already lifted, or miss one set since. The probe is a +/// handful of `/proc` reads on a path that has already failed. +#[cfg(target_os = "linux")] +fn userns_spawn_hint() -> Option { + sandbox2::user_namespaces_restriction() + .map(|r| format!("{r} — fix: {}", crate::userns_restriction_fix(r))) +} + +/// Off Linux no user namespace is involved, so there is nothing to name. +#[cfg(not(target_os = "linux"))] +fn userns_spawn_hint() -> Option { + None +} + /// The error a failed host attach surfaces: the bare symptom, plus the -/// startup probe's diagnosis and fix when it has one. A host that dies in -/// the launch-to-attach window on a userns-restricted host (stock Ubuntu -/// 24.04+) otherwise leaves the client with a symptom that names neither -/// the restriction nor the fix — the probe already logged both, so carry -/// them into the error the client actually sees. +/// userns diagnosis and fix when there is one (see [`userns_spawn_hint`]). +/// A host that dies in the launch-to-attach window on a userns-restricted +/// host (stock Ubuntu 24.04+) otherwise leaves the client with a symptom +/// that names neither the restriction nor the fix. fn spawn_failed_error(userns_spawn_hint: Option<&str>) -> std::io::Error { match userns_spawn_hint { Some(hint) => std::io::Error::other(format!( @@ -212,13 +231,6 @@ pub(crate) struct SessionConfig { /// it so a diagnostics bundle can name the posture without the daemon's /// flags. pub deny_all_opt_out: bool, - - /// The startup probe's diagnosis of why this host refuses the - /// unprivileged user namespace every sandbox needs, with the fix to - /// run — `None` when the probe found nothing (or never ran, off-Linux). - /// A spawn failure that lands here names the restriction instead of the - /// bare "host exited" symptom. - pub userns_spawn_hint: Option, } /// The egress *section* the gate compiles for a session: the materialized @@ -931,12 +943,6 @@ pub struct Session { /// path reads it through the handle for the same resolution. deny_all_opt_out: bool, - /// The startup probe's diagnosis of why this host refuses the - /// unprivileged user namespace every sandbox needs, with the fix to - /// run — `None` when the probe found nothing. A spawn failure names it - /// (see [`spawn_failed_error`]) so the attach error explains itself. - userns_spawn_hint: Option, - /// The live direct-tcpip forwards opened for this session: one abort /// handle per relay the connection layer spawned. Pruned as relays /// finish; every live one is aborted by [`Session::stop_running`], so a @@ -1021,7 +1027,6 @@ impl Session { net_switch, manager, deny_all_opt_out, - userns_spawn_hint, #[cfg(target_os = "linux")] hostnames, #[cfg(target_os = "linux")] @@ -1035,7 +1040,6 @@ impl Session { daemon_ctx, net_switch, deny_all_opt_out, - userns_spawn_hint, tracker: OpTracker::new_root(), inner, workspace_baseline: WorkspaceBaseline::Unarmed, @@ -4687,7 +4691,7 @@ impl Session { ) .await .map_err(|_| { - AttachError::SpawnFailed(spawn_failed_error(self.userns_spawn_hint.as_deref())) + AttachError::SpawnFailed(spawn_failed_error(userns_spawn_hint().as_deref())) })?; let SessionInner::Active { host, .. } = &mut self.inner else { unreachable!("mint_session_host is only reachable from the Active state"); diff --git a/crates/minimald/src/sessions.rs b/crates/minimald/src/sessions.rs index 4630202d21..82132f5ec1 100644 --- a/crates/minimald/src/sessions.rs +++ b/crates/minimald/src/sessions.rs @@ -265,13 +265,6 @@ pub struct Manager { /// so each one resolves its own effective egress (NET-074) the same way /// the RPC path does. deny_all_opt_out: bool, - - /// The startup probe's diagnosis of why this host refuses the - /// unprivileged user namespace every sandbox needs, with the fix to - /// run — `None` when the probe found nothing. Threaded from the server - /// config into every session actor so a spawn failure names the - /// restriction instead of the bare "host exited" symptom. - userns_spawn_hint: Option, } impl Manager { @@ -283,7 +276,6 @@ impl Manager { daemon_ctx: Arc, net_switch: Arc>, deny_all_opt_out: bool, - userns_spawn_hint: Option, ) -> Result { let store = Store::init(minimal_state_dir.clone()).await?; @@ -590,7 +582,6 @@ impl Manager { #[cfg(target_os = "linux")] loopback, deny_all_opt_out, - userns_spawn_hint, }; tokio::spawn(mngr.mainloop()); @@ -1102,7 +1093,6 @@ impl Manager { net_switch: Arc::clone(&self.net_switch), manager: self.weak_self.clone(), deny_all_opt_out: self.deny_all_opt_out, - userns_spawn_hint: self.userns_spawn_hint.clone(), #[cfg(target_os = "linux")] hostnames: Arc::clone(&self.hostnames), #[cfg(target_os = "linux")] @@ -2085,14 +2075,13 @@ pub(crate) mod tests { .unwrap(); let daemon_ctx = Arc::new(mctx::DaemonContext::init(mctx_config).unwrap()); // `false`: these tests run the default the build ships, not the - // opt-out. `None`: no startup probe ran, so no diagnosis to name. + // opt-out. Manager::init( daemon_abs(&state), daemon_abs(&cache), daemon_ctx, switch, false, - None, ) .await .unwrap() diff --git a/crates/minimald/src/test_harness.rs b/crates/minimald/src/test_harness.rs index 3a312c2949..0b39977dfb 100644 --- a/crates/minimald/src/test_harness.rs +++ b/crates/minimald/src/test_harness.rs @@ -288,8 +288,6 @@ fn config_in(temp: &TempDir, deny_all_opt_out: bool) -> Config { // runtime-dir lock, deriving the octet from the per-start id. daemon_identity_dir: None, deny_all_opt_out, - // No startup probe ran for a harness server, so no diagnosis. - userns_spawn_hint: None, } } From 1dc3f6af6d10d26b1e15342964474296fb1213a9 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:29:29 -0700 Subject: [PATCH 3/4] fix(minimald): name the userns restriction on a failed launch too Append the userns diagnosis to a launch_host failure as well as a failed first attach, keeping the launch error's kind, and give the attach hint only to a host whose loop closed, never to a timed-out live one. --- crates/minimald/src/session.rs | 33 ++++++++++++++++++++++------ crates/minimald/src/session/tests.rs | 14 ++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/crates/minimald/src/session.rs b/crates/minimald/src/session.rs index e50995f836..7d2b483cc0 100644 --- a/crates/minimald/src/session.rs +++ b/crates/minimald/src/session.rs @@ -64,11 +64,21 @@ fn userns_spawn_hint() -> Option { /// host (stock Ubuntu 24.04+) otherwise leaves the client with a symptom /// that names neither the restriction nor the fix. fn spawn_failed_error(userns_spawn_hint: Option<&str>) -> std::io::Error { + with_userns_hint( + std::io::Error::other("session host exited before its channel could attach"), + userns_spawn_hint, + ) +} + +/// `err` with the userns diagnosis and fix appended when there is one, +/// keeping its kind. A launch that fails outright on a userns-restricted +/// host (an own-ip session wiring the netns of a child that already died on +/// its `uid_map` write) otherwise reaches the client with the same +/// cause-less symptom as a host that dies before its attach. +fn with_userns_hint(err: std::io::Error, userns_spawn_hint: Option<&str>) -> std::io::Error { match userns_spawn_hint { - Some(hint) => std::io::Error::other(format!( - "session host exited before its channel could attach — {hint}" - )), - None => std::io::Error::other("session host exited before its channel could attach"), + Some(hint) => std::io::Error::new(err.kind(), format!("{err} — {hint}")), + None => err, } } @@ -4360,7 +4370,9 @@ impl Session { } None => (None, spawn.await), }; - let (host, task, host_ip_enforcement) = spawned.map_err(AttachError::SpawnFailed)?; + let (host, task, host_ip_enforcement) = spawned.map_err(|e| { + AttachError::SpawnFailed(with_userns_hint(e, userns_spawn_hint().as_deref())) + })?; // The confirmation was a read, not a reservation: the VM host daemon // may have withdrawn the row at its grace's end between that read // and this launch (NET-138). Read it again now the new host is up, @@ -4690,8 +4702,15 @@ impl Session { session_keys, ) .await - .map_err(|_| { - AttachError::SpawnFailed(spawn_failed_error(userns_spawn_hint().as_deref())) + .map_err(|e| { + // Only a host whose loop ended can be one that died on its + // namespace setup; a timed-out one is alive, so the userns + // hint would misattribute it. + let hint = match e { + session_host::HostAttachError::Closed(..) => userns_spawn_hint(), + session_host::HostAttachError::Timeout => None, + }; + AttachError::SpawnFailed(spawn_failed_error(hint.as_deref())) })?; let SessionInner::Active { host, .. } = &mut self.inner else { unreachable!("mint_session_host is only reachable from the Active state"); diff --git a/crates/minimald/src/session/tests.rs b/crates/minimald/src/session/tests.rs index 04927de55f..1749e55821 100644 --- a/crates/minimald/src/session/tests.rs +++ b/crates/minimald/src/session/tests.rs @@ -192,6 +192,20 @@ fn spawn_failed_error_with_a_hint_names_the_restriction_and_fix() { assert!(msg.contains(hint), "the diagnosis must travel whole: {msg}"); } +/// A launch failure keeps its own message and kind, and gains the +/// diagnosis only when the probe found one. +#[test] +fn with_userns_hint_appends_the_diagnosis_and_keeps_the_kind() { + let base = || std::io::Error::new(std::io::ErrorKind::PermissionDenied, "uid_map write"); + let bare = super::with_userns_hint(base(), None); + assert_eq!(bare.kind(), std::io::ErrorKind::PermissionDenied); + assert_eq!(bare.to_string(), "uid_map write"); + + let hinted = super::with_userns_hint(base(), Some("restricted — fix: x")); + assert_eq!(hinted.kind(), std::io::ErrorKind::PermissionDenied); + assert_eq!(hinted.to_string(), "uid_map write — restricted — fix: x"); +} + /// Reads the session record for `id`, or `None` once it has been deleted. async fn record_exists(client: &mut TestClient, id: SessionId) -> bool { client From 9c130f2763e4cf27ff95793ced2429bab1fb85c7 Mon Sep 17 00:00:00 2001 From: "gominimal-aw-bot[bot]" <281738952+gominimal-aw-bot[bot]@users.noreply.github.com> Date: Fri, 9 Oct 2026 18:11:33 -0700 Subject: [PATCH 4/4] fix(minimald): label the userns hint as the likely cause of a launch error --- crates/minimald/src/session.rs | 6 ++++-- crates/minimald/src/session/tests.rs | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/minimald/src/session.rs b/crates/minimald/src/session.rs index 7d2b483cc0..db2154417d 100644 --- a/crates/minimald/src/session.rs +++ b/crates/minimald/src/session.rs @@ -74,10 +74,12 @@ fn spawn_failed_error(userns_spawn_hint: Option<&str>) -> std::io::Error { /// keeping its kind. A launch that fails outright on a userns-restricted /// host (an own-ip session wiring the netns of a child that already died on /// its `uid_map` write) otherwise reaches the client with the same -/// cause-less symptom as a host that dies before its attach. +/// cause-less symptom as a host that dies before its attach. The probe +/// sees the host, not this error, so the hint is labelled the likely cause +/// and the error's own message stays first. fn with_userns_hint(err: std::io::Error, userns_spawn_hint: Option<&str>) -> std::io::Error { match userns_spawn_hint { - Some(hint) => std::io::Error::new(err.kind(), format!("{err} — {hint}")), + Some(hint) => std::io::Error::new(err.kind(), format!("{err} — likely cause: {hint}")), None => err, } } diff --git a/crates/minimald/src/session/tests.rs b/crates/minimald/src/session/tests.rs index 1749e55821..2fcc8951ec 100644 --- a/crates/minimald/src/session/tests.rs +++ b/crates/minimald/src/session/tests.rs @@ -203,7 +203,10 @@ fn with_userns_hint_appends_the_diagnosis_and_keeps_the_kind() { let hinted = super::with_userns_hint(base(), Some("restricted — fix: x")); assert_eq!(hinted.kind(), std::io::ErrorKind::PermissionDenied); - assert_eq!(hinted.to_string(), "uid_map write — restricted — fix: x"); + assert_eq!( + hinted.to_string(), + "uid_map write — likely cause: restricted — fix: x" + ); } /// Reads the session record for `id`, or `None` once it has been deleted.