Repository navigation
Let self-host operators allow named private origins for app egress - #2597
Open
rasmushjulskov wants to merge 1 commit into
Open
rasmushjulskov wants to merge 1 commit into
rasmushjulskov wants to merge 1 commit into
Conversation
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
force-pushed
the
app-egress-private-origins
branch
from
November 25, 2026 19:03
d9a0bff to
f82f7bf
Compare
rasmushjulskov
marked this pull request as ready for review
November 25, 2026 20:31
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 to100.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.netname also fails in a confusing way. It passes the outbound's name check (isPrivateHostname), thenPUBLIC_FETCHrefuses it after DNS, so the app sees a generic connection failure instead ofNetworkRefused.Change
EXECUTOR_APPS_ALLOW_PRIVATE_ORIGINSis a JSON array of exact HTTP(S) origins, such as'["https://my-mac.example-tailnet.ts.net"]'. It is parsed with the existingHttpOriginschema fromurl-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.credential-handles.ts).AppEgresshas optionalprivateOrigins.egressRefusallets a request through when its wholeurl.originis listed. Matching is by exact origin, never by hostname or prefix. A listed hostname under another scheme or port is refused withNetworkRefused(private_address), even when the name looks public (a*.ts.netname), 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 toPUBLIC_FETCHand fails there after DNS as a generic network error, the same as today.workerd-entry.ts,AppOutbound). A request to a listed origin goes out through the Worker's ownfetch, which can reach private addresses, instead ofPUBLIC_FETCH. It is sent withredirect: "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 asprivate_addresswhen the hostname shows it, or byPUBLIC_FETCHwhen only DNS does. Workers already deliver incoming requests to the outbound withredirect: "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.apps/hosted/self-host/src/contracts/config.tsreads the setting, andworkerdAppspasses it to the apps Worker as theAPPS_PRIVATE_ORIGINSJSON binding. For the Docker image,native/main.govalidates the value (privateAppOrigins) and substitutes it into the generatedworkerd.capnp(package-runtime.ts). Go'surl.Parsedoes 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 (no127.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 thanHttpOriginin one place: it rejects port0. Export mode always uses[].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 listedhttp://origin can receive requests but not placed credentials.Release-note: Feature:line is pinned to Self-host only (note-audiences.ts).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 needsEXECUTOR_URL_ALLOW_HTTP_ORIGINS. Updated the self-host settings table and egress section inapps/docs/content/run/self-host.mdx, the self-hostREADME.md,compose.yaml, and the app-authoringdeploy.mdskill (digest regenerated withbun run executor:intro). There is also a changeset.Why a new setting instead of
EXECUTOR_URL_ALLOW_HTTP_ORIGINSThat 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 sameHttpOriginschema and exact-origin rules.Follow-ups (not in this PR)
{ "<origin>": ["<app id>"] }or resolve slugs on the host side.private_addressmessage still says apps "can reach only public addresses". Changing it touches the publicappscontract (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 withEXECUTOR_APPS_ALLOW_PRIVATE_FETCH=falseand lists two origins: one loopback upstream's origin, and a decoy that is a prefix of a second upstream's origin. It checks:localhostis refused asprivate_address.httpsis refused asprivate_address.private_address, although a prefix of its origin is listed.private_address.docker-release.spec.ts, explicit mode: added, not run (no Docker daemon here). After the restart onto the new image, the launcher getsEXECUTOR_APPS_ALLOW_PRIVATE_ORIGINS='["http://allowed.example.test:8091"]'. A probe app must:allowed.example.test:8091(the fixture answersGETwith 404);private_addressrefusal forallowed.example.test:8092;blocked.example.test:8092and 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 thee2eblock; the Docker release suite runs it.Go (
apps/hosted/self-host/native, with Go 1.27.4):gofmt -l .is clean,go vet .passes, andgo 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 itsURL.parse(...).origin. It also confirmed that every rejected value failsHttpOrigin, except port0, where Go is deliberately stricter. The fullgo 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 formatleaves no changes.bun run pr:check --description:static,apps-versionandrelease-notespass; 1 of 4 fails.v2shares no history withmain, so I ran it withv2's tip served asmain. The note's audience is pinned to Self-host inscripts/releases/note-audiences.ts(hash1a11ba91f327dd31), because only self-host operators can set this.descriptionfails because it reads.github/workflows, whichv2does not have, the same as in Keep offline MCP grants working after their approving session expires #2587. Thee2eblock below is for the change once it reachesmain.Not run locally:
an app's fetch to a private address fails as Executor's refusal and never reaches the address. This file'sHostedLivescenarios fail locally before any app code runs (UND_ERR_INVALID_ARG: Argument dispatcher must implement dispatchfrom 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).e2e:prepare, because the pinned toolchain is not installed. The other prepare steps were run individually.🤖 Generated with Claude Code