Skip to content

fix(sandbox): refuse exec env names that override the proxy, PATH or the loader - #895

Open
thecorporatetractor wants to merge 2 commits into
BaaRai:mainfrom
thecorporatetractor:fix/sandbox-reserved-env
Open

thecorporatetractor wants to merge 2 commits into
BaaRai:mainfrom
thecorporatetractor:fix/sandbox-reserved-env

Conversation

@thecorporatetractor

@thecorporatetractor thecorporatetractor commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Found while fixing the review of #780.

  • ValidateEnv refuses secret-looking names only. In the Docker backend the exec Env is merged over the worker container's env, so a request can set HTTP_PROXY, HTTPS_PROXY, ALL_PROXY or NO_PROXY and take the command off the egress proxy (the worker network is internal, so this breaks egress rather than opening it). A request can also set PATH, LD_*, or a variable that makes a shell or interpreter run extra code (BASH_ENV, SHELLOPTS+PS4, NODE_OPTIONS, PERL5OPT, ...). The panel always sends bash -c <command>, so this is defence in depth: the runner API should not accept env names that the worker owns.
  • Scope entries are not checked one by one. The Docker backend joins them with commas into the egress proxy's environment (docker.go), and the Kubernetes backend in feat(sandbox): Kubernetes backend for artex-runner #780 does the same. So a scope CIDR 1.2.3.4/32,10.0.0.0/8 adds 10.0.0.0/8, which nobody approved.

Behavior change

  • ValidateEnv refuses these names with 400, in any case: the proxy variables, PATH, LD_*, BASH_ENV, ENV, SHELLOPTS, BASHOPTS, PS4, IFS, PROMPT_COMMAND, GCONV_PATH, GLIBC_TUNABLES, PYTHONPATH, PYTHONSTARTUP, PYTHONHOME, NODE_OPTIONS, PERL5OPT, PERL5LIB, RUBYOPT, JAVA_TOOL_OPTIONS, GIT_SSH_COMMAND and GIT_CONFIG_PARAMETERS. FilterPanelEnv drops them, so the panel never sends a request the runner refuses. The panel only forwards proxy and CA variables today (agent/worker.go), so nothing it sends is affected.
  • ValidateExecRequest checks every scope entry and passes it on in canonical form (netip String()), which never holds a comma or space.
    • It drops an entry that is not a valid domain, prefix or address.
    • It drops an IPv6 address with a zone: the zone may hold any text, commas included.
    • It reads IPv4-mapped entries as the IPv4 range they map.
    • Invalid entries are dropped whole, never split. The panel builds scope from free-text fields (server/sandbox.go), so one odd entry such as example.com:8443 must not fail every command. A narrower scope fails closed at the deny-by-default proxy.
    • The runner logs dropped entries with the task ID and their values (up to 20).
  • Each scope list is capped at 8,192 entries and 120 KiB, since the proxy gets each list as one environment string, limited to 128 KiB. Over the cap is a 400.

Tested

  • TestValidateEnvRefusesReservedNames: the names above, in mixed case, are refused by ValidateEnv and dropped by FilterPanelEnv. Ordinary names (PYTHONUNBUFFERED, LANGUAGE, ENVIRONMENT) pass.
  • TestValidateExecRequestFiltersScopeEntries:
    • Kept, in canonical form: valid domains (wildcard, IDN, trailing dot), CIDRs (v4, v6, host bits set), bare addresses, and IPv4-mapped prefixes and addresses (as IPv4).
    • Dropped: example.com:8443, https://x, api-*.example.com, comma and space entries, fe80::1%eth0,10.0.0.0/8, ::1%a,0.0.0.0/0 and fe80::1%eth0.
    • Refused with 400: over either cap.
  • go test -race ./sandbox/ ./cmd/... and the Docker live tests (ARTEX_SANDBOX_DOCKER_TEST=1) pass.

#780 relies on this for the env names; please merge this first.

…the loader

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.
… zones

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.
thecorporatetractor added a commit to thecorporatetractor/ARTEX that referenced this pull request Dec 3, 2026
The unit tests that did not fit in the backend PR: create and exec with
pod hardening, scope change, a foreign Service, recover (strict pod
names), delete of an untracked task, task ID and env revalidation, IPv6
proxy env, timeout kill and no kill for a command that exits 124 itself,
stale kill, failed setup, an exec queued behind a real Delete, stream
errors, scope limits for cluster ranges, isolation probe outcomes, and a
delayed exec that must not land in a replacement worker. They run
against the fake API server. The reserved env case needs the shared
ValidateEnv change (BaaRai#895).

TestKubeSandboxE2E (ARTEX_SANDBOX_KUBE_E2E=1) drives a deployed runner:
identity and hardening, workdir and env, exit codes, timeout and
truncation, cluster objects, network isolation (only timed out or
refused connects count as blocked), in-scope egress through the proxy
and its audit file, kill, runner restart and delete. Task pods are found
by label, since their names carry a generation suffix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant