DEV Community

Cover image for NetBird behind a Cloudflare Tunnel: gRPC trailers get stripped, clients loop
Christian Anderson
Christian Anderson

Posted on

NetBird behind a Cloudflare Tunnel: gRPC trailers get stripped, clients loop

I self-host NetBird, the WireGuard mesh VPN. I've written before about why I picked it over Tailscale. What I didn't cover is the fight I had getting devices outside my house to connect to it, because my public services all sit behind a Cloudflare Tunnel, and NetBird's control plane speaks gRPC.

It took four goes. One of them returned HTTP 200 and still didn't work, and that's the bit worth writing down.

The setup

NetBird's server (management, signal, relay, plus an embedded Dex for login, all in one container) runs on a Docker box at home. Login goes through my own SSO via Dex. The dashboard and login pages are published through a Cloudflare Tunnel, same as everything else I expose.

The web dashboard is plain HTTPS, so it was fine through the tunnel from day one. The problem is the NetBird client. It talks to the management and signal services over native gRPC, and that's a different animal.

Four attempts to reach NetBird's gRPC from outside: 403 through the tunnel with gRPC off, 404 with an http origin, 200 but no grpc-status trailer through an https origin, and finally 200 with grpc-status via a DNS-only name

Attempt 1, July: 403

When I first built it on 2 July 2026, clients pointed at the public name got 403. Cloudflare passes a browser's gRPC-web, but not a native gRPC client, unless gRPC is switched on for the zone. And the API token I was using couldn't change zone settings.

At the time every device was at home anyway. So I took the shortcut: enrolled every peer against the server's internal LAN address, and set NetBird's exposedAddress to that internal address so it advertised internal signal and relay too. Peers connected directly over the LAN. The cost, which I wrote down at the time, was that nothing off the LAN could ever join.

Attempt 2, October: 404

On 8 October I wanted my laptop to work away from home, so it was time to fix it properly. I switched on gRPC in the Cloudflare dashboard, under the zone's Network settings.

Result: 404 instead of 403. Progress, sort of.

The tunnel rules for the two gRPC paths (/management.ManagementService and /signalexchange.SignalExchange) pointed at the NetBird server over plain http://, with http2Origin: true set. That flag reads like "speak HTTP/2 to the origin". It isn't quite. cloudflared only speaks HTTP/2 to an https:// origin. Set http2Origin on an http:// service and it silently falls back to HTTP/1.1. NetBird's server then gets gRPC over HTTP/1.1 and answers 404.

No warning anywhere. The flag is just ignored.

Attempt 3: 200, and still broken

So I gave cloudflared an https:// origin. I pointed the two gRPC rules at my reverse proxy (NPMplus, which already has a valid wildcard certificate) with http2Origin: true and originServerName set, TLS verification on. On the proxy, a custom block for that hostname does grpc_pass to the NetBird server for those two paths.

I tested it with curl, sending a real gRPC call to the management service:

curl --http2 -X POST \
  -H 'content-type: application/grpc' -H 'te: trailers' \
  --data-binary $'\x00\x00\x00\x00\x00' \
  https://<netbird-name>/management.ManagementService/GetServerKey
Enter fullscreen mode Exit fullscreen mode
  1. Lovely. I set exposedAddress to the public name, and the relay showed up as available over WebSocket.

Then I tried an actual client from outside. It never logged in. In the reverse proxy's access log I could see it arriving from outside and calling GetServerKey. Then calling it again. And again. It never got as far as Login.

Here's why. A gRPC response isn't finished when the body arrives. The status of the call (grpc-status, and grpc-message if it failed) comes after the body, in HTTP/2 trailers. No trailer, and the client doesn't know if the call worked, so it retries forever.

I compared the response headers both ways:

  • straight to the reverse proxy: grpc-status present
  • through the Cloudflare Tunnel: grpc-status absent

The tunnel was handing back a 200 with the body but dropping the trailers. Even with gRPC switched on in the zone. And the NetBird client has no WebSocket fallback for this, so there's no way round it on the client side.

That's the lesson I'd pin on the wall: for gRPC, a 200 proves nothing. Check the trailers. Add -D - to that curl and grep for grpc-status. If it's not there, it's not working, whatever the status code says.

Attempt 4: take Cloudflare out of the gRPC path

The fix was to stop trying to push gRPC through the tunnel at all.

Off-LAN traffic now: the dashboard and SSO login go through the Cloudflare Tunnel; management and signal gRPC plus the relay go to a separate DNS-only name straight to the reverse proxy

  • A second public name, DNS-only (grey cloud, not proxied), pointing at my home IP.
  • A tiny DDNS script runs every 10 minutes to keep that A record on my current home IP.
  • My router forwards the management traffic to the reverse proxy, and STUN (UDP) to the NetBird server.
  • The reverse proxy serves that name too, with the same grpc_pass block plus a WebSocket proxy for /relay.
  • NetBird's exposedAddress is set to the new name, so the server advertises it to clients.

The dashboard and the SSO login stay exactly where they were, behind the tunnel. Only the gRPC and relay traffic goes direct. A client off the LAN is enrolled with both:

netbird up --management-url https://<mgmt-name> --admin-url https://<dashboard-name>
Enter fullscreen mode Exit fullscreen mode

Trailers present, client logs in, done.

The trade-off, which I accepted on purpose: my home IP is now public on that one DNS-only name. Everything else is still behind Cloudflare.

The next day: "NetBird doesn't work"

On 9 October the laptop stopped connecting. Server side, everything was green: DNS matched my IP, the trailers were there, the relay was up.

It was the laptop's login. Peers enrolled through SSO inherit the account's login expiry, 24 hours by default. Peers enrolled with a setup key don't. So all my servers, enrolled by key, were fine, and the one device I'd enrolled by logging in had quietly expired.

I turned off login and inactivity expiry for that peer via the API, and it needed one more SSO login on the laptop. If a user's device "stops working" with NetBird, check login_expired on the peer before anything else.

Keeping an eye on it

All of this can drift. Your home IP changes, a certificate expires, someone "tidies" the tunnel config. So my IT-admin agent's fact-gathering script now checks the bits that can break: does the DNS-only name match my current IP, are the gRPC trailers present on the direct path, how many days are left on the proxy's certificate, are any peers stale or waiting for approval, and is any tunnel hostname bypassing the reverse proxy.

What I'd do differently

  • Don't put gRPC through a Cloudflare Tunnel. Even with gRPC enabled, I couldn't get trailers through. If your app needs gRPC from outside, give it a direct path from the start.
  • Test with trailers, not status codes. curl -D - and look for grpc-status. A 200 alone fooled me.
  • http2Origin needs an https:// origin. On http:// it's silently ignored.
  • Know which of your peers can expire. SSO-enrolled and key-enrolled peers behave differently, and the difference only shows up a day later.

Are you running anything gRPC through a tunnel? I'd love to know if anyone's actually got trailers to survive.


🤖 Drafted with AI assistance from my own homelab notes, logs and repos, and fact-checked against them before publishing.

Top comments (4)

Collapse
 
userxnom profile image
Abdullah Naseer •

That 200 that still did not work is the part that would have fooled me longest — a status code feels like proof until the client keeps retrying GetServerKey and never reaches Login. The http2Origin silent fallback is a nasty one too; no warning anywhere is exactly the kind of detail that costs an afternoon. With the DNS-only second name now exposing your home IP, do you do anything extra to protect the management endpoint, or is that trade-off just accepted because the dashboard and SSO stay behind the tunnel?

Collapse
 
iam-tech profile image
Christian Anderson •

That trade-off is the point, though I did keep the router port mapped only to the reverse proxy itself and let its grpc_pass block gate what reaches NetBird's server directly. The other bit isn't really security, just noise reduction: my fact-gathering script checks whether the DNS-only A record still matches the current home IP, since once it drifts the whole loop starts again. Are you running gRPC through a tunnel at all?

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

The 200 that still didn't work is the part to keep. A proxy that strips trailers and still answers 200 leaves the client retrying a success.

Collapse
 
iam-tech profile image
Christian Anderson •

Yeah, that's the one that wasted the most time. The worst bit was there was zero warning from the NetBird client either, it just retried in silence until the debug log showed the pattern. Curl was the only way to see what was actually happening.