Add the variable to the runner environment of the three compose files,
document it in .env.example, docs/SANDBOX.md and the CHANGELOG, and
correct the TaskDNS comment: only the egress proxy resolves names.
- parseDNSList: split on comma or any unicode.IsSpace rune so tabs and
newlines in ARTEX_TASK_DNS act as separators, not address bytes.
- proxySpec: add HostConfig.Dns only when the list is non-empty so the
serialized spec is byte-identical when ARTEX_TASK_DNS is unset.
- workerSpec: drop Dns entirely — the worker sits on the --internal
task network and resolves through the egress proxy; setting Dns there
would relay worker DNS around the proxy.
- add cmd/artex-runner/main_test.go: TestParseDNSList covers valid
comma/space/mixed/newline-separated lists, IPv6, empty and
separator-only input, invalid entries dropped (with valid kept),
hostnames dropped, and asserts every output entry parses as an IP.
On Docker Desktop the embedded resolver (127.0.0.11) forwards to the
host's resolver path; when that path is slow or changes underneath
running containers (host roaming networks), per-request DNS in the
worker and egress proxy exceeds resolve budgets or times out entirely.
ARTEX_TASK_DNS (comma/space separated IP list) sets HostConfig.Dns on
every runner-created task container (worker + egress proxy). Empty
keeps Docker's default. Invalid entries are dropped with a warning:
DNS placement is a reliability knob, not a security control — the
egress proxy's scope allowlist remains the security boundary.
Review of the scope filter:
- netip.ParseAddr accepts any text after % as an IPv6 zone, commas
included, so "fe80::1%eth0,10.0.0.0/8" was kept and the comma join
added 10.0.0.0/8. Zoned addresses are now dropped, and every kept
entry is passed on in canonical form (p.Masked().String(),
a.String()), which never holds a comma or space. IPv4-mapped entries
become the IPv4 range they map.
- The cap was 1,024 entries; a company scope can be larger. It is now
8,192 entries and 120 KiB per list (the proxy gets each list as one
environment string, limited to 128 KiB).
- The runner logs dropped entries with the task ID and their values (up
to 20), so an operator can see why an approved target is refused.
- More names that make a shell or interpreter run extra code are
refused: SHELLOPTS, BASHOPTS, PS4, IFS, PROMPT_COMMAND, GLIBC_TUNABLES,
PYTHONSTARTUP, PYTHONHOME, NODE_OPTIONS, PERL5OPT, PERL5LIB, RUBYOPT,
JAVA_TOOL_OPTIONS, GIT_SSH_COMMAND, GIT_CONFIG_PARAMETERS.
ValidateEnv refused secret-looking names only. An exec request could set
HTTP_PROXY, HTTPS_PROXY, ALL_PROXY or NO_PROXY (any case) and send the
command around the egress proxy, or set PATH, LD_* (LD_PRELOAD,
LD_LIBRARY_PATH, LD_AUDIT, ...), BASH_ENV, ENV, GCONV_PATH or PYTHONPATH
and run code before the command. In the Docker backend the exec Env
overrides the worker container's env, so this applied there.
- ValidateEnv refuses these names with 400. FilterPanelEnv drops them, so
the panel does not send a request the runner refuses.
- ValidateExecRequest checks every scope entry: a domain must be a host
name (optionally "*."), a CIDR entry a valid prefix or address. Both
backends join the entries with commas into the egress proxy
environment, so "1.2.3.4/32,10.0.0.0/8" added an entry nobody
approved. Invalid entries (including any with a comma or a space) are
dropped whole, never split, and the valid ones are kept: the panel
builds scope from free-text fields, and a narrower scope fails closed
at the deny-by-default proxy. The runner logs how many entries it
dropped. More than 1,024 entries in either list is still a 400.
- Each worker and proxy pod gets a new name per generation
(artex-w-<hash>-<6 hex>). Exec targets the exact pod of the task state,
so an exec delayed at the API server fails with 404 instead of running
in a replacement pod before that pod passed its network probes.
- setupTask lists the task's pods by label and deletes every pod except
the ones it keeps, with a UID precondition, before it creates new ones.
Same-named pods are no longer deleted without an ownership check.
- Recover adopts only pods whose name matches artex-[wp]-<32 hex>-<6 hex>
and whose name, labels and task annotation agree.
- podAlive returns an error for API failures. Only 404, a UID mismatch, a
deletion timestamp, or a pod that is not running and ready count as
dead. On other errors (a cancelled request too) the exec fails and the
task's pods and policies stay.
- waitPodReady fails fast on CrashLoopBackOff and on exited containers.
- The deny probes print one token per outcome. Only timed out, refused or
unroutable connections count as blocked. Any other result (missing
timeout binary, failed fork, no API env) fails setup at once.
- Probe output, stderr and HTTP client errors go to the runner log only.
The returned errors are generic. A cancelled API request returns a
cancellation error, not "runner unavailable".
- Add fd20:ce::254/128 (GCE IPv6 metadata) to the never-reachable ranges.
- Document that ARTEX_KUBE_CLUSTER_CIDRS must also list the API server
endpoint addresses when they lie outside the cluster ranges (managed
clusters).
- Exec, Kill and Delete reject task IDs with surrounding whitespace.
- go.mod: gopkg.in/yaml.v3 back to indirect (go mod tidy).
- Test: a cancelled exec keeps the task. The scope and probe tests move to
the test PR to stay inside the size limit.
From a second review of the backend:
- Scope CIDRs written as IPv4-mapped IPv6 (::ffff:10.0.0.0/104) are read
as the IPv4 range they map, so the private-range filter and the
never-reachable excepts apply to them. netip treats the two families as
distinct, so such an entry skipped both.
- The never-reachable list adds 0.0.0.0/8 and :: (they reach the proxy's
own host), ::ffff:0:0/96 and link-local through NAT64
(64:ff9b::a9fe:0/112).
- ARTEX_KUBE_CLUSTER_CIDRS and ARTEX_KUBE_PROXY_DENIED_CIDRS refuse /0
(an except equal to its block is rejected by the API server) and
IPv4-mapped prefixes (they would never match).
ARTEX_RUNNER_BACKEND=kubernetes runs each task in a worker pod behind its own
egress-proxy pod, created through the Kubernetes API (kube_client.go) with no
container runtime socket. Per-task NetworkPolicies are applied before the pods
and removed after them; the runner proves they are in effect before the first
command, runs commands through pods/exec under env -i and artex-exec-wrap, and
re-adopts task pods after a restart. Unit tests run against a fake API
server; this commit keeps the tests for the review items, and the other
unit tests and the live cluster test follow in a separate PR.
Changes since the first review (502e42d):
NetworkPolicies and scope:
- Delete and failed setups delete the task's pods and wait until they are
gone before removing the service and, last, the policies. If a pod
cannot be deleted, the policies stay and the task stays tracked. Pods
get a 1s grace, not 0: a zero grace removes the API object before the
kubelet has stopped the containers.
- applyPolicy replaces an existing policy only when it carries the
runner's labels for the same task, and sends its resourceVersion.
- ARTEX_KUBE_PROXY_DENIED_CIDRS adds to DefaultProxyDeniedCIDRs instead
of replacing it. An empty DNSPodLabels map falls back to k8s-app=kube-dns.
- No scope opens the cluster: ARTEX_KUBE_CLUSTER_CIDRS (pod, service and
node CIDRs) plus metadata, loopback, link-local and the API server
address form a never-reachable list. Each scope ipBlock gets them as
except (a block inside one is dropped), the public rule excepts them,
and the proxy refuses them through ARTEX_NEVER_CIDRS (new
EgressPolicy.Never; Docker does not set it). Without
ARTEX_KUBE_CLUSTER_CIDRS, scope CIDRs overlapping private, loopback or
link-local ranges are dropped (logged), so the scope fails closed.
- Isolation does not rely on an outside default-deny policy: every task
pod has its own Ingress+Egress policy, adopted tasks get theirs applied
again, and before the first command the runner checks that the worker
reaches neither the API server nor a public address directly and that
the proxy cannot reach the API server; setup fails otherwise. A scope
change replaces the worker too, so the checks run in a worker no
command has used.
- The proxy pod uses ndots 1, so scope names are not first looked up as
cluster names.
Exec:
- The worker base env comes after the request env in the env(1) argv.
Refusing PATH, proxy and loader variables (LD_*, BASH_ENV, ...) in a
request is a separate change to the shared ValidateEnv, which also
covers the Docker backend.
- Any exec error after the stream started (cancel, broken stream, read
limit) kills the worker's processes, and so does a wrapper timeout
(exit 124 after at least timeout_ms, the Docker rule).
- Exec, Kill and Delete validate the task ID; Exec validates the request.
Concurrency and cleanup:
- Kill takes the task lock; stored tasks are copied, never changed in
place. A Kill caused by an exec acts only on the worker pod UID that
ran it; pod deletes carry a UID precondition.
- An exec queued behind a Delete returns ErrNotFound instead of creating
the task again. Per-task locks are reference counted and removed.
- A failed setup removes what it created, found by label (a foreign
object with the same name stays). Delete returns ErrNotFound only when
no object of the task exists.
- Recover adopts only pods named artex-w-/artex-p-<hash> and services
with a real ClusterIP; adopted tasks are re-checked on first use.
- Scope hash: full SHA-256; task object names use 128 bits.
Config: http:// API servers are refused, the tasks and audit sub paths
must not be ".", equal or nested, and NewKubernetesBackend documents what
the deployment must provide (PID limits, restricted namespace, quotas,
shared volume, shared Kill).
The probe looked for task B under /app/data/tasks, which the worker
image does not mount, so it always reported TASKB_BLOCKED. Probe
/workspace instead: secret-a.txt is the positive control that the
task's own workspace is mounted, and secret-b.txt must stay invisible.
CheckURL refused an empty DNS answer with "dns lookup failed for <host>:
<nil>" because the empty-answer case shared the error branch. Report it
as "dns lookup for <host> returned no addresses" instead. The check stays
fail-closed, and a real lookup error is still reported with its cause.
the timeout by exit code 124. artex-exec-wrap returns 124 when it enforces
timeout_ms, but the command can also exit 124 itself: coreutils
`timeout 1 sleep 5` does. The runner then removed the worker and stopped
the task's background jobs after an ordinary inner timeout.
Count an exit 124 as the runner's timeout only when the exec ran for at
least timeout_ms, which is the only way the wrapper can return it.
The worker image does not ship make(1), so the case failed on the fixture
rather than on containment. A repo-delivered build script exercises the same
path and works in the real sandbox image.
Replay the artifact shapes used against autonomous pentest agents in the
ArtexPot research (cloned repository, archive, pickle, .pth, package setup,
vendored SDK) as harmless markers, then assert that executing each one still
cannot reach the panel's keys, config, database or LLM secrets, cloud
metadata, another task's workspace, or a writable path outside /workspace.
Each case first proves the payload ran, so containment is tested rather than
assumed. Opt-in via ARTEX_SANDBOX_DOCKER_TEST=1, like the existing Docker
end-to-end suite, so normal CI skips it.
The runner always dials /var/run/docker.sock, and all three Compose files
mount that exact host path. Rootless Podman exposes its API under
XDG_RUNTIME_DIR, so the install builds four images and then leaves an
unhealthy runner.
Mount ${ARTEX_DOCKER_SOCK:-/var/run/docker.sock} at the fixed in-container
path instead, and resolve the host side in install.sh/update.sh: an explicit
Unix DOCKER_HOST wins, otherwise a Podman engine is asked for its socket.
The resolver refuses non-Unix DOCKER_HOST values, symlinks, missing sockets,
sockets the invoking user cannot use, and world-writable sockets.
Only the host side is configurable. The in-container path stays fixed so
every deployment dials one known socket and no runtime input can point the
runner elsewhere, and artex-runner remains the only service that mounts it.
Refs #742
EgressPolicy.CheckURL, the check WebFetch, the shared browser and the
custom http tool run on a URL under ARTEX_SANDBOX=required, was fail-open
in two ways:
- a lookup error (or an empty answer) for a name in scope returned nil,
so the URL was allowed;
- a name answering several addresses was allowed as soon as one of them
was public, the others being private, loopback, IPv6 or the cloud
metadata address (169.254.169.254).
CheckURL pins nothing. On a direct call the sandbox dialer resolves again
and pins an allowed address, but through an explicit proxy the panel only
dials the proxy, which resolves the target itself and may pick any answer
(or reach a name the panel could not resolve); the shared browser
resolves on its own as well. For those paths CheckURL is the only check
on the target.
CheckURL now denies a lookup error or an empty answer, and requires every
answer to be allowed (in the scope CIDRs, or outside the default deny
list): a dual-A [IMDS, public] answer is refused, in either order. The
dialer path (ResolveAndCheck, also used by the egress proxy) is
unchanged: it already fails closed on a lookup error and dials only the
allowed address it pinned.
sandboxHTTPTransport now turns keep-alive off on every transport it
returns, not only on the one it builds when httpToolTransport returned
nil: an operator proxy, or the recording proxy setting without a CA file,
kept idle connections to the proxy.
Two existing tests expected an in-scope name that does not resolve to be
allowed, which only the fail-open lookup gave them: the scope drift test
(its resolver reached the proxy policy only, not the policy WebFetch and
the browser build) and the shared browser navigation test. Both now pass
an offline resolver through the context (sandbox.WithResolver); their
assertions are unchanged.
The panel tools (WebFetch, the shared browser, the custom http tool) build
their EgressPolicy themselves, so a test could not hand them a resolver.
WithResolver carries one on the context; a policy without its own Resolver
uses it. Nothing in production sets it, and behaviour is unchanged.
removeContainer and removeNetwork discarded Docker transport failures and
non-2xx statuses, so Kill could clear the worker ID and return nil while the
worker kept running, and Delete removed the task from the in-memory map before
killing, ignored the resulting not-found, and cleaned up unchecked.
removeContainer/removeNetwork now return errors (404 counts as proven absent),
Kill clears the worker ID only after the container is proven stopped or absent,
and Delete kills from the captured task state, keeps the entry until every
resource is proven gone, and returns a retryable error otherwise. Cleanup runs
on a fresh bounded context instead of inheriting a cancelled request, and a
per-task mutex serializes concurrent Kill/Delete.
Introduce the sandbox MVP architecture separating panel credentials and
PostgreSQL access from model-controlled tool execution:
- Runner service (cmd/artex-runner, sandbox/) owning /var/run/docker.sock
behind bearer-token auth (ARTEX_RUNNER_TOKEN) with POST /v1/tasks/{id}/exec,
POST /v1/tasks/{id}/kill, DELETE /v1/tasks/{id}, and GET /v1/health.
- Strict input and env validation (400 on forbidden secret/DB/cloud env
patterns or values > 8192 bytes, strict task ID and /workspace workdir).
- Hardened per-task worker containers (Dockerfile.worker, artex-worker:local,
cmd/artex-exec-wrap): uid/gid 10001, artex-exec-wrap --init PID 1 zombie
reaper, read-only rootfs, cap-drop ALL, no-new-privileges, pids/mem/cpu
limits, tmpfs /tmp and /home/exec, only /app/data/tasks/<id>:/workspace:rw,
only verified internal=true runner-labeled network artex-task-<id>.
- Kernel-backed kill-switch (zero agent-writable state): Kill executes
artex-exec-wrap --kill-uid 10001 as uid 10001 scanning /proc directly
(defeating setsid, nohup, nested double-forked trap-TERM daemons, and /tmp
tampering), verifies zero non-PID-1 uid-10001 processes remain, and falls
back to force-removing the worker container if any check fails. Dead
workers/proxies are recreated automatically when startContainer fails.
- Operator-only scope approval (migration 0023_task_scope_operator_approval.sql):
adds task_scope.approved_by_operator BOOLEAN NOT NULL DEFAULT FALSE, set
true exclusively by operator API/UI (AddOperatorScope) and operator-selected
TaskCreateOptions.CompanyIDs (insertTaskCompanies). AddAgentScope and
AddAutoScope leave it false (coverage-only). taskSandboxRunInfo reads only
approved, non-expanded rows (and expands company scope only for approved
company rows); tasks with no approved scope deny all egress.
- Per-task egress proxy (cmd/artex-egress-proxy, Dockerfile.egress-proxy,
artex-egress-proxy:local): HTTP/HTTPS CONNECT (:3128) and SOCKS5 (:1080),
deny-by-default allowlist with strict domain suffix enforcement, blocks
RFC1918/loopback/link-local/IMDS and IPv6 unless in scope CIDRs, DNS
pinning, and tamper-proof JSONL audit logging to a proxy-only mount
(/app/data/egress-audit/<id>:/audit:rw) never mounted into the worker.
- Panel integration (agent/sandbox.go, agent/webfetch.go, server/sandbox.go,
server/sharedbrowser_guard.go, server/assembly.go, server/customtool.go,
docker-compose.sandbox.yml): ARTEX_SANDBOX defaults to required (fail closed,
no local fallback), WebFetch and opt-in shared browser inherit the
operator-approved sandbox.EgressPolicy (with target_gate or explicit proxy
required for shared browser), custom script tools staged via symlink-confined
workspace files (avoiding argv E2BIG), Pause/Stop/Delete wired to runner
Kill/Delete.
- Documented breaking change and hardening details in docs/SANDBOX.md,
README.md, and CHANGELOG.md.