TestCheckNormaTaskDir runs every rule of checkNormaTaskDir on stat facts
alone, without root and without a file system.
On a real directory, with and without root:
- TestPrepareNormaTaskDirAlreadyThere: a directory the executor uid owns, one
its gid can write in and an other-writable one fail the start, and the error
names the path, the owner and group, the mode, the executor and the remedy;
one of another user or of root that the executor cannot write in is used as
found. Owners, modes, times and contents of the directory and of what it
holds are hashed before and after: nothing changes in either case.
- TestPrepareNormaTaskDirParent: a parent the executor can write in and that
is not sticky fails the start; the same parent with the sticky bit passes.
- TestPrepareNormaTaskDirNotADirectory: a symlink, a dangling symlink and a
regular file fail the start, and nothing is created through the link.
- TestPrepareNormaTaskDirDropDisabled: with the drop disabled nothing is
checked or created.
As root, TestNormaTaskDirPlantedByExecutorAsRoot lets an executor process
create <temp>/norma with a symlink in it, as it could before a start:
PrepareExecPrivilege fails and leaves the directory as it is.
The root fixture now gives each test its own temp directory, 1777 like /tmp.
PrepareExecPrivilege and Norma's Bash tool reach <temp>/norma, and before
this every root test went to the one of the host. The new tests set TMPDIR to
t.TempDir() for the same reason.
The check of <temp>/norma, where Norma writes background-task output from
the server process, now lives in checkNormaTaskDir. It takes the Lstat of
the path, the Stat of its parent and the executor uid and gid, and decides
from the owners and the mode bits. An access check would answer for root,
which the server is.
The start fails when:
- the path is a symlink or not a directory;
- the executor uid owns the directory: under a sticky /tmp the owner can
still rename it and put another in its place;
- the group or other bits let the executor write in it;
- the parent directory is writable by the executor and not sticky, or the
executor owns the parent: the sticky bit does not stop the owner of a
directory from renaming an entry in it.
The error names the path, its owner and group, its mode, the executor uid
and gid, and the remedy: remove the directory or set TMPDIR to a directory
the executor cannot write.
Any other directory already there is used as found, with the same warning as
before when root does not own it or its group can write in it. A missing
directory is still created root:root 0755 and goes through the same check.
A directory that was already there is never chmodded, chowned, renamed or
removed. With the privilege drop disabled nothing is checked or created.
TestSecretEnvCoversCredentialURLs calls ScrubSecretEnv, which unsets every
name in secretEnv for the rest of the test binary, ARTEX_PG_DSN and
ARTEX_SECRET_KEY included. The leak is new on this branch: main has no such
test. Without the fix a merge would silently skip 148 server DB tests in CI:
they skip when ARTEX_PG_DSN is not set, and the run stays green.
The fix is in the test: the loop over secretEnv restores every name with
t.Setenv, so each one gets its value back when the test ends.
Norma keeps the output of background tasks in os.TempDir()/norma
(<tmp>/norma/<session>/tasks/task_<n>.output), written from the server
process with MkdirAll and an open that follows symlinks. ARTEX does not
choose that path, and the temp directory is world-writable: an executor
process that runs before the first session creates the directory (a stdio
MCP server, a process left from an earlier start) could create it first and
place symlinks in it for the server to write through.
- PrepareExecPrivilege, only when the drop is enabled, now creates
<TempDir>/norma itself (prepareNormaTaskDir): Mkdir 0755 as root, then
Lstat. A symlink or a file in its place is refused and the server does
not start.
- A directory that is already there is used as found. It is not chowned:
it may belong to another user of the host. When root does not own it or
others can write in it, a warning is logged and nothing else changes.
- SECURITY.md adds this output to the residual list of the Agent Process
Isolation paragraph, with what the start-up step does and does not cover.
Norma is unchanged.
Tests: TestPrepareNormaTaskDir (created when absent, kept when there,
symlink and file refused, nothing created through the symlink);
root-only TestNormaTaskDirAsRoot (PrepareExecPrivilege leaves
<TMPDIR>/norma root:root 0755 in a sticky world-writable directory, and
an executor process can neither add an entry nor rename it).
The staged copy of an ask_operator image was written by the server with
os.Create under a name built from the second, in an uploads directory made
with MkdirAll. An agent that can write in uploads/ (a task directory from
before the run-directory layout) could prepare that name as a symlink, and a
symlinked uploads/ was followed.
- uploads/ is created with Mkdir and checked with Lstat: a symlink or a
file in its place is refused.
- The name is ask-operator-<unixnano>-<8 random hex>.<ext>, created with
O_CREATE|O_EXCL, mode 0640. A taken name is never opened: another name is
tried, five at most.
- The source is opened only when it is still the regular file Lstat saw
(os.SameFile on the Lstat and the Stat of the open file), which refuses a
file swapped for a symlink between the EvalSymlinks check and the open.
The run-directory confinement is unchanged.
Not closed: a directory inside the run directory swapped for a symlink
between the check and the open still leads both Lstat and the open to the
same file elsewhere.
The layout commit made tasks/<id> root:root 0755 and shared only the run
directories. Entries that sat directly in a task directory before it
(uploads/, files the main agent wrote there) were left as found and
nothing shared them any more: after an archive restore, which keeps
neither owners nor modes, the executor could not use them. ask_operator
still resolved a relative image_path from tasks/<id>, not from the
directory the agent works in.
- shareTaskDir: after the task directory is set root:root 0755, each
direct entry that is not a run directory (main, i<N>) is shared with
the executor group again (shareWithExecGroup: group owner, group
read/write, traverse and setgid on directories). Run directories are
handled as before. The task directory stays root-only, so the executor
works inside an old entry and cannot rename, remove or add one. A
symlink among the entries is not followed. The pass runs at start-up
and on archive restore (installTaskArchiveFiles calls
shareRestoredTaskDir and rolls back on failure), with no operator step.
- ask_operator: image_path is resolved inside the run directory of the
agent that asks (agent.EnsureRunDir: tasks/<id>/i<N> for a worker,
tasks/<id>/main without an intent). An absolute path outside it, "..",
and a symlink leading out are refused as before. The copy is still
staged in tasks/<id>/uploads. The tool description says so.
Tests: root-only TestShareTaskDirLegacyEntriesAsRoot (owners and modes,
an executor probe, links to a root-only directory and file left alone);
TestRunDirLayoutOnExistingTreeAsRoot now expects the old file shared;
TestTaskArchiveRestoreRunDirOwnershipAsRoot restores an entry of the task
directory; TestStageAskOperatorImage uses the i<N> and main leaves.
SECURITY.md states the sharing of the old entries and the empty main/.
Norma's tool.Capture writes an oversized tool output to a file in
ToolOutputDir, from the server process. ARTEX passed <run dir>/cmd-output:
the executor can write in the run directory and could turn cmd-output into
a symlink, so root wrote the spill where the link pointed.
- With the privilege drop on, ToolOutputDir is <data>/spill/tasks/<id> for
the worker, the main agent and the planner of a task, and
<data>/spill/sessions/<id> for a chat. The server creates it when the
run starts (agent.SetSpillDirMaker, same style as SetRunDirMaker):
root:<exec gid> 0750 below root:root 0755 parents, each level through a
descriptor opened with O_NOFOLLOW. A directory that cannot be created
leaves the run without a spill directory (output is truncated), never
with the run directory. Without the drop the path stays
<run dir>/cmd-output.
- Norma v0.4.11 writes the spill file 0600 (directory 0700), so the
executor could not read it. The runs wrap their hooks (agent.SpillHooks):
after a tool call whose result carries the spill marker, the server makes
the files of the directory root:<exec gid> 0640. The agent reads a spill
with Bash; the file tools do not reach outside the run directory.
- The spill directory follows the task: stageTaskFiles moves it to the
delete staging with tasks/<id>, stageTaskArchiveFiles packs it as
files/spill/tasks/<id>, and installTaskArchiveFiles restores it and puts
its ownership back. Deleting a conversation removes
spill/sessions/conv-<id>.
Tests: TestToolOutputDir (agent); TestDeleteTaskFilesRemovesSpillDir,
TestRemoveConversationSpill and the archive round trip (server); root-only
TestSpillDirAsRoot, and the spill directory in
TestTaskArchiveRestoreRunDirOwnershipAsRoot. SECURITY.md drops the spill
from the residual list.
The task and chat workspace trees were shared whole with the executor
group, and the main agent and the planner worked in tasks/<id>, the parent
of every worker directory: the executor could rename, remove or replace a
run directory, its own included, and plant entries beside them.
- Layout: no agent working directory is an ancestor of another. The main
agent and the planner work in tasks/<id>/main, a worker in
tasks/<id>/i<N>, a chat in sessions/<id>. With the privilege drop on,
tasks/, sessions/ and tasks/<id> are root:root 0755 and only the leaves
are root:<exec gid> 2775.
- PrepareExecPrivilege no longer shares tasks/ and sessions/. It sets the
parents, shares the leaves found on disk with what they hold, and
registers the run-directory maker (agent.SetRunDirMaker). ensureRunDir
and the chat session directory go through it: each level is created
with Mkdir and set through a descriptor opened with O_NOFOLLOW, parents
before the leaf, so a link planted where a run directory goes is
refused. Without the drop both stay a plain MkdirAll.
- Uploads for the main agent land in tasks/<id>/main/uploads, and the
attachment paths given to it use the same directory; session uploads
create sessions/<id> by the same rule.
- Task archives still pack and delete the whole task directory, so the
package holds files/tasks/<id>/main and i<N>. The package keeps neither
owners nor directory modes: the restore puts the layout back
(installTaskArchiveFiles takes the privilege).
- Existing data is not migrated. Files a task wrote directly in
tasks/<id>/ stay there with their owner and mode; the main agent starts
in an empty tasks/<id>/main and its file tools no longer reach them.
Tests: TestRunDirLayout and TestIsRunDirName (agent); root-only
TestRunDirLayoutAsRoot, TestRunDirSiblingsProtectedAsRoot,
TestRunDirLayoutOnExistingTreeAsRoot and
TestTaskArchiveRestoreRunDirOwnershipAsRoot (server). The archive tests
use the main/ and i<N> leaves. SECURITY.md states the invariant, names the
race that remains and drops ensureRunDir from the residual list.
Two root file operations took a path the agent controls.
- ingest_bbot opened the path it was given with os.Open in the server
process, which is root in the image: any root-readable file could be
named, and the result counts told its line structure. The tool now opens
the file through the file tools' confinement (openWorkRoot on the run's
working directory under the data directory, then os.Root): an absolute
path elsewhere, "..", a symlink, a hard-linked file and a run directory
reached by a symlink are refused. It fails closed without a data
directory or a working directory. The worker passes its data directory
to the ToolSet (SetWorkBase); the tool reads the ToolContext for the
working directory, like ingest_scan_output.
- execPython wrote the script of a custom tool as root to
<run dir>/.tools and then chowned it. The executor can write the run
directory, so it could turn .tools into a symlink and have root create
and chown a file elsewhere. With the privilege drop on, the script now
goes to <data>/exec-scripts, created by PrepareExecPrivilege as
root:<exec gid> 0750, outside tasks/ and sessions/: the executor reads
the 0640 script and cannot create, rename or replace an entry. An
enabled drop without that directory is an error, not a fallback to the
run directory. Without the drop nothing changes. PrepareExecPrivilege
takes the privilege by pointer to record ExecPrivilege.ScriptDir.
Tests: TestOpenBbotOutputConfined and TestIngestBbotToolConfined (no
Postgres), TestExecPythonNeedsScriptDirWhenDropping, and the root-only
TestExecPythonScriptDirAsRoot (.tools planted as a symlink to a root-only
directory). TestIngestBbotScopeSplit now places its file in a run
directory. SECURITY.md: the two paths leave the residual list; the
command-output spill stays.
- openWorkRoot: refuse the run directory when its resolved path differs from
the path under the data directory, so a relative symlink that stays inside
the data directory (run -> traffic/_ca) no longer reaches root-only files.
- Test: TestConfinedFileToolsRunDirRelativeSymlinkInside targets <base>/traffic/_ca.
- secretEnv: add ARTEX_ARCHIVE_S3_ACCESS_KEY_ID, ARTEX_ARCHIVE_S3_SECRET_ACCESS_KEY,
ARTEX_ARCHIVE_S3_SESSION_TOKEN; the sealed-env test covers them.
- SECURITY.md: document the run-dir race and the residual root writes through
agent-influenced paths (cmd-output spill, .tools, bbot ingest).
The SDK file tools Read, Write, Edit, MultiEdit, LS, Glob and Grep run in
the server process, which is root in the image, and took any absolute or
relative path: Read returned /app/keys/jwt.key or the config file, and
Write could plant a skill or rewrite the config past the approval gate.
- agent/filetools.go: defaultTools replaces the seven tools for every
agent kind (chat, main agent, planner, worker). Same names, prompts and
schemas; every path goes through an os.Root on the run's working
directory, opened component by component below the data directory, so
absolute paths elsewhere, "..", symlinks leading out, a run directory
swapped for a symlink and files with extra hard links are refused. Grep
no longer starts ripgrep. The LLM connection test passes an empty tool
list instead of nil (nil meant the unconfined defaults).
- traffic: chmod the go-mitmproxy CA private key to 0600 after the proxy
creates or loads it; the CA certificate stays readable.
- server: the executor gets HOME and XDG_CACHE_HOME in <data>/exec-home,
owned by it, on the bash shim, the MCP drop shim and the custom-tool
credential path.
- server: ARTEX_LLM_PROXY and ARTEX_LLM_BASE_URL can carry user:pass@;
they are scrubbed and sealed with the other startup secrets.
- docker: no-new-privileges for the artex service, setuid/setgid bits
stripped in the image, PLAYWRIGHT_BROWSERS_PATH kept at root's cache.
- db: the persistence approval seed inserts each rule only when no rule
of that name exists, so a re-run does not duplicate rules.
- Root-gated tests run the bash shim, a custom tool and an MCP stdio
command as the executor and check the uid, a 0600 root file, the
server's /proc environ and a cache write.
GHSA-prm8-vw2v-wjwh: the agent command executor ran as root in the server's
container and PID namespace, so it could read /app/keys and recover the
server secrets from /proc/<pid>/environ.
Deliverable 1, executor identity. Agent processes (Bash, the interactive
shell, custom tools, stdio MCP servers) run as the uid/gid set by
-exec-uid and -exec-gid (default 10001). Custom tools use
SysProcAttr.Credential. Norma starts Bash and the shell itself, so a PATH
shim (the server binary named bash) drops the identity before exec; MCP
stdio commands run through the same binary in drop mode. The task and chat
workspace trees are shared with the executor group (setgid, group rw,
umask 002). The key files and the config file become root-only, and
/app/keys is 0700 in the image. An explicit -exec-uid that cannot be applied
stops the start; the default logs once that same-uid isolation is
unavailable when the server is not root.
Deliverable 2, sealed environment. On Linux, SealProcessEnv re-executes the
server once with the secret variables removed from its environment block,
passing the values through an inherited pipe. The new image restores them
into the Go environment, so readers see the same configuration. Off Linux it
logs that the environment is not sealed.
Deliverable 3, approval gate. Custom tools, MCP servers and skill files
(create_/update_ of custom tool and MCP, create_skill, update_skill_file)
meet built-in ask rules seeded once (intercept_persistence_rules_v1). A user
allow rule cannot skip them; a user deny still wins. The rules are data the
agent cannot edit.
Tests: resolution and refusal of root identities, drop command wrapping,
sealed-environment encoding, and an end-to-end handoff test on Linux that
checks the kernel environment block and a child process hold no secret
names and that the values survive (empty and multi-line included). Approval
matching is tested in intercept.
The workspace file manager roots every path at the data directory, so the
capture proxy CA private key under traffic/_ca and the SQLite exchange index
under traffic/_index were listable, downloadable, overwritable and deletable
through /api/workspace/*. Refuse those two subtrees after resolving the path,
so a symlink alias or a Windows spelling a trailing dot cannot reach them.
The argv allow denylist is the only gate that stops an always-allow rule
from naming a program whose flags can run arbitrary commands. git (aliases,
hooks, -c), cmake (-P), ctest and cpack run commands from user-controlled
files, so an allow prefix for them is never safe. Also key the arity table
by the normalised program name so a path-qualified binary derives the same
prefix length as the bare name.
GET /api/traffic/stream and the traffic_messages tool take an optional
direction (c2s or s2c) to list one side of a WebSocket or SSE
conversation. total and offset apply to the filtered list, seq stays the
position in the whole stream, and the meta limit marker is kept in a
filtered page so dropped messages are never hidden. Any other value is
rejected (400 / tool error).
Part of #379 (traffic inspection: filter by direction).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Introduced uniform skipping functions in the db package: SkipPGUnavailable and SkipNoPG.
- Updated all relevant test files to utilize these new functions for better consistency and readability.
- Added new db/testpg.go file to house the skipping logic.
- Created architecture and operations documentation to provide a comprehensive overview of the ARTEX system.
- Added a verification script to streamline local testing and ensure code quality.
The gate treated a call as direct whenever only the recording proxy or a
custom tool's own proxy was in the path, so it stored IP pins the proxy
did not enforce. ProxyAddr now covers the recording and global proxies,
a per-tool check covers a custom http tool's own proxy, and the gate
marks the pin name-only for any of them.
Closes#368.
GET /api/conversations/{id}/messages passed limit through to the
database with no upper bound, so a huge query could load the whole
transcript. Clamp history pages to 200 and keep the since tail at 1000.
The stock seed was npx @playwright/mcp, but the UI mock and common
invocations use npx -y, which the first pass left untouched. Also add
--browser chromium to a leftover playwright-mcp --headless row, resolve
the MCP's playwright-core CLI via require.resolve, and cover proxy-arg
stripping so capture sync does not depend on args[0].
npx @playwright/mcp queries the npm registry on every start even with
the package installed globally, so the image's pin did not decide what
ran and offline starts failed. Seed playwright-mcp --headless --browser
chromium, rewrite leftover stock npx rows once, and install the Chromium
build the MCP's own playwright-core expects.
Fixes#329
POST /api/auth/change-password checked the current password with bcrypt
and had no limiter. A stolen session could guess without backoff.
Reuse the login limiter, keyed by client IP and by the session token,
so rotating the source address with the same token still blocks.
A successful change clears both buckets.
image_path was opened as a raw filesystem path, so any readable
png/jpg/jpeg/webp/gif on the host could be copied into the operator
transcript. The path is now resolved from the task working directory
and refused when it contains .. or EvalSymlinks outside that tree.
json.Unmarshal of JSON null into a map yields nil. syncBrowserMCPProxy
then assigned NODE_EXTRA_CA_CERTS under traffic capture and panicked,
including during NewManager on every restart once that row was stored.
A turn the provider's safety system declines (Anthropic stop_reason
"refusal", OpenAI-compatible finish_reason "content_filter") has no text
and no tool calls. Norma passes the stop reason through and the harness
ends any tool-less turn with ReasonCompleted, so the run summary said the
model "ended this turn normally", and steerHooks.Stop took the empty turn
for an idle one and resent the conversation up to the empty-response retry
count.
The LLM recorder is the one layer that sees the stop reason. It now hands
each completed call's stop reason to an optional context sink
(llmrec.WithStopSink). captureRunSession installs a per-run tracker
(agent.WithStopTracker) on that sink. With it:
- steerHooks.Stop does not inject the idle-turn rerun after a refusal;
- terminalText reports "provider refusal (stop_reason ...)" and says the
intent was not completed, instead of the completed wording.
Other terminal states and ordinary empty turns are unchanged.
Fixes#327
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FindingFilename cut the name at 120 bytes, which can split a multi-byte
character. archive/zip only sets the UTF-8 flag on valid names, so the
entry was written without it and unzip tools decoded the whole name as
CP437, garbling every non-ASCII character in it.
The /system/llm/ badge read llm_profile_health, which only the failover
Pool wrote. A task pinned to an explicit chain, a bound agent with
failover off, and the global provider all call the provider directly, so
a dead backend stayed "Healthy".
One policy now lives in llmpool.Registry.RecordCall, used by the Pool and
by the task runtimes: a success clears the state, a failover-eligible
failure trips it, context cancellation and deterministic 400s do not, and
a stream that already delivered output is left alone. The selection
carries the profile whose breaker the call updates, and a provider
already wrapped in the Pool reports nothing to avoid double counting.
The LLM recording page also explains an empty list while the llm_record
toggle is off, after the settings call resolves.
Originally reported in #257.