Skip to content

Commit 279679d

Browse files
Enrique SaurezCopilot
authored andcommitted
sandbox: run a workload once through the managed VM API
sandbox run still booted a one-shot VM: it passed its shares and its workload as boot tokens, and ran OpenVMM on the terminal with its lifecycle option, so that the shell /init booted the layered root through the old one-shot init, and it exited with OpenVMM's status. A run now launches the VM that a provision and a start of the same options would launch, without a state directory. It serializes the configuration that provision records, reads it back as start does, and launches it through host::vm in a temporary VM directory, with nvx_sandbox=1 and no OpenVMM lifecycle option, so that nvx-init boots its root. Once nvx-init is ready and has mapped the shares, the run executes its workload once over NVXC, with exec's --cwd, --environment, --environment-file, and --inherit-default-environment, asks nvx-init to stop the VM, waits up to --timeout for it to exit before it forces it down, then writes the workload's output and exits with its status. A run takes provision's --layer-format, for an EROFS or a GPT image, and --ram-upper-percent, for a RAM upper's cap, 50 percent by default. It refuses --state-dir, and checks its command line and its request before it downloads or launches anything. It refuses the shares that start refuses, with its temporary VM directory in place of a state directory, through which the workload could change what OpenVMM writes there, and those of the OpenVMM that it runs, which NVX_OPENVMM may name instead of the artifact root's; provision and start refuse a share of that one too (#818). --outcome-report forwards OpenVMM's report of the run, which keeps its owner's permissions whatever the umask. The one-shot plan, its boot tokens, and its prepared launch, which nothing else used, are gone. The CLI tests of the run cover each format and upper, exec's options, shares, the refusal of the sandbox's own files, of its VM directory, and of the OpenVMM that NVX_OPENVMM names, a guest that exits during startup, a workload that the guest refuses, a VM that does not stop, and the outcome report under restrictive umasks; the dry-run, validation, and one-shot tests take the managed run's command and refusals. The public sandbox scenarios and the CI smoke steps run the smoke probe with the init profile, which a managed execution has, and expect a caller-owned share to fail the run before its workload, as it fails a start. This replays esaurez's first implementation, a734c60, adapted to the typed record, the CLI-owned lifecycle, and SL3.4a's cold boot. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5583fe3 commit 279679d

30 files changed

Lines changed: 1753 additions & 1250 deletions

‎.github/workflows/run-nvx-microvm-tests.yml‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,14 @@ jobs:
341341
)
342342
scratch="build/ubuntu-smoke-${{ inputs.backend }}.ext4"
343343
cp --reflink=auto build/ubuntu-smoke-scratch.ext4 "${scratch}"
344-
# The probe checks the security profile.
344+
# A run executes the probe once, as nvx-init runs each execution,
345+
# and the probe checks the security profile of that execution.
345346
nvx-rs/target/release/nvx-rs sandbox \
346347
--hypervisor "${{ inputs.backend }}" \
347348
--layer "distro,build/ubuntu-distro.erofs,${uuid}" \
348349
--scratch "${scratch}" \
349350
--entrypoint /sbin/nvx-sandbox-smoke \
351+
--arg init \
350352
--workload-user 65534:65534 \
351353
--memory-mib 256
352354
@@ -377,6 +379,7 @@ jobs:
377379
--mount "/workspace,${share},rw" \
378380
--mount-deny nvx-denied \
379381
--entrypoint /sbin/nvx-sandbox-smoke \
382+
--arg init \
380383
--arg /workspace \
381384
--arg rw \
382385
--workload-user 65534:65534 \
@@ -403,6 +406,7 @@ jobs:
403406
--mount "/opt/hostedtoolcache,${share},ro" \
404407
--mount-deny nvx-denied \
405408
--entrypoint /sbin/nvx-sandbox-smoke \
409+
--arg init \
406410
--arg /opt/hostedtoolcache \
407411
--arg ro \
408412
--workload-user 65534:65534 \
@@ -511,18 +515,30 @@ jobs:
511515
# group. With --mount-owner caller, every share operation must fail
512516
# with EPERM instead of running as the runner. The OpenVMM unit tests
513517
# cover the identity of each request, including guest root squash.
518+
# A run maps its shares as a start does: its guest agent reaches the
519+
# share as guest root, which the mode squashes to the share's owner,
520+
# before any workload runs, so that request fails with EPERM, and the
521+
# run fails without running its workload.
514522
cp --reflink=auto build/ubuntu-smoke-scratch.ext4 "${scratch}"
515-
nvx-rs/target/release/nvx-rs sandbox \
523+
errors=$(mktemp)
524+
if nvx-rs/target/release/nvx-rs sandbox \
516525
--hypervisor "${{ inputs.backend }}" \
517526
--layer "distro,build/ubuntu-distro.erofs,${uuid}" \
518527
--scratch "${scratch}" \
519528
--mount "/workspace,${share},rw" \
520529
--mount-owner caller \
521530
--entrypoint /sbin/nvx-sandbox-smoke \
531+
--arg init \
522532
--arg /workspace \
523533
--arg eperm \
524534
--workload-user 65534:65534 \
525-
--memory-mib 256
535+
--memory-mib 256 2>"${errors}"; then
536+
echo "the caller-owned run reached its share as the runner" >&2
537+
exit 1
538+
fi
539+
cat "${errors}" >&2
540+
grep -q 'could not mount a mapped host path (error 1)' "${errors}"
541+
rm -f "${errors}"
526542
test "$(ls -A "${share}")" = nvx-host-marker
527543
# A managed sandbox persists the ownership mode and applies it on
528544
# start. Its guest agent reaches the share as guest root, which the
@@ -645,7 +661,7 @@ jobs:
645661
--layer "distro,build/ubuntu-distro.erofs,${uuid}" \
646662
--scratch "${scratch}" \
647663
"${share_options[@]}" \
648-
"${smoke_arguments[@]}" \
664+
--arg init "${smoke_arguments[@]}" \
649665
--workload-user 65534:65534 \
650666
--memory-mib 256
651667
check_shares
@@ -770,7 +786,7 @@ jobs:
770786
--layer "distro,build/ubuntu-distro.erofs,${uuid}" \
771787
--scratch "${scratch}" \
772788
"${share_options[@]}" \
773-
"${smoke_arguments[@]}" \
789+
--arg init "${smoke_arguments[@]}" \
774790
--workload-user 65534:65534 \
775791
--memory-mib 256
776792
check_share
@@ -844,12 +860,14 @@ jobs:
844860
ConvertFrom-Json
845861
$scratch = "build\ubuntu-smoke-${{ inputs.backend }}.ext4"
846862
Copy-Item build\ubuntu-smoke-scratch.ext4 $scratch
847-
# The probe checks the security profile.
863+
# A run executes the probe once, as nvx-init runs each execution,
864+
# and the probe checks the security profile of that execution.
848865
nvx-rs\target\release\nvx-rs.exe sandbox `
849866
--hypervisor "${{ inputs.backend }}" `
850867
--layer "distro,build\ubuntu-distro.erofs,$($manifest.uuid)" `
851868
--scratch $scratch `
852869
--entrypoint /sbin/nvx-sandbox-smoke `
870+
--arg init `
853871
--workload-user 65534:65534 `
854872
--memory-mib 256
855873
@@ -878,6 +896,7 @@ jobs:
878896
--mount "/workspace,$share,rw" `
879897
--mount-deny nvx-denied `
880898
--entrypoint /sbin/nvx-sandbox-smoke `
899+
--arg init `
881900
--arg /workspace `
882901
--arg rw `
883902
--workload-user 65534:65534 `
@@ -921,6 +940,7 @@ jobs:
921940
--mount "/opt/hostedtoolcache,$share,ro" `
922941
--mount-deny nvx-denied `
923942
--entrypoint /sbin/nvx-sandbox-smoke `
943+
--arg init `
924944
--arg /opt/hostedtoolcache `
925945
--arg ro `
926946
--workload-user 65534:65534 `
@@ -1101,7 +1121,7 @@ jobs:
11011121
if ([IO.File]::ReadAllText((Join-Path $files "results\other.txt")) -ne "other`n") { throw "guest changed a file beside a shared file" }
11021122
}
11031123
Initialize-Shares
1104-
Invoke-Nvx sandbox --hypervisor "${{ inputs.backend }}" --layer $layer --scratch $scratch @shareOptions @smokeArguments --workload-user 65534:65534 --memory-mib 256
1124+
Invoke-Nvx sandbox --hypervisor "${{ inputs.backend }}" --layer $layer --scratch $scratch @shareOptions --arg init @smokeArguments --workload-user 65534:65534 --memory-mib 256
11051125
Test-Shares
11061126
# A managed sandbox persists every share and reattaches them on start.
11071127
Initialize-Shares
@@ -1202,7 +1222,7 @@ jobs:
12021222
}
12031223
}
12041224
Initialize-Share
1205-
Invoke-Nvx sandbox --hypervisor "${{ inputs.backend }}" --layer $layer --scratch $scratch @shareOptions @smokeArguments --workload-user 65534:65534 --memory-mib 256
1225+
Invoke-Nvx sandbox --hypervisor "${{ inputs.backend }}" --layer $layer --scratch $scratch @shareOptions --arg init @smokeArguments --workload-user 65534:65534 --memory-mib 256
12061226
Test-Share
12071227
# A managed sandbox persists the access policy and reapplies it on
12081228
# start.

‎doc/ci.md‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,13 @@ that read it as a workflow artifact of its own, under its build filenames (see
537537
[Guest artifact handoff](#guest-artifact-handoff)). Each
538538
backend also boots the Ubuntu initramfs and runs
539539
`/sbin/nvx-sandbox-smoke` from the Ubuntu EROFS layer as UID/GID 65534 over a
540-
fresh ext4 scratch copy. The probe verifies the
541-
[sandbox security profile](run.md#experimental-single-workload-sandbox): the
542-
fixed identity, empty capability sets and `no_new_privs`, private mount, PID,
543-
and UTS namespaces, the private device view and read-only sysfs, the
544-
container cgroup, and the overlay root over read-only image layers with its
545-
upper directory on scratch. The live-share runs below repeat the profile
546-
checks. Each
540+
fresh ext4 scratch copy, as the one workload of an `nvx-rs sandbox run`, which
541+
nvx-init executes. The probe verifies the
542+
[sandbox security profile](run.md#experimental-single-workload-sandbox) of
543+
such an execution: the fixed identity, empty capability sets and
544+
`no_new_privs`, the host name, the device view and read-only sysfs, and the
545+
overlay root over read-only image layers with its upper directory on scratch.
546+
The live-share runs below repeat the profile checks. Each
547547
backend also runs the public `managed-exec-config`, `sandbox-lifecycle`,
548548
`sandbox-proxy-only`, and `sandbox-ram-upper` scenarios of `test-microvm`,
549549
which drive `nvx-rs sandbox run`, `provision`, `start`,
@@ -587,7 +587,7 @@ read-write file but neither remove nor rename either one. The host requires
587587
the guest's writes in the workspace and the read-write file, an unchanged tool
588588
cache, read-only file, and denied files, and unchanged files beside the shared
589589
files, both for a
590-
one-shot run and for a managed sandbox whose format-6 configuration must
590+
run and for a managed sandbox whose format-6 configuration must
591591
persist every share and its kind and whose `stop` must leave a cleanly
592592
unmounted scratch
593593
filesystem. Each backend then attaches a read-write `/workspace` share whose
@@ -599,8 +599,8 @@ writes to succeed only in `nvx-writable` and to fail with `EROFS` everywhere
599599
else, a hard link of a read-only file into `nvx-writable` to fail, and
600600
`nvx-denied` to list only `nvx-allowed`, whose file stays readable while
601601
`nvx-denied/secret` stays hidden. The host requires the guest's writes in
602-
`nvx-writable` and no other change to the share, both for a one-shot run and
603-
for a managed sandbox whose format-5 configuration must persist the denied,
602+
`nvx-writable` and no other change to the share, both for a run and for a
603+
managed sandbox whose format-5 configuration must persist the denied,
604604
allowed, and writable paths and whose `stop` must leave a cleanly unmounted
605605
scratch filesystem. The default `filesystem-policy` scenario of `test-microvm`
606606
covers the same policy as guest root, whose permission checks mode bits never
@@ -612,13 +612,14 @@ writable handle open across the capture. On Linux, a
612612
world-writable share then runs with `--mount-owner caller`. The runners grant
613613
OpenVMM neither `CAP_SETUID` nor `CAP_SETGID`, so it can neither assume the
614614
65534 workload identity nor drop the backend group through which it opens
615-
`/dev/kvm` or `/dev/mshv`. The smoke script's `eperm` mode therefore
616-
requires reading and listing the share to fail with `EPERM` and writes to
617-
fail, and the host requires the share to be unchanged, both for a one-shot
618-
run and for a managed sandbox whose configuration must persist the mode. The `filesystem-owner` scenario of
619-
`test-microvm` likewise requires guest root and a foreign guest identity to
620-
fail with `EPERM` on the runners, and a root-owned export to be rejected
621-
before boot; on Windows, `--mount-owner caller` must be rejected before boot.
615+
`/dev/kvm` or `/dev/mshv`. The guest agent of a run, and of a managed
616+
sandbox whose configuration must persist the mode, therefore fails to map the
617+
share with `EPERM` before any workload runs, which fails the run and the
618+
start, and the host requires the share to be unchanged. The `filesystem-owner`
619+
scenario of `test-microvm` likewise requires guest root and a foreign guest
620+
identity to fail with `EPERM` on the runners, and a root-owned export to be
621+
rejected before boot; on Windows, `--mount-owner caller` must be rejected
622+
before boot.
622623
OpenVMM's unit tests, which its own CI runs (see [OpenVMM CI](#openvmm-ci)),
623624
check the host identity that each request runs as,
624625
including guest root squashed to an export owner other than OpenVMM. Where

0 commit comments

Comments
 (0)