Repository navigation
Run agent processes under the executor identity with a sealed environment - #478
Conversation
The confined file tools (Read, Write, Edit, MultiEdit, LS, Glob, Grep) and the opens of ingest_bbot and ingest_scan_output ran inside the server, as root, and relied on the os.Root path confinement alone. With the executor privilege drop active, PrepareExecPrivilege now gives them the executor uid and gid: each call runs on a thread of its own whose file system uid, file system gid and supplementary groups are the executor's (setfsuid, setfsgid and the per-thread setgroups of x/sys/unix). The thread is never unlocked, so the runtime ends it with the call and no other goroutine runs with those ids. The kernel then checks every open, create and directory read against the rights of the agent's shell, on top of the path confinement. Output over the cap is still spilled, after the call, with the server's identity. Linux only. Elsewhere the identity is not set and a log line says the file tools keep the server's identity. golang.org/x/sys becomes a direct dependency (already in the module graph at the same version).
An agent process inherited the server's environment minus the names that ScrubSecretEnv removes: a deny list, so a credential under any other name (one an operator or an image adds) reached the agent's shell, its custom tools and its MCP stdio servers. When a process crosses from the server's identity to the executor's, its environment is now rebuilt from a fixed allowlist: the search path and locale, the temp directory, the non-interactive defaults, the proxy and CA trust variables the agents pass to their shells, PLAYWRIGHT_BROWSERS_PATH and the shim's own variables. The Bash shim and the MCP drop shim rebuild it before the drop; a custom tool starts from it. What the caller passes on purpose still crosses: the agent's Bash env, the TOOL_* parameters, and the configured env of an MCP server, which the drop shim keeps because connectMCP names it in ARTEX_EXEC_KEEP. A nested shell is not filtered again. The startup scrub and the environment seal stay as they are; they are no longer the boundary for agent processes. With the drop disabled nothing changes.
When the privilege drop could not be applied (the server not root, or
-exec-uid negative), the start went on with one log line, and nothing
checked that an applied drop really isolated the agent. Before the stores
open, the server now runs a self-test: a probe started the way the
agent's Bash starts ("bash" on PATH, so through the shim) checks from
inside the executor process that it runs as the executor uid, gid and
only group, cannot read jwt.key, secret.key, the config file or the MITM
CA key, cannot read the server's /proc environ or memory, sees only the
allowlisted environment, and cannot open a session on the server's
database with the server's user and no password (only host, port, user
and database name reach the probe). The file tools are checked too: the
secrets must not open through their identity.
A failed or impossible self-test stops the start. The development escape
-dev-insecure-no-isolation, off by default, lets the start go on and logs
a banner that says what is exposed. This changes the behaviour of a
non-root start (go run, the systemd example unit, Windows, macOS): it now
needs that flag.
PrepareExecPrivilege chmodded jwt.key, secret.key and the config file to 0600 but left their owner as it was: a file owned by the executor uid (created by an agent process, or on the host under the uid the executor has in the container) stayed readable by the agent. It now makes root their owner first. The startup self-test also checks the directories: the probe, as the executor, must not be able to create an entry in the data directory, the key directory or the config file's directory (it could plant a key, a config or a data tree for the next start), and none of their parents may let the executor replace them (owned by it, or writable by it without the sticky bit). For the database, a test against PostgreSQL shows the server's role refused without its password (SQLSTATE 28P01); the probe already fails the start when the database lets that role in. No Unix socket is introduced: in the compose deployment PostgreSQL runs in its own container and is reached over TCP with a password that the executor cannot read (sealed environment, root-only config).
The six platform tools that durably change skills, custom tools and MCP servers already need operator approval (intercept/persistence.go, the built-in ask rules of db/intercept_persistence_seed.go, guard.go). Custom tools and MCP servers live in the database, which the agent's shell cannot reach. Skills live on disk: an agent process that can write the skill directory adds or changes a skill without create_skill or update_skill_file, and every agent then loads it as instructions. The startup self-test now checks the skill directory: the probe, as the executor, must not be able to create an entry in it, its parent must not let the executor replace it, and no file or directory below it may be owned by the executor uid or writable by the executor gid or by others (judged from owners and mode bits, symlinks by their target, nothing written).
The new root tests hold a file tool call open and check, at that moment, that only the call's thread has file system uid 10001: the caller, 32 goroutines locked on other threads and every other thread listed in /proc keep uid 0, root's groups and root's access, and goroutines the call starts do not inherit the ids. A panic and runtime.Goexit inside the call reach the caller and end the thread instead of returning it to the runtime. Calls under load with live and cancelled contexts never show the executor's ids on an observer thread, and no thread keeps them afterwards. Both mutations that would leak the identity are caught: unlocking the thread without restoring its ids, and a process-wide setgroups. The comment of runWithFileIdentity now states the limits: the ids cover fn's goroutine only, and fn must not start goroutines or programs.
The isolation self-test stopped every start it failed, so a non-root server (the systemd unit), dev.sh, Windows and macOS no longer started without -dev-insecure-no-isolation. EnforceIsolation now decides from the platform and the privilege drop: - self-test passed: isolated; - Linux with the privilege drop on (root, the Docker image): a failure stops the start, unless -dev-insecure-no-isolation is set; - elsewhere (not Linux, not root, -exec-uid=-1): the server starts degraded, without a flag. A degraded start logs a banner with the self-test failure and what is exposed, and GET /api/health reports the isolation status to a signed-in caller; the web UI shows a red banner on every page while it is degraded. The systemd deployment guide and dev.sh describe the mode.
The self-test probe tried only the first host of the DSN. It now tries each host and port the DSN lists, fallbacks included, and nothing else, and a DSN it cannot parse fails the self-test instead of skipping the database check. docker-compose.yml sets POSTGRES_HOST_AUTH_METHOD=scram-sha-256: a TCP connection from another container, artex's included, needs the password. It takes effect when a new pgdata volume is initialised.
b42bffc to
303acd7
Compare
|
Independent re-test of PR #478 at commit Results
Coverage limit: The model did not poll its first asynchronous |
jamesKhor
left a comment
There was a problem hiding this comment.
Confirmed a security vulnerability at head 303acd7: an executor process can race the permission-sharing walk and cause it to make a root-only file readable. I tested the production shareWithExecGroup function directly with a root process and a UID/GID 10001 child on Ubuntu 24.04 under WSL2. In five of five runs, a synthetic root-owned 0600 file outside the run directory became 0777, and the UID 10001 child read its contents. This was a focused helper-level reproduction; I did not run an end-to-end archive restore or use real secrets. The restore path calls this helper after sharing the run directory. Please fix the race before merging. A separate lower-severity allowlist observation is noted inline.
The vulnerable call is in server/execpriv_unix.go at line 565. Archive restore reaches it through shareRestoredTaskDir in server/task_archive_package.go at line 304. Use directory-descriptor-anchored no-follow traversal and descriptor-based ownership/permission changes.
| } | ||
|
|
||
| // executorEnvPrefixes are kept by prefix: the locale categories. | ||
| var executorEnvPrefixes = []string{"LC_"} |
There was a problem hiding this comment.
[P3, conditional] This prefix admits arbitrary LC_... variable names, so the executor environment is not a fixed set of names. A synthetic LC_REVIEW_SECRET value passed executorEnv in a focused test, while OPENAI_API_KEY was filtered. I did not observe a standard ARTEX secret leaking; exposure requires a secret supplied under an LC_ name. Enumerating the locale variables actually needed would make the stated fixed-name guarantee accurate.
|
Follow-up to my changes-requested security review: I submitted the tested permission-race fix as PR #505, targeting this PR's The patch makes the run-directory sharing walk operate on opened descriptors with no-follow child opens and refuses hard-linked file aliases. The concurrent UID 10001 regression failed on this PR's original code (a synthetic root-owned PR #505 is open for review and has not been merged into #478. The separate conditional |
Fix executor run-directory permission race in #478
The executor environment kept every name starting with LC_, so a secret supplied under an LC_ name crossed the allowlist even though the comment promised a fixed set of names. The POSIX locale categories are now enumerated and the prefix rule is gone. Found by jamesKhor in the review of #478.
|
Thanks @jamesKhor. Merged. Your review changed the PR before merge: the sharing walk now works on opened descriptors and refuses hard-linked aliases (#505), and only the fixed POSIX locale names cross the environment allowlist. Your local Ollama run with a real task is the model gate, and the numeric uid coverage limit you noted is recorded in the body. |
Summary
Extends agent process isolation on top of
main(565f448). Agent processes (Bash, the interactive shell, custom tools, stdio MCP servers and the file tools) run under the executor uid and gid (default 10001), with a fixed environment and a startup self-test that fails closed. Branch head:60a1ffc(tree6a0ede0b).Includes #505 by @jamesKhor: the run-directory sharing walk now opens each entry relative to its already-open parent with
O_NOFOLLOWand changes ownership and mode through that descriptor, and refuses regular files with another hard link. It also drops theLC_prefix from the environment allowlist, so only the fixed POSIX locale names cross.Changes and controls
os.Rootconfinement to the run directory./healthreportsisolation.modeandisolation.reason.-dev-insecure-no-isolationis the explicit opt-out.docker-compose.ymlusesscram-sha-256for TCP connections to PostgreSQL.Verification
Run on the tested tree (head
303acd7, treed1272e01), rebased onmain565f448, against PostgreSQL 16 withARTEX_PG_DSNset.gofmtclean;go buildfor linux, windows and darwin;go vetclean.go test ./...): 1748 PASS, 0 FAIL, 33 SKIP.*AsRoottests run as root): 1776 PASS, 0 FAIL, 5 SKIP. All 30*AsRoottests ran and passed.TestLiveContextReview, which needs an external model configuration. The root run also skips two tests that expect a non-root process.60a1ffc):go test ./serveras root from the package directory with an executable test binary: PASS, includingTestShareWithExecGroupCannotChmodOutsideAsRoot,TestShareWithExecGroupRejectsHardLinkAsRootandTestExecutorEnvAllowlistwith anLC_REVIEW_SECRETvalue that no longer crosses. The full modulego test -raceruns in CI on this head.303acd7, treed1272e01) with the repository's Dockerfile and compose file:/healthreportsisolation.modeisolated./proc/1/environare refused.303acd7with local Ollamaqwen3:1.7b. The startup self-test passed, the model made realshell_opentool calls, and the captured shell output showed gid 10001 inside the confined run directory. A wrong synthetic database password was refused; keys and config were root-owned with mode0600. Coverage limit: the model did not poll its first asynchronousid -usession, so the numeric uid was covered by the root tests and the live gid output, not by that call.Not covered
psql; the self-test performs that probe itself).