Skip to content

Let self-host operators allow named private origins for app egress - #2597

Open
rasmushjulskov wants to merge 1 commit into
UsefulSoftwareCo:v2from
rasmushjulskov:app-egress-private-origins
Open

rasmushjulskov wants to merge 1 commit into
UsefulSoftwareCo:v2from
rasmushjulskov:app-egress-private-origins

Conversation

@rasmushjulskov

@rasmushjulskov rasmushjulskov commented Nov 25, 2026 •

Copy link
Copy Markdown

Problem

A self-hosted Executor runs apps in workerd, and their outbound requests go through a network that allows only public addresses. That is the right default, but it means an app cannot reach a service on the operator's own tailnet or LAN, such as an MCP server served through Tailscale at https://my-mac.example-tailnet.ts.net. Tailnet names resolve to 100.64.0.0/10, which counts as private.

The only escape today is EXECUTOR_APPS_ALLOW_PRIVATE_FETCH=true. It gives every app the whole private network: loopback, LAN, tailnet and Executor's own ports.

A *.ts.net name also fails in a confusing way. It passes the outbound's name check (isPrivateHostname), then PUBLIC_FETCH refuses it after DNS, so the app sees a generic connection failure instead of NetworkRefused.

Change

  • Setting. EXECUTOR_APPS_ALLOW_PRIVATE_ORIGINS is a JSON array of exact HTTP(S) origins, such as '["https://my-mac.example-tailnet.ts.net"]'. It is parsed with the existing HttpOrigin schema from url-policy.ts, so each entry must equal its URL's origin: lowercase, no path, no trailing slash, no default port. The default is [], so behaviour is unchanged unless an operator sets it.
  • Egress check (credential-handles.ts). AppEgress has optional privateOrigins. egressRefusal lets a request through when its whole url.origin is listed. Matching is by exact origin, never by hostname or prefix. A listed hostname under another scheme or port is refused with NetworkRefused (private_address), even when the name looks public (a *.ts.net name), so an operator who lists one port of a tailnet host gets a clear refusal for the others. Other private hostnames are refused as before. A public-looking name that is not listed still goes to PUBLIC_FETCH and fails there after DNS as a generic network error, the same as today.
  • Routing (workerd-entry.ts, AppOutbound). A request to a listed origin goes out through the Worker's own fetch, which can reach private addresses, instead of PUBLIC_FETCH. It is sent with redirect: "manual", so every redirect returns to the app, and the app's fetch sends the next hop back through the same check. A redirect from a listed origin to an unlisted private address is never sent: it is refused as private_address when the hostname shows it, or by PUBLIC_FETCH when only DNS does. Workers already deliver incoming requests to the outbound with redirect: "manual", so this is a guard rather than a change in behaviour: the e2e scenario still passed with it removed. I kept it because this path is the one fetch that can reach every private address.
  • Self-host wiring. apps/hosted/self-host/src/contracts/config.ts reads the setting, and workerdApps passes it to the apps Worker as the APPS_PRIVATE_ORIGINS JSON binding. For the Docker image, native/main.go validates the value (privateAppOrigins) and substitutes it into the generated workerd.capnp (package-runtime.ts). Go's url.Parse does not canonicalise hosts the way a browser does, so the launcher checks each entry is already in the form a browser prints as an origin: lowercase host, canonical IPv4 and IPv6 literals (no 127.1, fd00:0::1, zones or IPv4-mapped addresses), and a port of 1–65535 without leading zeros that is not the scheme's default. Every accepted entry can therefore match a request; an entry that never could is rejected at startup. Go is stricter than HttpOrigin in one place: it rejects port 0. Export mode always uses [].
  • Unchanged. Cloud keeps its public-only network. Local already allows private fetch. App builds (tarball downloads) and EXECUTOR_URL_ALLOW_HTTP_ORIGINS, which covers only host-side MCP import and OAuth, are untouched. Credential placement still requires HTTPS, or loopback HTTP when private fetch is on, so a listed http:// origin can receive requests but not placed credentials.
  • Release note. The commit's Release-note: Feature: line is pinned to Self-host only (note-audiences.ts).
  • Docs. The docs say that a listed http:// origin cannot receive placed credentials, that listing a name trusts its DNS answer, and that importing an MCP server at a private address by URL also needs EXECUTOR_URL_ALLOW_HTTP_ORIGINS. Updated the self-host settings table and egress section in apps/docs/content/run/self-host.mdx, the self-host README.md, compose.yaml, and the app-authoring deploy.md skill (digest regenerated with bun run executor:intro). There is also a changeset.

Why a new setting instead of EXECUTOR_URL_ALLOW_HTTP_ORIGINS

That setting already means "origins Executor's own host-side requests may reach on a private address" (OAuth and MCP discovery through safeHttpClient / bindingHttpClient). Reusing it for app code would quietly widen what every app can reach for operators who set it for OAuth. A sibling setting keeps the two decisions separate, and reuses the same HttpOrigin schema and exact-origin rules.

Follow-ups (not in this PR)

  • Per-app scoping. The outbound knows the app's ID, not its slug, and slugs are per organization, so an origin → slugs map does not fit naturally into this layer. If wanted, a follow-up could accept { "<origin>": ["<app id>"] } or resolve slugs on the host side.
  • The private_address message still says apps "can reach only public addresses". Changing it touches the public apps contract (packages/apps/src/contracts/network.ts) and its version, so I left it alone.

Verification

  • bun run e2e:self-host --test-name 'with private fetch off, an app reaches only the private origins its operator allows, and a redirect cannot leave them': passes (1 passed, 10.2 s). This is a new scenario with a server it owns. It starts with EXECUTOR_APPS_ALLOW_PRIVATE_FETCH=false and lists two origins: one loopback upstream's origin, and a decoy that is a prefix of a second upstream's origin. It checks:

    • The allowed origin answers, and a redirect within it is followed.
    • The same port under localhost is refused as private_address.
    • The same host and port over https is refused as private_address.
    • The second upstream is refused as private_address, although a prefix of its origin is listed.
    • A redirect from the allowed origin to the second upstream is refused as private_address.
    • The second upstream receives no requests.
  • docker-release.spec.ts, explicit mode: added, not run (no Docker daemon here). After the restart onto the new image, the launcher gets EXECUTOR_APPS_ALLOW_PRIVATE_ORIGINS='["http://allowed.example.test:8091"]'. A probe app must:

    • reach allowed.example.test:8091 (the fixture answers GET with 404);
    • get a private_address refusal for allowed.example.test:8092;
    • get a network refusal for blocked.example.test:8092 and for a redirect to it.

    The fixture must record exactly the expected requests, and the blocked port must take no connections. The first boot can use the previously released image, which doesn't know the setting, so the probe runs only after the restart. This file is not in e2e/test-plan.ts, so it is not in the e2e block; the Docker release suite runs it.

  • Go (apps/hosted/self-host/native, with Go 1.27.4): gofmt -l . is clean, go vet . passes, and go test -run TestPrivateAppOrigins . passes. The table test covers 35 rejected values and checks that the accepted ones are kept unchanged. A Bun script confirmed that every accepted value equals its URL.parse(...).origin. It also confirmed that every rejected value fails HttpOrigin, except port 0, where Go is deliberately stricter. The full go test ./... did not finish on macOS and I stopped it; CI runs it on Linux.

  • bun run check: 18 of 18 checks pass (lint, typecheck, format, skill texts, host protocols and others). bun run format leaves no changes.

  • bun run pr:check --description: static, apps-version and release-notes pass; 1 of 4 fails. v2 shares no history with main, so I ran it with v2's tip served as main. The note's audience is pinned to Self-host in scripts/releases/note-audiences.ts (hash 1a11ba91f327dd31), because only self-host operators can set this. description fails because it reads .github/workflows, which v2 does not have, the same as in Keep offline MCP grants working after their approving session expires #2587. The e2e block below is for the change once it reaches main.

  • Not run locally:

    • The existing an app's fetch to a private address fails as Executor's refusal and never reaches the address. This file's HostedLive scenarios fail locally before any app code runs (UND_ERR_INVALID_ARG: Argument dispatcher must implement dispatch from the test client on Node 26). An untouched scenario (app-fetch-brotli.spec.ts) fails the same way, so this is my local environment.
    • docker-release.spec.ts (see above).
    • The Rust collector build in e2e:prepare, because the pinned toolchain is not installed. The other prepare steps were run individually.
app-fetch-errors.spec.ts

🤖 Generated with Claude Code

App code on self-host reaches only public addresses unless the operator
sets EXECUTOR_APPS_ALLOW_PRIVATE_FETCH, which opens the whole private
network to every app: loopback, LAN, tailnet and Executor's own ports.
A service on the operator's tailnet, such as an MCP server at
https://my-mac.example-tailnet.ts.net, needed that switch, because
tailnet names resolve to 100.64.0.0/10.

EXECUTOR_APPS_ALLOW_PRIVATE_ORIGINS takes a JSON array of exact HTTP(S)
origins. The app outbound lets a request through when its whole origin
is listed and sends it on the network that can reach private addresses,
with redirect: "manual", so each redirect returns to the app and its
next hop is checked again. A private hostname, or a listed hostname
under another scheme or port, is refused with NetworkRefused
(private_address). A public-looking name that resolves to a private
address still goes to the public-only network and fails there as a
network error, as before. The Docker launcher accepts only origins in
the form a browser prints them, so every entry can match, and passes
the list to the apps Worker as a JSON binding.

Release-note: Feature: Self-host operators can let apps reach specific private services, such as an MCP server on a tailnet, by listing their exact origins, instead of opening the whole private network to every app.
@rasmushjulskov
rasmushjulskov force-pushed the app-egress-private-origins branch from d9a0bff to f82f7bf Compare November 25, 2026 19:03
@rasmushjulskov
rasmushjulskov marked this pull request as ready for review November 25, 2026 20:31

This branch has not been deployed

No deployments
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