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
70 changes: 70 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ this file is the overview. Order within a section is priority.
verified with a GitHub sign-in, without an instance admin's approval
- [ ] GitHub sign-in as a way to sign in to fctl
- [ ] Merging two accounts into one with both their addresses
- [ ] Linux hosts with Firecracker microVMs
- [x] Linux hosts with Firecracker microVMs: the `firecracker` driver, experimental
- [ ] Windows hosts through WSL 2
9 changes: 9 additions & 0 deletions crates/fctl-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ tokio.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

# The init of Firecracker microVMs (src/vm).
[target.'cfg(target_os = "linux")'.dependencies]
flate2.workspace = true
nix = { workspace = true, features = ["hostname", "mount", "net", "reboot", "resource", "socket", "time"] }
tar.workspace = true
tokio-tun = "0.15.2"
tokio-vsock = "0.7.2"
vsock = "0.5.4"

[dev-dependencies]
tempfile = "3"

Expand Down
51 changes: 51 additions & 0 deletions crates/fctl-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! - `fctl-agent serve` runs the supervisor (started detached by the host).
//! - `fctl-agent attach` connects stdin/stdout to it (the host's channel).
//! - As PID 1 it is a Firecracker microVM's init, and `vm-serve` and
//! `vm-run` run what the host asks there (src/vm).
//!
//! See docs/architecture.md and crates/fctl-proto/src/agent.rs.

Expand All @@ -16,6 +18,8 @@ mod prompt;
mod refresh;
mod supervisor;
mod tasks;
#[cfg(target_os = "linux")]
mod vm;
mod workspace;

use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -59,10 +63,42 @@ enum Command {
)]
socket: PathBuf,
},
/// Run what the host asks in a Firecracker microVM, under its init.
#[cfg(target_os = "linux")]
#[command(hide = true)]
VmServe,
/// Run a program as a user, in a session of its own (for vm-serve).
#[cfg(target_os = "linux")]
#[command(hide = true)]
VmRun {
uid: u32,
gid: u32,
/// Supplementary groups, separated by commas.
groups: String,
cwd: String,
#[arg(last = true, required = true)]
argv: Vec<String>,
},
}

fn main() -> anyhow::Result<()> {
// As a microVM's PID 1, fctl-agent is its init.
#[cfg(target_os = "linux")]
if std::process::id() == 1 {
vm::init();
}
let cli = Cli::parse();
#[cfg(target_os = "linux")]
if let Command::VmRun {
uid,
gid,
groups,
cwd,
argv,
} = &cli.command
{
return vm::run_as(*uid, *gid, groups, cwd, argv);
}
let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.enable_all()
Expand All @@ -77,6 +113,21 @@ fn main() -> anyhow::Result<()> {
r
}
Command::Attach { socket } => rt.block_on(link::attach(&socket)),
#[cfg(target_os = "linux")]
Command::VmServe => {
// To the VM's console, which the host keeps in a file.
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_env("FCTL_LOG")
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.with_ansi(false)
.with_writer(std::io::stderr)
.init();
rt.block_on(vm::serve())
}
#[cfg(target_os = "linux")]
Command::VmRun { .. } => Ok(()),
}
}

Expand Down
Loading