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
23 changes: 22 additions & 1 deletion ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,30 @@ The site is a read-only disk built from the app root with `mke2fs -d`, mounted a
(or `--guest-root`, the root nginx sends in `SCRIPT_FILENAME`). The guest's root is read-only
too, so core, plugins and themes can't be written. Its PID 1 is `securecore-fpm` again, as
`/sbin/securecore-init`: it mounts the disks, forwards vsock and starts php-fpm, whose log comes
back to the launcher's stderr. Layers 2 and 3 run in the guest's php-fpm unchanged; layer 3's
back to the launcher's stderr, every line numbered and acknowledged, so a line that can't be
delivered is counted in the launcher's log, never silently dropped (#86). When php-fpm exits,
the guest sends its last lines and its exit status first, and the launcher's stop line quotes
them (#87). Layers 2 and 3 run in the guest's php-fpm unchanged; layer 3's
isolated children need Landlock and seccomp in the guest kernel (mirab#89 adds them to mirab's).

**Editing `securecore.json` while the guest runs** (#90). The launcher follows the file, as the
extension does on a host (a look a second, the same parser), reading it as the pool user, never
through a link and at most 128 KiB (a link, a device or a larger file is refused and logged): an
invalid file is refused and
logged, and the guest keeps the last valid config; a valid one is also checked against what a
start would check (a config the microVM can't run is refused the same way), then put in place
of the guest's copy, where the extension reloads it within a second. As on a host, layers 2 and
3 change in place, and a change to `layer1` or the vault applies at the next start
(`restart_needed`); the host's egress takes layer 2's new hosts at once.

**The site's php.ini settings** (#90). php.ini in the guest is the root image's, the same for
every site. `--guest-ini <file>` names a file of the extension's per-site debug settings
(`securecore.debug_* = …` lines with plain-word values, `[a-z0-9_.,:-]`, so no `${VAR}`; any
other setting is refused with the reason, which never quotes the file), delivered in
each start message and again whenever the file changes, with php-fpm started again gracefully,
as a php.ini change needs on a host. A value the extension refuses stops php-fpm, as it would
on a host, and the launcher's log says why.

**Snapshots.** A start restores a snapshot of a warmed-up VM when there is one for this key: the
sha256s of Firecracker, the kernel, the root image, the site tree (every path, mode, owner, size
and mtime, writable folders excepted) and `securecore.json`, plus the memory, vCPUs, boot
Expand Down
248 changes: 242 additions & 6 deletions ext/fpm/src/guest.rs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions ext/fpm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const USAGE: &str = "usage: securecore-fpm --config <securecore.json> [--php-fpm
[--vm-dir <dir>] [--vm-user <name>|<uid>:<gid>] [--pool-user <name>|<uid>:<gid>] [--kvm <device>] [--state-dir <dir>] \
[--listen unix:<path>|<host>:<port>] [--listen-owner <user>] [--listen-group <group>] [--listen-mode <octal>] \
[--guest-root <path>] [--mem <MiB>] [--vcpus <n>] [--write-disk-mib <MiB>] [--no-snapshot] \
[--guest-arg <word>]... [--guest-env <NAME>]... [--] [php-fpm args...] | securecore-fpm --migrate-config <securecore.json>";
[--guest-arg <word>]... [--guest-env <NAME>]... [--guest-ini <file>] [--] [php-fpm args...] | securecore-fpm --migrate-config <securecore.json>";

struct Args {
config: PathBuf,
Expand All @@ -49,6 +49,7 @@ struct Args {
snapshot: bool,
guest_args: Vec<String>,
guest_env: Vec<String>,
guest_ini: Option<PathBuf>,
rest: Vec<OsString>,
}

Expand All @@ -75,6 +76,7 @@ fn parse(args: impl IntoIterator<Item = OsString>) -> Result<Option<Args>, Strin
snapshot: true,
guest_args: Vec::new(),
guest_env: Vec::new(),
guest_ini: None,
rest: Vec::new(),
};
let mut config = None;
Expand All @@ -91,7 +93,7 @@ fn parse(args: impl IntoIterator<Item = OsString>) -> Result<Option<Args>, Strin
a.snapshot = false;
}
"--config" | "--php-fpm" | "--vm-dir" | "--vm-user" | "--pool-user" | "--kvm" | "--state-dir" | "--listen" | "--listen-owner"
| "--listen-group" | "--listen-mode" | "--guest-root" | "--mem" | "--vcpus" | "--write-disk-mib" | "--guest-arg" | "--guest-env" => {
| "--listen-group" | "--listen-mode" | "--guest-root" | "--mem" | "--vcpus" | "--write-disk-mib" | "--guest-arg" | "--guest-env" | "--guest-ini" => {
args.next();
let value = args.next().ok_or_else(|| format!("{flag} needs a value"))?;
let text = || value.to_str().map(str::to_owned).ok_or_else(|| format!("{flag}: not UTF-8"));
Expand All @@ -118,6 +120,7 @@ fn parse(args: impl IntoIterator<Item = OsString>) -> Result<Option<Args>, Strin
"--vcpus" => a.vcpus = number()?,
"--write-disk-mib" => a.write_disk_mib = u64::from(number()?),
"--guest-env" => a.guest_env.push(text()?),
"--guest-ini" => a.guest_ini = Some(PathBuf::from(&value)),
_ => a.guest_args.push(text()?),
}
}
Expand Down Expand Up @@ -183,6 +186,7 @@ mod microvm {
snapshot: a.snapshot,
guest_args: a.guest_args.clone(),
guest_env: a.guest_env.clone(),
guest_ini: a.guest_ini.clone(),
})
}

Expand Down
Loading
Loading