Repository navigation
fix(sandbox): refuse exec env names that override the proxy, PATH or the loader - #895
Open
thecorporatetractor wants to merge 2 commits into
Open
thecorporatetractor wants to merge 2 commits into
thecorporatetractor wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Found while fixing the review of #780.
ValidateEnvrefuses secret-looking names only. In the Docker backend the execEnvis merged over the worker container's env, so a request can setHTTP_PROXY,HTTPS_PROXY,ALL_PROXYorNO_PROXYand take the command off the egress proxy (the worker network is internal, so this breaks egress rather than opening it). A request can also setPATH,LD_*, or a variable that makes a shell or interpreter run extra code (BASH_ENV,SHELLOPTS+PS4,NODE_OPTIONS,PERL5OPT, ...). The panel always sendsbash -c <command>, so this is defence in depth: the runner API should not accept env names that the worker owns.docker.go), and the Kubernetes backend in feat(sandbox): Kubernetes backend for artex-runner #780 does the same. So a scope CIDR1.2.3.4/32,10.0.0.0/8adds10.0.0.0/8, which nobody approved.Behavior change
ValidateEnvrefuses 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_COMMANDandGIT_CONFIG_PARAMETERS.FilterPanelEnvdrops 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.ValidateExecRequestchecks every scope entry and passes it on in canonical form (netipString()), which never holds a comma or space.server/sandbox.go), so one odd entry such asexample.com:8443must not fail every command. A narrower scope fails closed at the deny-by-default proxy.Tested
TestValidateEnvRefusesReservedNames: the names above, in mixed case, are refused byValidateEnvand dropped byFilterPanelEnv. Ordinary names (PYTHONUNBUFFERED,LANGUAGE,ENVIRONMENT) pass.TestValidateExecRequestFiltersScopeEntries: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/0andfe80::1%eth0.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.