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 (#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> |
||
|---|---|---|
| .. | ||
| lists | ||
| logs | ||
| Dockerfile | ||
| entrypoint.sh | ||
| export-scope.sh | ||
| README.md | ||
| report.sh | ||
| selftest.sh | ||
| test_entrypoint_shim.sh | ||
egress-guard
DNS-driven egress allowlist for the ARTEX container. It blocks data from leaving to arbitrary hosts (e.g. a malicious PoC sending the keys to an attacker) without breaking asset discovery: any subdomain of an in-scope domain is allowed automatically the moment it resolves.
Opt-in and Linux-only. It is a separate compose file and needs NET_ADMIN; it
edits the host firewall, so read this before enabling it.
How it works
- ARTEX uses
172.31.250.1(this service's dnsmasq) as its DNS. DNS queries to any other server (dnsx, bbot,dig @8.8.8.8) are redirected here. - Names matching a suffix in
lists/base-domains.txtorlists/scope-domains.txthave their resolved IPs added to theartex_allowipset (they expire 6 h after the last query). - In the
DOCKER-USERchain, new outbound connections from the ARTEX network are allowed only if the destination is inartex_allowor inlists/scope-cidrs.txt. Everything else is logged (ARTEX-EGRESS-*in the kernel log) and, inenforce, rejected.
Modes (EGRESS_MODE in .env)
| Mode | Effect |
|---|---|
enforce (default when scope lists exist) |
the allowlist actively blocks outbound traffic outside scope-domains.txt / scope-cidrs.txt / base-domains.txt |
monitor (fallback only when scope lists are empty) |
observe only — logs a loud warning and blocks nothing |
off |
no firewall rules; DNS redirect only (logs a loud warning) |
EGRESS_MODE=enforce is the default whenever lists/scope-domains.txt or
lists/scope-cidrs.txt has at least one entry. Leave EGRESS_MODE unset (or
set EGRESS_MODE=enforce explicitly) once your scope lists are populated; only
set EGRESS_MODE=monitor temporarily when calibrating. In enforce,
setup is fail-closed: a blanket deny is installed before the allowlist is
built, so if setup fails the ARTEX container loses outbound connectivity (except
DNS) until the guard restarts cleanly.
Operation
- New engagement: edit
lists/scope-domains.txtandlists/scope-cidrs.txt(or generate them, see "Deriving the scope lists from ARTEX"), thendocker compose -f docker-compose.yml -f docker-compose.egress.yml restart egress-guard. - Calibrate:
sudo egress-guard/report.sh(or pass"48 hours ago"). Lists flagged connections and resolved names outside the allowlist. - Turn blocking on: set
EGRESS_MODE=enforcein.envand bring the service up again. - Stopping the service removes the rules. If dnsmasq dies on its own, the rules stay (fail-closed).
Deriving the scope lists from ARTEX
export-scope.sh writes lists/scope-domains.txt and lists/scope-cidrs.txt from
the ARTEX database instead of by hand, so the overlay cannot drift from the scope
the operator approved:
egress-guard/export-scope.sh # every task that is not finished
egress-guard/export-scope.sh --tasks 12,15
docker compose -f docker-compose.yml -f docker-compose.egress.yml restart egress-guard
- Same source as the sandbox egress proxy. The export runs the derivation the
per-task
artex-egress-proxypolicy is built from (seedocs/SANDBOX.md): operator-approved task scope (approved_by_operator = true), the company grants frozen at approval, and enabled operator task allow rules. Agent-added, auto-added and expanded rows are coverage-only and are never exported. - One allowlist for all tasks. The overlay filters the whole ARTEX network, so
the lists are the union over the exported tasks; it cannot tell tasks apart the
way the per-task proxy does.
base-domains.txtis not touched. - Fails closed. The lists are replaced only when the whole export succeeded
(database read, every entry parsed, output complete); an export that fails or
is malformed changes neither file. Each file is then replaced by rename, one
after the other. An export with no entry is refused unless
--allow-emptyis given: withEGRESS_MODEunset, empty scope lists make the guard fall back tomonitor. SetEGRESS_MODE=enforceexplicitly when the lists are generated. - Not live. The guard reads the lists at startup. Re-run the export and restart the guard after approving or revoking scope, and when a task starts or finishes; the restart also flushes the IPs allowed for a revoked domain.
- IPv4 only. IPv6 scope entries are reported and skipped (see Known gaps). A domain is allowed for whatever it resolves to, including a private address the proxy would refuse.
- The script runs
docker compose exec -T artex /app/artex -export-egress-guard-scope. Pass another command after--for a different compose invocation or a binary outside the container (withARTEX_PG_DSNset). The command opens the database the way the server does, which applies the schema and migrations, so that binary must be the same version as the running server.
Known gaps
- IPv6 is not filtered. The allowlist is IPv4-only (ipset
hash:ip/hash:net). Keep the ARTEX network IPv4-only (do not setenable_ipv6on it) — then the container has no IPv6 address and the gap is latent. If you do enable IPv6, setARTEX_SUBNET6soenforceinstalls anip6tablesdeny for it; the guard logs a warning when IPv6 is left unfiltered. - Traffic to the host/gateway bypasses the filter. Container→gateway traffic
goes through the host
INPUTchain, notDOCKER-USER(FORWARD), so a proxy bound on the gateway IP is reachable. Don't run a forward proxy on the gateway, or setEGRESS_FILTER_GATEWAY=1to haveenforceadd anINPUTrule that drops everything from the subnet to the gateway except DNS (off by default — it edits the hostINPUTchain). - Exfiltration through an allowed destination (a GitHub gist, OAST servers, an in-scope host the attacker controls).
- Data hidden in DNS queries (slow; visible in
logs/dnsmasq.log). - CDN-shared IPs: allowing one name allows the IP for other sites on the same IP.