Skip to content

Commit beebeac

Browse files
authored
fix(gateway): restore external Tailscale Serve and Funnel proxies (#125412)
* fix(gateway): allow trusted external Tailscale routes * fix(gateway): require auth for external Funnel * docs(gateway): clarify external Funnel probe behavior
1 parent daafb2b commit beebeac

9 files changed

Lines changed: 149 additions & 46 deletions

‎docs/gateway/configuration-reference.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,13 @@ Gateway or node host and check `openclaw nodes pending` again.
815815
`tailscale.mode = "serve"`, OpenClaw checks `tailscale funnel status` before
816816
re-applying Serve at startup. If that status cannot be inspected, startup
817817
fails before the ordinary Gateway listener opens. An external Funnel that
818-
still targets the ordinary Gateway port cannot provide request provenance.
819-
OpenClaw leaves the
820-
external route unchanged and warns; plugin-authenticated webhooks retain
821-
their own authentication, while Gateway-authenticated routes reject that
822-
ingress. First configure `gateway.auth.password` (prefer a SecretRef) or
818+
still targets the ordinary Gateway port does not receive managed-ingress
819+
provenance. OpenClaw leaves the external route unchanged and warns. The
820+
route can use generic proxy attribution only through an explicitly configured
821+
`gateway.trustedProxies` source with a valid forwarded client address;
822+
Gateway-protected routes then require configured auth, while aggregate probes
823+
and plugin-authenticated webhooks retain their own response and authentication
824+
policies. First configure `gateway.auth.password` (prefer a SecretRef) or
823825
`OPENCLAW_GATEWAY_PASSWORD`, and set `gateway.auth.mode` to `password`. Then
824826
run `openclaw config set gateway.tailscale.mode funnel`, followed by
825827
`openclaw config unset gateway.tailscale.preserveFunnel`. Default `false`.

‎docs/gateway/security/index.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,15 @@ Rotation checklist (token/password): generate/set a new secret (`gateway.auth.to
638638

639639
### Tailscale Serve identity headers
640640

641-
When `gateway.auth.allowTailscale` is `true` (default for Serve), OpenClaw accepts the Tailscale Serve identity header `tailscale-user-login` for Control UI/WebSocket authentication. It verifies identity by resolving the `x-forwarded-for` address through the local Tailscale daemon (`tailscale whois`) and matching it to the header. This only triggers on OpenClaw's dedicated managed-Tailscale listener and requires `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-host`; headers on the ordinary Gateway listener do not establish Serve provenance. For this async check, failed attempts for the same `{scope, ip}` are serialized before the limiter records the failure, so concurrent bad retries from one Serve client can lock out the second attempt immediately.
641+
When `gateway.auth.allowTailscale` is `true` (default for Serve), OpenClaw accepts the Tailscale Serve identity header `tailscale-user-login` for Control UI/WebSocket authentication. It verifies identity by resolving the `x-forwarded-for` address through the local Tailscale daemon (`tailscale whois`) and matching it to the header. This only triggers on OpenClaw's dedicated managed-Tailscale listener and requires `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-host`; headers on the ordinary Gateway listener do not establish Serve provenance or tokenless auth. For this async check, failed attempts for the same `{scope, ip}` are serialized before the limiter records the failure, so concurrent bad retries from one Serve client can lock out the second attempt immediately.
642642

643643
HTTP API endpoints (`/v1/*`, `/tools/invoke`, `/api/channels/*`) do not use Tailscale identity-header auth - they follow the gateway's configured HTTP auth mode.
644644

645645
Gateway HTTP bearer auth is effectively all-or-nothing operator access. Credentials that can call `/v1/chat/completions`, `/v1/responses`, plugin routes such as `/api/v1/admin/rpc`, or `/api/channels/*` are full-access operator secrets for that gateway: shared-secret bearer auth restores the full default operator scopes (`operator.admin`, `operator.approvals`, `operator.pairing`, `operator.read`, `operator.talk.secrets`, `operator.write`) and owner semantics for agent turns, and narrower `x-openclaw-scopes` values do not reduce that shared-secret path. Per-request scope semantics only apply when the request comes from an identity-bearing mode (trusted proxy auth) or an explicitly no-auth private ingress; in those modes, omitting `x-openclaw-scopes` falls back to the normal operator default scope set, and owner-level headers like `x-openclaw-model` require `operator.admin` when scopes are narrowed. `/tools/invoke` and HTTP session history endpoints follow the same shared-secret rule. Do not share these credentials with untrusted callers; prefer separate gateways per trust boundary.
646646

647647
Tokenless Serve auth assumes the gateway host itself is trusted - it is not protection against hostile same-host processes. If untrusted local code may run on the gateway host, disable `allowTailscale` and require explicit shared-secret auth (`token` or `password`).
648648

649-
Do not forward these headers from your own reverse proxy. If you terminate TLS or proxy in front of the gateway, disable `allowTailscale` and use shared-secret auth or [Trusted Proxy Auth](/gateway/trusted-proxy-auth) instead.
649+
An externally managed Tailscale Serve or Funnel route may forward these headers to the ordinary listener only through an explicitly configured `gateway.trustedProxies` source with a valid non-loopback forwarded client address. OpenClaw treats that request as generic proxy ingress: the configured gateway auth applies, `allowTailscale` grants nothing, and no WhoIs lookup runs. Gateway-protected routes reject external Funnel ingress when auth mode is `none`; aggregate health, readiness, and startup probes keep their bounded unauthenticated responses. See [Tailscale](/gateway/tailscale#externally-managed-serve-and-funnel), [Health and readiness](/gateway/health), and [Trusted Proxy Auth](/gateway/trusted-proxy-auth).
650650

651651
See [Tailscale](/gateway/tailscale) and [Web overview](/web).
652652

‎docs/gateway/security/rate-limiting.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ Tailscale's rewritten source address selects a normal non-exempt, resettable
121121
per-client bucket. Serve tokenless identity auth additionally requires a
122122
matching WhoIs result; Funnel requires its marker and password authentication.
123123

124-
An externally preserved Funnel route that still targets the ordinary Gateway
125-
listener cannot establish this request provenance. OpenClaw leaves that route
126-
unchanged and logs migration guidance. Plugin-authenticated webhook routes
127-
remain available under the rule above; Gateway-authenticated routes reject the
128-
unattributable ingress. Use `gateway.tailscale.mode: "funnel"` so OpenClaw can
129-
point the full Gateway route at its dedicated ingress.
124+
An externally managed Serve or Funnel route targeting the ordinary Gateway
125+
listener can establish generic proxy attribution only when its immediate source
126+
is explicitly configured in `gateway.trustedProxies` and it supplies a valid
127+
non-loopback forwarded client address. OpenClaw then uses that client address
128+
for rate limits and applies normal gateway auth; Tailscale headers do not grant
129+
managed-ingress or tokenless-auth semantics. Without that trust configuration,
130+
Gateway-authenticated routes reject the unattributable ingress. Prefer
131+
`gateway.tailscale.mode: "serve"` or `"funnel"` when OpenClaw should own the
132+
route and its dedicated listener.
130133

131134
### Webhooks
132135

‎docs/gateway/tailscale.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ openclaw gateway --tailscale funnel --auth password
9696

9797
### Tailscale identity headers (Serve only)
9898

99-
When `tailscale.mode: "serve"` and `gateway.auth.allowTailscale` is `true`, Control UI/WebSocket auth can use Tailscale identity headers (`tailscale-user-login`) instead of a token/password. OpenClaw verifies the header by resolving the request's `x-forwarded-for` address via the local Tailscale daemon (`tailscale whois`) and matching it to the header login before accepting it. A request only qualifies when it reaches OpenClaw's dedicated managed-Tailscale listener with Tailscale's `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-host` headers; sending those headers to the ordinary Gateway listener is rejected.
99+
When `tailscale.mode: "serve"` and `gateway.auth.allowTailscale` is `true`, Control UI/WebSocket auth can use Tailscale identity headers (`tailscale-user-login`) instead of a token/password. OpenClaw verifies the header by resolving the request's `x-forwarded-for` address via the local Tailscale daemon (`tailscale whois`) and matching it to the header login before accepting it. A request only qualifies when it reaches OpenClaw's dedicated managed-Tailscale listener with Tailscale's `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-host` headers. Those headers never establish managed Serve provenance or tokenless auth on the ordinary Gateway listener.
100100

101101
This tokenless flow assumes the gateway host is trusted. If untrusted local code may run on the same host, set `gateway.auth.allowTailscale: false` and require token/password auth instead.
102102

@@ -106,14 +106,20 @@ Scope of the bypass:
106106
- For Control UI operator sessions that already carry browser device identity, a verified Tailscale identity skips the bootstrap-token/QR pairing round trip.
107107
- It does not bypass device identity itself: device-less clients are still rejected, and node-role connections still go through normal pairing and auth checks.
108108

109+
### Externally managed Serve and Funnel
110+
111+
You can point a native Tailscale Serve or Funnel route at the ordinary Gateway listener when another service owns the route. Configure the route's immediate source narrowly in `gateway.trustedProxies`, and ensure it overwrites or safely rebuilds `X-Forwarded-For`. OpenClaw then treats the request as generic `trusted-proxy` ingress, uses the forwarded client address for rate limits, and applies the configured gateway auth mode normally. Because Funnel is public, Gateway-protected routes reject externally managed Funnel ingress when `gateway.auth.mode` is `none`; configure token, password, or trusted-proxy authentication. The aggregate health, readiness, and startup probes retain their existing unauthenticated responses, without exposing detailed readiness or startup data. See [Health and readiness](/gateway/health).
112+
113+
This compatibility path does not grant managed Tailscale semantics: `gateway.auth.allowTailscale` cannot provide tokenless auth, OpenClaw does not call `tailscale whois`, and it does not own or clean up the external route. Without an explicitly trusted source and a valid non-loopback forwarded client address, Gateway-authenticated routes fail with `proxy_attribution_required`. If the proxy connects over loopback, adding `127.0.0.1` to `trustedProxies` explicitly trusts same-host processes to supply proxy attribution; keep token or password auth enabled unless every process on the host belongs to the same trust boundary.
114+
109115
## Notes
110116

111117
- Tailscale Serve/Funnel requires the `tailscale` CLI installed and logged in.
112118
- `tailscale.mode: "funnel"` refuses to start unless auth mode is `password`, to avoid public exposure.
113119
- OpenClaw holds Serve/Funnel as a foreground Tailscale claim. Gateway startup succeeds only after the claim is active, and stopping or losing the Gateway releases it automatically.
114120
- Named Tailscale Services are not supported by managed ingress because Tailscale requires them to run as persistent background routes. Existing `gateway.tailscale.serviceName` installs must run `openclaw doctor --fix`; Doctor disables managed ingress and removes the key. Inspect the retained Service route, clear it with `tailscale serve clear <service-name>`, then enable device Serve with `gateway.tailscale.mode: "serve"` if desired.
115-
- Older releases could advertise an externally configured default HTTPS Serve route that targeted a `gateway.bind: "lan"` listener. That route no longer has trusted ingress provenance. Run `openclaw doctor` to preview an atomic migration to `gateway.bind: "loopback"` plus `gateway.tailscale.mode: "serve"`; apply it with `openclaw doctor --fix`, then restart the Gateway so it can claim the route through managed ingress. Doctor does not reset Tailscale state or guess how to rewrite custom Serve ports and Tailscale Services; migrate those manually.
116-
- `gateway.tailscale.preserveFunnel: true` is a deprecated migration guard. It detects an externally configured `tailscale funnel` route before reapplying Serve. If that route still targets the ordinary Gateway listener, OpenClaw leaves it unchanged and warns because requests lack managed-ingress provenance. Plugin-authenticated webhook routes such as Google Chat and SMS keep using their own signature/auth checks and ignore forwarded client claims; Gateway-authenticated HTTP and WebSocket routes reject that ingress. First configure a durable `gateway.auth.password` (prefer a SecretRef) or `OPENCLAW_GATEWAY_PASSWORD`, then set `gateway.auth.mode` to `password`. After password auth is ready, run `openclaw config set gateway.tailscale.mode funnel`, then `openclaw config unset gateway.tailscale.preserveFunnel`; managed Funnel targets the dedicated ingress.
121+
- Older releases could advertise an externally configured default HTTPS Serve route that targeted a `gateway.bind: "lan"` listener. That route does not automatically gain trusted ingress provenance. Prefer migrating to managed ingress: run `openclaw doctor` to preview an atomic change to `gateway.bind: "loopback"` plus `gateway.tailscale.mode: "serve"`; apply it with `openclaw doctor --fix`, then restart the Gateway. Doctor does not reset Tailscale state or guess how to rewrite custom Serve ports and Tailscale Services. If another service must retain ownership, use the explicit `trustedProxies` compatibility path above.
122+
- `gateway.tailscale.preserveFunnel: true` is a deprecated migration guard. It detects an externally configured `tailscale funnel` route before reapplying Serve. If that route still targets the ordinary Gateway listener, OpenClaw leaves it unchanged and warns because the route is not managed ingress. Gateway-authenticated routes work only through the explicit `trustedProxies` compatibility path above and continue to require the configured auth; plugin-authenticated webhook routes such as Google Chat and SMS keep using their own signature/auth checks. To migrate, first configure a durable `gateway.auth.password` (prefer a SecretRef) or `OPENCLAW_GATEWAY_PASSWORD`, set `gateway.auth.mode` to `password`, run `openclaw config set gateway.tailscale.mode funnel`, then `openclaw config unset gateway.tailscale.preserveFunnel`.
117123
- `gateway.bind: "tailnet"` uses a direct Tailnet bind (no HTTPS, no Serve/Funnel) plus required local `127.0.0.1` when a Tailnet IPv4 is available; otherwise it falls back to loopback only.
118124
- `gateway.bind: "auto"` prefers loopback; use `tailnet` to limit network exposure to the Tailnet while retaining same-host loopback access.
119125
- Serve/Funnel only expose the **Gateway control UI + WS**. Nodes connect over the same Gateway WS endpoint, so Serve works for node access too.

‎src/gateway/auth.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,25 @@ describe("gateway auth", () => {
527527
expect(res).toEqual({ ok: false, reason: "proxy_attribution_required" });
528528
});
529529

530+
it("keeps externally managed Tailscale ingress on ordinary trusted-proxy auth semantics", async () => {
531+
const tailscaleWhois = vi.fn(createTailscaleWhois());
532+
const authorize = (connectAuth: { token: string } | null) =>
533+
authorizeWsControlUiGatewayConnect({
534+
auth: { mode: "token", token: "secret", allowTailscale: true },
535+
connectAuth,
536+
tailscaleWhois,
537+
req: createTailscaleForwardedReq(false),
538+
trustedProxies: ["127.0.0.1"],
539+
});
540+
541+
await expect(authorize({ token: "secret" })).resolves.toMatchObject({
542+
ok: true,
543+
method: "token",
544+
});
545+
await expect(authorize(null)).resolves.toEqual({ ok: false, reason: "token_missing" });
546+
expect(tailscaleWhois).not.toHaveBeenCalled();
547+
});
548+
530549
it("keeps managed Serve shared-secret auth independent of WhoIs availability", async () => {
531550
const limiter = createAuthRateLimiter({
532551
maxAttempts: 1,

‎src/gateway/auth.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ async function authorizeGatewayConnectCore(
511511
}
512512

513513
if (auth.mode === "none") {
514+
if (
515+
ingressAttribution?.kind === "trusted-proxy" &&
516+
ingressAttribution.externalTailscaleExposure === "funnel"
517+
) {
518+
return { ok: false, reason: "gateway_auth_required" };
519+
}
514520
const originResult = authorizeHttpBrowserOrigin({
515521
authSurface,
516522
browserOriginPolicy: params.browserOriginPolicy,

‎src/gateway/ingress-attribution.test.ts‎

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ function request(params?: {
1414
}): IncomingMessage {
1515
return {
1616
socket: { remoteAddress: params?.remoteAddress ?? "127.0.0.1" },
17-
headers: params?.forwardedFor
18-
? {
19-
"x-forwarded-for": params.forwardedFor,
20-
"x-forwarded-proto": "https",
21-
"x-forwarded-host": "gateway.tailnet.ts.net",
22-
...(params.funnel ? { "tailscale-funnel-request": "?1" } : {}),
23-
...(params.login ? { "tailscale-user-login": params.login } : {}),
24-
}
25-
: {},
17+
headers: {
18+
...(params?.forwardedFor
19+
? {
20+
"x-forwarded-for": params.forwardedFor,
21+
"x-forwarded-proto": "https",
22+
"x-forwarded-host": "gateway.tailnet.ts.net",
23+
}
24+
: {}),
25+
...(params?.funnel ? { "tailscale-funnel-request": "?1" } : {}),
26+
...(params?.login ? { "tailscale-user-login": params.login } : {}),
27+
},
2628
} as IncomingMessage;
2729
}
2830

@@ -47,17 +49,43 @@ describe("gateway ingress attribution", () => {
4749
});
4850
});
4951

50-
it("rejects externally managed Funnel headers on an ordinary trusted-proxy listener", async () => {
51-
const attribution = prepareGatewayIngressAttribution({
52-
req: request({ forwardedFor: "203.0.113.10", funnel: true }),
53-
trustedProxies: ["127.0.0.1"],
54-
});
55-
56-
expect(attribution).toMatchObject({
57-
kind: "unattributable-proxy",
58-
reason: "proxy_attribution_required",
59-
});
60-
});
52+
it.each([
53+
["Serve identity", { login: "[email protected]" }, {}],
54+
["Funnel marker", { funnel: true }, { externalTailscaleExposure: "funnel" }],
55+
])(
56+
"attributes externally managed Tailscale %s as an ordinary trusted proxy",
57+
async (_name, headers, expected) => {
58+
const attribution = prepareGatewayIngressAttribution({
59+
req: request({ forwardedFor: "203.0.113.10", ...headers }),
60+
trustedProxies: ["127.0.0.1"],
61+
});
62+
63+
expect(attribution).toMatchObject({
64+
kind: "trusted-proxy",
65+
clientIp: "203.0.113.10",
66+
rateLimit: { subject: { key: "203.0.113.10" } },
67+
...expected,
68+
});
69+
},
70+
);
71+
72+
it.each([
73+
["missing", undefined],
74+
["loopback", "127.0.0.1"],
75+
])(
76+
"rejects trusted Tailscale headers with a %s forwarded client",
77+
async (_name, forwardedFor) => {
78+
const attribution = prepareGatewayIngressAttribution({
79+
req: request({ forwardedFor, login: "[email protected]" }),
80+
trustedProxies: ["127.0.0.1"],
81+
});
82+
83+
expect(attribution).toMatchObject({
84+
kind: "unattributable-proxy",
85+
reason: "proxy_attribution_required",
86+
});
87+
},
88+
);
6189

6290
it("attributes managed Serve by listener provenance and verifies its identity lazily", async () => {
6391
const req = request({ forwardedFor: "100.64.0.10", login: "[email protected]" });

0 commit comments

Comments
 (0)