Commit Graph
9 Commits
Author SHA1 Message Date
BaaRai 36940cdf0b security(server): decide the Norma temp directory check from the executor identity
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.
2026-11-20 06:36:48 +01:00
BaaRai 992fcf7030 security(server): refuse to start when the executor can write the Norma temp directory 2026-11-20 06:36:48 +01:00
BaaRai ebb90199c5 security(agent): name the Norma background output directory
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).
2026-11-20 05:35:57 +01:00
BaaRai 7be765bff2 security(agent): restore group sharing for legacy task entries; resolve ask_operator paths from the run dir
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/.
2026-11-20 05:35:56 +01:00
BaaRai 7520c6e588 security(agent): command-output spills go to a root-owned per-task dir
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.
2026-11-20 05:35:55 +01:00
BaaRai e73cdeda93 security(agent): share only run-dir leaves; main agent gets its own leaf
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.
2026-11-20 05:35:55 +01:00
BaaRai c1c1fe9141 security(agent): confine ingest_bbot; write tool scripts outside the run dir
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.
2026-11-20 05:35:54 +01:00
BaaRai eb5d3d73c1 security(agent): confine the file tools and close the executor review
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.
2026-11-20 05:35:54 +01:00
BaaRai 04a7ab3c39 security(server): keep server secrets from agent processes
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.
2026-11-20 05:35:53 +01:00