docs: Refactor and improve TURN documentation #1740
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
continuwuation/continuwuity!1740
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "stratself/continuwuity:stratself/docs-turn-improvements"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR edits the entire turn.mdx page for better flow and readability. Notably, insecure config options like guest access/password credentials have been deprioritized into the Appendix section. Furthermore, links to guidance for eturnal (another STUN/TURN software) and TURNS-over-443 are added. Lastly, the LiveKit page is also given a polish once-over. See the commit messages and previews below for more.
Current docs: https://continuwuity.org/calls/turn.html, https://continuwuity.org/calls/livekit.html
Preview: https://muc.muoi.me/calls/turn.html, https://muc.muoi.me/calls/livekit.html
I also intend to add some guidance for TURNS-over-443 (in the Appendix), but it would probably go into a future PR.Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
4e19a0f5d102008de778docs: Refactor and improve TURN documentationto WIP: docs: Refactor and improve TURN documentation02008de778aea9b66c13WIP: docs: Refactor and improve TURN documentationto docs: Refactor and improve TURN documentationUn-WIP and ready. I was wondering if LiveKit's TURN docs could be deprioritized, but can deal with it later.
1bac3968f14d043e27db@ -215,0 +394,4 @@By default, TURN credentials require client authentication. To allow unauthenticated access:```tomlturn_allow_guests = trueThis config option no longer exists in
main.Removed
4d043e27db57d99044cd57d99044cddfcb5ade99@ -215,0 +302,4 @@```{servers {I'm assuming you have tested these setups 😓
I've tested that TURN-over-TLS-over-443 works against Trickle ICE, but not legacy calls, probably due to my complex IP setup.
I hope this could be merged after I fix some other stuff and remove the WIP, and I'll test further along as I have time, thanks.
I've successfully tested all scenarios with livekit and coturn using host networking mode (which is what we recommend anyways). This should be good to do
docs: Refactor and improve TURN documentationto WIP: docs: Refactor and improve TURN documentation8005a485711d4fb592161d4fb59216cd9b581251cd9b5812519ab0ec6e4dWIP: docs: Refactor and improve TURN documentationto docs: Refactor and improve TURN documentationdocs: Refactor and improve TURN documentationto WIP: docs: Refactor and improve TURN documentation9ab0ec6e4d74b86d3afdWIP: docs: Refactor and improve TURN documentationto docs: Refactor and improve TURN documentation838bc76af7e269cdbae1e269cdbae19842680195cd0403139c7011d353f17011d353f1f2567e1408f2567e14085ea980b943@ -90,3 +96,3 @@### 3. Telling clients where to find LiveKitTo tell clients where to find LiveKit, you need to add the address of your `lk-jwt-service` to the `[global.matrix_rtc]` config section using the `foci` option.To tell clients where to find LiveKit, you need to add your `lk-jwt-service`'s address to the `[global.matrix_rtc] > foci` field of your Continuwuity config file.@ -100,6 +106,12 @@ foci = []```If you configure Continuwuity via environment variables, use the following:Is this not already covered by the existence of the environment variables documentation?
This is provided as a convenience for most users
@ -134,1 +146,4 @@**Note**: if you run Caddy inside a container (e.g. by following the example [here](../deploying/docker.mdx#caddy-using-caddyfile)) instead of on the host, then:- Put these containers on the same bridge network as caddy (by defining `networks: [ caddy ]` in each of the services), andInconsistent capitalisation of Caddy.
@ -135,0 +147,4 @@**Note**: if you run Caddy inside a container (e.g. by following the example [here](../deploying/docker.mdx#caddy-using-caddyfile)) instead of on the host, then:- Put these containers on the same bridge network as caddy (by defining `networks: [ caddy ]` in each of the services), and- Use appropriate container hostnames (`lk-jwt-service` and `livekit`) instead of `127.0.0.1` in the CaddyfileThis is not technically necessary, and does require additional configuration to work (i.e. having hostname resolution on the network)
Aren't hostname resolutions on by default?
@ -442,1 +396,4 @@### Incorrect IP address for LiveKitBy default, LiveKit auto-discovers its public IP address(es), which is reflected in the "Establishing WebRTC connection" section of the connection test page. If these IPs are incorrect, you may want to hardcode your own IP by doing the following:Autodiscover is a standardised term. It should either be unhyphenated or avoided here. Try:
This should also link to the connection test page in question.
@ -475,0 +457,4 @@Other:- [Matrix VOIP and LiveKit][sspaeth-matrix-voip] - Community member deep dive on current VOIP solutions on Matrix"VoIP"
It may also be courteous to attribute authors, rather than "community member"
I (or you) can attribute all "community member" authors in future PR(s)
@ -475,0 +464,4 @@## Appendix### Additional TURNS-over-443 configurationI can't select the line above for some reason, but "TURNS-over-443" should be "TURNS over TCP/443"
there is no TURNS over UDP but I can be pedantic
@ -475,0 +465,4 @@### Additional TURNS-over-443 configurationMost of the time, LiveKit [**does not need TURN**][sspaeth-matrix-voip-turn] to function. However, there are situations where clients are in very restrictive networks that disallows non-standard ports and UDP. In these cases, a TURN-over-TLS server on port :443 could be employed to relay traffic for them.Try:
Also, does this necessitate TURNS, or would an ordinary TURN server running on TCP/443 suffice? It is unclear from this section whether TLS is a necessity.
TLS is likely a necessity - https://docs.livekit.io/transport/self-hosting/deployment/#turn-tls
@ -475,0 +482,4 @@turn:enabled: true# note: the TLS port will always be advertised as :443"as 443"
@ -462,2 +428,2 @@- [Community guide with overview of LiveKit's mechanisms](https://tomfos.tr/matrix/livekit/)- [Community guide using systemd](https://blog.kimiblock.top/2024/12/24/hosting-element-call/)- [Element Call self-hosting documentation from element-hq][element-call-selfhosting]- [Community guide with overview of LiveKit's mechanisms][tom-livekit-guide]"an overview"
@ -475,0 +485,4 @@# note: the TLS port will always be advertised as :443tls_port: 5349# optional: configure an extra UDP port on :3478The documentation should probably make it clear which circumstances I would want to do this in. Also, same note about port numbers.
@ -475,0 +507,4 @@# "3478:3478/udp" # (optional UDP port)```Recreate the LiveKit container (with `docker-compose up -d livekit`) to apply these changes. Remember to allow the new `50300:50400/udp` ports through your firewall.This has not been correct for several versions of docker compose, to my knowledge. It should just be
docker compose. The syntax used here is also invalid for a port range.@ -467,2 +442,2 @@- [MSC4143 - MatrixRTC proposal](https://github.com/matrix-org/matrix-spec-proposals/pull/4143)- [MSC4195 - LiveKit proposal](https://github.com/matrix-org/matrix-spec-proposals/pull/4195)- [MSC4143 - MatrixRTC proposal][MSC4143]- [MSC4195 - LiveKit proposal][MSC4195]While we're here, these should probably use the correct titles of the proposals.
@ -475,0 +499,4 @@``````yaml### add these ports to livekit's docker-compose ###What's with the variance in number of #s? Is that standardised throughout Continuwuity's documentation? If it is, it's quite jarring.
@ -475,0 +509,4 @@Recreate the LiveKit container (with `docker-compose up -d livekit`) to apply these changes. Remember to allow the new `50300:50400/udp` ports through your firewall.Then, we will configure a route from port 443 of the host back to our `livekit-turn.example.com` service on port 5349. To both **multiplex** this and LiveKit's websocket on the same port, we will use a layer-4 reverse proxy with **SNI routing** capabilities, such as [caddy-l4][caddy-l4] on the host system.@ -475,0 +532,4 @@}# livekit stuffhttps://livekit.example.com {Drop
# livekit stuff, and thehttps://is unnecessary here.@ -475,0 +548,4 @@<details><summary>Using an external TURN server (coturn)</summary>Before continuing, make sure coturn's `min-port` and `max-port` do not overlap with LiveKit's port range:Try "First, make sure"
@ -475,0 +556,4 @@max-port=65535```Then, generate a long random secret for LiveKit, and add it to your coturn config under the `static-auth-secret` option. You can add as many secrets as you want, so set a different one for LiveKit to use.This would be my suggested wording, but you already mention generating a secret for LiveKit in the first sentence, so I am not sure what you mean by the second.
This is the TURN secret
@ -475,0 +558,4 @@Then, generate a long random secret for LiveKit, and add it to your coturn config under the `static-auth-secret` option. You can add as many secrets as you want, so set a different one for LiveKit to use.After that, refer to the following [**TURN instructions**](./turn#turns-over-443) to set up coturn with TLS, as well as multiplexing with LiveKit's websocket on port 443.These TURN instructions need not be bold, nor are they following. Also, if there's already a TURNS over 443 section in another file, perhaps they should be merged?
This section's main purpose is to generate a new TURN secret just for LiveKit. The rest should follow the real TURN documentation.
@ -475,0 +573,4 @@secret: "COTURN_SECRET"```Restart LiveKit, coturn, and Caddy-l4 to apply these changes.When I was researching caddy-l4's intended capitalisation, I discovered it has a different official name, which may be worth noting: https://github.com/mholt/caddy-l4#project-conncept-a-tcpudp-app-for-caddy
Nobody calls it that way
@ -475,0 +577,4 @@</details>After finishing configuration, you can run the Testing steps again to check that TURN-over-TLS is working. In the LiveKit connection test page, there should be a green tick saying "Can connect to TURN".Also, link to Testing. I would additionally highlight that the TURN over TLS / TURNS over 443 thing is still inconsistent.
@ -1,36 +1,95 @@# Setting up TURN/STUN[TURN](https://en.wikipedia.org/wiki/Traversal_Using_Relays_around_NAT) and [STUN](https://en.wikipedia.org/wiki/STUN) are used as a component in many calling systems. Matrix uses them directly for legacy calls and indirectly for MatrixRTC via Livekit.[TURN][turn] and [STUN][stun] are used as a component in many calling systems. Matrix uses them directly for legacy calls and indirectly for MatrixRTC via Livekit.This should be "are used as components", and I strongly suspect "or" rather than "and".
Most use cases combine them into one component.
@ -4,2 +3,3 @@[TURN][turn] and [STUN][stun] are used as a component in many calling systems. Matrix uses them directly for legacy calls and indirectly for MatrixRTC via Livekit.Continuwuity recommends using [Coturn](https://github.com/coturn/coturn) as your TURN/STUN server, which is available as a Docker image or a distro package.Continuwuity recommends using [Coturn][coturn] as your TURN/STUN server, which is available as a Docker image or a distro package. This guide assumes that you are using docker compose for deployment.Inconsistent capitalisation of coturn.
@ -7,3 +15,3 @@## Installing Coturn### Configuration### 1. DomainThese headings should be consistent with the LiveKit documentation.
@ -24,3 +35,3 @@:::#### Port ConfigurationIf you want to enable TURN-over-TLS (TURNS), add the appropriate cert/key paths to your `coturn.conf` by adding the following lines:"cert/key" -> "certificate and key"
@ -27,0 +41,4 @@pkey=/etc/letsencrypt/coturn.example.com.key```The cert and key must be encoded in PEM format and are readable by the coturn user."and be readable" although I'd honestly prefer "and the coturn user must be able to read them."
@ -27,0 +43,4 @@The cert and key must be encoded in PEM format and are readable by the coturn user.Check out the [`turnserver.conf`][turnserver-conf] example for all coturn options.This is phrased rather directly for a reminder. "Make sure you [...]" would be friendlier
This is not a reminder, but linking to a reference
@ -27,0 +49,4 @@### 3. Running the coturn containerNext, we will start the Coturn container with the [official image][coturn-image]. **Host networking mode** will be used, as it is better for performance and reduces configuration complexity (see [Coturn Docker docs][coturn-docker-docs] for rationale).Good citation, but:
@ -27,0 +57,4 @@Create a `docker-compose.yml` file as follows and run `docker compose up -d`:```yamlversion: '3'The version key of the compose format is obsolete.
@ -31,3 +78,3 @@- `49152-65535` (UDP): Media relay portsIf you're also running LiveKit, you'll need to avoid port conflicts. Configure non-overlapping port ranges:You will need to allow them through your firewall. If you use UFW, the commands are:The other guide does not presume a specific firewall. I do not see why this guide should either. If it were up to me, I wouldn't mention this at all, but if it's going to be there, this is too much.
It does - https://continuwuity.org/calls/livekit#firewall-hints
@ -34,0 +87,4 @@ufw allow 49152-65535/udp```::: tip For LiveKit usersThis tip appears improperly formatted compared to the tip earlier in the file.
@ -39,2 +98,4 @@``````bash# With ufwAgain, this should be removed.
@ -74,2 +109,3 @@### 5. Security RecommendationsFor security best practices, see Synapse's [Coturn documentation](https://element-hq.github.io/synapse/latest/turn-howto.html), which includes important firewall and access control recommendations.For Coturn hardening and security best practices, see Synapse's [Coturn documentation][synapse-coturn-guide],This is the first place where hard wrapping has been used.
@ -146,3 +143,3 @@### Testing CredentialsVerify that Continuwuity is correctly serving TURN credentials to clients:Get an access token for your current login session. These can be found in your client's settings or obtained via [this website](https://timedout.uk/mxtoken.html).According to @nex's own site, this should not be used. It does link to https://starstruck.systems/matrix/tools/mxtoken2 though, which may be a suitable alternative.
@ -182,1 +173,3 @@4. Look for successful `relay` candidates in the results1. Copy the URIs and credentials from the response above2. Paste them into the Trickle ICE testing tool, and click on "Add server"3. When finished adding all URIs and credentials, click "Gather candidates"This should read "Once all the URIs and credentials have been added,"
@ -186,3 +181,3 @@## Troubleshooting### Clients can't connect to TURN serverTo gather debug logs while troubleshooting Coturn, add `verbose` to your `coturn.conf`. You can then view these logs with `docker-compose logs --follow coturn`.docker compose@ -196,0 +192,4 @@- Ensure your `turn_secret` matches coturn's `static-auth-secret`- Ensure the credentials you obtained from the Testing steps has not expired yet. You can adjust `turn_ttl` in your Continuwuity configuration to increase this, or simply re-request a new one- Wrong IP address advertised- This may be caused by coturn not recognizing its public-facing IP correctly, due to particular network setups. You can configure `external-ip=<desired-public-ip>` to fix this issue."due to particular network setups" is broadly unhelpful
@ -215,0 +225,4 @@### TURNS-over-443Normally, TURN would work on their default setups. However, there are situations where clients are in very restrictive networks that disallows non-standard ports and UDP. In these cases, a TURN-over-TLS server on port :443 could be employed to relay traffic for them.Mirrored feedback here from the other document. Also, given that these seem to touch on a very similar topic, they should probably both live in a single section in a single document.
@ -29,19 +29,12 @@ we can't cross-build static binaries - contributions are welcome here.The changes in this file are not TURN related.
lveneris referenced this pull request2026-08-04 19:50:03 +00:00