mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
A first run built its tool images one after another, each paying a build VM's boot (5.7 s on vz, 9.3 s on QEMU) before a download of a few seconds to a minute. Share.Build now hands the images out to up to four slots (buildAll), each slot's builds one after another in a build VM of its own: - slots: as many as the host's memory, less what the backend's running VMs have, and its CPUs give a build VM of 2 GiB and 2 CPUs each after keeping 6 GiB and 2 CPUs, at most backend.MaxToolSlots (4) and the number of images; one alone keeps base's size. A backend that can't list its VMs builds one at a time. A running VM's memory counts whole (7.5 GiB, not 7): TestBuildSlotsFit's running VMs fail when it isn't counted or is truncated. - plan lowers the slots until the backend's disks have room: Floors.ForTools counts Tools once for each build VM at once, as on a disk without copy on write each is a whole copy of base. - backend.ToolsSpec gets Slot, Slots, Size and Hold; Lima's slot VMs are the constants ToolsVM to ToolsVM4, sized with --cpus/--memory, and the first slot's build deletes what a killed run left in the slots this run doesn't use. Builds hold the share's lock, so one devvm uses the slots. - A failed build's VM goes in the run's cleanup, which runs after the build let go of the share's lock: it deletes the VM only once it has the lock again (ToolsSpec.Hold, Env.holdShare's TryLockFile), and leaves it while another devvm holds it (a build, gc or the daily refresh) (TestBuildToolsCleanupHolds, TestBuildHoldsShareForCleanup). The next tools build deletes what it finds in the slots, and so does devvm gc, which holds the share's lock: backend.Images' DeleteToolsLeft, Lima's deleting the slots' build VMs that are there and no other VM, which gc asks of every backend first, without asking, a backend that can't being a run log line. It returns what it deleted, which gc names in one line (tools_build_vms_deleted), and gc then never says nothing_to_clean or nothing_deleted (gc_tools_build.txtar, TestDeleteToolsLeft in lima and vm, the fake's ToolsLeft). The cli skill's judgment.md names this exception to "gc --force deletes exactly what gc lists". The conformance suite's delete-tools-left checks that it deletes no other VM, not even the project VM of a folder named tools (devvm-tools-<hash>), and no image (TestConformanceFinds: deletesAllVMs, deletesImage, deletesByPrefix). The share's lock is the data folder's, so devvms with their own data folders and one Lima home don't exclude each other's builds: the docs say not to build tools or run gc in two at once (a lock per build VM in the Lima home would close it, but it would replace Hold and needs e2e). - Side by side, one status line covers the builds (building_tools_together), and their commands' lines in the run log are tagged with their tool (msg.WithLogTag): the UI's LoggedCmd prefixes them and shows no status line of its own. Every write starts with the tag, as does every line in it, one ended by "\r" included, so no build can pass a line off as another's (TestTaggedWrites), and a tool's lines are found after another's "\r" (taggedLines splits there, a progress bar's updates staying one line: TestTaggedLines). The first failure cancels the others and is what Build returns, tagged (backend.LoggedIn), so ErrorLogged shows that tool's lines' end. - A test build's DEVVM_TOOL_SLOTS caps the slots; the CLI tests set 1, so the stub's calls keep their order, and tools_side_by_side.txtar sets 3, with an interrupt that leaves no build VM. The stub keeps each build VM's folder by its name, and the fake backend's BuildTools runs its builds outside its lock, as a real backend's would, passing ToolsBuild its context. Docs: images.md's Building tools and Free space, ports-size.md, space.md, images.md (using) and gc's help (the build VMs gc deletes), settings.md (one Lima home for two data folders), extending.md, testing.md and tests.md; the cli skill's judgment.md; the CHANGELOG's first highlight and the release page's A faster first run. New messages: building_tools_together, tools_build_vms_deleted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
488 lines
21 KiB
Go
488 lines
21 KiB
Go
//go:build e2e
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/devvmhq/devvm/internal/backend"
|
|
)
|
|
|
|
// The container images the --from checks start from, by digest, so the
|
|
// bases made from them stay cached until these pins move
|
|
// (scripts/bump.sh e2e-from moves the digests). One check keeps a tag,
|
|
// so devvm's registry lookup is checked too: the company proxy's
|
|
// alpine:3.21, converted each run anyway.
|
|
const fromNodeDigest = "sha256:6b33b0be1647d1a577f9cebb6c8fc2587cc02c98c9956af8d0289df1791a3d10"
|
|
|
|
const fromAlpineDigest = "sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf"
|
|
|
|
const fromUbuntuDigest = "sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db"
|
|
|
|
const (
|
|
fromNode = "node:24@" + fromNodeDigest
|
|
fromAlpine = "alpine:3@" + fromAlpineDigest
|
|
fromUbuntu = "ubuntu:26.04@" + fromUbuntuDigest
|
|
)
|
|
|
|
// fromSection: VMs from node:24 (Debian 12) and alpine:3, base from
|
|
// ubuntu:26.04, with a docker that's installed but not running (it logs
|
|
// what devvm asked it, which may only be whether it has the image:
|
|
// launches ask only the backends a VM's state names), then a --from
|
|
// conversion behind a company proxy.
|
|
func fromSection(s *S) {
|
|
s.Section("--from")
|
|
s = s.Needing(backend.FeatureFrom)
|
|
nd, _ := NoDocker(s)
|
|
fromDebian(s, nd)
|
|
fromAlpineVM(s, nd)
|
|
// Ubuntu's container image has empty package lists, which apt.sh fills
|
|
// from its own sources.
|
|
s.Check("base builds from ubuntu:26.04", func() error {
|
|
_, err := s.Run(Cmd{Args: []string{s.sb.devvm, "build", "--from", fromUbuntu, "base"}, Env: nd})
|
|
return err
|
|
}, Builds())
|
|
s.Check("none of them needed Docker", func() error {
|
|
b, err := os.ReadFile(DockerCalls(s))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, line := range strings.Split(strings.TrimRight(string(b), "\n"), "\n") {
|
|
if line != "" && !strings.HasPrefix(line, "docker image inspect ") {
|
|
return errors.New("devvm asked docker: " + line)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
s.Check("and the build VM and its temporary folders are gone", func() error {
|
|
r, _ := s.Limactl("list", "-q")
|
|
if r.Has("devvm-oci-build") {
|
|
return errors.New("the build VM is still there")
|
|
}
|
|
return ociTempsGone()
|
|
})
|
|
// An image only Docker has (built, never pushed) isn't checked: making
|
|
// one would change Docker's images.
|
|
fromCorp(s)
|
|
}
|
|
|
|
// ociTempsGone: no devvm-oci.* folder is left in the temporary folder.
|
|
func ociTempsGone() error {
|
|
tmp := os.Getenv("TMPDIR")
|
|
if tmp == "" {
|
|
tmp = "/tmp"
|
|
}
|
|
if m, _ := filepath.Glob(filepath.Join(tmp, "devvm-oci.*")); len(m) > 0 {
|
|
return errors.New("left: " + strings.Join(m, " "))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// fromRecord is the key of a base built from that --from.
|
|
func fromRecord(p Paths, ref string) string {
|
|
for _, k := range p.KeysOf("base") {
|
|
if p.Record(k, "from") == ref {
|
|
return k
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// toolField is a string field of a tool image's record (base: the base
|
|
// digest of a musl one; glibc: the newest glibc it needs).
|
|
func toolField(p Paths, file, field string) string {
|
|
b, err := os.ReadFile(filepath.Join(p.Share, file+".json"))
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
var rec map[string]any
|
|
if json.Unmarshal(b, &rec) != nil {
|
|
return ""
|
|
}
|
|
v, _ := rec[field].(string)
|
|
return v
|
|
}
|
|
|
|
// toolsBuiltIn is the keys of the images the log's tool builds cloned, in
|
|
// every slot's build VM, a build side by side's line named for its tool.
|
|
func toolsBuiltIn(log string) []string {
|
|
b, _ := os.ReadFile(log)
|
|
var keys []string
|
|
re := regexp.MustCompile(`^(\[[^]]+\] )?\+ limactl clone .* devvm-img-([0-9a-f]{12}) devvm-tools-build(-[2-4])?$`)
|
|
for _, line := range strings.Split(string(b), "\n") {
|
|
if m := re.FindStringSubmatch(line); m != nil {
|
|
keys = append(keys, m[2])
|
|
}
|
|
}
|
|
return keys
|
|
}
|
|
|
|
// newerGlibc is whether glibc version need (major.minor) is newer than
|
|
// have.
|
|
func newerGlibc(need, have string) bool {
|
|
n, h := strings.SplitN(need, ".", 3), strings.SplitN(have, ".", 3)
|
|
for i := range 2 {
|
|
var a, b int
|
|
if i < len(n) {
|
|
a, _ = strconv.Atoi(n[i])
|
|
}
|
|
if i < len(h) {
|
|
b, _ = strconv.Atoi(h[i])
|
|
}
|
|
if a != b {
|
|
return a > b
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// fromDebian: a VM from node:24 (Debian 12) with node, python, Claude
|
|
// Code and the docker and nix layers.
|
|
func fromDebian(s *S, nd []string) {
|
|
f, _ := s.NewProject("fromdocker")
|
|
_ = os.WriteFile(filepath.Join(f, "package.json"), []byte("{}\n"), 0o644) //nolint:gosec // a project's file, as a user's
|
|
// The Claude Code VM's home: no agent config of yours.
|
|
fh := filepath.Join(s.sb.work, "from-home")
|
|
madeFile(s.sb, fh)
|
|
_ = os.MkdirAll(fh, 0o700)
|
|
env := append([]string{"HOME=" + fh}, nd...)
|
|
vm, launched, _ := launchWith(s, f, env, "--from", fromNode, "--network", "open", "--tools", "node,python", "--agents", "claude", "--layers", "docker,nix")
|
|
fromlog := NewestLog(s.Paths)
|
|
st := s.Paths.State(vm)
|
|
files := strings.Fields(st["tools.made.files"])
|
|
// Any VM may mount gnu tool images, so a --from image's code never runs
|
|
// in their builds. They may be cached from an earlier run: then the log
|
|
// has no build.
|
|
s.Check("its tool images built in a clone of devvm's own Ubuntu base, never the Debian image's, and record no base", func() error {
|
|
for _, k := range toolsBuiltIn(fromlog) {
|
|
if s.Paths.Record(k, "name") != "base" || s.Paths.Record(k, "from") != "" {
|
|
return errors.New("built in " + k)
|
|
}
|
|
}
|
|
for _, f := range files {
|
|
if b := toolField(s.Paths, f, "base"); b != "" {
|
|
return errors.New(f + " records a base: " + b)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
s.Check("a VM with node, python, Claude Code and the docker and nix layers from node:24 (Debian 12) boots, its base keyed by its pinned digest", func() error {
|
|
if vm == "" {
|
|
return errors.Join(errors.New("no VM: the launch printed"), errorsOf(launched))
|
|
}
|
|
r, _ := s.Limactl("shell", "--workdir", "/", vm, "cat", "/etc/os-release")
|
|
switch {
|
|
case !r.Has("VERSION_CODENAME=bookworm"):
|
|
return errors.New("not Debian 12")
|
|
case st["from"] != fromNode || st["tools.made.libc"] != "gnu":
|
|
return errors.New("its state: from=" + st["from"] + " tools.made.libc=" + st["tools.made.libc"])
|
|
case s.Paths.Record(fromRecord(s.Paths, fromNode), "digest") != fromNode:
|
|
return errors.New("its base isn't keyed by its pinned digest")
|
|
}
|
|
return nil
|
|
})
|
|
s.Check("its base records the image's glibc, as its VM does, and no tool image of the VM needs a newer one", func() error {
|
|
r, err := s.Limactl("shell", "--workdir", "/", vm, "getconf", "GNU_LIBC_VERSION")
|
|
g := strings.TrimPrefix(out(r), "glibc ")
|
|
switch {
|
|
case err != nil || g == "":
|
|
return errors.New("no glibc version")
|
|
case s.Paths.Record(fromRecord(s.Paths, fromNode), "glibc") != g:
|
|
return errors.New("its base doesn't record glibc " + g)
|
|
case s.Paths.State(vm)["tools.made.glibc"] != g:
|
|
return errors.New("its state doesn't record glibc " + g)
|
|
}
|
|
for _, f := range files {
|
|
if n := toolField(s.Paths, f, "glibc"); n != "" && newerGlibc(n, g) {
|
|
return fmt.Errorf("%s needs glibc %s", f, n)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
for _, f := range files {
|
|
n := toolField(s.Paths, f, "glibc")
|
|
if n == "" {
|
|
n = "none"
|
|
}
|
|
s.r.out.line(" glibc: %s needs %s", f, n)
|
|
}
|
|
fromDebianRuns(s, vm)
|
|
// Its generic kernel's nftables, systemd-resolved over networkd, and Debian 12's dnsmasq and
|
|
// socat, confined for one start.
|
|
fromTransparent(s, vm, f, "Debian 12", env)
|
|
_, _ = s.Run(Cmd{Args: []string{s.sb.devvm, "rm", "--force", "--no-export"}, Dir: f, Env: []string{"HOME=" + fh}})
|
|
}
|
|
|
|
// inVMCheck is a check that script passes in the VM's login shell.
|
|
func inVMCheck(s *S, title, vm, script string, opts ...CheckOpt) {
|
|
s.Check(title, func() error {
|
|
_, err := s.InVM(vm, script)
|
|
return err
|
|
}, opts...)
|
|
}
|
|
|
|
// gnuTar: the VM's commands run GNU tar, which devvm history import needs.
|
|
func gnuTar(s *S, vm string) error {
|
|
_, err := s.Limactl("shell", "--workdir", "/", vm, "bash", "-c", `tar --version | head -1 | grep -q "GNU tar"`)
|
|
return err
|
|
}
|
|
|
|
func fromDebianRuns(s *S, vm string) {
|
|
inVMCheck(s, "its node, claude and every feature work", vm,
|
|
`node --version && claude --version && eza --version && bat --version && fd --version && fzf --version && tldr --version && [[ -d ~/.oh-my-bash ]]`)
|
|
py, cl := s.Paths.ToolVersion("python"), s.Paths.ToolVersion("claude")
|
|
inVMCheck(s, "python, python3 and claude are the locked versions", vm,
|
|
"[[ $(python --version) == 'Python "+py+"' && $(python3 --version) == 'Python "+py+"' && $(claude --version) == '"+cl+" '* ]]")
|
|
s.Check("an interactive shell starts without errors", func() error {
|
|
r, err := s.Limactl("shell", "--workdir", "/", vm, "bash", "-ic", "true")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return not(Matches(r.Out, `(?i)error|unknown option|not found`), "its shell printed an error")
|
|
})
|
|
s.Check("its commands run GNU tar, which devvm history import needs", func() error { return gnuTar(s, vm) })
|
|
inVMCheck(s, "the docker layer's Docker runs in it (Docker's Debian repository), for the VM's user too", vm,
|
|
`sudo docker run --rm hello-world | grep -q Hello && id -nG | grep -qw docker`, Needs(backend.FeatureDockerLayer))
|
|
inVMCheck(s, "the nix layer's Nix runs in it (systemd): nix run nixpkgs#hello, and a build in Nix's sandbox", vm,
|
|
`systemctl is-active --quiet nix-daemon.socket && nix run nixpkgs#hello | grep -qx 'Hello, world!' &&
|
|
nix build --no-link --impure --expr '`+nixBuilt+`'`, Needs(backend.FeatureNixLayer))
|
|
}
|
|
|
|
// fromAlpineVM: Alpine: apk, OpenRC and musl, so its own (musl) tool
|
|
// images; the docker layer from Alpine's packages; the nix layer's daemon
|
|
// as an OpenRC service of devvm's; the desktop layer from Alpine's
|
|
// packages.
|
|
func fromAlpineVM(s *S, nd []string) {
|
|
al, _ := s.NewProject("fromalpine")
|
|
_ = os.WriteFile(filepath.Join(al, "package.json"), []byte("{}\n"), 0o644) //nolint:gosec // a project's file, as a user's
|
|
_ = os.WriteFile(filepath.Join(al, "global.json"), []byte("{}\n"), 0o644) //nolint:gosec // a project's file, as a user's
|
|
vm, launched, _ := launchWith(s, al, nd, "--from", fromAlpine, "--network", "open", "--layers", "docker,nix,desktop")
|
|
s.Check("an Alpine VM runs node from musl tool images", func() error {
|
|
if vm == "" || s.Paths.State(vm)["tools.made.libc"] != "musl" || s.Paths.Record(fromRecord(s.Paths, fromAlpine), "libc") != "musl" {
|
|
return errors.Join(errors.New("no Alpine VM on musl tool images: the launch printed"), errorsOf(launched))
|
|
}
|
|
return nil
|
|
})
|
|
alog := NewestLog(s.Paths)
|
|
s.Check("its musl tool images built in its own base, and are keyed and recorded by that base's digest", func() error {
|
|
b := fromRecord(s.Paths, fromAlpine)
|
|
d := s.Paths.Record(b, "digest")
|
|
if d == "" {
|
|
return errors.New("no base with a digest")
|
|
}
|
|
for _, k := range toolsBuiltIn(alog) {
|
|
if k != b {
|
|
return errors.New("built in " + k)
|
|
}
|
|
}
|
|
for _, f := range strings.Fields(s.Paths.State(vm)["tools.made.files"]) {
|
|
if tb := toolField(s.Paths, f, "base"); tb != d {
|
|
return errors.New(f + ": " + tb)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
inVMCheck(s, "and node, pnpm work there", vm,
|
|
"grep -q '^ID=alpine' /etc/os-release && [[ $(node -v) == v"+s.Paths.ToolVersion("node")+` ]] && node -e 'require("os")' && pnpm -v`)
|
|
inVMCheck(s, "and dotnet, its global.json's: the musl SDK, with ICU, makes and runs a console project", vm,
|
|
"[[ $(dotnet --version) == "+s.Paths.ToolVersion("dotnet")+" ]] && cd /tmp && dotnet new console -o hello >/dev/null && [[ $(dotnet run --project hello) == 'Hello, World!' ]]")
|
|
inVMCheck(s, "the docker layer's Docker runs in it (OpenRC)", vm, `sudo docker run --rm hello-world | grep -q Hello`, Needs(backend.FeatureDockerLayer))
|
|
inVMCheck(s, "the desktop layer's programs are in it (Alpine's packages)", vm,
|
|
`command -v Xvnc && command -v startxfce4 && command -v vncconfig && [[ -x /usr/local/bin/devvm-desktop ]]`)
|
|
inVMCheck(s, "ports below 1024 are open to the VM's user after the setup (Alpine's kernel starts at 1024)", vm,
|
|
`[[ $(cat /proc/sys/net/ipv4/ip_unprivileged_port_start) == 0 ]]`)
|
|
inVMCheck(s, "and every feature", vm, `eza --version && bat --version && fd --version && fzf --version && tldr --version && [[ -d ~/.oh-my-bash ]]`)
|
|
// As root: syslog's and acpid's pid files are root-only, so a user's
|
|
// rc-status calls them crashed.
|
|
inVMCheck(s, "no crashed services", vm, `[[ -z "$(sudo rc-status --crashed 2>/dev/null)" ]]`)
|
|
inVMCheck(s, "the nix layer's Nix runs in it (OpenRC, musl): nix run nixpkgs#hello, and a build in Nix's sandbox", vm,
|
|
`sudo rc-service nix-daemon status >/dev/null && nix run nixpkgs#hello | grep -qx 'Hello, world!' &&
|
|
nix build --no-link --impure --expr '`+nixBuilt+`'`, Needs(backend.FeatureNixLayer))
|
|
fromAlpineMore(s, nd, al, vm)
|
|
_, _ = s.Devvm(al, "rm", "--force", "--no-export")
|
|
}
|
|
|
|
// fromAlpineMore: with network policy, OpenRC's service reads the proxy
|
|
// from its settings; devvm history import works on Alpine as on Ubuntu:
|
|
// base's Alpine branch installs GNU tar, which the import's listing and
|
|
// unpacking need (busybox's refuses their options), and the rest of its
|
|
// script runs on busybox's grep and find. busybox's grep -r over the home
|
|
// and /tmp runs past the check's limit there, so the refusal's check
|
|
// looks for the file by name, on the root's disk alone.
|
|
func fromAlpineMore(s *S, nd []string, al, vm string) {
|
|
// On the allowlist tier from here: transparent mode on OpenRC, musl, busybox's ip and
|
|
// linux-virt's nftables.
|
|
fromTransparent(s, vm, al, "Alpine", nd)
|
|
s.Needing(backend.FeatureNixLayer).Check("devvm network allowlist: after devvm restart, its nix-daemon goes through the proxy", func() error {
|
|
if s.Paths.State(vm)["net.tier"] != "allowlist" || s.Paths.State(vm)["net.made.check"] != "ok" {
|
|
return errors.New("it isn't on the allowlist tier, or its self-check didn't pass")
|
|
}
|
|
// A download only the daemon makes, from a host that isn't
|
|
// allowed, gets the proxy's 403.
|
|
_, err := s.InVM(vm, `sudo grep -q "^export http_proxy=http://devvm:" /etc/conf.d/nix-daemon &&
|
|
! nix build --no-link --impure --expr '`+nixFetch+`' 2>/tmp/fetch.err && grep -q "response 403" /tmp/fetch.err`)
|
|
return err
|
|
})
|
|
s.Check("an Alpine VM's commands run GNU tar", func() error { return gnuTar(s, vm) })
|
|
// Alpine's remount of the folder fails (the share busy after its
|
|
// unmount), so this checks the restart that mounts it.
|
|
mountCacheSwitch(s, vm, al, "Alpine")
|
|
export := filepath.Join(s.sb.work, "export")
|
|
madeFile(s.sb, export)
|
|
s.Check("history import puts an export into an Alpine VM", func() error {
|
|
x := filepath.Join(export, "alpine")
|
|
_ = os.RemoveAll(x)
|
|
if err := os.MkdirAll(filepath.Join(x, ".claude", "projects", "e2e"), 0o700); err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(filepath.Join(x, ".claude", "projects", "e2e", "t.jsonl"), []byte("e2e-alpine\n"), 0o600); err != nil {
|
|
return err
|
|
}
|
|
if _, err := s.Run(Cmd{Args: []string{"tar", "-czf", "../alpine.tar.gz", ".claude"}, Dir: x}); err != nil {
|
|
return err
|
|
}
|
|
if _, err := s.Devvm(al, "history", "import", filepath.Join(export, "alpine.tar.gz")); err != nil {
|
|
return err
|
|
}
|
|
_, err := s.Limactl("shell", "--workdir", "/", vm, "bash", "-c", `[[ $(cat ~/.claude/projects/e2e/t.jsonl) == e2e-alpine ]]`)
|
|
return err
|
|
})
|
|
s.Check("and an export with a path outside the agents' history imports nothing there", func() error {
|
|
ev := filepath.Join(export, "evil")
|
|
_ = os.RemoveAll(ev)
|
|
if err := os.MkdirAll(filepath.Join(ev, "d"), 0o700); err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(filepath.Join(ev, "e2e-escape"), []byte("e2e-escape\n"), 0o600); err != nil {
|
|
return err
|
|
}
|
|
if _, err := s.Run(Cmd{Args: []string{"tar", "-czPf", "../evil.tar.gz", "../e2e-escape"}, Dir: filepath.Join(ev, "d")}); err != nil {
|
|
return err
|
|
}
|
|
tgz := filepath.Join(ev, "evil.tar.gz")
|
|
r, err := s.Devvm(al, "history", "import", tgz)
|
|
switch {
|
|
case err == nil:
|
|
return errors.New("devvm history import went on")
|
|
case !strings.Contains(r.Out, s.Msg("history_import_unsafe", "file="+tgz)):
|
|
return errors.New("devvm history import didn't say it's unsafe")
|
|
}
|
|
o, err := s.Limactl("shell", "--workdir", "/", vm, "sudo", "find", "/home", "/root", "/tmp", "/etc", "-xdev", "-name", "e2e-escape")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return not(strings.TrimSpace(o.Stdout) != "", "imported: "+o.Stdout)
|
|
})
|
|
}
|
|
|
|
// fromCorp: behind a company proxy with a password, a --from conversion
|
|
// (an Alpine release no other check uses, so it's converted each run)
|
|
// and the builds on it go through a proxy of devvm's for each build,
|
|
// which alone goes through the company proxy: the registry, base's and
|
|
// its features' downloads and a layer's own all reach it, while nothing a
|
|
// build runs sees its password, and no converted disk, image or log keeps
|
|
// it. The layer prints what its commands, and sudo's, have of the proxy
|
|
// settings.
|
|
func fromCorp(s *S) {
|
|
corp, cerr := StartCorp(s)
|
|
_, _ = s.Layer("e2ecorp.sh", "#!/bin/bash\nset -euo pipefail\n"+
|
|
`echo "e2e-env: $(env | grep -i "_proxy=" | sort | tr "\n" " ")"`+"\n"+
|
|
`echo "e2e-sudo: $(sudo env | grep -i "_proxy=" | sort | tr "\n" " ")"`+"\n"+
|
|
"curl -fsS -m 30 -o /dev/null https://github.com\n")
|
|
nd, _ := NoDocker(s)
|
|
s.Check("behind a company proxy, --from's conversion and the builds on it reach it through devvm's own proxies", func() error {
|
|
if cerr != nil {
|
|
return cerr
|
|
}
|
|
if _, err := s.Run(Cmd{Args: []string{s.sb.devvm, "build", "--from", "alpine:3.21", "e2ecorp"}, Env: append(corp.Env(), nd...)}); err != nil {
|
|
return err
|
|
}
|
|
switch {
|
|
case !corp.Saw(`"event":"tunnel","host":"[a-z0-9.-]*docker\.io"`):
|
|
return errors.New("the registry didn't go through the company proxy")
|
|
case !corp.Saw(`"host":"dl-cdn\.alpinelinux\.org"`):
|
|
return errors.New("Alpine's packages didn't go through the company proxy")
|
|
case !corp.Saw(`"event":"tunnel","host":"github\.com"`):
|
|
return errors.New("the layer's download didn't go through the company proxy")
|
|
}
|
|
return nil
|
|
}, Builds())
|
|
s.Own("e2ecorp")
|
|
var kac, kcl string
|
|
re := regexp.MustCompile(`^base=([0-9a-f]*) e2ecorp=.*$`)
|
|
for _, k := range s.Paths.KeysOf("e2ecorp") {
|
|
if m := re.FindStringSubmatch(s.Paths.Record(k, "chain")); m != nil && kac == "" {
|
|
kac = m[1]
|
|
}
|
|
}
|
|
if kac != "" {
|
|
s.sb.created = append(s.sb.created, "devvm-img-"+kac)
|
|
}
|
|
if keys := s.Paths.KeysOf("e2ecorp"); len(keys) > 0 {
|
|
kcl = keys[0]
|
|
}
|
|
// The run log writes a proxy key (32 to 64 hex digits) as <key>: its
|
|
// stand-in there says the build's commands had one, and no key of
|
|
// devvm's is left in the log.
|
|
s.Check("what the builds' commands and sudo have is devvm's proxy for the build, with a password of its own", func() error { return corpLog(s) })
|
|
s.Check("the company proxy's password is in no converted disk, image, log, build file or process's arguments", func() error {
|
|
if cerr != nil {
|
|
return cerr
|
|
}
|
|
img := func(k string) string { return filepath.Join(s.sb.lima, "devvm-img-"+k) }
|
|
if kac == "" || kcl == "" || !Exists(img(kac)) || !Exists(img(kcl)) {
|
|
return errors.New("no converted image")
|
|
}
|
|
if err := NoLeak([]string{corp.Password()}, img(kac), img(kcl), filepath.Join(s.Paths.Devvm, "logs"),
|
|
filepath.Join(s.Paths.Devvm, "run"), filepath.Join(s.Paths.Devvm, "vms")); err != nil {
|
|
return err
|
|
}
|
|
if have, err := ProcsHave(s, corp.Password()); err != nil || have {
|
|
return errors.Join(errors.New("a process has the password in its arguments"), err)
|
|
}
|
|
if m, _ := filepath.Glob(filepath.Join(s.Paths.Devvm, "run", "builds", "*", "run", "build-proxy")); len(m) > 0 {
|
|
return errors.New("left: " + strings.Join(m, " "))
|
|
}
|
|
// The builds went through a broker and its child, the build proxy, and neither is left.
|
|
if ps, err := psAll(s.r.window().ctx); err != nil || Matches(string(ps), `_proxy(-child)? -(config|for) \S*/build-proxy/proxy\.json`) {
|
|
return errors.Join(errors.New("a build proxy's broker or child still runs"), err)
|
|
}
|
|
return ociTempsGone()
|
|
})
|
|
if corp != nil {
|
|
corp.Stop()
|
|
}
|
|
}
|
|
|
|
// corpLog: the last run log with the layer's lines has devvm's proxy for
|
|
// the build, its key written <key>, and neither a key of devvm's nor the
|
|
// company proxy's port.
|
|
func corpLog(s *S) error {
|
|
var log string
|
|
for _, f := range s.Paths.RunLogs() {
|
|
if b, err := os.ReadFile(f); err == nil && Matches(string(b), `^e2e-env: `) {
|
|
log = string(b)
|
|
}
|
|
}
|
|
switch {
|
|
case log == "":
|
|
return errors.New("no run log has the layer's lines")
|
|
case !Matches(log, `^e2e-env: .*HTTPS_PROXY=http://devvm:<key>@192\.168\.5\.2:[0-9]+ `):
|
|
return errors.New("the build's commands don't have devvm's proxy")
|
|
case !Matches(log, `^e2e-sudo: .*HTTPS_PROXY=http://devvm:<key>@192\.168\.5\.2:[0-9]+ `):
|
|
return errors.New("sudo's commands don't have devvm's proxy")
|
|
case Matches(log, `devvm:[0-9a-f]{32,64}@`):
|
|
return errors.New("a proxy key of devvm's is in the run log")
|
|
case strings.Contains(log, ":"+strconv.Itoa(s.Port(corpPort))):
|
|
return errors.New("the company proxy's port is in the run log")
|
|
}
|
|
return nil
|
|
}
|