Repository navigation
feat(egress-guard): derive the scope lists from the operator-approved task scope - #859
Merged
Merged
Conversation
… task scope egress-guard reads hand-edited lists/scope-domains.txt and scope-cidrs.txt, while the sandbox egress proxy builds its policy from PostgreSQL. Nothing connected the two, so the overlay could drift from the approved scope (BaaRai#421). egress-guard/export-scope.sh regenerates both lists through the new artex -export-egress-guard-scope. The export calls taskSandboxRunInfoChecked (the error-returning form of taskSandboxRunInfo) and sandbox.NewEgressPolicy, the derivation and parser of the per-task proxy, so only operator-approved task scope, frozen company grants and operator task allow rules are exported. Agent-added, auto-added and expanded rows are not. Fail closed: taskSandboxRunInfoChecked reports the read errors the proxy path ignores, any error fails the whole export, and the script touches neither list until a complete, well-formed export was read; each list is then replaced by rename. An empty export is refused unless --allow-empty, because empty lists with EGRESS_MODE unset make the guard fall back to monitor. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
Refs #421 (closed with "a focused egress-guard exporter PR is still welcome").
Problem
The per-task sandbox egress proxy builds its policy from PostgreSQL (
taskSandboxRunInfo: operator-approvedtask_scoperows, the company grants frozen intask_scope_egress, enabled task allow rules). The optional egress-guard overlay still readsegress-guard/lists/scope-domains.txtandscope-cidrs.txt, edited by hand per engagement. Nothing connects the two, so forARTEX_SANDBOX=offand for tools that bypass a proxy, the overlay can allow a scope the operator revoked or miss one the operator approved.Change
egress-guard/export-scope.shregenerates the two scope lists from the database. It runsartex -export-egress-guard-scope(new flag, same pattern as-rotate-secrets), checks the output, and replaces the lists by rename.server.ExportEgressGuardScopedoes not derive scope itself. It callstaskSandboxRunInfoChecked(see below) and parses the result withsandbox.NewEgressPolicy, the same two steps the proxy path uses, and takes the union over the exported tasks. Agent-added, auto-added and expanded rows are therefore excluded for the same reason they are excluded from the proxy.db.IsTerminal).--tasks 12,15names tasks explicitly; an unknown id is an error.taskSandboxRunInfois split into a wrapper andtaskSandboxRunInfoChecked, which returns the same scope plus the read errors the function used to drop. The proxy path keeps ignoring them (a narrower scope is a denial there); the export needs them to refuse a partial result. No other behaviour change in that function.Nothing changes for installs that do not run the script.
entrypoint.sh,docker-compose.egress.ymlandbase-domains.txtare untouched, and the guard still reads the lists at startup, so it is restarted to apply an export.Fail closed
domain/cidrentry, and the trailer counts match what was read. On any of those failures both files stay as they were and no staged file is left behind.scope-domains.txtis already new, and the script says so and exits non-zero. A list path that is a directory is refused before the export runs (mvwould otherwise move the new list inside it and report success).--allow-empty. WithEGRESS_MODEunset, empty scope lists makeentrypoint.shfall back tomonitor, so writing them would open the overlay instead of closing it. The consequence: after the last approved scope is revoked, the previous lists stay in force until the operator setsEGRESS_MODE=enforceand passes--allow-empty. The script prints this.ipset=/<suffix>/artex_allowline.Design choices a reviewer may want changed
egress-guard/listswritable into theartexcontainer would let agent commands edit their own allowlist inARTEX_SANDBOX=off, which is the mode the overlay is for. The cost is that the export is an operator step, not automatic on scope change.--tasksalways.monitorfallback inentrypoint.sh, which I left alone to keep this PR to the exporter.db.Open, like-rotate-secrets, so it takes the schema migration lock and runs the idempotent schema and migration step while the server is up. The README says that a binary passed after--must therefore be the same version as the running server.db.TaskEgressGrants. security: satisfy the target gate from operator-approved egress grants #838 addedTaskEgressGrantsfor the target gate, which leaves out task allow rules. The export followstaskSandboxRunInfobecause the overlay is meant to match what the proxy allows, allow rules included.export-scope.shis not added to theshellchecklist inci.yml. Its behaviour is covered by a Go test that runs it with bash, asrotate_secrets_test.godoes forrotate-secrets.sh. I can add it to the list if wanted.Tests
server/egress_guard_export_test.go(PostgreSQL):TestEgressGuardExportMatchesSandboxPolicy: operator rows and an enabled allow rule are exported; agent-added, auto-added, deny and disabled entries are not; the export equals the IPv4 content of the two tasks' proxy policies; a revoked row disappears from the next export.TestEgressGuardExportDefaultsToNonTerminalTasksTestEgressGuardExportFailsClosed: unknown task, nil database, closed database, an entryNewEgressPolicycannot parse, and a pattern carrying dnsmasq syntax.cmd/artex/egress_guard_export_test.go(unix, bash):TestExportScopeScriptReplacesLists,TestExportScopeScriptAllowEmptyTestExportScopeScriptLeavesListsOnFailure: failing command, missing trailer, count mismatch, no output, data after the trailer, malformed domain, non-IPv4 cidr, unknown line, empty export.TestExportScopeScriptRefusesDirectoryTarget: a list path that is a directory is refused, the export command is not run, the other list is unchanged.TestExportEgressGuardScopeToLists: real-export-egress-guard-scopeoutput from PostgreSQL through the script into the lists.What I ran
On this branch rebased onto main at 048e8a8 (after #775, #779, #789, #838), go1.26.11 linux/amd64, PostgreSQL 18 with password auth (CI uses 16):
The two failures are
ghidra TestComposeOverlayConfigHasInternalNetworkAndHardeningandsandbox TestComposeSandboxConfigBoundary, bothdocker compose config failedbecause this machine has no compose plugin. They are in packages this PR does not touch.Manual, on the branch before the last rebase (the exporter code did not change in the rebase): a locally built binary driven through the script against a copy of the lists, with an empty database (refused, lists unchanged), an unknown task id (exit 1), a wrong database password (exit 1), and a seeded task with operator domain/CIDR/IP/IPv6 rows, an agent-added row and allow rules (operator and allow-rule entries written, agent row absent, IPv6 reported as skipped).
What I did not run
docker compose exec -T artex /app/artex -export-egress-guard-scope, in a real container. I had no Docker daemon; the script was driven by a stub and a locally built binary.read_listonly.Related
task_scope_egressas narrowed by security: promote company scope egress only when approved by the operator #779, throughtaskSandboxRunInfo.exact_ipallow rules reach the proxy policy; the export picks that up through the same function.taskSandboxRunInfo. It edits the same function this PR splits inserver/sandbox.go, so whichever lands second may need a small rebase (I did not test-merge the two). Block rules are not exported here: the overlay is allowlist-only.cmd/artex/main.go; no other file is shared.🤖 Generated with Claude Code