Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions crates/mctx/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ pub struct EnvArgs<'a> {
/// The hostname to set, if any.
pub hostname: Option<String>,

/// If set, enables or disables networking.
pub override_disable_networking: Option<bool>,
/// If set, overrides the network isolation mode for the sandbox.
pub override_network_mode: Option<sandbox2::NetworkMode>,
/// The operation tracker to use downstream, if applicable.
pub ot: Option<OpTracker>,
}
Expand Down Expand Up @@ -562,14 +562,17 @@ impl<'a> Env<'a> {
)
.with_state_dir(&args.state_base_dir)
.with_dns(
args.override_disable_networking
.map(|v| !v)
args.override_network_mode
.map(|m| !matches!(m, sandbox2::NetworkMode::NoNet))
.unwrap_or(needs_dns),
)
.with_disable_networking(
args.override_disable_networking
.unwrap_or(!needs_dns && !needs_internet),
)
.with_network_mode(args.override_network_mode.unwrap_or(
if !needs_dns && !needs_internet {
sandbox2::NetworkMode::NoNet
} else {
sandbox2::NetworkMode::HostNet
},
))
.with_env_vars(pkg_env_vars.into_iter());
if let Some(hn) = &args.hostname {
config = config.with_hostname(hn);
Expand Down
2 changes: 1 addition & 1 deletion crates/mctx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ impl Context {
patches,
env_vars,
hostname: Some(name.to_string()),
override_disable_networking: Some(false),
override_network_mode: Some(sandbox2::NetworkMode::HostNet),
ot: self.config.ot.clone(),
},
)
Expand Down
1 change: 1 addition & 0 deletions crates/minimal2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async fn cmd_activate(global: &GlobalArgs, args: ActivateArgs) -> Result<(), ()>
name: args.name.clone(),
username,
project_path: abs_path,
network: sessions::NetworkMode::default(),
attrs: Default::default(),
};

Expand Down
2 changes: 2 additions & 0 deletions crates/minimald-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use chrono::Utc;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use sessions::SessionId;

pub use sessions::{IpProto, NetworkMode};

pub const RPC_SUBSYSTEM_PREFIX: &str = "minimald-v1-";

/// Describes a minimal-specific RPC method sent over ssh.
Expand Down
11 changes: 11 additions & 0 deletions crates/minimald/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use ot::OpTracker;
use paths::DaemonAbsPath;
use sandbox2::config::{Config, SandboxMapped};
use sandbox2::{Container, Sandbox};
use sessions::NetworkMode;
use tempfile::TempDir;
use tokio::sync::mpsc;
use tokio::task::{JoinHandle, spawn_blocking};
Expand All @@ -69,6 +70,7 @@ pub struct EnvArgs {
patches: Option<EnvPatches>,
env_vars: Option<HashMap<String, EnvVarValue>>,
ot: Option<OpTracker>,
network_mode: NetworkMode,
}

impl EnvArgs {
Expand All @@ -90,6 +92,7 @@ impl EnvArgs {
patches: None,
env_vars: None,
ot: None,
network_mode: NetworkMode::HostNet,
}
}

Expand Down Expand Up @@ -132,6 +135,13 @@ impl EnvArgs {
self.username = Some(username);
self
}

/// Sets the network isolation mode for the session sandbox.
#[must_use]
pub fn with_network_mode(mut self, mode: NetworkMode) -> Self {
self.network_mode = mode;
self
}
}

/// A fully-owned, session-scoped runtime environment.
Expand Down Expand Up @@ -233,6 +243,7 @@ impl Env {
)
.with_state_dir(args.state_base_dir.as_utf8_path())
.with_env_vars(pkg_env_vars.into_iter())
.with_network_mode(args.network_mode)
.with_hostname(args.name.clone())
.with_username(args.username.unwrap_or_else(|| "user".to_string()));

Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ mod tests {
name: Some("exec-test".to_string()),
username: None,
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
})
Expand Down
4 changes: 4 additions & 0 deletions crates/minimald/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ mod tests {
name: Some("stream-test".to_string()),
username: None,
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
})
Expand Down Expand Up @@ -507,6 +508,7 @@ mod tests {
name: Some("my session".to_string()),
username: None,
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
})
Expand Down Expand Up @@ -551,6 +553,7 @@ mod tests {
name: Some("my session".to_string()),
username: None,
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
})
Expand All @@ -567,6 +570,7 @@ mod tests {
name: Some("my session".to_string()),
username: None,
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
})
Expand Down
2 changes: 2 additions & 0 deletions crates/minimald/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl<S: SessionObject> Session<S> {
) -> Result<session_host::SandboxLauncher, AttachError> {
Ok(session_host::SandboxLauncher {
ctx: self.context().map_err(AttachError::ContextCreationFailed)?,
network_mode: self.session.record().network,
session,
})
}
Expand Down Expand Up @@ -370,6 +371,7 @@ mod tests {
name: Some("shell-test".to_string()),
username: None,
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: Default::default(),
attrs: Default::default(),
},
})
Expand Down
4 changes: 4 additions & 0 deletions crates/minimald/src/session_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use crate::RequestedPty;
#[cfg(not(test))]
use crate::session::SessionHandle;
use crate::session::SessionPaths;
#[cfg(not(test))]
use sessions::NetworkMode;

/// Command sequence for the ctrl-w key chord, when the kitty keyboard protocol
/// is negotiated.
Expand Down Expand Up @@ -572,6 +574,7 @@ pub(crate) struct SandboxLauncher {
// the prior `Host::spawn` signature).
#[allow(dead_code)]
pub(crate) session: SessionHandle,
pub(crate) network_mode: NetworkMode,
}

#[cfg(not(test))]
Expand Down Expand Up @@ -618,6 +621,7 @@ impl SessionLauncher for SandboxLauncher {
)]
.into(),
)
.with_network_mode(self.network_mode)
.with_username(username),
)
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ mod tests {
name: Some("doomed".to_string()),
username: None,
project_path: HostAbsPath::try_new("/proj").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ mod tests {
name: Some("sftp-test".to_string()),
username: None,
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
})
Expand Down
1 change: 1 addition & 0 deletions crates/minvmd/examples/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async fn run_session_exec(
username: None,
project_path: paths::HostAbsPath::try_new("/tmp")
.map_err(|e| format!("project_path: {e}"))?,
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
};
Expand Down
1 change: 1 addition & 0 deletions crates/minvmd/tests/minimald_session_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ async fn run_session_exec(
username: None,
project_path: paths::HostAbsPath::try_new("/tmp")
.map_err(|e| format!("project_path: {e}"))?,
network: sessions::NetworkMode::default(),
attrs: Default::default(),
},
};
Expand Down
6 changes: 5 additions & 1 deletion crates/op/src/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ impl<'a, SF: crate::SourceFetcher> Runnable for SpecBuild<'a, SF> {
.with_isolated_wd(inputs.into_iter())
.with_rootfs(rootfs.into_iter())
.with_dns(needs_dns)
.with_disable_networking(!needs_dns && !needs_internet);
.with_network_mode(if !needs_dns && !needs_internet {
sandbox2::NetworkMode::NoNet
} else {
sandbox2::NetworkMode::HostNet
});
if let Some(a) = &build.build_args {
config = config.with_build_args(a.iter());
}
Expand Down
6 changes: 5 additions & 1 deletion crates/op/src/standalone_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ impl<'a> Runnable for StandaloneTest<'a> {
let config = sandbox2::config::Config::new("test")
.with_rootfs(deps.into_iter())
.with_dns(needs_dns)
.with_disable_networking(!needs_dns && !needs_internet)
.with_network_mode(if !needs_dns && !needs_internet {
sandbox2::NetworkMode::NoNet
} else {
sandbox2::NetworkMode::HostNet
})
.with_hostname("test")
.with_env_var("HOME", "/tmp");
let mut sandbox = config.build(&opts.exec_base, ()).await?;
Expand Down
1 change: 1 addition & 0 deletions crates/sandbox2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tokio-util.workspace = true
walkdir.workspace = true

common.workspace = true
sessions.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
hakoniwa.workspace = true
Expand Down
14 changes: 8 additions & 6 deletions crates/sandbox2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::fs;
use std::hash::Hash;
use std::path::{Path, PathBuf};

pub use sessions::NetworkMode;

/// Something in the FS that needs to be mapped into the sandbox.
#[derive(Debug)]
pub enum SandboxMapped {
Expand Down Expand Up @@ -123,8 +125,8 @@ pub struct Config {

/// Synthesize DNS config.
pub setup_dns_config: bool,
/// Disable all networking.
pub disable_networking: bool,
/// The network isolation mode for this sandbox.
pub network_mode: NetworkMode,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW | Spec Compliance | R1.2 (task proof artifact)

The task sub-issue (#495) lists two additional files in scope that are absent from this PR:

  • vendor/gvproxy/ (new) — vendored gvproxy Go source at a pinned commit
  • .github/workflows/ — CI step to build gvproxy from source with SHA-256 verification

And the corresponding proof artifact: "vendor/gvproxy/go.sum exists at a pinned version — fails on base (directory absent)."

PR #503 landed a pre-built binary approach (chore(vendor): pin and verify pre-built gvproxy switch binary), which is a different strategy from "build from vendored Go source" that the spec's Technical Considerations section prefers ("building from source is preferred for reproducibility and eliminates supply-chain risk from a pre-built download"). Neither vendor/gvproxy/go.sum nor any .github/workflows/ build step appears in this diff.

This is low-severity because the pre-built binary in #503 may be an accepted alternative, but if Go-source vendoring is still required per the task sub-issue, it should either be included here or the task scope amended with a note that #503 satisfies the intent.


/// The hostname to set in the environment, if any.
pub hostname: Option<String>,
Expand Down Expand Up @@ -162,7 +164,7 @@ impl Config {
Self {
name: name.into(),
setup_dns_config: true,
disable_networking: false,
network_mode: NetworkMode::HostNet,
env_vars: HashMap::with_capacity(12),
hostname: None,
username: None,
Expand Down Expand Up @@ -247,9 +249,9 @@ impl Config {
self.rootfs.insert(file);
self
}
/// Sets whether networking is required.
pub fn with_disable_networking(mut self, disable_networking: bool) -> Self {
self.disable_networking = disable_networking;
/// Sets the network isolation mode for this sandbox.
pub fn with_network_mode(mut self, mode: NetworkMode) -> Self {
self.network_mode = mode;
self
}
/// Sets whether DNS should be configured.
Expand Down
1 change: 1 addition & 0 deletions crates/sandbox2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

pub mod config;
use config::Config;
pub use config::NetworkMode;
use std::fs::{self, Permissions};
use std::io::{Read, Write};
use std::os::unix::fs::PermissionsExt;
Expand Down
33 changes: 33 additions & 0 deletions crates/sessions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ pub mod core;
pub mod store;
pub mod wire;

/// The network isolation mode for a `PTask` (session).
///
/// Defaults to [`NetworkMode::HostNet`] for backwards compatibility with
/// existing sessions that predate this field.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
pub enum NetworkMode {
/// No network namespace; all network syscalls fail or see no interfaces.
NoNet,
/// Share the host (or VM) network namespace. Current default.
#[default]
HostNet,
/// Own IP via the gvproxy switch: new netns + tap + switch attachment.
OwnIp,
}

/// An IP transport protocol, used in egress/ingress policy rules.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum IpProto {
Tcp,
Udp,
Icmp,
}

/// A session ID, a newtype over a UUID.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SessionId(Uuid);
Expand Down Expand Up @@ -65,6 +92,12 @@ pub struct Record {
/// The absolute path upon which this session was built from.
pub project_path: HostAbsPath,

/// The network isolation mode for this session.
///
/// Defaults to [`NetworkMode::HostNet`] when absent (existing sessions).
#[serde(default)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM | Spec Compliance | R1.2

sessions::Record::network is stored and serialised but never read by any session-launch code path. Tracing the execution: minimald passes an mctx::EnvArgs to build the sandbox config, and EnvArgs::override_network_mode is the only knob that flows into sandbox2::Config::network_mode. But no caller sets override_network_mode from record.network — in mctx/src/lib.rs it is hardcoded to Some(sandbox2::NetworkMode::HostNet), and every other call-site omits the field (None).

As a result a session whose record carries network: NoNet (or OwnIp) will still launch with the default HostNet sandbox config. R1.2 says "For NoNet PTasks, minimald shall configure the sandbox with an empty network namespace," which requires the field to actually be propagated.

The fix is for the session-launch code (in minimald) to read record.network and pass it as override_network_mode when constructing EnvArgs. Actual OS-level enforcement (a unshare(Namespace::Network) call in hakoniwa) will also be needed, but the field-propagation gap blocks even a future attempt at enforcement.

If the intent is to defer this to the gvproxy infrastructure task, the task sub-issue should document that R1.2 enforcement is intentionally incomplete here — the proof artifact only tests compilation, not isolation behaviour.

pub network: NetworkMode,

/// Free-form attributes.
pub attrs: BTreeMap<String, String>,
}
1 change: 1 addition & 0 deletions crates/sessions/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ mod tests {
name: Some("my-session".to_string()),
username: Some("alice".to_string()),
project_path: HostAbsPath::try_new("/home/alice/proj").unwrap(),
network: crate::NetworkMode::default(),
attrs: [("color".to_string(), "blue".to_string())]
.into_iter()
.collect(),
Expand Down
Loading