Repository navigation
feat(cli): declare the Incus sandbox backend of a managed deployment - #5015
Merged
Merged
Conversation
The observation file reader and the client export directory check each walked a path's ancestors with their own copy of the rules. One helper, untrustedAncestor, now holds them and both call it, keeping their own messages. The two walks differed in two places and the helper takes the stricter of each. A sticky directory is trusted only when root owns it, where the export check also accepted one the CLI's own account owned; the filesystem root is examined, where the observation reader skipped it. Every real layout is unaffected: the system temporary directory is a root-owned sticky directory and the root is root-owned.
The calls that ask the spawner container to drain, read its status and wait for its sessions to end lived inside the configuration activation. A second caller needs the same calls, so they move to runtime-spawner.ts without a change of behaviour. They keep the strict status shape, the latch, and the wait of up to 60 reads within 300 seconds in steps of 5 seconds. The activation calls them and keeps its own messages and tests.
prepareRuntime takes a sandbox option, an address and an egress proxy, and turns the release's own compose.yml into a bundle whose sandbox service runs against an Incus node. The spawner mounts no Docker socket and no session root, only the credentials directory ../sandbox-incus read-only at /run/secrets/incus; it loses the three variables the Docker shape sets, takes the declared egress proxy, and gets the six literals that name the backend, the image alias and source, and the three PEM paths. The backend API and the LLM gateway publish their ports on the declared address. The other eight services are byte for byte what the Docker bundle holds, and a call without the option writes the same files as before. The image alias is the first 32 digits of the runtime image digest, so one alias names one image, and both alias and source are recorded in runtime.json beside the address and the proxy. readRuntimeBundle derives them again and holds the compose file to the record, using only what the bundle holds. The Incus mount and the two port lists are accepted only for a bundle that records the shape. Preparation refuses a revision that lacks the spawner's Incus backend and a source whose sandbox service lacks a variable the shape replaces. Everything the shape needs to agree on is one module, runtime-sandbox.ts. Nothing declares the shape yet.
Applying a bundle that records the Incus sandbox first holds the state directory's sandbox-incus directory to the CLI's custody rules, before the first Docker call and so also in a dry run: a real directory that root or the CLI's account owns and only that account can enter, below ancestors nobody else can replace, holding client.crt, client.key and server.crt as private, single-link, non-empty regular files within the runtime input limit. Only metadata is read and no message carries content. A host without POSIX account ids is refused. The directory is the one entry besides src and .tale that a fresh runtime of this shape accepts, and the host workspace of sessions is created only for the Docker shape. Container custody at admission of a changing apply lets the sandbox container still hold exactly the mounts of the other shape, the state a switch between the Docker and the Incus shape starts from, and reports that shape. The check after the start, the ready-state check, every other service and every extra mount keep the exact rule. The managed .env drops what the other shape left in it: the Incus shape removes the ten variables it owns, the Docker shape removes the Incus variables and a backend of incus, unless the declaration being applied names them. An environment that names an owned variable is refused when the bundle declares the Incus sandbox.
A session outlives its spawner process: the next process adopts it, but only the backend that created it sees it, and the replaced container leaves it running. When container custody finds the sandbox container in the other shape, the apply now latches the outgoing spawner's drain and reads its status through the managed path's own spawner control before the runtime's images are pulled or any runtime file is written, and refuses while sessions remain after the activation's budget. The one earlier pull is the platform image of a release whose writer protocol is 2. The refusal names the outgoing backend and the number of sessions, never a session id. It says the spawner stops sessions itself after its linger (SANDBOX_SESSION_MAX_LINGER_MS, 30 minutes by default), that the same bundle can be applied again after that, and that restarting the spawner lifts the drain. A spawner that is not running cannot say whether it holds sessions, so that is refused too, with the way to abandon them. Nothing is deleted. The gate runs before the receipt write of a pending takeover as well, so a refusal leaves the state as it was. A dry run, which every real apply makes first, logs one line that the backend changes and that the apply will drain, and execs into nothing. First deploys, replays of the ready bundle and changes inside one shape are not gated.
A deployment specification may declare sandbox with backend incus, the IPv4 address of the Docker host that the node's sessions dial for the backend API and the LLM gateway, and the egress proxy. Address and proxy are checked by the same rules the prepared runtime holds them to and may each be an environment reference, resolved when the bundle is prepared like the origin. A specification without the field accepts exactly what it accepted before; with it, the environment may not name any variable the shape sets itself. prepare passes the declaration to the runtime preparation and logs one step. The guard that the prepared runtime and the specification agree now compares the backend, the address and the egress proxy as well as the revision, platform and container prefix, in both directions, so a runtime prepared with a sandbox is refused for a specification without one and the reverse.
The sandbox environment of a prepared Incus bundle is only right if the spawner accepts it. A suite now prepares the bundle from this repository's own compose.yml, resolves its variables as Compose does beside a representative specification, and runs the spawner's real loadConfig over the result in a process of its own, so that nothing from services/sandbox joins this workspace's type program. It asserts that the Incus backend boots with the declared egress proxy, the pinned image alias and registry source, and the three credential paths under the mount point, and that the spawner reports no setting as ignored and no runtime tier. It also shows the check can fail: a bundle without the image, a credential path or the egress proxy is refused by the spawner naming the variable, and one without the backend variable runs the Docker backend and reports its Incus settings as ignored. The spawner modules loadConfig imports are test inputs of the CLI in turbo, and a test holds that list to the real imports, so an edit to one of them re-runs the suites instead of replaying a cached verdict.
The install guide gains a section beside the additional-origins and organization-creators ones for the sandbox field of a managed deployment, in English, German and French: the three keys and the values that are refused, the credentials directory with its three files and the custody the apply holds them to, what the CLI sets, removes and refuses in the sandbox service, the two ports published on the declared address, what does not apply under Incus, and the switch between the Docker and the Incus backend in both directions with its drain, its refusal while sessions remain and the way to retry or to abandon them. The environment reference rows for the backend, the image alias and source, and the three credential paths say that a managed deployment that declares sandbox sets them. The CLI readme gets one paragraph. The two header comments that called the Incus shape an override of the service now say what the CLI does. A test resolves the guide's example declaration in every locale.
The post-start check of the sandbox mounts rejected a start that left the Docker mounts in place, but the test kept only part of each mount, so it could not tell the shape from a missing volume name. It now restores the container's mounts exactly, shows that the retry of the same bundle admits them and completes the switch, and adds the passing case beside each refusal of an extra mount: the same change is admitted once the extra mount is gone.
A release whose writer protocol is 2 makes the runtime pull its platform image, up to 1800 s, before the backend switch drain ran. A refused switch therefore pulled that image first, and the comment on the drain claimed otherwise. The drain now runs directly after admission and the planning of the environment files, which write nothing, and before that pull and every write of the runtime. The test prepares a protocol 2 release, runs it as a Docker runtime and refuses the switch to Incus with a session left: no image is pulled and no runtime file is written. It fails on the previous order.
A switch of the sandbox backend that the drain refuses has already taken the deployment's recovery snapshot and recorded its bundle as pending, because the drain runs inside the runtime apply. Two cases now hold that state at the deployment level, against a ready Docker deployment that still has two sessions: The refusal leaves the ready receipt unchanged and the pending record with its snapshot. The bundle that is ready is refused as a different bundle, the switch bundle retries on the same snapshot, and once the sessions end it completes without taking another. Giving up the switch works as the install guide describes: the spawner restarts, and a bundle of the backend kept that names the pending bundle in supersedesPendingBundle takes it over with its snapshot.
The proxy URL is refused when the port is missing or is 80, because a URL parser drops the default port of http and the written value would not round-trip. The refusal said only "with an explicit port", which a proxy URL ending in :80 satisfies. The schema and preparation messages and the install guide in all three languages now say the port is 1 to 65535 and not 80, and a test holds the schema message.
A refused backend switch leaves the runtime untouched, but the deployment has already taken its recovery snapshot and recorded the bundle as pending. The install guide in all three languages now says that only the same bundle applies again and takes no second snapshot, that any other bundle is refused until it names the pending bundle in supersedesPendingBundle, and that giving up the switch means restarting the spawner and applying such a bundle of the backend kept. It also says that Compose replaces the sandbox, backend API and model gateway containers, and that only the drain stops and deletes nothing. Every apply of a Docker-backend deployment removes SANDBOX_BACKEND=incus and the SANDBOX_INCUS_ variables the specification does not declare from the managed environment file, switch or not. The guide and the CLI README no longer promise that a deployment without a sandbox declaration is applied exactly as before.
Giving up a sandbox backend switch ends with applying a bundle that declares the pending bundle as supersedesPendingBundle. The paragraph stopped there, so an operator who followed only it kept the declaration. Every later apply then warned that no bundle is pending, and configuration-only apply stayed refused. The paragraph now says to remove the declaration and prepare again once that apply is ready, in English, German and French.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A managed deployment can now declare
"sandbox": { "backend": "incus", "address": "<IPv4>", "egressProxy": "http://<IPv4>:<port>" }.tale deploy preparethen turns the release's owncompose.ymlinto a runtime in which thesandboxservice mounts no Docker socket and no session root, only the three Incus PEM files, anddeploy --bundlechecks and applies it. An environment switches from the Docker shape to the Incus shape and back in place; the outgoing spawner is drained first, and the switch is refused while it still holds sessions. A spec without the field prepares and applies as before.compose.yml's values, the workspace generator,services/sandbox/and every workflow are untouched.What changes
The Incus shape differs from the Docker bundle
prepareRuntimewrites today in three services only; the other eight are byte-identical to it.sandboxdeclared)sandboxvolumes/var/lib/tale-sandbox,config-data../sandbox-incus:/run/secrets/incus:ro,config-datasandboxenvironmentSANDBOX_RUNTIME,SANDBOX_EGRESS_NETWORK,SANDBOX_HUB_PORT;SANDBOX_EGRESS_PROXYis the declared proxy; plusSANDBOX_BACKEND=incus, the image alias and source, and the three credential pathsbackend-api/sandbox-llm-gatewayports[]["<address>:3005:3005"]/["<address>:8080:8080"]tale-sandbox-runtime-plus the first 32 hex digits of the runtime image digest (53 characters); the source is the digest reference itself.runtime.jsonrecordssandbox: { backend, address, egressProxy, image: { alias, source } }andreadRuntimeBundlederives the image again and compares.readRuntimeBundleholds each invariant that the bundle alone can show: the Incus mount and ports exist only in a bundle that recordssandbox; with it, the volumes, the literals, the removed variables, the egress literal and the ports are exactly those above.prepareRuntimerefuses a source revision that does not listservices/sandbox/src/backend/incus/incus-config.ts(select a revision from v0.5.91 or later), and a source whose sandbox environment lacks one of the four keys it rewrites.<stateDirectory>/sandbox-incusto be a real directory owned by root or the CLI's user, mode 0700, with a trusted ancestor chain, holdingclient.crt,client.keyandserver.crtas regular, single-link, owner-only, non-empty files of at most 2 000 000 bytes. It useslstatonly and never opens or prints a file./var/lib/tale-sandboxis created for the Docker shape only. The managed.envloses the names of the shape it leaves: for the Incus shape the ten the CLI owns, for the Docker shape everySANDBOX_INCUS_*name andSANDBOX_BACKEND=incusthat the specification does not declare.sandboxcontainer in the other known shape is accepted and reported; afterupand inobserveReadyStatethe bundle's own shape is checked exactly. A mixed set, an extra mount, a drifted ready runtime and the Incus mount on any other service are refused as before.sandboxis a strict optional field of the deployment specification.address(unicast IPv4) andegressProxy(http:, IPv4 host, explicit port 1..65535 but not 80, nothing else) may each be an{env}reference. A specification that declaressandboxmay not name any of the ten owned variables inenvironment. The guard that the prepared runtime and the specification agree comparessandboxin both directions.observationFileandvalidateClientExportDirectorynow lives inprivate-path.ts, and the spawner control calls of the managed runtime (control,status, the drain loop) inruntime-spawner.ts. Both keep their messages and tests.docs/{en,de,fr}/self-hosted/install/cli-install.mdgain a section for thesandboxfield, the credential directory, the switch and its drain; the threeenvironment-reference.mdrows andtools/cli/README.mdsay that a managed deployment that declaressandboxsets the Incus variables. The two header comments on the sandbox service (compose.yml,create-sandbox-service.ts) now say what the CLI does.Dormancy
A specification without
sandboxprepares the same bytes. A scratch script prepared the base commit's owncompose.ymland proxy source (c9d5ea8a02) into a temporary repository with the test helper's fake Docker digests, once with the base CLI and once with this branch:compose.ymlb05835711e5b87c4812091c27c10cd8e6e26d4b79be2c8e6164cfc000bde7c7fCaddyfile.production098ccb12bd0f2987c9ee086653127941cd77cadb7733155d35d553e632be0f38runtime.json9a258a58f4863a53401801601fd5c435f62384a1d791500e0b562744465d5f06.env(noSANDBOX_INCUS_*, noSANDBOX_BACKEND=incusbefore)fcb3591f854cda4d3567653eed9d2cdd58793cbce21bf6ae8dfafb7f23ca6527The one effect on a specification without
sandboxis the.envcleanup above. WithSANDBOX_INCUS_ENDPOINTleft in the previous.env, the base keeps it (d9ca2c3a25eb…) and this branch drops it (fcb3591f854c…). No existing declaration names either variable. Tests hold the boundary:SANDBOX_BACKEND=docker,SANDBOX_RUNTIME=sysboxand a declaredSANDBOX_INCUS_ENDPOINTare kept byte for byte.Checklist
bun run checkpasses (format, lint, typecheck, all tests), 49 of 49 turbo tasks on the branch tip. Details under Test plan.bun run lint:sastpasses (Opengrep): 476 rules on 5870 files, 0 findings.docs/{en,de,fr}/.README.md/README.de.md/README.fr.md: N/A, no root README changes.tools/cli/README.mdhas one paragraph.Test plan
Local, on the branch tip rebased on
origin/mainc9d5ea8a02(no rebase was needed), bun 1.4.2:bun run check: format,lint:conflicts,lint:links, thenturbo run lint typecheck test test:uiover 49 tasks, all green.@tale/clilint 0 warnings and 0 errors, typecheck clean, test 3489 pass, 35 skip, 0 fail (3524 tests in 192 files).@tale/docs716 pass,@tale/platformtest 90253 pass,test:ui8377 pass. Under this Mac's load the first runs timed out or lost races in a few tests of@tale/sandbox,@tale/sandbox-runtime-daemonand@tale/platform; the diff has no path underservices/orpackages/, each of those files passes alone, and the last whole run, with fewer parallel tasks, is green.bunx knipexit 0,bun run lint:manualok,commitlintover every commit and this title ok.docker compose config(v5.3.0, no pull, no build) over the prepared Incus bundle laid out as the managed apply lays out a state directory: thesandboxbind source is<state>/sandbox-incus, read-only at/run/secrets/incus;backend-apipublishes<address>:3005andsandbox-llm-gateway<address>:8080. The Docker bundle keeps the socket,/var/lib/tale-sandboxand no published port.compose.yml, resolves its variables as Compose does, and runs the spawner's realloadConfigover it in a child process: the Incus backend boots with the declared proxy, the pinned alias and registry source and the three credential paths, with no ignored-setting warning and no runtime tier; dropping one owned variable shows the spawner's own refusal naming it.tools/cli/turbo.jsonandplatform-docs.test.tslist the spawner modules it reads.runtime-sandbox,runtime-sandbox-credentials,runtime-sandbox-spawner,runtime-apply-sandbox,runtime-spawner,private-path, plus cases in the prepare, apply, env, configuration, inputs, declaration-text and deployment apply tests. Tests that depend on a file mode, an owner or a child process run behinddescribe.skipIf(process.platform === 'win32')(private-path,runtime-sandbox-credentials,runtime-apply-sandbox,runtime-sandbox-spawner, parts ofapply,inputsandruntime-configuration); the prepare, reader and specification tests have no platform assumption.Not run, and not claimed:
bc021cc3e4when this was written.Ops follow-up
Nothing in this PR is used until a deployment declares
sandbox. After a release contains it, the ops repository has to place the three PEM files in<stateDirectory>/sandbox-incus/(mode 0600 in a 0700 directory, by the deployment automation and never by the CLI), give the Docker host an address the node can reach, open the node's API and the two published ports between the Docker host and the sandbox bridge, pin the new CLI, and add thesandboxblock to thetale.jsonof the environments that move. Switching an environment is a later, deliberate step.