ARTEX/egress-guard
Dukotah ebb37c20bb feat(egress-guard): derive the scope lists from the operator-approved 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 (#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>
2026-12-02 10:27:57 -08:00
..
lists feat: optional DNS-driven egress allowlist (separate compose file) 2026-11-20 10:47:36 -05:00
logs feat: optional DNS-driven egress allowlist (separate compose file) 2026-11-20 10:47:36 -05:00
Dockerfile feat: optional DNS-driven egress allowlist (separate compose file) 2026-11-20 10:47:36 -05:00
entrypoint.sh sec(p0): fail-closed startup, atomic secret rotation, scoped target-gate backfill, and kernel kill-switch 2026-11-30 17:41:46 +01:00
export-scope.sh feat(egress-guard): derive the scope lists from the operator-approved task scope 2026-12-02 10:27:57 -08:00
README.md feat(egress-guard): derive the scope lists from the operator-approved task scope 2026-12-02 10:27:57 -08:00
report.sh Merge main into contrib/egress-allowlist (resolve CHANGELOG.md) 2026-11-26 23:07:44 +01:00
selftest.sh Merge main into contrib/egress-allowlist (resolve CHANGELOG.md) 2026-11-26 23:07:44 +01:00
test_entrypoint_shim.sh sec(p0): fail-closed startup, atomic secret rotation, scoped target-gate backfill, and kernel kill-switch 2026-11-30 17:41:46 +01:00

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

  1. 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.
  2. Names matching a suffix in lists/base-domains.txt or lists/scope-domains.txt have their resolved IPs added to the artex_allow ipset (they expire 6 h after the last query).
  3. In the DOCKER-USER chain, new outbound connections from the ARTEX network are allowed only if the destination is in artex_allow or in lists/scope-cidrs.txt. Everything else is logged (ARTEX-EGRESS-* in the kernel log) and, in enforce, 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.txt and lists/scope-cidrs.txt (or generate them, see "Deriving the scope lists from ARTEX"), then docker 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=enforce in .env and 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-proxy policy is built from (see docs/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.txt is 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-empty is given: with EGRESS_MODE unset, empty scope lists make the guard fall back to monitor. Set EGRESS_MODE=enforce explicitly 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 (with ARTEX_PG_DSN set). 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 set enable_ipv6 on it) — then the container has no IPv6 address and the gap is latent. If you do enable IPv6, set ARTEX_SUBNET6 so enforce installs an ip6tables deny 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 INPUT chain, not DOCKER-USER (FORWARD), so a proxy bound on the gateway IP is reachable. Don't run a forward proxy on the gateway, or set EGRESS_FILTER_GATEWAY=1 to have enforce add an INPUT rule that drops everything from the subnet to the gateway except DNS (off by default — it edits the host INPUT chain).
  • 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.