Repository navigation
feat(deploy): scope-restricted panel egress for sandbox off mode - #792
Open
thecorporatetractor wants to merge 5 commits into
Open
thecorporatetractor wants to merge 5 commits into
thecorporatetractor wants to merge 5 commits into
Conversation
ARTEX_RUNNER_BACKEND=kubernetes runs each task in a worker pod behind its own egress-proxy pod, created through the Kubernetes API with no container runtime socket. Per-task NetworkPolicies are applied before the pods and removed after them; the runner waits until 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; a live test (TestKubeSandboxE2E) drives a deployed runner.
deploy/helm/artex deploys the panel, PostgreSQL and artex-runner with a namespace-scoped Role, default-deny NetworkPolicies and a values schema. A volume-permissions init container restores root ownership of /app/data and /app/keys, fixing the isolation self-test failure on world-writable volumes (BaaRai#620). scripts/k3d-e2e.sh and the kubernetes CI job test it live on k3d.
ARTEX_RUNNER_BACKEND=panel-egress turns artex-runner into a policy-only controller for ARTEX_SANDBOX=off on Kubernetes. It accepts the panel's scope union over the token-authenticated PUT /v1/panel-egress (GET reports the state) and keeps one NetworkPolicy selecting the panel pod: approved CIDRs as they are, and the addresses the scope hosts resolve to as /32 ipBlocks. Resolved addresses in DefaultProxyDeniedCIDRs (or the configured list) and IPv6 answers are dropped unless an approved CIDR covers them, mirroring the per-task proxy policy. Hosts are re-resolved every refresh; an address stays allowed for the retention window after a host last resolved to it, a failed lookup keeps the last known addresses until they expire, and a host that leaves the scope loses its addresses on that push. Before the first push and while it is down, the last policy stays in place (fail closed). Exec, kill and delete are refused. The API connection setup of the Kubernetes backend is shared through newKubeConn.
With ARTEX_SANDBOX=off and ARTEX_PANEL_EGRESS_URL set (the Helm chart sets it), the panel builds the union of the operator-approved scope of every live task with taskSandboxRunInfo, adds the known asset hostnames under the approved domains and the LLM endpoints from the environment and the saved profiles, and pushes it to the controller before each planner/worker turn when it changed and every 30 s. A failed push is retried by the periodic sync and, after 15 s, by the next turn. The state is logged on change and reported to signed-in sessions in GET /api/health as sandbox_egress. Nothing changes without the variable: Docker deployments and required mode behave as before. ARTEX_RUNNER_TOKEN, which now also authorizes scope pushes, is scrubbed and sealed like the other startup secrets.
With sandbox.mode=off the chart now restricts the panel's egress by default (sandbox.offModeEgress.enabled=true): a static NetworkPolicy allows only cluster DNS, the database (bundled, or postgresCIDRs) and the panel egress controller, which runs from the runner image as non-root with no capabilities and a Role limited to creating NetworkPolicies and reading/updating the one scope policy. extraHosts/extraCIDRs, refresh and retention are configurable. Rendering fails instead of running open when NetworkPolicy is disabled or an external database has no CIDRs; values from an older release count as enabled. enabled=false keeps the previous unrestricted behaviour, documented as unsafe. Chart render tests cover the policies, RBAC, wiring and schema rejections, and lint both modes. TestPanelEgressOffModeE2E checks live, as the agent uid inside the panel, that in-scope hosts (including nmap -sT) are reachable and other namespaces, the API server, nodes, metadata and out-of-scope hosts are not, that revocation and task deletion remove access, and that a stopped controller fails closed; scripts/k3d-e2e.sh runs it with OFF_MODE=1. scripts/k3d-e2e.sh reads the panel log before grepping it for the isolation self-test: with pipefail, grep -q exiting early failed the check on the longer off-mode log.
4 tasks
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
With
sandbox.mode=offthere is no runner and no task pod: agent commands run inside the panel pod. On Kubernetes the panel's egress is then open to the internet, other namespaces, the nodes and the Kubernetes API. The operator-approved scope is not enforced at the network level (see #421 for the general issue).Change
artex-runnergainsARTEX_RUNNER_BACKEND=panel-egress: a policy-only controller. It accepts the panel's scope over the token-authenticatedPUT /v1/panel-egress(GETreports the state) and keeps one NetworkPolicy that selects the panel pod: approved CIDRs as they are, resolved addresses of the scope hosts as/32. Resolved private, metadata and IPv6 addresses are dropped unless an approved CIDR covers them, as in the per-task proxy policy. Hosts are re-resolved everyrefresh; an address stays allowed forretentionafter it was last seen (DNS rotation). Before the first push, and while the controller is down, the last policy stays (fail closed). Exec, kill and delete are refused.ARTEX_SANDBOX=offandARTEX_PANEL_EGRESS_URLset, it builds the union of the approved scope of every live task with the same code as the per-task proxy, adds known hostnames under the approved domains and the LLM endpoints, and pushes it before each planner/worker turn when it changed and every 30 s. It holds no Kubernetes credentials.GET /api/healthreportssandbox_egress.ARTEX_RUNNER_TOKENis scrubbed and sealed like the other startup secrets. Nothing changes without the variable.sandbox.offModeEgress.enabled=trueby default withsandbox.mode=off. A static NetworkPolicy allows the panel only cluster DNS, the database and the controller. The controller runs from the runner image, non-root, no capabilities, read-only root filesystem, with a Role limited to creating NetworkPolicies and reading/updating the one scope policy.extraHosts,extraCIDRs,postgresCIDRs,refresh,retentionare configurable. Rendering fails instead of running open when NetworkPolicy is disabled or an external database has no CIDRs.enabled=falsekeeps the old open egress and is documented as unsafe.scripts/k3d-e2e.shgainsOFF_MODE=1. Limits are in the chart README: union of all live tasks, IP-based, DNS still resolvable, no IPv6, noNET_RAW(in-scopenmap -sTworks).sandbox.mode=requiredare unchanged.Depends on
Depends on #783 (Helm chart), which depends on #780. The diff includes their commits until they merge. Review the last 3 commits.
Tests
go build ./...,go vet ./..., gofmt clean, cross-builds for darwin/arm64, darwin/amd64, windows/amd64: OK.helm lint --strictwith default values and withsandbox.mode=off: 0 failed. Chart render tests for off mode (helmchart_offmode_test.go: policies, RBAC, wiring, schema rejections, lint of both modes): pass.go test -race -count=1 ./sandbox ./cmd/...: OK../serverunder-racewith PostgreSQL hit the default 10 mingo testtimeout on this loaded machine (no failure, the timeout fired in an unrelated tamper-hooks test); the same package passes without-race.go test -p 1 ./...against a throwaway PostgreSQL 16 container: 25 packages OK, 0 failures.go build,go vet, andgo test -p 1 ./sandbox ./server ./db ./cmd/...with PostgreSQL: all pass.shellcheck -S warning scripts/k3d-e2e.sh: clean.OFF_MODE=1 scripts/k3d-e2e.shon a new k3d cluster with images built from this branch:helm testSucceeded, isolation self-test passed, controller rolled out,TestPanelEgressOffModeE2Epassed in 240 s, 5/5 subtests: baseline (other namespaces, API server, nodes, metadata and out-of-scope hosts unreachable as the agent uid), in-scope hosts reachable includingnmap -sT, revocation removes access, a stopped controller fails closed, task deletion removes its scope.Notes
cmd/artex-runner/main.go,server/server.go,deploy/helm/artex/templates/_helpers.tpl,scripts/k3d-e2e.shandCHANGELOG.md. Merged together they give textual conflicts in those files; all are "keep both sides" (bothifblocks inmain.go, both struct fields and calls inserver.go, both helpers in_helpers.tpl, bothset_argsadditions in the script, both CHANGELOG entries;server.goneedsgofmtafter). The test clock inpaneleggress_test.gois namedegressClockso it does not clash with the scaling tests'fakeClock. Checked with a throwaway merge: build, vet, gofmt, chart lint in both modes, andgo test ./sandboxpass.Part of #781.