An open-source, faster Devin alternative
TypeScript
microvm image: split the base Dockerfile at an OSB_CUSTOM_TEMPLATE_LAYERS marker and embed it, so custom templates compile from the SAME definition the pool image is built from — the marker sits after useradd (steps can chown into the home dir), before ENV PIP_USER=1 (a build-time pip install lands system-wide instead of /root/.local, invisible to the sandbox user), and before the agent COPY and ENTRYPOINT (no customer layer can shadow the agent); Split() fails loudly if the marker is ever removed
Brian Reardon731764fa689e
diff --git a/deploy/microvm/Dockerfile b/deploy/microvm/Dockerfileindex 9efae93a..c6d4aa3c 100644--- a/deploy/microvm/Dockerfile+++ b/deploy/microvm/Dockerfile@@ -69,13 +69,6 @@ RUN set -eux; \cd /tmp && unzip -q rclone.zip && cp rclone-*-linux-${rc}/rclone /usr/local/bin/rclone; \chmod +x /usr/local/bin/rclone; rm -rf /tmp/rclone.zip /tmp/rclone-*-linux-${rc}-# osb-agent is the same binary the QEMU backend runs in-guest; only its-# listener differs (TCP here, virtio-serial there), selected by the env var the-# hook server sets when it spawns the agent.-COPY osb-agent /usr/local/bin/osb-agent-COPY microvm-hooks /usr/local/bin/microvm-hooks-RUN chmod +x /usr/local/bin/osb-agent /usr/local/bin/microvm-hooks-# A sandbox user so customer commands do not run as root — matching the QEMU# backend, where exec deliberately runs unprivileged. internal/agent runs every# exec as this user with cwd /home/sandbox, so both must exist.@@ -91,6 +84,30 @@ RUN useradd --create-home --shell /bin/bash sandbox \RUN echo 'sandbox ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/sandbox \&& chmod 0440 /etc/sudoers.d/sandbox+# ==== OSB_CUSTOM_TEMPLATE_LAYERS ====+# Custom-template layers are spliced in HERE, and nowhere else.+#+# This position is load-bearing in three ways:+# - AFTER useradd/sudoers, so a customer step can chown to `sandbox` and+# write into /home/sandbox.+# - BEFORE the ENV block below, so a customer `pip install` at build time+# runs WITHOUT PIP_USER=1 and lands system-wide, visible to the sandbox+# user. With PIP_USER set it would install into /root/.local and simply+# not exist for the customer — a silent "my template did not apply".+# - BEFORE the agent COPY and ENTRYPOINT below, so no customer layer can+# remove or shadow the agent, and ENTRYPOINT is always ours.+#+# Splitting the real image definition here (rather than duplicating a prologue+# in Go) is what guarantees a custom-template box is the pool box plus the+# customer's layers, and cannot drift from it.++# osb-agent is the same binary the QEMU backend runs in-guest; only its+# listener differs (TCP here, virtio-serial there), selected by the env var the+# hook server sets when it spawns the agent.+COPY osb-agent /usr/local/bin/osb-agent+COPY microvm-hooks /usr/local/bin/microvm-hooks+RUN chmod +x /usr/local/bin/osb-agent /usr/local/bin/microvm-hooks+# User-space install defaults.## The customer runs unprivileged and cannot write to /usr/local or /opt (sudodiff --git a/deploy/microvm/embed.go b/deploy/microvm/embed.gonew file mode 100644index 00000000..2e5e0e96--- /dev/null+++ b/deploy/microvm/embed.go@@ -0,0 +1,43 @@+// Package microvmimage exposes the MicroVM base image definition to the Go+// build, so custom templates are compiled from the SAME Dockerfile the pool+// image is built from rather than from a copy of it.+//+// The alternative — writing a prologue/epilogue in Go — was rejected: it puts+// the agent contract (which binaries land where, who PID 1 is, where the+// sandbox user comes from) in two places that must be edited together, and the+// failure mode when they drift is a custom-template box that builds fine and+// then never becomes ready.+package microvmimage++import (+ _ "embed"+ "fmt"+ "strings"+)++//go:embed Dockerfile+var dockerfile string++// customLayerMarker is the single point where custom-template layers may be+// spliced. See the comment around it in Dockerfile for why the position is+// load-bearing.+const customLayerMarker = "# ==== OSB_CUSTOM_TEMPLATE_LAYERS ===="++// Split returns the base image definition either side of the custom-layer+// marker. Customer layers go between them, and nowhere else.+//+// An error here means someone edited Dockerfile and removed the marker. That+// must fail loudly at startup rather than silently producing an image with no+// customer layers in it — which would look like a successful build of a+// template that does nothing.+func Split() (prologue, epilogue string, err error) {+ idx := strings.Index(dockerfile, customLayerMarker)+ if idx < 0 {+ return "", "", fmt.Errorf("microvmimage: %q not found in Dockerfile — custom templates cannot be compiled", customLayerMarker)+ }+ return dockerfile[:idx], dockerfile[idx:], nil+}++// Dockerfile returns the unmodified base image definition, for the pool image+// build path that has no customer layers.+func Dockerfile() string { return dockerfile }