Live screen

How a browser watches the screen of a Computer through the Media Relay, and the TURN variant.

A browser watches an Agent's Computer through the Media Relay. A Computer publishes no media port at all, so a browser never sends media to a container. The daemon relay copies packets between the browser and the Computer. The Computer registers outbound from its Tenant Network. With the turn relay, the Computer runs a full ICE agent and allocates its own TURN candidate. The TURN server carries the screen, and the daemon carries no media packet.

The [screen] section of config.toml names the relay. ADR-0014 holds the decision behind it.

A local installation

Set nothing. The relay advertises 127.0.0.1 and the browser is on the same machine. In Remote Access, a browser on another machine reaches the relay through the TURN server of Pagis, which the Funnel publishes on port 8443. A machine that reaches this computer over UDP, on the tailnet or on the LAN, takes a direct path where advertise_ip names that address. The live screen for other people gives both, and how many people watch at once.

The TURN server of Remote Access

With Remote Access on, the daemon runs a TURN server on a loopback TCP port, and Funnel publishes it on port 8443 of the public name, where tailscaled ends TLS and forwards plain TCP. On a local installation the Remote Access switch turns on that Funnel. On a server at home, the tailscale service of the compose deployment does (Remote Access at home). A browser that is not on this machine gets turns:<machine>.<tailnet>.ts.net:8443?transport=tcp from GET /api/v1/screen/ice, with a credential of its own. A browser on this machine gets none.

[screen]
# The loopback port of the TURN server. The turn-on of Remote Access names
# it in the Funnel configuration, so it is fixed.
remote_access_turn_port = 4402

The TURN server relays to the Media Relay's advertised address, on a port of the Media Relay's range, and refuses every other peer, also another port of loopback. Its credentials follow the scheme of the turn relay below, under a secret that the daemon makes at each start and keeps out of config.toml, and each one lives twelve hours. The server takes at most 64 connections, and it closes a connection that makes no allocation in ten seconds.

A server with a public address

One advertised address and one UDP port range serve every Computer of the installation, so a firewall rule and a compose port list name them once.

[screen]
# The address browsers resolve for this server. The relay advertises it in
# every screen session's ICE candidate.
advertise_ip = "203.0.113.10"
# The UDP ports the relay may bind. One port carries one viewer, so this range
# is how many people may watch a screen at once.
media_port_first = 50000
media_port_last = 50099
# The daemon forwards the media itself. This is the default.
relay = "daemon"

Open media_port_first to media_port_last for UDP, and nothing else. The daemon needs no other inbound port for a screen. The Computers register with the relay on the same range from the Docker bridges, so a firewall that filters traffic from the bridges must accept that range from them too.

PAGIS_SCREEN_ADVERTISE_IP, PAGIS_SCREEN_MEDIA_PORT_FIRST and PAGIS_SCREEN_MEDIA_PORT_LAST set the same three for one run. A container deployment states them there once and publishes exactly that range; see Deploy with Compose.

A server behind an external TURN server

Use this where the firewall or the load makes a daemon-owned public UDP range wrong. Both the browser and the Computer reach the TURN server outbound. The daemon gives the Computer a session credential over its authenticated control port. It opens no UDP forwarder for this relay.

[screen]
relay = "turn"

[screen.turn]
urls = ["turn:relay.example.net:3478?transport=udp"]
# The same value as coturn's static-auth-secret.
secret = "the-shared-secret"
# How long one minted credential lives.
ttl_seconds = 3600

The daemon mints one credential for each viewer session under the TURN REST API long-term credential scheme, which is coturn's use-auth-secret mode: the username carries the expiry and the password is its HMAC under the shared secret. No account exists on the TURN server, and a credential that leaks expires. The matching coturn settings are:

use-auth-secret
static-auth-secret=the-shared-secret
realm=relay.example.net

The Computer gathers host and server-reflexive candidates and allocates a relay candidate. str0m runs the connectivity checks and selects the pair. The control port can answer a viewer offer or make an offer for a viewer that answers. Session cancellation closes the allocation through control.

The egress rules open only the TURN server's address and port. In the compose deployment, set these to the IPv4 address and port of the server in screen.turn.urls:

PAGIS_TURN_IP=10.0.1.7
PAGIS_TURN_PORT=3478

The exception opens UDP and TCP on that port. It opens no other private address or port. The daemon relay still uses its UDP range.

What the daemon refuses at boot

  • A relay that is not daemon or turn.
  • relay = "turn" with no urls or no secret, because the daemon would have nothing to mint a credential for.
  • A media_port_first above media_port_last, or a first port of zero.
  • A remote_access_turn_port of zero.
  • In Remote Access, a remote_access_turn_port that another process holds, and an advertise_ip that is not an IP address, because the TURN server relays to it.

When a viewer sees no screen

  • Every port of the range is in use. The daemon refuses the next viewer and says so; widen the range.
  • A browser reaches the advertised address on TCP but not on UDP. The range is UDP only, and the payload is DTLS-SRTP.
  • The advertised address is the one the machine holds, not the one browsers resolve. The relay advertises exactly what this setting says.
  • The Computer's registration does not reach the relay. A Computer reaches the daemon as host.docker.internal; a firewall that refuses UDP from the Docker bridges to the range stops the registration, and the relay then has no Computer to copy the browser's packets to.
  • In Remote Access, port 8443 of the Funnel does not serve the TURN server of Pagis, for example after remote_access_turn_port changed. The Remote Access switch says what the port serves; remove it with tailscale funnel --tls-terminated-tcp=8443 off and turn on Remote Access again.
Edit on GitHub

On this page