Repository navigation
docs(config): document the sandbox's AF_UNIX restriction in tend.example.yaml - #1313
Conversation
The sandbox config section never said what the sandbox may write. Name the write set, say /tmp is read-only and unwidenable, and give the .NET SDK as the case where a tool fails from a hard-coded /tmp path of its own. Refs #1312
…e write set memory_gist: true is a config key that widens the sandbox write set — the auto_memory step mktemps /tmp/tend-auto-memory.XXXXXXXXXX and sandbox_runtime.mjs adds it to allowWrite. The consumer-facing point is that no key makes /tmp itself writable, so say that instead. Also drop the implication that $TMPDIR is the sandbox home; it is /home/tend-sandbox/tmp, a directory under it.
tend-agent
left a comment
There was a problem hiding this comment.
The .NET example under-states the reach of the failure. It names build, restore and new, but the abort happens in DotnetFirstTimeUseConfigurer.Configure(), which runs ahead of every managed SDK command — on SDK 10.0.400 in this session's sandbox, dotnet test, dotnet run, dotnet tool list --global and dotnet nuget locals all --list each exit 1 with the same mkdtemp("/tmp/.dotnet.*") == nullptr; errno == EROFS. Only the host-level queries (--info, --version, --list-sdks) skip the configurer. dotnet test is the command a consumer configuring tend for a .NET repo reaches for first, so a reader who takes the three-command list as the affected set concludes that the case mattering most to them is fine — which is the conclusion this paragraph exists to prevent.
DOTNET_SKIP_FIRST_TIME_EXPERIENCE, DOTNET_CLI_HOME and NUGET_PACKAGES don't avoid it, so there is no env workaround the text is leaving out.
Suggestion inline; I'm pushing the same wording to both copies of the file.
Reproduction
Run as the sandbox user from a writable cwd, SDK 10.0.400:
dotnet new console -o app -> exit=1 System.IO.IOException ... : 'NuGet-Migrations'
dotnet build -> exit=1 (same)
dotnet restore -> exit=1 (same)
dotnet test -> exit=1 (same)
dotnet run -> exit=1 (same)
dotnet tool list --global -> exit=1 (same)
dotnet nuget locals --list -> exit=1 (same)
dotnet --list-sdks -> exit=0
System.IO.IOException: The system cannot open the device or file specified. : 'NuGet-Migrations'.
One or more system calls failed: mkdtemp("/tmp/.dotnet.V921dk") == nullptr; errno == EROFS;
at System.Threading.Mutex.CreateMutexCore(...)
at NuGet.Common.Migrations.MigrationRunner.Run(...)
at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(...)
… commands The abort fires in DotnetFirstTimeUseConfigurer.Configure(), ahead of every managed SDK command; dotnet test, run, tool and nuget fail identically to build/restore/new. Only the host-level queries skip it.
tend-agent
left a comment
There was a problem hiding this comment.
The mount-namespace route masks the checkout, so it fails at the case the paragraph offers it for. The agent workspace is always under /tmp — prepare_agent_workspace.py creates it with tempfile.mkdtemp(prefix="tend-agent-workspace-", dir="/tmp") — so mount -t tmpfs tmpfs /tmp hides it. The wrapped command keeps its inherited working directory, which is why ls still lists the tree, but nothing reaches the checkout by absolute path, and MSBuild resolves the project path against the absolute working directory before opening it, so a relative app/app.csproj fails too. A dotnet build through the recipe as written stops at MSBUILD : error MSB1009: Project file does not exist. — a second failure, with no more relation to the real problem than the first one had. Binding the checkout back over the tmpfs fixes it: suggestion inline, and I'm pushing the same wording to both copies of the file.
Separately, and left out of the suggestion: the route needs unprivileged user namespaces, which Tend only arranges on GitHub-hosted runners. install-sandbox-runtime.sh sets kernel.apparmor_restrict_unprivileged_userns=0 there and deliberately leaves self-hosted policy alone, where the same prerequisite may be met by a bwrap-scoped AppArmor profile instead — and a profile scoped to bwrap wouldn't extend to an unshare the agent runs inside it. I have no self-hosted runner to test that on, so I'd rather not qualify the text on a guess; it's worth a clause if you know which way it goes.
Verification
Run as the sandbox user in this session's checkout (/tmp/tend-agent-workspace-*/checkout), .NET SDK 10.0.400.
The masking, with the recipe exactly as the diff writes it:
$ unshare --map-root-user --mount bash -c 'mount -t tmpfs tmpfs /tmp; ls "$GITHUB_WORKSPACE/CLAUDE.md"'
ls: cannot access '/tmp/tend-agent-workspace-.../checkout/CLAUDE.md': No such file or directory
A three-project build with the checkout masked versus carried across, otherwise identical:
masked -> MSBUILD : error MSB1009: Project file does not exist.
carried over -> Build succeeded. 0 Warning(s) 0 Error(s)
The suggested preamble, checked under set -e in this sandbox: mount --bind and the tmpfs mount both return 0, and $TMPDIR is outside /tmp so the staging bind survives the mask. (mount --move also works but exits non-zero on the read-only /etc/mtab, which would abort a set -e script — hence the second --bind.)
The two claims the diff already made hold as written: /tmp is read-only, and socket(AF_UNIX, …) returns EPERM for both SOCK_STREAM and SOCK_DGRAM while socketpair and AF_INET succeed — matching the probe_boundary() assertion in shared/steps/agent_lifecycle.py. The multi-project Build FAILED. with 0 Error(s), and -m:1 clearing it, reproduce too.
The checkout lives under /tmp, so a tmpfs mounted over /tmp hides it and the wrapped build fails on an unresolvable project file. Bind it back over the new filesystem.
tend-agent
left a comment
There was a problem hiding this comment.
The recipe runs the wrapped command even when its preamble fails. sh -c without set -e continues past a failed mount, so if the staging bind doesn't take, the tmpfs still masks the checkout and the build reaches exactly the "project file does not exist" failure the paragraph above spends four lines warning about — the mount's own error is on stderr, but a build's output scrolls past it and the exit code comes from the build. set -e stops at the mount, where the message names the real cause. Suggestion inline; I'm pushing the same line to both copies of the file.
Verification
Run as the sandbox user in this session's checkout, with the staging path forced to fail ($NOPE unset in place of $TMPDIR) and everything else exactly as the diff writes it:
as written mount: /tmp/.../checkout: special device /ws does not exist.
ls: cannot access '/tmp/.../checkout/CLAUDE.md': No such file or directory
exit=2 (the wrapped command ran, against a masked checkout)
set -e mount: /tmp/.../checkout: special device /ws does not exist.
exit=32 (the wrapped command never ran)
The recipe's success path is unaffected — as written it carries the checkout across, /tmp is writable inside, and both absolute and relative paths into the workspace resolve.
Without `set -e` the wrapped command runs even when a mount in the preamble failed, against a checkout the tmpfs has masked — the second, misleading failure the paragraph above exists to prevent.
#1324 added /tmp to the sandbox's allowWrite set, so the write-set paragraph and the unshare mount-namespace recipe now describe a constraint that no longer exists. The AF_UNIX paragraph is independent of the write policy and still holds, so it stays.
tend-agent
left a comment
There was a problem hiding this comment.
Pipes between a process and its own children are unaffected. splits the sandbox's behaviour on the wrong axis, and the next two lines are the counterexample: MSBuild's worker nodes are its own children, and it talks to them over what .NET calls named pipes — which on Unix are AF_UNIX sockets and so fail. A reader who files MSBuild's parent-to-child pipes under "unaffected" gets the opposite of the paragraph's own conclusion. What actually survives the boundary is the mechanism, not the relationship: pipe() and socketpair() work however the ends are related, and anything that opens a named socket does not.
In this session's sandbox, .NET splits its own "pipes" exactly where the boundary does — NamedPipeServerStream throws while AnonymousPipeServerStream succeeds — so the word is doing real damage in a .NET-facing paragraph.
Suggestion inline; I'm pushing the same wording to both copies of the file. The rest of the paragraph holds as written: socket(AF_UNIX, …) returns EPERM for both SOCK_STREAM and SOCK_DGRAM, probe_boundary() runs ahead of sandbox_setup: and fails the run if one can be created, and the multi-project Build FAILED. with 0 Error(s) reproduces with -m:1 clearing it.
Verification
Run as the sandbox user, .NET SDK 10.0.400. /tmp is read-only in this session (the action runs the released pin, which predates #1324), so the dotnet probes ran inside the private mount namespace this PR used to document.
NamedPipeServerStream: SocketException: Permission denied
AnonymousPipeServerStream: created OK
socket(AF_UNIX, SOCK_STREAM) -> EPERM
socket(AF_UNIX, SOCK_DGRAM) -> EPERM
socketpair() -> OK
pipe() -> OK
Three-project solution, otherwise identical invocations:
dotnet build s.slnx -> Build FAILED. 0 Warning(s) 0 Error(s)
dotnet build s.slnx -m:1 -> Build succeeded. 0 Warning(s) 0 Error(s)
`Pipes between a process and its own children are unaffected` reads as covering MSBuild's parent-to-child node pipes, which is exactly the case the next sentence says fails: .NET's named pipes are AF_UNIX sockets. Name the mechanisms that survive — pipe() and socketpair() — instead.
Adds one paragraph to the two mirrored
tend.example.yamlfiles recording that the sandbox refusesAF_UNIXsockets, and what that costs a build tool. Creating one returnsEPERM;socketpairstill works, so a process and its own children are unaffected and only cross-process Unix-socket IPC is lost. MSBuild loses its workers to this and says nothing useful — a multi-projectdotnet buildprintsBuild FAILED.with0 Error(s)and no diagnostic, which-m:1turns back into real errors. A consumer hitting that has no way to reach the explanation from the symptom, which is what the paragraph is for.This is a durable property rather than a knob the config can relax:
probe_boundary()fails the run if anAF_UNIXsocket can be created, so it is the liveness check for seccomp. Documenting it is therefore the whole fix.Scope narrowed since this was opened. The PR also documented a read-only
/tmpand carried anunshare --map-root-user --mountrecipe for working around it. #1324 has since merged, adding/tmpto the sandbox'sallowWriteset, so both of those paragraphs described a constraint that no longer exists — shipping them would have put a false claim about the write set plus a costly workaround into every consumer's example config. They are removed; theAF_UNIXhalf is independent of the write policy and is all that remains.What the two removed paragraphs said
The first stated that
/tmpis read-only inside the sandbox with no config key to change it, and walked through the .NET SDK's first-runMutexfailing withEROFS. The second gave a private-mount-namespace recipe (mount -t tmpfs tmpfs /tmp, with the checkout bind-mounted across) to give a single command a writable/tmp.Both were accurate when written and are not now. #1324 removed the underlying constraint — the motivation it gives is that a read-only
/tmp"buys a per-tool workaround every time one surfaces", of which the .NET case (#1312) was the latest.