Skip to content

feat(api): operator-configured private-host exception for the Jev client - #808

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
kayahk:feat/jev-private-hosts
Nov 21, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
kayahk:feat/jev-private-hosts

Conversation

@kayahk

@kayahk kayahk commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Problem

The Jev client (autofill, auto-assign, automation jev_condition nodes, auto-agent resolution, and POST /projects/:id/jev-config/test) dials through netguard.NewSafeHTTPClient, an SSRF guard that refuses any hostname resolving to a private/internal address (RFC 1918, loopback, link-local, CGNAT, IPv6 ULA/transition literals).

For deployments that host their own Jev-compatible gateway on an internal address (e.g. an in-cluster gateway behind a ClusterIP), every Jev request is refused client-side before it reaches the network — regardless of the project's stored base URL.

Solution

Mirrors the existing operator opt-in for the plugin fetch client (PLUGIN_FETCH_PRIVATE_HOSTS → netguard.NewPrivateHosts → NewSafeHTTPClientWithPrivateHosts):

  • Config: new JEV_PRIVATE_HOSTS env var (config.JevConfig.PrivateHosts, comma-separated exact hostnames, empty by default). Also plumbed through docker-compose.prod.yml, the Helm chart (api.jev.privateHosts) and both .env.example files.
  • Client: jev.New / jev.ClientForProject take the operator's set and build the client with netguard.NewSafeHTTPClientWithPrivateHosts; the client puts the allowance on each request's context (netguard.WithAllowedPrivateHosts), mirroring how the plugin runtime does it for paca.fetch. Because every Jev consumer builds its client through this single construction path, all of them are covered — no per-consumer overrides.
  • Automation consumer: its jev_condition path swaps in the consumer's shared outbound client, so that client is built with the same set in bootstrap. call_api keeps its full guard: the dialer only opens when the request context names the host, which call_api never does.

Behavior

  • No hosts configured → byte-for-byte today's behavior (NewSafeHTTPClientWithPrivateHosts with a nil set is NewSafeHTTPClient).
  • Hosts configured → only the listed exact hostnames may resolve to private addresses; loopback, link-local (cloud metadata), CGNAT and everything else netguard blocks stays blocked, and the dial stays pinned to the IP it just validated.
  • Public hosts are unaffected either way.

Tests

  • TestLoad_JevPrivateHosts — env parsing (default empty; comma/whitespace list).
  • TestNew_PrivateHosts — the configured set is kept on the client, nil leaves it off (dial-side set semantics are covered by netguard's own tests).
  • TestSystemOne_PrivateHostExceptionRidesOnRequestContext — the allowance reaches the transport only via the request context, and only when hosts are configured (netguard's second key).
  • TestSystemOne_RejectsPrivateAddress (existing) still passes, proving the default client keeps refusing a loopback destination.

The Jev client dials through netguard's SSRF-safe HTTP client, which
refuses any hostname resolving to a private/internal address — so an
instance that hosts its own Jev-compatible gateway on an internal
address (e.g. an in-cluster gateway behind a ClusterIP) can never call
it: every request is refused client-side.

This mirrors the existing PLUGIN_FETCH_PRIVATE_HOSTS opt-in for the
plugin fetch client: a new JEV_PRIVATE_HOSTS env var (config.Jev.
PrivateHosts, Helm api.jev.privateHosts) lists exact hostnames the Jev
client may reach on a private address. The set flows through jev.New /
ClientForProject into netguard.NewSafeHTTPClientWithPrivateHosts and
into the request context (netguard.WithAllowedPrivateHosts), so every
Jev consumer — TestJevConfig, autofill, auto-assign, automation
jev_condition, auto-agent resolution — is covered at the single point
where its client is built. netguard's two-key contract is preserved:
the shared automation consumer client carries the set, but call_api
keeps its full guard because its requests never name the host in their
context.

With no hosts configured the guard stays strict: loopback, link-local
and cloud metadata addresses stay blocked even for listed hosts.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

call_api does not actually keep its full guard: it shares one pooled transport with the Jev client, so a connection opened by a Jev request lets an unkeyed call_api request to the same operator-listed host skip the dial check.

Approach: sound — mirrors the existing PLUGIN_FETCH_PRIVATE_HOSTS opt-in, and routing every consumer through ClientForProject keeps the set in one place.

Reviewed changes

  • Config plumbing — JEV_PRIVATE_HOSTS is parsed into config.JevConfig.PrivateHosts and carried through compose, the Helm chart (api.jev.privateHosts), both .env.example files and the deploy README.
  • Client construction — jev.New / ClientForProject accept the operator set, build netguard.NewSafeHTTPClientWithPrivateHosts, and attach the set to each request's context so the dialer opens only for the listed hosts.
  • Consumers — autofill, auto-assign, automation jev_condition, auto-agent resolution and TestJevConfig all pass the set, and bootstrap rebuilds the automation consumer's shared outbound client with it.
  • Tests — env parsing, client-set retention and context wrapping are covered, and the existing loopback-refusal test still proves the default guard.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread services/api/internal/bootstrap/app.go Resolved
…d the dial check

resolveJevAnswer swapped in the automation consumer's shared outbound
client, which since the JEV_PRIVATE_HOSTS wiring carried a transport
whose dialer opens for operator-listed private hosts. The netguard
check lives in dialContext, but transports pool idle connections: once
a keyed Jev request opened a connection to a listed host:port, a later
unkeyed call_api request to the same host:port reused it without ever
dialing — reaching the private address with no context key, the
project-admin-authored path the guard exists to fence off.

Split the wiring: the consumer's shared client returns to its
constructor default (netguard.NewSafeHTTPClient, strict), and Jev
rides a dedicated, test-only jevHTTPClient — the per-project client's
own transport (built with the operator set) serves production.
E2E harnesses point Jev at the local test server through the dedicated
setter; call_api keeps WithHTTPClient for its own loopback needs.

Reported by pullfrog review on Paca-AI#808.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound — the fix confines the private-host exception to the transport each Jev client owns, so call_api keeps its strict dialer without giving up the operator opt-in for Jev.

Reviewed changes

  • Automation consumer transport split — AutomationConsumer gained a dedicated, test-only jevHTTPClient; resolveJevAnswer uses it only when set and otherwise resolves through the per-project client built from JEV_PRIVATE_HOSTS.
  • bootstrap wiring reverted — the automation consumer's shared httpClient is back to its netguard.NewSafeHTTPClient default, so pool reuse can no longer carry an unkeyed call_api request to an operator-listed private host.
  • Harness updates — the worker Jev tests and both e2e automation harnesses now wire WithJevHTTPClient instead of WithHTTPClient, keeping the local httptest.Server reachable without sharing call_api's transport.

The prior review's pooled-connection concern is fully addressed by ddec3af: call_api and Jev no longer share a transport in production, and the dedicated override is unavailable outside test wiring. go build ./..., go vet, and the worker/jev/netguard/config test suites pass at this head.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit fb57815 into Paca-AI:master Nov 21, 2026
11 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.

2 participants