Add TURN/STUN server for audio/video calls.

Jingle A/V (XEP-0166/0167/0176) needs a STUN/TURN server for NAT
traversal. Add coturn and advertise it to clients via XEP-0215.

- coturn container, host networking (a relay needs its full UDP port
  range reachable, and Docker NAT hides the peer addresses coturn needs).
- mod_turn_external in Prosody to advertise the service and mint
  time-limited credentials from a shared secret.
- Advertise UDP and TCP transports plus turns: on 5349, so clients on
  UDP-blocking networks can still connect.
- Deny relaying to private ranges, so this is not an open proxy into
  internal services.

TURN host is guschin.info rather than turn.guschin.info because only the
former is in the certificate SANs and turns: clients validate the name.

TURN_HOST/TURN_SECRET go in .env, which is gitignored and set per
deployment; TURN_SECRET must match static-auth-secret in turnserver.conf.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
mguschin
2026-08-18 22:17:44 +03:00
parent 218b1be0dd
commit 3fc1ac3d12
4 changed files with 162 additions and 0 deletions

View File

@@ -13,6 +13,8 @@ services:
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
SLIDGRAM_COMPONENT_SECRET: ${SLIDGRAM_COMPONENT_SECRET}
TURN_HOST: ${TURN_HOST}
TURN_SECRET: ${TURN_SECRET}
extra_hosts:
- "host.docker.internal:172.17.0.1"
ports:
@@ -58,6 +60,21 @@ services:
networks:
- prosody
coturn:
image: coturn/coturn:4.6-alpine
container_name: coturn
# Host networking: a TURN relay needs its whole UDP port range reachable,
# and Docker's userland NAT both mangles the source addresses coturn needs
# to see and makes publishing the range impractical.
network_mode: host
volumes:
- ./coturn/turnserver.conf:/etc/coturn/turnserver.conf:ro
- /etc/letsencrypt/live/guschin.info:/etc/coturn/certs:ro
- /etc/letsencrypt/archive/guschin.info:/etc/letsencrypt/archive/guschin.info:ro
command: ["-c", "/etc/coturn/turnserver.conf"]
restart: unless-stopped
mem_limit: 128M
networks:
prosody:
driver: bridge