8000 feat(minimald,minvmd,minimal2): end-to-end VM/guest/session networking integration by norrietaylor · Pull Request #581 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
da39e86
feat(minimal2): add --network and --ingress flags to activate
norrietaylor Jun 24, 2026
52c4821
feat(minvmd): spawn host gvproxy + per-PTask vsock shuttle bridge
norrietaylor Jun 25, 2026
6b8c726
feat(minimald): shuttle OwnIp PTask taps to host gvproxy on DM1/3/4
norrietaylor Jun 25, 2026
5031d29
Merge branch 'main' into feat/activate-network-ingress-flags
norrietaylor Jun 25, 2026
1299c3c
chore: add justfile recipes to bring up minimal2 -> minvmd -> minimald
norrietaylor Jun 25, 2026
03decd1
feat(mctx,minimald): scaffold a default minimal.toml for empty sessions
norrietaylor Jun 25, 2026
bf53b37
feat(minimald,minvmd): guest root-netns egress via host gvproxy shuttle
norrietaylor Jun 25, 2026
6d02dde
refactor(mctx): make minimal.toml scaffolding a self-contained tempor…
norrietaylor Jun 25, 2026
e1236db
Merge branch 'feat/activate-network-ingress-flags' of https://github.…
norrietaylor Jun 25, 2026
caa4092
feat(minimald): apply own-IP ingress over the gvproxy control channel…
norrietaylor Jun 26, 2026
482be01
fix(minimald,minimal2): make the in-sandbox interactive attach work (…
norrietaylor Jun 26, 2026
a71d96a
fix(minvmd,minimald): grow VM RAM and exec the shell at /usr/bin/bash
norrietaylor Jun 26, 2026
73395f6
fix(minimald): mount devpts so the in-sandbox session PTY works
norrietaylor Jun 26, 2026
b9ad4f3
chore(minimald): devpts ptmx instance fix + session exit-code logging
norrietaylor Jun 26, 2026
9b9af44
fix(minimald): make the in-sandbox session shell work in the minvmd g…
norrietaylor Jun 26, 2026
a1d8399
style(minimald): rustfmt the ingress control-channel code
norrietaylor Jun 26, 2026
6a92e82
feat(minimald): start the host-side proxies in-VM and publish them on…
norrietaylor Jun 26, 2026
72d8055
docs(spec-networking): add the full-session-path CLI test plan + runner
norrietaylor Jun 26, 2026
455722d
fix(minimald): recover host routing from a poisoned registry lock
norrietaylor Jun 26, 2026
5161676
fix(minimald): bind in-VM proxies on 0.0.0.0 and expose only bound ports
norrietaylor Jun 26, 2026
df19d9b
perf(minimald): fence the blocking scaffold clone with block_in_place
norrietaylor Jun 26, 2026
66a9133
chore(minimald): log routine session exits at debug
norrietaylor Jun 26, 2026
a4b703e
fix(minvmd): fail own-ip boot when the gvproxy binary is missing
norrietaylor Jun 26, 2026
9da27a0
fix(minimald): adapt netns test to the ControlChannel ingress API
norrietaylor Jun 26, 2026
2b55134
docs(minimald,minvmd): drop references to the superseded host-shuttle PR
norrietaylor Jun 26, 2026
bac5b31
style(minvmd): rustfmt the switch-socket setup line
norrietaylor Jun 26, 2026
95b3213
style(minimald): derive SwitchTransport Default
norrietaylor Jun 26, 2026
dcecd6a
fix(minimald): mark ControlChannel non_exhaustive
norrietaylor Jun 26, 2026
cb5b868
fix(minvmd): tolerate a failed gvproxy spawn on non-own-IP boots
norrietaylor Jun 26, 2026
8e9fd7a
fix(minvmd): accept case-insensitive truthy MINVMD_VM_OWN_IP
norrietaylor Jun 26, 2026
1192223
fix(minimald): log fatal proxy accept-loop errors
norrietaylor Jun 26, 2026
460ee62
refactor(minimald): drop the duplicate non-zero session-exit log
norrietaylor Jun 26, 2026
c479def
fix(minimald): keep rustls optional to avoid a dual crypto-provider p…
norrietaylor Jun 26, 2026
ceec7cf
feat(sandbox2): add a Network abstraction for per-sandbox networking
norrietaylor Jun 26, 2026
9e0a8b4
refactor(minimald,minvmd): disambiguate the two GvproxySwitch types
norrietaylor Jun 26, 2026
62fe1c4
feat(minimald): move own-IP switch wiring into a sandbox2 Network impl
norrietaylor Jun 26, 2026
c6c2b53
feat(sandbox2): apply the configured Network in the generic run path
norrietaylor Jun 26, 2026
03b0be6
refactor(minvmd): remove the dead PtaskAttachment lease path
norrietaylor Jun 26, 2026
f55c810
refactor(switch,minimald,minvmd): unify gvproxy switch primitives in …
norrietaylor Jun 26, 2026
11c909d
fix(minvmd): re-export DEFAULT_MTU for the linux-only relay module
norrietaylor Jun 26, 2026
3290a6e
fix(minvmd,minimal2): make VM bring-up timeouts and guest RAM configu…
norrietaylor Jun 26, 2026
cdbf14a
fix(sandbox2): clean up the sandbox on Network attach/wait failure
norrietaylor Jun 26, 2026
3f921b5
fix(switch): canonicalize SwitchSubnet base in new()
norrietaylor Jun 26, 2026
019f820
fix(minimald): harden vsock relay, scaffold fence, and rename routing
norrietaylor Jun 26, 2026
6d28308
fix(minvmd): wait for the switch socket before reporting gvproxy ready
norrietaylor Jun 26, 2026
6bbd317
feat(minimald,mctx): run tasks under their session network mode
norrietaylor Jun 26, 2026
aeee85f
docs(spec-networking): fix test-plan, codesign, and env-doc nits
norrietaylor Jun 26, 2026
156ddd3
build: bump upstream pkgs pin to the new rootfs build
norrietaylor Jun 26, 2026
6b53c0b
fix(minvmd): update vsock relay e2e test to post-refactor switch API
norrietaylor Jun 27, 2026
4f73967
test(spec-networking): guard own-ip test-plan steps with per-step tim…
norrietaylor Jun 27, 2026
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
2 changes: 1 addition & 1 deletion .minimal/minimal.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[upstream] # Source of software & tooling
repo = "https://github.com/gominimal/pkgs"
branch = "main"
locked_commit = "087287e4b6f448eaf3d0ca7198dad384a0778b6d"
locked_commit = "23193970569b93e5e7a980aa598c3342c386d33f"

[stack]
use = "rust"
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [
"crates/sandbox2",
"crates/sessions",
"crates/stdlib",
"crates/switch",
]
resolver = "3"

Expand Down Expand Up @@ -159,5 +160,6 @@ remote-proto = { version = "0.0.1", path = "crates/remote-proto" }
remote-client = { version = "0.0.1", path = "crates/remote-client" }
sandbox2 = { version = "0.0.1", path = "crates/sandbox2" }
sessions = { version = "0.0.1", path = "crates/sessions" }
switch = { version = "0.0.1", path = "crates/switch" }

stdlib = { version = "0.0.16", path = "crates/stdlib" }
1 change: 1 addition & 0 deletions crates/mctx/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl From<sandbox2::Error> for Error {
"internal: file {} mapped to rootfs",
p.display()
)),
sandbox2::Error::Network(e) => Self::Other(anyhow::anyhow!(e.to_string())),
}
}
}
Expand Down
39 changes: 38 additions & 1 deletion crates/mctx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub use sandbox2::config::Invocation;
mod mfile_search_strategy;
pub use mfile_search_strategy::MFileSearchStrategy;

// TEMPORARY: default-`minimal.toml` scaffolding for empty session workspaces.
// See `scaffold.rs`; remove with the workspace-upload gap.
mod scaffold;
pub use scaffold::scaffold_default_mfile;

pub use env::Env;
use tokio::sync::Semaphore;
use toml_edit::{Array, DocumentMut, Item, TableLike, Value};
Expand Down Expand Up @@ -627,6 +632,9 @@ impl Context {

/// Constructs an environment from which executions can be run, based on the given parameters.
#[allow(clippy::too_many_arguments)]
/// Builds an [`env::Env`] with the default `HostNet` sandbox network. Use
/// [`make_env_with_network`](Self::make_env_with_network) to run the sandbox
/// in another [`sandbox2::NetworkMode`] (e.g. a `NoNet`/`OwnIp` PTask).
pub async fn make_env<'a, S: PackageSelection>(
&'a mut self,
name: &'a str,
Expand All @@ -636,6 +644,35 @@ impl Context {
patches: Option<&'a EnvPatches>,
env_vars: Option<&'a HashMap<String, EnvVarValue>>,
packages: S,
) -> Result<env::Env<'a>, Error> {
self.make_env_with_network(
name,
graph,
wd,
state_key,
patches,
env_vars,
packages,
sandbox2::NetworkMode::HostNet,
)
.await
}

/// Like [`make_env`](Self::make_env) but runs the sandbox in the given
/// [`sandbox2::NetworkMode`], so callers (e.g. the minimald task-exec path)
/// can give a task the same network isolation as its session rather than
/// always `HostNet`.
#[allow(clippy::too_many_arguments)]
pub async fn make_env_with_network<'a, S: PackageSelection>(
&'a mut self,
name: &'a str,
graph: &'a mut Graph,
wd: Option<PathBuf>,
state_key: Option<&String>,
patches: Option<&'a EnvPatches>,
env_vars: Option<&'a HashMap<String, EnvVarValue>>,
packages: S,
network_mode: sandbox2::NetworkMode,
) -> Result<env::Env<'a>, Error> {
let mfile = self.minimal_file();

Expand Down Expand Up @@ -708,7 +745,7 @@ impl Context {
patches,
env_vars,
hostname: Some(name.to_string()),
override_network_mode: Some(sandbox2::NetworkMode::HostNet),
override_network_mode: Some(network_mode),
ot: self.config.ot.clone(),
},
)
Expand Down
125 changes: 125 additions & 0 deletions crates/mctx/src/scaffold.rs
Original file line number Diff line number D 10BC8 iff line change
@@ -0,0 +1,125 @@
//! TEMPORARY: scaffolding a default `minimal.toml` for empty session workspaces.
//!
//! This is a stop-gap. A session whose workspace has no `minimal.toml` (the
//! workspace-upload gap) cannot build a [`crate::Context`], so [`minimald`]
//! writes a default shell-stack one here on first attach. Remove this module
//! once sessions receive their project files (including a real `minimal.toml`)
//! and minimald no longer needs to fabricate one.
//!
//! [`generate_mfile`] below is a deliberate COPY of
//! `minimal::cmd_init::generate_mfile` (and its `DEFAULT_PKGS` /
//! `DEFAULT_PKGS_BRANCH` / `FALLBACK_STACK` constants). It is duplicated rather
//! than shared on purpose: this whole module is temporary, so keeping it
//! self-contained means deleting one file removes the workaround cleanly,
//! without unpicking a refactor of `cmd_init`. Keep the two in sync only if it
//! is cheap to; otherwise let this copy lag — it is on its way out.

use std::path::{Path, PathBuf};

use common::SpecOrigin;
use common::repo_spec::Repo;

use crate::{Config, Context, Error};

/// TEMPORARY (see module docs): default upstream package source.
const DEFAULT_PKGS: &str = "https://github.com/gominimal/pkgs";
/// TEMPORARY (see module docs): branch tracked for [`DEFAULT_PKGS`].
const DEFAULT_PKGS_BRANCH: &str = "main";
/// TEMPORARY (see module docs): stack used when no matcher applies.
const FALLBACK_STACK: &str = "shell";

/// TEMPORARY (see module docs): resolve the latest [`DEFAULT_PKGS_BRANCH`]
/// commit and write a default shell `minimal.toml` into `repo_dir`, returning
/// the written path. Used to bootstrap a session workspace that has none.
pub fn scaffold_default_mfile(
config: &Config,
repo_dir: impl AsRef<Path>,
) -> Result<PathBuf, Error> {
let (mut vcs, _cache, _stdlib) = Context::sub_setup(config)?;
let (_dir, rev) = vcs.checkout_of(
DEFAULT_PKGS,
checkouts::GitRef::Branch(DEFAULT_PKGS_BRANCH.to_string()),
)?;

let origin = SpecOrigin::Repo(Repo::Git {
url: DEFAULT_PKGS.to_string(),
rev,
tracking: Some(common::repo_spec::GitRef::Branch(
DEFAULT_PKGS_BRANCH.to_string(),
)),
});

let content = generate_mfile(None, &origin);
let path = repo_dir.as_ref().join(mfile::MFILE_NAME);
std::fs::write(&path, &content)
.map_err(|e| Error::IO("writing scaffolded minimal.toml", path.clone(), e))?;
Ok(path)
}

/// TEMPORARY (see module docs): a verbatim copy of
/// `minimal::cmd_init::generate_mfile`. Renders a `minimal.toml` for the given
/// upstream `origin`; `matched_stack` falls back to the `shell` stack here since
/// minimald does no project auto-detection.
fn generate_mfile(
matched_stack: Option<(String, Vec<String>, Vec<String>)>,
origin: &SpecOrigin,
) -> String {
// Fall back to the "shell" stack if no project-specific matcher hit.
let (stack_name, build_packages, runtime_packages) = matched_stack
.map(|h| (h.0, h.1, h.2))
.unwrap_or_else(|| (FALLBACK_STACK.to_string(), vec![], vec![]));

let mut content = String::new();
content.push_str("# Generated by `minimal init`\n\n");

// [upstream]
content.push_str("[upstream] # Source of software & tooling\n");
match &origin {
SpecOrigin::Repo(Repo::Git { url, rev, tracking }) => {
content.push_str(&format!("repo = \"{}\"\n", url));
if let Some(common::repo_spec::GitRef::Branch(b)) = tracking {
content.push_str(&format!("branch = \"{}\"\n", b));
}
content.push_str(&format!("locked_commit = \"{}\"\n", rev,));
}
SpecOrigin::LocalDir { given, .. } => {
content.push_str(&format!("dir = \"{}\"\n", given.to_str().unwrap()))
}
SpecOrigin::Inline => unreachable!(),
}
content.push('\n');

content.push_str("[stack]\n");
content.push_str(&format!("use = \"{}\"\n", stack_name));
if !build_packages.is_empty() {
content.push_str(&format!(
"build_packages = [{}]\n",
build_packages
.into_iter()
.map(|s| format!("\"{}\"", s))
.collect::<Vec<_>>()
.join(", ")
));
}
if !runtime_packages.is_empty() {
content.push_str(&format!(
"runtime_packages = [{}]\n",
runtime_packages
.into_iter()
.map(|s| format!("\"{}\"", s))
.collect::<Vec<_>>()
.join(", ")
));
}

content.push('\n');

content.push_str("[defaults]\n");
content.push_str("state_key = \"dev\"\n");
content.push('\n');
content.push_str("[tasks.shell]\n");
content.push_str("interactive = true\n");
content.push_str("packages = [\"base\"]\n");
content.push_str("exec = \"bash --noprofile -l\"\n");
content
}
33 changes: 27 additions & 6 deletions crates/minimal2/src/autospawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,31 @@ use std::time::{Duration, Instant};
use minvmd::lifecycle::Lifecycle;

/// Default timeout in seconds to wait for the UDS when spawning minvmd (R4.5).
///
/// A cold VM boot (kernel bring-up + the in-VM minimald init: mount,
/// pivot_root, networking) was observed at ~22–28s before the bridge socket
/// accepts, and is slower under host load, so the default carries margin above
/// minvmd's own READY wait. This is an upper bound — the spawn returns as soon
/// as the UDS is ready — so it only costs time on a genuinely slow/failed boot.
/// Override with [`SPAWN_TIMEOUT_ENV`].
#[cfg(any(target_os = "macos", target_os = "linux"))]
const DEFAULT_SPAWN_TIMEOUT_SECS: u64 = 75;

/// Environment variable overriding [`DEFAULT_SPAWN_TIMEOUT_SECS`].
#[cfg(any(target_os = "macos", target_os = "linux"))]
const DEFAULT_SPAWN_TIMEOUT_SECS: u64 = 8;
const SPAWN_TIMEOUT_ENV: &str = "MINIMAL_SPAWN_TIMEOUT_SECS";

/// The minvmd UDS-readiness wait, overridable via [`SPAWN_TIMEOUT_ENV`]. A
/// non-numeric, empty, or zero value falls back to [`DEFAULT_SPAWN_TIMEOUT_SECS`]
/// — a zero timeout would give the boot no readiness window.
#[cfg(any(target_os = "macos", target_os = "linux"))]
fn spawn_timeout_secs() -> u64 {
std::env::var(SPAWN_TIMEOUT_ENV)
.ok()
.and_then(|v| v.trim().parse::<u64>().ok())
.filter(|&secs| secs > 0)
.unwrap_or(DEFAULT_SPAWN_TIMEOUT_SECS)
}

/// Poll interval while waiting for a shutting-down minvmd to reach a terminal
/// state before deciding whether to spawn.
Expand Down Expand Up @@ -104,15 +127,13 @@ pub fn ensure_minvmd_running() -> io::Result<()> {
}

// Not running; spawn minvmd run --detach with timeout (R4.5).
tracing::info!(
"spawning minvmd run --detach with timeout {}",
DEFAULT_SPAWN_TIMEOUT_SECS
);
let timeout_secs = spawn_timeout_secs();
tracing::info!("spawning minvmd run --detach with timeout {timeout_secs}");
let output = Command::new("minvmd")
.arg("run")
.arg("--detach")
.arg("--timeout")
.arg(DEFAULT_SPAWN_TIMEOUT_SECS.to_string())
.arg(timeout_secs.to_string())
.output()
.map_err(|e| io::Error::new(e.kind(), format!("failed to spawn minvmd: {}", e)))?;

Expand Down
Loading
Loading
0