Skip to content
Closed
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
10 changes: 9 additions & 1 deletion crates/minimald/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ pub struct ListenArgs {
#[arg(long)]
#[clap(hide = true)]
mount_rootfs: Option<String>,

/// Path to the gvproxy ("gvisor-tap-vsock") binary backing the per-host
/// `OwnIp` switch. Overrides the fixed install path so a dev build can point
/// at a fetched binary (e.g. `scripts/fetch-gvproxy.sh`) without installing
/// it system-wide.
#[arg(long)]
gvproxy_bin: Option<std::path::PathBuf>,
}

/// An error at the top level of minimald.
Expand Down Expand Up @@ -234,6 +241,7 @@ async fn async_main() -> Result<(), MainError> {
vsock: true,
mount_dev: true,
mount_rootfs: Some("/dev/vda".to_string()),
gvproxy_bin: None,
}),
global_args: GlobalArgs {
minimal_state_dir: Some(DaemonAbsPath::try_new("/run/minimal").unwrap().into()),
Expand Down Expand Up @@ -298,7 +306,7 @@ async fn async_main() -> Result<(), MainError> {
},
minimal_state_dir: cli.minimal_state_dir(),
minimal_cache_dir: cli.minimal_cache_dir(),
gvproxy_bin: None,
gvproxy_bin: listen_args.gvproxy_bin.clone(),
};
// Ensure the SSH host key is accessible in a instance-specific known_hosts file.
russh::keys::known_hosts::learn_known_hosts_path(
Expand Down
7 changes: 5 additions & 2 deletions crates/minimald/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ pub enum HostKey {
}

/// Default install path for the gvproxy ("gvisor-tap-vsock") switch binary,
/// used when [`Config::gvproxy_bin`] is unset. The `GVPROXY_BIN` env var is
/// scoped to the `#[ignore]` netns proof and is never consulted by the daemon.
/// used when [`Config::gvproxy_bin`] is unset. Override it for a dev build with
/// `minimald run --gvproxy-bin <path>` (e.g. a binary fetched by
/// `scripts/fetch-gvproxy.sh`) to avoid installing it system-wide. The
/// `GVPROXY_BIN` env var is scoped to the `#[ignore]` netns proof and is never
/// consulted by the daemon.
const DEFAULT_GVPROXY_BIN: &str = "/usr/lib/minimal/bin/gvproxy";

/// Global Configuration for the minimald server.
Expand Down
77 changes: 77 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,80 @@
codesign-minvmd:
cargo build -p minvmd --release
codesign --entitlements crates/minvmd/minvmd.entitlements --force -s - target/release/minvmd

# --- Networking / VM bring-up (epic #478) ---------------------------------
#
# Lane A = native minimald on the host (DM2). Lane B = minvmd microVM (DM1, KVM).
# These recipes mirror the CI lanes (.github/workflows/ci-netns.yml and
# ci-linux-kvm.yml) so a dev reproduces them locally with one command each.
# Lane A needs passwordless sudo; Lane B needs /dev/kvm (see `setup-kvm-group`).

# Host arch, used to name guest artifacts and the musl target.
# Override per-invocation: `just arch=x86_64 setup-minvmd`.
arch := `uname -m`

# libkrun runtime/link prefix for Lane B. Override with the KRUN_PREFIX env var.
krun_prefix := env_var_or_default("KRUN_PREFIX", env_var("HOME") / ".krun")

# Fetch the pinned gvproxy switch binary into .scratch/ (no sudo, no install).
fetch-gvproxy:
@mkdir -p .scratch
./scripts/fetch-gvproxy.sh .scratch/gvproxy

# Lane A — netns proofs: UC1 (no-net refuses egress) + UC6 (PTask-to-PTask).
test-netns: fetch-gvproxy
MINIMALD_NETNS_TEST=1 GVPROXY_BIN="{{justfile_directory()}}/.scratch/gvproxy" \
cargo test -p minimald -p sandbox2 -p minimald-rpc netns -- --include-ignored --nocapture

# Lane A — UC7 WireGuard mesh netns proof (builds unprivileged, runs as root).
test-mesh-netns: fetch-gvproxy
#!/usr/bin/env bash
set -euo pipefail
bin=$(cargo test -p minimald --features networking-wg --test mesh_uc7 \
--no-run --message-format=json \
| jq -r 'select(.executable != null and (.target.name? == "mesh_uc7")) | .executable' \
| tail -1)
echo "mesh_uc7 binary: $bin"
sudo -E MINIMALD_NETNS_TEST=1 GVPROXY_BIN="$PWD/.scratch/gvproxy" \
"$bin" --include-ignored --nocapture
Comment on lines +41 to +47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Guard against empty mesh_uc7 executable resolution before sudo execution.

If the JSON filter returns nothing, "$bin" is empty and the recipe fails with a non-actionable error. Add an explicit check with a clear message.

Suggested patch
     bin=$(cargo test -p minimald --features networking-wg --test mesh_uc7 \
             --no-run --message-format=json \
           | jq -r 'select(.executable != null and (.target.name? == "mesh_uc7")) | .executable' \
           | tail -1)
+    if [[ -z "${bin:-}" ]]; then
+        echo "mesh_uc7 executable not found; cargo test --no-run did not emit a binary path" >&2
+        exit 1
+    fi
     echo "mesh_uc7 binary: $bin"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
bin=$(cargo test -p minimald --features networking-wg --test mesh_uc7 \
--no-run --message-format=json \
| jq -r 'select(.executable != null and (.target.name? == "mesh_uc7")) | .executable' \
| tail -1)
echo "mesh_uc7 binary: $bin"
sudo -E MINIMALD_NETNS_TEST=1 GVPROXY_BIN="$PWD/.scratch/gvproxy" \
"$bin" --include-ignored --nocapture
bin=$(cargo test -p minimald --features networking-wg --test mesh_uc7 \
--no-run --message-format=json \
| jq -r 'select(.executable != null and (.target.name? == "mesh_uc7")) | .executable' \
| tail -1)
if [[ -z "${bin:-}" ]]; then
echo "mesh_uc7 executable not found; cargo test --no-run did not emit a binary path" >&2
exit 1
fi
echo "mesh_uc7 binary: $bin"
sudo -E MINIMALD_NETNS_TEST=1 GVPROXY_BIN="$PWD/.scratch/gvproxy" \
"$bin" --include-ignored --nocapture
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@justfile` around lines 41 - 47, The mesh_uc7 recipe can invoke sudo with an
empty binary path if the cargo/jq pipeline returns nothing, so add an explicit
guard after resolving bin in the justfile recipe. In the recipe that sets bin
and runs "$bin", check that mesh_uc7 binary resolution succeeded and fail early
with a clear message before the sudo execution if it did not.


# Lane A — networking feature unit suites (networking-wg + networking-proxy).
test-net-features:
cargo test -p minimald --features networking-wg
cargo test -p minimald --features networking-proxy

# Lane A — netns proofs + mesh proof + feature suites.
test-net-lane-a: test-netns test-mesh-netns test-net-features

# Lane B — one-time setup: fetch libkrun + guest kernel/rootfs, build initramfs.
# build-initramfs.sh uses `cross` (Docker); on a native-arch host you can skip
# Docker — see crates/minvmd/README.md ("No Docker?") for the musl-gcc path.
setup-minvmd:
@mkdir -p .scratch
./scripts/fetch-libkrun.sh "{{krun_prefix}}" "{{arch}}"
./scripts/fetch-artifact.sh virtio-kernel .scratch/vmlinuz "{{arch}}"
./scripts/fetch-artifact.sh minvmd-rootfs .scratch/rootfs.img "{{arch}}"
./scripts/build-initramfs.sh .scratch/initramfs.cpio "{{arch}}-unknown-linux-musl"

# Lane B — minvmd VM E2E: boot READY round-trip + session command over the bridge.
test-minvmd-e2e:
#!/usr/bin/env bash
set -euo pipefail
krun="{{krun_prefix}}"
common="LIBKRUN_PREFIX=$krun LD_LIBRARY_PATH=$krun MINVMD_E2E=1 \
MINVMD_KERNEL_PATH=$PWD/.scratch/vmlinuz \
MINVMD_ROOTFS_PATH=$PWD/.scratch/rootfs.img \
MINVMD_INITRAMFS=$PWD/.scratch/initramfs.cpio"
sg kvm -c "env $common MINVMD_BOOT_LOG=$PWD/.scratch/boot-e2e.log \
cargo test -p minvmd --test boot_e2e -- --include-ignored --nocapture"
sg kvm -c "env $common \
cargo test -p minvmd --test minimald_session_e2e -- --include-ignored --nocapture --exact minimald_exec_over_bridge"

Comment on lines +68 to +80

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

test-minvmd-e2e should depend on setup-minvmd for first-run reliability.

On a clean repo, this recipe can fail because .scratch/vmlinuz, .scratch/rootfs.img, and .scratch/initramfs.cpio may not exist yet. Add setup-minvmd as a prerequisite so Lane B is runnable directly.

Suggested patch
-test-minvmd-e2e:
+test-minvmd-e2e: setup-minvmd
     #!/usr/bin/env bash
     set -euo pipefail
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test-minvmd-e2e:
#!/usr/bin/env bash
set -euo pipefail
krun="{{krun_prefix}}"
common="LIBKRUN_PREFIX=$krun LD_LIBRARY_PATH=$krun MINVMD_E2E=1 \
MINVMD_KERNEL_PATH=$PWD/.scratch/vmlinuz \
MINVMD_ROOTFS_PATH=$PWD/.scratch/rootfs.img \
MINVMD_INITRAMFS=$PWD/.scratch/initramfs.cpio"
sg kvm -c "env $common MINVMD_BOOT_LOG=$PWD/.scratch/boot-e2e.log \
cargo test -p minvmd --test boot_e2e -- --include-ignored --nocapture"
sg kvm -c "env $common \
cargo test -p minvmd --test minimald_session_e2e -- --include-ignored --nocapture --exact minimald_exec_over_bridge"
test-minvmd-e2e: setup-minvmd
#!/usr/bin/env bash
set -euo pipefail
krun="{{krun_prefix}}"
common="LIBKRUN_PREFIX=$krun LD_LIBRARY_PATH=$krun MINVMD_E2E=1 \
MINVMD_KERNEL_PATH=$PWD/.scratch/vmlinuz \
MINVMD_ROOTFS_PATH=$PWD/.scratch/rootfs.img \
MINVMD_INITRAMFS=$PWD/.scratch/initramfs.cpio"
sg kvm -c "env $common MINVMD_BOOT_LOG=$PWD/.scratch/boot-e2e.log \
cargo test -p minvmd --test boot_e2e -- --include-ignored --nocapture"
sg kvm -c "env $common \
cargo test -p minvmd --test minimald_session_e2e -- --include-ignored --nocapture --exact minimald_exec_over_bridge"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@justfile` around lines 68 - 80, The test-minvmd-e2e Just recipe assumes
.scratch artifacts already exist, so it can fail on a clean checkout. Update the
test-minvmd-e2e target in the justfile to depend on setup-minvmd before running
the two sg kvm cargo test commands, so the generated boot and rootfs files are
prepared first and the recipe is runnable directly.

# Lane B — print the one-time `sudo usermod -aG kvm` step (durable /dev/kvm access).
setup-kvm-group:
@echo "Run once, then re-login (or prefix VM commands with 'sg kvm -c ...'):"
@echo " sudo usermod -aG kvm $USER"

# Run a native minimald (DM2) foreground, OwnIp switch -> fetched gvproxy (no install).
run-minimald *ARGS: fetch-gvproxy
cargo run -p minimald -- run --gvproxy-bin "{{justfile_directory()}}/.scratch/gvproxy" {{ARGS}}
Loading