Repository navigation
2.4: Cloudflare Tunnel and Access, and gRPC
Two additions: services published to the internet through a Cloudflare Tunnel, and what gRPC needs from a proxy. Upgrading a cluster: update every node (see Updates).
One thing changes without being asked for, on HAProxy 3.0 or later: an HTTP service whose Server timeout is longer than the client timeout now gives its visitors that longer timeout too. It is described below.
Cloudflare Tunnel and Access
A service can be published through a Cloudflare Tunnel, with no open port on the node. cloudflared runs beside HAProxy and holds an outbound connection to Cloudflare; visitors reach Cloudflare and come down that connection. Cloudflare Access can ask them to sign in first. It is optional and off until switched on. The guide has a page for it.
- Access › Cloudflare takes one API token. Saving with Enable Cloudflare ticked makes a tunnel in your account and runs
cloudflaredon every node. - In the service form, the Cloudflare section, on HTTP and HTTPS services: Publish through Cloudflare, who may reach it (anyone, or a Cloudflare Access sign-in for a list of emails and
@domains), and Through Cloudflare only. - Apply keeps three things in step for each such service: the tunnel's route, the DNS record, and the Access application with its policy. Unticking the service takes them away again.
- A service published only this way needs no certificate and no port: publish it as
http://app.example.com, and Cloudflare serves it over HTTPS.
Worth knowing:
- Only what haproxy-manager made is changed or removed. A tunnel that is already in use is refused, not taken over. Routes added to the tunnel by hand, a host name's existing DNS record and an Access application made in the dashboard are left alone; Apply warns when a record still sends visitors elsewhere.
- The visitor's address is the real one. The log, the forwarded headers, allow-lists, rate limits and CrowdSec all see the visitor, not Cloudflare.
- Tick Through Cloudflare only on a service with a sign-in. Otherwise anybody who reaches the node's own port gets the service without one.
- A service that is not published refuses what comes down the tunnel, so publishing one path of a host does not publish the rest of it.
- In a cluster every node connects to the same tunnel, and Cloudflare spreads visitors over them.
- The API token needs Cloudflare Tunnel: Edit, Access: Apps and Policies: Edit, DNS: Edit and Zone: Read.
Limits: HTTP and HTTPS services only; one policy per service (richer ones are made in the Cloudflare dashboard); HAProxy does not verify the Access token itself; HSTS set on a service is not sent to visitors who come through the tunnel.
HTTP/2 to the servers, for gRPC
HAProxy spoke HTTP/1.1 to a server whatever visitors spoke to it, and gRPC cannot do without HTTP/2. Requested in #37.
- In the service form, in the Service section under Forward to: HTTP/2 to the servers. To an
https://server HTTP/2 is offered and the server chooses, so one that only knows HTTP/1.1 still works. To anhttp://server it is HTTP/2 only. - A gRPC service recipe, under Web: HTTPS, HTTP/2 to the servers, a connect check and a Server timeout of a day.
- PROXY protocol moved there too, from Balancing and timeouts.
A service that waits longer than the listener
A stream that is silent in both directions, a bidirectional gRPC call above all, was closed after 50 seconds: the visitor's side is held to the listener's client timeout, whatever the service's Server timeout says.
On HAProxy 3.0 or later, a service whose Server timeout is longer than the client timeout now gives its own requests that longer client timeout too. Nothing has to be ticked.
- This changes existing services at the next Apply. Every HTTP service with a Server timeout longer than the client timeout (many recipes set one) gets a line on its listener, and its visitors' idle streams then live as long as the Server timeout says.
- It is never shortened. A service with a short Server timeout leaves the client timeout alone.
- HAProxy before 3.0 does not know the directive, so on Debian 12, Ubuntu 24.04 and Rocky 9 nothing is written. There, add
timeout client 1hto the listener's Extra directives. The container image carries HAProxy 3.4, and Debian 13 has 3.0.
gRPC beside CrowdSec AppSec
To let AppSec read a request body, the listener holds each request until its body is in. A gRPC stream is a request whose body never ends, so a bidirectional gRPC call through a listener with AppSec on never reached its server.
A service with HTTP/2 to the servers ticked is now taken to speak gRPC. Its requests with a Content-Type of application/grpc are let through without waiting, and CrowdSec is asked about them by address, path and headers, without their body. On any other service, a request that claims to be gRPC still waits and is inspected. The guide has it under gRPC beside AppSec.
Tested
- Cloudflare, against a real account, on the container image (HAProxy 3.4) and on Debian 13 under systemd (HAProxy 3.0): making the tunnel; a public service with the visitor's address in the log; a protected service redirecting to the Access login; a Cloudflare-only service refusing direct requests; an unpublished path refused through the tunnel; an in-use tunnel refused; a route added by hand kept; a second node joining the tunnel and carrying the traffic alone; Disconnect removing everything it made. A three-node cluster with a virtual IP has run connected to one tunnel, with no service published through it.
- gRPC, with a real gRPC server over TLS and a real CrowdSec AppSec, on the container image: calls failing with 502 without the tick and working with it; an idle stream cut at 50 s before and still open after; streams delivered with AppSec on, and a body attack still refused when it claimed to be gRPC.
Not tried: signing in through Access to the end (it stops at the login page), RPM systems, wildcard host names with Cloudflare, an http:// gRPC server (configuration check only), NetBird itself, gRPC through the Cloudflare Tunnel.