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
60 changes: 42 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ driver: libkrun, QEMU, GPU passthrough and virtiofs bind mounts are not part of

It also differs from OpenShell's driver in three behaviors: a sandbox starts the way a
container does, with the image's `ENV` and in the image's `WORKDIR`
([Image ENV and WORKDIR](#image-env-and-workdir)); a sandbox can set its memory and disk size
and have files copied in from the host ([Per-sandbox memory, disk size and files](#per-sandbox-memory-disk-size-and-files));
([Image ENV and WORKDIR](#image-env-and-workdir)); a sandbox can set its vCPUs, memory and disk size
and have files copied in from the host ([Per-sandbox CPU, memory, disk size and files](#per-sandbox-cpu-memory-disk-size-and-files));
and, if enabled, the driver issues SPIFFE JWT-SVIDs to its host supervisors itself, without
a SPIRE agent ([Supervisor identity](#supervisor-identity)).

Expand Down Expand Up @@ -435,9 +435,10 @@ The driver's `OPENSHELL_VM_DEFAULT_WORKDIR` (default `/sandbox`) sets the workin
sandboxes whose image has none ([Image ENV and WORKDIR](#image-env-and-workdir)).
The driver's `OPENSHELL_VM_SUPERVISOR_IDENTITY*` options (optional, off by default) are in
[Supervisor identity](#supervisor-identity).
The driver's `OPENSHELL_VM_MAX_MEM_MIB`, `OPENSHELL_VM_MAX_OVERLAY_DISK_MIB`,
`OPENSHELL_VM_FILES_ROOT` and `OPENSHELL_VM_FILES_MAX_BYTES` limit what a sandbox can request in its `driver_config`; see
[Per-sandbox memory, disk size and files](#per-sandbox-memory-disk-size-and-files).
The driver's `OPENSHELL_VM_MAX_VCPUS` and `OPENSHELL_VM_MAX_MEM_MIB` limit what a sandbox can request
with `--cpu` and `--memory`, and `OPENSHELL_VM_MAX_OVERLAY_DISK_MIB`, `OPENSHELL_VM_FILES_ROOT` and
`OPENSHELL_VM_FILES_MAX_BYTES` what it can request in its `driver_config`; see
[Per-sandbox CPU, memory, disk size and files](#per-sandbox-cpu-memory-disk-size-and-files).
The driver's `OPENSHELL_VM_IMAGE_CACHE_MAX_IDLE_HOURS` (default 48, 0 to keep everything)
sets when unused image disks are removed; see [Image cache cleanup](#image-cache-cleanup).
The driver's `OPENSHELL_VM_LOCAL_IMAGE_SOURCE` (default `auto`) and
Expand All @@ -463,16 +464,40 @@ guest gets compressed swap in its own memory (zram), half its memory by default

zram stretches memory; it does not add any. To give VMs more, raise the driver's default,
`OPENSHELL_VM_DRIVER_MEM_MIB` (`2048`), or let a sandbox ask for more with
`driver_config.mem_mib` ([Per-sandbox memory, disk size and files](#per-sandbox-memory-disk-size-and-files)).
`--memory` ([Per-sandbox CPU, memory, disk size and files](#per-sandbox-cpu-memory-disk-size-and-files)).

It needs the guest kernel from this release or later, and `mkswap` and `swapon` in the
bootstrap image. Without either, the guest boots without swap. `rootfs-console.log`
says which happened: `openshell-firecracker: zram swap on (1024 MiB)`, or why it is off.

## Per-sandbox memory, disk size and files
## Per-sandbox CPU, memory, disk size and files

A sandbox can set its memory and the size of its writable disk, and have files copied in
from the host, through its `driver_config`. None of these is in upstream OpenShell.
A sandbox sets its vCPUs and memory with the standard `--cpu` and `--memory` options of
`openshell sandbox create`. It can also set the size of its writable disk, and have files
copied in from the host, through its `driver_config`. Upstream's VM driver ignores
`--cpu` and `--memory`, and has none of the `driver_config` settings.

### CPU and memory

```shell
openshell sandbox create --cpu 4 --memory 8Gi ...
```

**`--cpu`** is the VM's vCPU count. A Firecracker VM has whole vCPUs, so the value must be
a whole number of CPUs (`4`, or `4000m`); `1.5` is refused rather than rounded. Without
it, a VM gets `OPENSHELL_VM_DRIVER_VCPUS` (2). A request must be between 1 and
`OPENSHELL_VM_MAX_VCPUS`, which defaults to the default vCPUs: set it, up to Firecracker's
32, to let sandboxes ask for more.

**`--memory`** is the VM's memory, as a Kubernetes quantity (`8Gi`, `8192Mi`, `8G`),
rounded down to whole MiB. Without it, a VM gets `OPENSHELL_VM_DRIVER_MEM_MIB` (2048). A
request must be between 256 MiB and `OPENSHELL_VM_MAX_MEM_MIB`, which defaults to the
default memory: set it to let sandboxes ask for more. Unlike the disk, the memory is real
host RAM once the guest touches it.

Neither needs `allow_driver_config`: anyone who can create a sandbox can ask for up to
the two maximums. Stop and start keep the requests, and a start fails if one is outside
the limits in force, for instance after a maximum was lowered.

### Enable driver_config

Expand Down Expand Up @@ -511,7 +536,6 @@ drops the rest:

```shell
openshell sandbox create --driver-config-json '{"firecracker": {
"mem_mib": 4096,
"overlay_disk_mib": 16384,
"files": [
{"source": "app/app.toml", "target": "/etc/app/app.toml", "mode": "0640"},
Expand All @@ -520,11 +544,8 @@ openshell sandbox create --driver-config-json '{"firecracker": {
]}}' ...
```

**`mem_mib`** is the VM's memory. The default is `OPENSHELL_VM_DRIVER_MEM_MIB` (2048). A
request must be between 256 and `OPENSHELL_VM_MAX_MEM_MIB`, which defaults to the default
memory: set it to let sandboxes ask for more. Unlike the disk, the memory is real host RAM
once the guest touches it. Stop and start keep the request; a start fails if it is outside
the limits in force, for instance after the maximum was lowered.
The memory is not a `driver_config` setting: a `mem_mib` there is refused, with a pointer
to `--memory` ([CPU and memory](#cpu-and-memory)).

**`overlay_disk_mib`** is the size of the sandbox's writable overlay disk, which holds
everything the workload writes. The default is `OPENSHELL_VM_OVERLAY_DISK_MIB` (4096). A
Expand Down Expand Up @@ -715,7 +736,7 @@ Limits:

- No virtiofs bind mounts and no GPU passthrough on Firecracker. A sandbox that asks for
either is rejected at validation, not ignored. To get host files into a guest, use
[`driver_config.files`](#per-sandbox-memory-disk-size-and-files), which copies them in.
[`driver_config.files`](#per-sandbox-cpu-memory-disk-size-and-files), which copies them in.
- `[openshell.supervisor.network].additional_ca_bundle` and the shared supervisor pool
are rejected by the gateway for any external driver.
- Rootfs tar uploads need the driver and gateway on the same filesystem and UID.
Expand All @@ -737,9 +758,12 @@ Limits:
- The guest environment file sits in the sandbox's own overlay (mode `0600`, root-owned).
It holds what the driver passes to the guest init.
- Firecracker's `jailer` is not used.
- Anyone who can create a sandbox can ask for vCPUs up to `OPENSHELL_VM_MAX_VCPUS` and
memory up to `OPENSHELL_VM_MAX_MEM_MIB`, with or without `allow_driver_config`; keep
the memory maximum within what the host can give every sandbox at once.
- With `allow_driver_config` on, anyone who can create a sandbox can read every file under
`OPENSHELL_VM_FILES_ROOT` by copying it into their sandbox, can ask for memory up to
`OPENSHELL_VM_MAX_MEM_MIB` and a disk up to `OPENSHELL_VM_MAX_OVERLAY_DISK_MIB`. Put only what all sandbox users may see in the files
`OPENSHELL_VM_FILES_ROOT` by copying it into their sandbox, and can ask for a disk up to
`OPENSHELL_VM_MAX_OVERLAY_DISK_MIB`. Put only what all sandbox users may see in the files
root, and keep the maximum within the host's free space: overlays are sparse, so the host
disk fills only as guests write, but it can fill.

Expand Down
22 changes: 14 additions & 8 deletions examples/firecracker-driver.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ OPENSHELL_VM_LAUNCHER_BIN=/usr/local/libexec/openshell-firecracker/openshell-fir

# Compressed swap (zram) in each guest, as a percentage of its memory: 0 to 200,
# 0 for none. For more memory, raise OPENSHELL_VM_DRIVER_MEM_MIB (default 2048), or set
# OPENSHELL_VM_MAX_MEM_MIB below and request driver_config.mem_mib per sandbox.
# OPENSHELL_VM_MAX_MEM_MIB below and create sandboxes with --memory.
# OPENSHELL_VM_FIRECRACKER_ZRAM_PERCENT=50

# --- Supervisor identity (optional) ------------------------------------------
Expand All @@ -61,17 +61,23 @@ OPENSHELL_VM_LAUNCHER_BIN=/usr/local/libexec/openshell-firecracker/openshell-fir
# OPENSHELL_VM_SUPERVISOR_IDENTITY_ISSUER=https://openshell-identity.example.com
# OPENSHELL_VM_SUPERVISOR_IDENTITY_SVID_TTL_SECS=300

# --- Per-sandbox memory, disk size and files (optional) -----------------------
# --- Per-sandbox CPU, memory, disk size and files (optional) ------------------

# Limits for what a sandbox may request in its driver_config. See "Per-sandbox memory,
# disk size and files" in the README. Sandboxes can request these only when allow_driver_config is
# on (OPENSHELL_DRIVER_ADMISSION_CONFIG_JSON above, and the gateway table).
# Limits for what a sandbox may request. See "Per-sandbox CPU, memory, disk size and
# files" in the README. Any sandbox can request vCPUs and memory (sandbox create --cpu and
# --memory).
# Largest --cpu a sandbox may ask for, at most 32. Unset: no more than the default vCPUs,
# OPENSHELL_VM_DRIVER_VCPUS (2).
# OPENSHELL_VM_MAX_VCPUS=8
# Largest --memory a sandbox may ask for, in MiB. Unset: no more than the default memory,
# OPENSHELL_VM_DRIVER_MEM_MIB (2048).
# OPENSHELL_VM_MAX_MEM_MIB=8192
# The rest are driver_config settings, which sandboxes can request only when
# allow_driver_config is on (OPENSHELL_DRIVER_ADMISSION_CONFIG_JSON above, and the gateway
# table).
# Largest overlay_disk_mib a sandbox may ask for (the default size is
# OPENSHELL_VM_OVERLAY_DISK_MIB, 4096).
# OPENSHELL_VM_MAX_OVERLAY_DISK_MIB=65536
# Largest mem_mib a sandbox may ask for. Unset: no more than the default memory,
# OPENSHELL_VM_DRIVER_MEM_MIB (2048).
# OPENSHELL_VM_MAX_MEM_MIB=8192
# Host directory that driver_config.files sources are read from. Unset: no files.
# OPENSHELL_VM_FILES_ROOT=/home/USER/.local/share/openshell/sandbox-files
# Total bytes of files one sandbox may provision.
Expand Down
9 changes: 8 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,18 @@ install_config() {
fi
if [ -f "$envfile" ] && ! grep -q 'OPENSHELL_VM_MAX_MEM_MIB' "$envfile"; then
printf '\n%s\n%s\n%s\n' \
"# Added by install.sh. Largest driver_config.mem_mib a sandbox may ask for." \
"# Added by install.sh. Largest --memory a sandbox may ask for, in MiB." \
"# Unset: no more than the default memory, OPENSHELL_VM_DRIVER_MEM_MIB (2048)." \
"# OPENSHELL_VM_MAX_MEM_MIB=8192" >> "$envfile"
say "added a commented-out OPENSHELL_VM_MAX_MEM_MIB to $envfile"
fi
if [ -f "$envfile" ] && ! grep -q 'OPENSHELL_VM_MAX_VCPUS' "$envfile"; then
printf '\n%s\n%s\n%s\n' \
"# Added by install.sh. Largest --cpu a sandbox may ask for, at most 32." \
"# Unset: no more than the default vCPUs, OPENSHELL_VM_DRIVER_VCPUS (2)." \
"# OPENSHELL_VM_MAX_VCPUS=8" >> "$envfile"
say "added a commented-out OPENSHELL_VM_MAX_VCPUS to $envfile"
fi
}

[ "$DO_BINARIES" -eq 0 ] || install_binaries
Expand Down
12 changes: 8 additions & 4 deletions vendor/openshell/crates/openshell-driver-vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ Changes from upstream:
that attested process. It serves OIDC discovery and JWKS endpoints over HTTP. The server
stub is generated in `build.rs` without `protoc`. See `src/supervisor_identity/` and
"Supervisor identity" in the repository README.
- **Per-sandbox memory, disk size and files.** `driver_config.mem_mib` sets a sandbox's
memory, from 256 MiB up to `OPENSHELL_VM_MAX_MEM_MIB` (default: `OPENSHELL_VM_DRIVER_MEM_MIB`,
which stays the default size). `driver_config.overlay_disk_mib` sets the size of a
- **CPU and memory limits.** Upstream ignores a template's `cpu_limit` and `memory_limit`
(`sandbox create --cpu / --memory`) and reports both limits unsupported. Here they set the
VM's vCPUs (whole CPUs only, up to `OPENSHELL_VM_MAX_VCPUS`, at most 32) and memory (256 MiB
up to `OPENSHELL_VM_MAX_MEM_MIB`); each maximum defaults to the default size,
`OPENSHELL_VM_DRIVER_VCPUS` and `OPENSHELL_VM_DRIVER_MEM_MIB`. Both are checked at create
and again at every launch. See `VmDriverConfig::sandbox_machine` in `src/driver.rs`.
- **Per-sandbox disk size and files.** `driver_config.overlay_disk_mib` sets the size of a
sandbox's writable overlay disk, up to `OPENSHELL_VM_MAX_OVERLAY_DISK_MIB`.
`driver_config.files` copies files and directories from `OPENSHELL_VM_FILES_ROOT` into the
guest: the driver stages them in the overlay's upper layer and a guest init drop-in copies
them into place with the requested owner and mode. See `src/sandbox_storage.rs` and
"Per-sandbox memory, disk size and files" in the repository README.
"Per-sandbox CPU, memory, disk size and files" in the repository README.
- **Image cache cleanup.** Upstream never deletes a prepared disk. When the driver starts
and after each sandbox start, stop or delete, it removes cache entries no sandbox
references: those from other driver builds at once, and its own build's once unused for
Expand Down
Loading
Loading