turn: accept PROXY protocol on the TCP listener (#4852)

* turn: accept PROXY protocol on the TCP listener

Behind a TLS-terminating or reverse proxy that dials from its own address,
the embedded TURN server reports the proxy's address to the client as
XOR-MAPPED-ADDRESS. Firefox rejects a loopback or wildcard mapped address
and abandons the allocation, so relay-only clients never get a relay
candidate (#4851).

Add turn.proxy_protocol. When set, the TCP listener requires a PROXY
protocol v1/v2 header on every connection and uses the client address it
carries; connections without the header are rejected. The header is read
before TLS, so it works with both the built-in TLS listener and
external_tls.

* turn: only trust PROXY headers from configured proxies

A PROXY header from any peer that can reach the port would let a direct
client claim an arbitrary source address. Add
turn.proxy_protocol_trusted_cidrs, defaulting to loopback, and close
connections from any other address before reading the header.
This commit is contained in:
Sapan Diwakar
2026-09-09 16:16:44 +08:00
committed by GitHub
parent 5121860448
commit adf44a2eb6
6 changed files with 230 additions and 21 deletions
+13
View File
@@ -317,6 +317,19 @@ keys:
# # set external_tls to true if using a L4 load balancer to terminate TLS. when enabled,
# # LiveKit expects unencrypted traffic on tls_port, and still advertise tls_port as a TURN/TLS candidate.
# external_tls: true
# # set proxy_protocol to true if the proxy or load balancer in front of tls_port does not preserve
# # the client address (it terminates TLS, or dials LiveKit from its own IP) and can send a
# # PROXY protocol v1/v2 header instead. Without it TURN reports the proxy's address to the
# # client as XOR-MAPPED-ADDRESS, which Firefox rejects when it is loopback or wildcard.
# # every connection on tls_port must then carry the header; connections without it are rejected.
# # prefer PROXY protocol v2 on the proxy side: the v1 text header must arrive in a single read.
# proxy_protocol: false
# # proxies whose PROXY header is trusted. connections from any other address are closed, so a
# # client that reaches tls_port directly cannot claim an arbitrary source address.
# # defaults to loopback, for a proxy running on the same host.
# proxy_protocol_trusted_cidrs:
# - 127.0.0.0/8
# - ::1/128
# # needs to match tls cert domain
# domain: turn.myhost.com
# # optional (set only if not using external TLS termination)