Skip to content

fix: non-blocking telemetry, post-DNS egress guardrails, writable bwrap workspace - #2

Merged
blitzcrieg1 merged 3 commits into
mainfrom
fix/phase1-egress-hardening
Nov 28, 2026
Merged

blitzcrieg1 merged 3 commits into
mainfrom
fix/phase1-egress-hardening

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

What

Phase 1 of the egress audit:

  1. Non-blocking telemetry (emit.rs). The ingest POST moved from the connection thread to a background worker with a bounded queue (128 lines). emit() writes the JSONL file synchronously (the authority) and enqueues; a stalled recorder can no longer add up to ~2s per request between the CONNECT reply and the tunnel. Undelivered posts retry twice (250ms pause), then stay file-only. Ingest URLs now resolve hostnames, so http://localhost:8000 works instead of silently falling back to file-only.
  2. Post-DNS egress guardrails (proxy.rs, new ssrf.rs). The deny/allow lists match the destination name; after DNS the dial address is now also checked. ssrf_guard in guard.json or AGENTMETRY_GUARD_SSRF selects the mode: metadata (default) refuses link-local destinations such as 169.254.169.254, strict also refuses loopback/RFC1918/ULA/unspecified, off keeps the lists as the whole policy. Denials are outcome=denied with policy="ssrf-guard" and cannot be voted away by allowlisting a name. Alternate IP encodings (glibc resolves the integer form of 169.254.169.254) and DNS rebinding land on the same decision.
  3. Writable Bubblewrap workspace (sandbox.rs). --ro-bind / / made every wrapped server or build fail with EROFS on its first write. By default (writable_defaults: true) the wrapper now binds the current directory writable and mounts a fresh /tmp, plus configurable writable_paths with tilde expansion. Sensitive overlays are applied after the writable binds, so hiding always wins; paths inside credential directories are skipped with a warning instead of silently shadowed.
  4. Strict config for the new keys (fileconf.rs). ssrf_guard, writable_paths, writable_defaults parse under the same fail-closed rules: unknown keys, bad booleans and bad enum values prevent startup.

Why

These were the three high-priority guard findings: telemetry on the hot path blocks tunnels and drops hostname ingest URLs; string-only policy lets encoded/rebound addresses reach metadata endpoints; and the Linux wrapper was unusable for anything that writes a file.

Evidence

  • cargo test --locked: 44 passed, 0 failed (21 new tests: async emit regression, hostname delivery, bounded retry, queue overflow, metadata/strict/off guardrail behavior, argv ordering and conflict refusals)
  • cargo clippy --all-targets --locked -- -D warnings: clean
  • cargo build --locked --release: OK
  • bash scripts/smoke.sh ./target/release/agentmetry-guard: OK (loopback, strict policy, destination-only evidence)
  • The integer-IP-encoding test is Linux-only (glibc resolver semantics); it does not run on the Windows/macOS matrices.

Notes for review

  • The agentmetry side whitelists guard policy values to allowlist/denylist in _guard_destination; a companion PR there accepts ssrf-guard so the denial reason survives into the canonical trail. The existing guard-egress-denied detection fires on outcome alone, so detection is unaffected either way.
  • Default metadata mode keeps loopback and RFC1918 reachable: local LLMs and internal APIs are legitimate wrapped destinations, and NO_PROXY already routes localhost around the proxy, so blocking loopback at the proxy would be theater. strict is available for operators who want it.
  • The --version flag in the first commit was authored in an earlier session and left uncommitted in the local clone; it is preserved as its own commit.

blitzcrieg1 and others added 2 commits November 27, 2026 23:15
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
…ap workspace

Phase 1 hardening from the egress audit:

- emit: POST moved to a background worker with a bounded queue (128) so a
  slow or absent ingest never delays a tunnel; emit() now writes the JSONL
  file (the authority) and enqueues. Undelivered posts retry twice with a
  250ms pause, then stay file-only. Ingest hostnames resolve, so
  http://localhost:8000 no longer silently falls back to file-only.
- proxy: after DNS resolution the dial address is checked against an
  egress guardrail (ssrf_guard in guard.json or AGENTMETRY_GUARD_SSRF):
  metadata (default) refuses link-local destinations such as
  169.254.169.254, strict also refuses loopback/private/ULA, off keeps the
  name lists as the whole policy. Denials are outcome=denied with
  policy=ssrf-guard and cannot be voted away by allowlisting. This closes
  the pre-DNS gap where alternate IP encodings and DNS rebinding slipped
  past string matching.
- sandbox: the Bubblewrap wrapper binds cwd and /tmp writable by default
  (writable_defaults) plus configurable writable_paths with tilde
  expansion, fixing EROFS on every wrapped server or build that writes
  files or caches. Sensitive overlays are applied after the writable
  binds, so hiding always wins; paths inside credential directories or
  missing paths are skipped with a warning.
- fileconf: strict parsing for the new keys (ssrf_guard, writable_paths,
  writable_defaults); unknown keys, bad booleans and bad enum values still
  fail closed.

Gates: cargo test --locked 44 passed, clippy --all-targets -D warnings
clean, release build OK, scripts/smoke.sh OK.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
blitzcrieg1 added a commit to blitzcrieg1/agentmetry that referenced this pull request Nov 28, 2026
* fix(external): accept the guard's ssrf-guard policy verdict

agentmetry-guard's post-DNS egress guardrail denies with policy=ssrf-guard.
The canonical ingest whitelist only knew allowlist and denylist, so the
refusal reached the trail with no reason attached. Accept the one new value;
anything else is still dropped so a client cannot stamp arbitrary text into
the canonical arguments. The guard-egress-denied detection fires on outcome
alone and is unaffected.

Companion to blitzcrieg1/agentmetry-guard#2.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>

* docs(readme): 3113 tests collected with the guard policy-value tests

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>

---------

Co-authored-by: Mistral Vibe <[email protected]>
@blitzcrieg1
blitzcrieg1 merged commit a76e769 into main Nov 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant