mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 17:30:56 +08:00
security(agent): refuse run dirs reached by symlink; scrub S3 archive keys
- 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).
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@ Operators running self-hosted LLM gateways or Ollama on a LAN or Docker bridge c
|
||||
|
||||
## Agent Process Isolation
|
||||
|
||||
The server runs as root, but the processes an agent starts (Bash, the interactive shell, custom tools and stdio MCP servers) run as the unprivileged uid and gid set by `-exec-uid` and `-exec-gid` (default 10001). Only the task workspace tree, shared with that group, and their own home (`<data>/exec-home`) are writable by them; `keys/` (`jwt.key`, `secret.key`), the config file and the MITM CA key are root-only, and the server's environment block no longer carries `ARTEX_PG_DSN`, `ARTEX_SECRET_KEY`, the LLM API keys or the LLM proxy and base URLs (Linux). The agent's file tools (Read, Write, Edit, MultiEdit, LS, Glob, Grep) run inside the server but reach only the run's working directory: paths are opened through `os.Root`, so absolute paths elsewhere, `..` and symlinks leading out are refused. The Docker image has no setuid programs and `docker-compose.yml` sets `no-new-privileges`. These are a containment layer, not a sandbox: an executor can still read world-readable files under the data directory, reach the loopback API and the database if the network allows it, and use any credential it was given through the platform. Persistence tools (custom tools, MCP servers, skills) need operator approval by default.
|
||||
The server runs as root, but the processes an agent starts (Bash, the interactive shell, custom tools and stdio MCP servers) run as the unprivileged uid and gid set by `-exec-uid` and `-exec-gid` (default 10001). Only the task workspace tree, shared with that group, and their own home (`<data>/exec-home`) are writable by them; `keys/` (`jwt.key`, `secret.key`), the config file and the MITM CA key are root-only, and the server's environment block no longer carries `ARTEX_PG_DSN`, `ARTEX_SECRET_KEY`, the LLM API keys or the LLM proxy and base URLs (Linux). The agent's file tools (Read, Write, Edit, MultiEdit, LS, Glob, Grep) run inside the server but reach only the run's working directory: paths are opened through `os.Root`, so absolute paths elsewhere, `..` and symlinks leading out are refused, and a working directory reached through any symlink is refused (a swap between that check and the open is not closed). Residual, not closed here: root writes whose path the agent can influence (the command-output spill, the `.tools/` scripts and bbot ingest) can be redirected by a symlink the executor places, so such a write may land outside the workspace as root. The Docker image has no setuid programs and `docker-compose.yml` sets `no-new-privileges`. These are a containment layer, not a sandbox: an executor can still read world-readable files under the data directory, reach the loopback API and the database if the network allows it, and use any credential it was given through the platform. Persistence tools (custom tools, MCP servers, skills) need operator approval by default.
|
||||
|
||||
## What to Expect
|
||||
|
||||
|
||||
@@ -115,6 +115,14 @@ func openWorkRoot(base, dir string) (*workRoot, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("data directory: %w", err)
|
||||
}
|
||||
// A relative symlink inside the data directory passes os.Root (it stays in the
|
||||
// root), so the path is also required to be free of symlinks: the agent's shell
|
||||
// can replace a run directory with a link to another run's tree or to a
|
||||
// root-only file such as the MITM CA key.
|
||||
want := filepath.Join(realBase, rel)
|
||||
if got, err := filepath.EvalSymlinks(want); err != nil || got != want {
|
||||
return nil, errors.New("the working directory path contains a symlink")
|
||||
}
|
||||
r, err := os.OpenRoot(realBase)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("data directory: %w", err)
|
||||
|
||||
@@ -272,6 +272,41 @@ func TestConfinedFileToolsRunDirSymlinkSwap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A relative symlink that stays inside the data directory is still a symlink in the
|
||||
// run directory path: os.Root would follow it, so the run directory is refused
|
||||
// instead. Here it points at a root-only file's directory (the MITM CA's).
|
||||
func TestConfinedFileToolsRunDirRelativeSymlinkInside(t *testing.T) {
|
||||
f := newConfinedFixture(t)
|
||||
ca := filepath.Join(f.base, "traffic", "_ca")
|
||||
if err := os.MkdirAll(ca, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(ca, "mitmproxy-ca.pem"), []byte(confinedSecret+"\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.RemoveAll(f.work); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The link sits in sessions/, so ../traffic/_ca is <base>/traffic/_ca: the in-base CA case.
|
||||
if err := os.Symlink(filepath.Join("..", "traffic", "_ca"), f.work); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
tool string
|
||||
in map[string]any
|
||||
}{
|
||||
{"Read", map[string]any{"file_path": "mitmproxy-ca.pem"}},
|
||||
{"Read", map[string]any{"file_path": "in.txt"}},
|
||||
{"LS", map[string]any{}},
|
||||
} {
|
||||
res := f.call(t, c.tool, c.in)
|
||||
if !res.IsError || strings.Contains(res.Flatten(), confinedSecret) {
|
||||
t.Errorf("relative run dir symlink: %s %v was not refused: %s", c.tool, c.in, res.Flatten())
|
||||
}
|
||||
}
|
||||
f.secretUnchanged(t)
|
||||
}
|
||||
|
||||
// Missing or misplaced working directories fail closed.
|
||||
func TestConfinedFileToolsNeedWorkDirUnderBase(t *testing.T) {
|
||||
f := newConfinedFixture(t)
|
||||
|
||||
+8
-2
@@ -5,8 +5,14 @@ import "os"
|
||||
// secretEnv lists the credentials read from the environment only at startup:
|
||||
// ARTEX_PG_DSN and ARTEX_SECRET_KEY by NewManager, the API keys by agent.FromEnv inside New.
|
||||
// agent.FromEnv also reads ARTEX_LLM_PROXY and ARTEX_LLM_BASE_URL: both are URLs that
|
||||
// can carry credentials in their userinfo (http://user:pass@proxy:3128).
|
||||
var secretEnv = []string{"ARTEX_PG_DSN", "ARTEX_SECRET_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "ARTEX_LLM_PROXY", "ARTEX_LLM_BASE_URL"}
|
||||
// can carry credentials in their userinfo (http://user:pass@proxy:3128). The ARTEX_ARCHIVE_S3_*
|
||||
// keys are not read by the server, but the container may carry them and the agent's
|
||||
// shells would inherit them.
|
||||
var secretEnv = []string{
|
||||
"ARTEX_PG_DSN", "ARTEX_SECRET_KEY", "ANTHROPIC_API_KEY", "OPENAI_API_KEY",
|
||||
"ARTEX_LLM_PROXY", "ARTEX_LLM_BASE_URL",
|
||||
"ARTEX_ARCHIVE_S3_ACCESS_KEY_ID", "ARTEX_ARCHIVE_S3_SECRET_ACCESS_KEY", "ARTEX_ARCHIVE_S3_SESSION_TOKEN",
|
||||
}
|
||||
|
||||
// ScrubSecretEnv removes secretEnv from the process environment once startup has
|
||||
// read it. Child processes (agent shells, custom tools, MCP stdio servers) copy
|
||||
|
||||
@@ -55,8 +55,11 @@ func TestSealedEnvironmentHandoff(t *testing.T) {
|
||||
"ANTHROPIC_API_KEY": "sk-ant-test",
|
||||
"OPENAI_API_KEY": "=leading-equals",
|
||||
// Proxy and endpoint URLs can carry credentials in their userinfo.
|
||||
"ARTEX_LLM_PROXY": "http://proxyuser:proxypass@proxy.internal:3128",
|
||||
"ARTEX_LLM_BASE_URL": "https://apiuser:apipass@llm.internal/v1",
|
||||
"ARTEX_LLM_PROXY": "http://proxyuser:proxypass@proxy.internal:3128",
|
||||
"ARTEX_LLM_BASE_URL": "https://apiuser:apipass@llm.internal/v1",
|
||||
"ARTEX_ARCHIVE_S3_ACCESS_KEY_ID": "AKIATESTONLY",
|
||||
"ARTEX_ARCHIVE_S3_SECRET_ACCESS_KEY": "s3-secret-test",
|
||||
"ARTEX_ARCHIVE_S3_SESSION_TOKEN": "",
|
||||
}
|
||||
env := os.Environ()
|
||||
for k, v := range want {
|
||||
|
||||
Reference in New Issue
Block a user