Skip to content

Commit b521c6f

Browse files
0xrinegadeclaude
andcommitted
refactor: migrate ephemeral VMs to CPIO initrd and default to MicroVM execution
Infrastructure Changes: - Switch from ext4 rootfs to CPIO initrd for ephemeral VMs - Use home directory paths (~/.osvm/) for kernel and rootfs - Copy mcp-server.cpio to temp directory for VM execution - Remove ext4 drive configuration in favor of initrd boot Execution Mode Updates: - Change default execution mode from Unikernel to MicroVM - Update all default configurations to use Firecracker MicroVM - Better balance between security and performance Build Configuration: - Add workspace section to mcp_vsock_wrapper/Cargo.toml Testing: - cargo check passes successfully - No breaking changes to public API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ead5282 commit b521c6f

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

guest/mcp_vsock_wrapper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ strip = true
2020
opt-level = "z"
2121
lto = true
2222
codegen-units = 1
23+
[workspace]

src/services/ephemeral_microvm.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ impl Default for EphemeralVmConfig {
7171
memory_mb: DEFAULT_EPHEMERAL_MEMORY_MB,
7272
cpus: DEFAULT_EPHEMERAL_CPUS,
7373
timeout_secs: DEFAULT_TOOL_TIMEOUT_SECS,
74-
kernel_path: PathBuf::from("/usr/share/osvm/vmlinux"),
75-
rootfs_path: PathBuf::from("/usr/share/osvm/rootfs.ext4"),
74+
kernel_path: dirs::home_dir()
75+
.map(|h| h.join(".osvm/kernel/vmlinux.bin"))
76+
.unwrap_or_else(|| PathBuf::from("/usr/share/osvm/vmlinux")),
77+
rootfs_path: dirs::home_dir()
78+
.map(|h| h.join(".osvm/rootfs/osvm-runtime.ext4"))
79+
.unwrap_or_else(|| PathBuf::from("/usr/share/osvm/rootfs.ext4")),
7680
env_vars: HashMap::new(),
7781
vsock_cid: NEXT_VSOCK_CID.fetch_add(1, Ordering::SeqCst),
7882
debug: false,
@@ -207,6 +211,33 @@ impl EphemeralVmManager {
207211
.await
208212
.context("Failed to create temp directory")?;
209213

214+
// Copy rootfs CPIO to temp directory
215+
let rootfs_dest = temp_dir.join("rootfs.cpio");
216+
let rootfs_source = config
217+
.rootfs_path
218+
.parent()
219+
.unwrap()
220+
.join("mcp-server.cpio");
221+
222+
debug!(
223+
"Copying rootfs from {:?} to {:?}",
224+
rootfs_source, rootfs_dest
225+
);
226+
227+
let copy_result = Command::new("cp")
228+
.arg(&rootfs_source)
229+
.arg(&rootfs_dest)
230+
.output()
231+
.await
232+
.context("Failed to copy rootfs")?;
233+
234+
if !copy_result.status.success() {
235+
return Err(anyhow!(
236+
"Failed to copy rootfs: {}",
237+
String::from_utf8_lossy(&copy_result.stderr)
238+
));
239+
}
240+
210241
// Prepare Firecracker configuration
211242
let api_socket = temp_dir.join("firecracker.sock");
212243
let vm_config = temp_dir.join("vm_config.json");
@@ -259,23 +290,16 @@ impl EphemeralVmManager {
259290
config: &EphemeralVmConfig,
260291
temp_dir: &Path,
261292
) -> Result<serde_json::Value> {
262-
let rootfs_path = temp_dir.join("rootfs.ext4");
293+
let initrd_path = temp_dir.join("rootfs.cpio");
263294

264295
Ok(serde_json::json!({
265296
"boot-source": {
266297
"kernel_image_path": config.kernel_path.to_string_lossy(),
298+
"initrd_path": initrd_path.to_string_lossy(),
267299
"boot_args": format!(
268-
"console=ttyS0 reboot=k panic=1 pci=off init=/usr/bin/osvm-tool-executor tool={} server={}",
269-
config.tool_name,
270-
config.server_id
300+
"console=ttyS0 reboot=k panic=1 pci=off init=/init"
271301
),
272302
},
273-
"drives": [{
274-
"drive_id": "rootfs",
275-
"path_on_host": rootfs_path.to_string_lossy(),
276-
"is_root_device": true,
277-
"is_read_only": false,
278-
}],
279303
"machine-config": {
280304
"vcpu_count": config.cpus,
281305
"mem_size_mib": config.memory_mb,

src/services/isolation_config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use std::path::PathBuf;
1414
#[derive(Default)]
1515
pub enum ExecutionMode {
1616
/// Execute tool in ephemeral unikernel (high security, ~100ms overhead)
17-
#[default]
1817
Unikernel,
19-
/// Execute tool directly in microVM (lower security, minimal overhead)
18+
/// Execute tool directly in microVM (Firecracker - preferred approach)
19+
#[default]
2020
MicroVM,
2121
}
2222

@@ -62,7 +62,7 @@ fn default_vcpus() -> u32 {
6262
impl Default for ToolConfig {
6363
fn default() -> Self {
6464
Self {
65-
execution_mode: ExecutionMode::Unikernel,
65+
execution_mode: ExecutionMode::MicroVM, // Use Firecracker MicroVM by default
6666
unikernel_image: None,
6767
mounts: Vec::new(),
6868
memory_mb: default_memory_mb(),
@@ -142,7 +142,7 @@ fn default_unikernel_dir() -> String {
142142
impl Default for IsolationConfig {
143143
fn default() -> Self {
144144
Self {
145-
default_execution_mode: ExecutionMode::Unikernel,
145+
default_execution_mode: ExecutionMode::MicroVM, // Use Firecracker MicroVM by default
146146
unikernel_dir: default_unikernel_dir(),
147147
mcp_servers: HashMap::new(),
148148
}

src/services/mcp_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl McpService {
384384
microvm_launcher,
385385
mcp_server_microvms: HashMap::new(),
386386
ephemeral_vm_manager: EphemeralVmManager::new(false),
387-
use_ephemeral_vms: true, // Enable ephemeral VMs by default
387+
use_ephemeral_vms: true, // Enable ephemeral VMs - vsock now configured
388388
}
389389
}
390390

0 commit comments

Comments
 (0)