Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 02f91d6

Browse files
committed
Update documentation for TURN server for 20.04
1 parent ccc126a commit 02f91d6

File tree

1 file changed

+108
-93
lines changed

1 file changed

+108
-93
lines changed

_posts/2019-02-14-setup-turn-server.md

Lines changed: 108 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ order: 4
99

1010
This document covers how to setup a TURN server for BigBlueButton to allow users behind restrictive firewalls to connect.
1111

12-
# Setup a TURN server
12+
You can also use [bbb-install.sh](https://github.com/bigbluebutton/bbb-install#install-a-turn-server) to automate the steps in this document.
1313

14-
** This section is being updated for steps to install on Ubuntu 20.04. If you want to setup a TURN server, please use [bbb-install.sh](https://github.com/bigbluebutton/bbb-install#install-a-turn-server). **
14+
# Setup a TURN server
1515

1616
BigBlueButton normally requires a wide range of UDP ports to be available for WebRTC communication. In some network restricted sites or development environments, such as those behind NAT or a firewall that restricts outgoing UDP connections, users may be unable to make outgoing UDP connections to your BigBlueButton server.
1717

@@ -44,7 +44,7 @@ Note: coturn will not automatically start until configuration is applied (see be
4444

4545
## Required DNS Entry
4646

47-
You need to setup a fully qualified domain name that resolves to the external IP address of your turn server. You'll used this domain name to generate a TLS certificate using Let's Encrypt (next section).
47+
You need to setup a fully qualified domain name that resolves to the external IP address of your turn server. You'll use this domain name to generate a TLS certificate using Let's Encrypt (next section).
4848

4949
## Required Ports
5050

@@ -66,41 +66,57 @@ $ sudo apt-get update
6666
$ sudo apt-get install certbot
6767
```
6868

69-
You can then run a `certbot` command like the following to generate the certificate, replacing `turn.example.com` with the domain name of your TURN server:
69+
You can then run a `certbot` command like the following to generate the certificate, replacing `<turn.example.com>` with the domain name of your TURN server:
7070

7171
```bash
7272
$ sudo certbot certonly --standalone --preferred-challenges http \
73-
--deploy-hook "systemctl restart coturn" \
74-
-d turn.example.com
73+
-d <turn.example.com>
74+
```
75+
76+
Current versions of the certbot command set up automatic renewal by default. To ensure that the certificates are readable by `coturn`, which runs as the `turnserver` user, add the following renewal-hook to Let's Encrypt. First, create the directory `/etc/letsencrypt/renewal-hooks/deploy`.
77+
78+
79+
```bash
80+
$ sudo mkdir -p /etc/letsencrypt/renewal-hooks/deploy
81+
```
82+
83+
Next, create the file `/etc/letsencrypt/renewal-hooks/deploy/coturn` with the following contents. Replace <turn.example.com> with the hostname of your TURN server.
84+
85+
```
86+
#!/bin/bash -e
87+
for certfile in fullchain.pem privkey.pem ; do
88+
cp -L /etc/letsencrypt/live/<turn.example.com>/"${certfile}" /etc/turnserver/"${certfile}".new
89+
chown turnserver:turnserver /etc/turnserver/"${certfile}".new
90+
mv /etc/turnserver/"${certfile}".new /etc/turnserver/"${certfile}"
91+
done
92+
systemctl kill -sUSR2 coturn.service
7593
```
7694

77-
Current versions of the certbot command set up automatic renewal by default. Note that when certbot renews the certificate, it will restart coturn so coturn will start to use the updated certificate files. This will interrupt any ongoing TURN connections. You may wish to change the schedule of certbot renewals or disable automatic renewal if this is a concern.
95+
Make this file executable.
96+
97+
```
98+
$ sudo chmod 0755 /etc/letsencrypt/renewal-hooks/deploy/coturn
99+
```
78100

79101
## Configure coturn
80102

81-
`coturn` configuration is stored in the file `/etc/turnserver.conf`. There are a lot of options available, all documented in comments in that file. We include a sample configuration below with comments indicating the recommended settings, with some notes in locations where customization is required.
103+
`coturn` configuration is stored in the file `/etc/turnserver.conf`. There are a lot of options available, all documented in comments in the default configuration file. We include a sample configuration below with the recommended settings (refer to the default configuration file for more information on the settings)..
82104

83-
You can repace the contents `/etc/turnserver.conf` with this file and make two changes:
105+
Use the file below for `/etc/turnserver.conf` and make the following changes:
84106

85-
* Replace `turn.example.com` with the hostname of your TURN server, and
86-
* Replace `<random value>` to a random value for a shared secret (instructions for generating a new secret are in a comment in the file).
107+
* Replace `<turn.example.com>` with the hostname of your TURN server, and
108+
* Replace `<example.com>` with the realm of your TURN server, and
109+
* Replace `<secret_value>` to a random value for a shared secret (you can generate one by running `openssl rand -hex 16`)
110+
* Replace `<IP>` with the external IP of your TURN server
87111

88-
Attention: The `turnserver` process will run as the `turnserver` user, which usually doesn't have access to the certificates/keys in `/etc/letsencrypt/live`. It is recommended that you either create a `ssl-cert` user group, add the `turnserver` user to it and adjust the permissions for `/etc/letsencrypt/live` such that the group can read it or, alternatively, copy the certificates/keys to a safe location (that `turnserver` has access to) after each certificate renewal.
112+
This configuration file assumes your TURN server is not behind NAT and has a public IP address.
89113

90114
```ini
91-
# Example coturn configuration for BigBlueButton
92-
93-
# These are the two network ports used by the TURN server which the client
94-
# may connect to. We enable the standard unencrypted port 3478 for STUN,
95-
# as well as port 443 for TURN over TLS, which can bypass firewalls.
96115
listening-port=3478
97116
tls-listening-port=443
98117

99-
# If the server has multiple IP addresses, you may wish to limit which
100-
# addresses coturn is using. Do that by setting this option (it can be
101-
# specified multiple times). The default is to listen on all addresses.
102-
# You do not normally need to set this option.
103-
#listening-ip=172.17.19.101
118+
listening_ip=$IP
119+
relay_ip=$IP
104120

105121
# If the server is behind NAT, you need to specify the external IP address.
106122
# If there is only one external address, specify it like this:
@@ -111,97 +127,96 @@ tls-listening-port=443
111127
#external-ip=172.17.19.131/10.0.0.11
112128
#external-ip=172.17.18.132/10.0.0.12
113129

114-
# Fingerprints in TURN messages are required for WebRTC
115-
fingerprint
130+
min-port=32769
131+
max-port=65535
132+
verbose
116133

117-
# The long-term credential mechanism is required for WebRTC
134+
fingerprint
118135
lt-cred-mech
119-
120-
# Configure coturn to use the "TURN REST API" method for validating time-
121-
# limited credentials. BigBlueButton will generate credentials in this
122-
# format. Note that the static-auth-secret value specified here must match
123-
# the configuration in BigBlueButton's turn-stun-servers.xml
124-
# You can generate a new random value by running the command:
125-
# openssl rand -hex 16
126136
use-auth-secret
127-
static-auth-secret=<random value>
128-
129-
# If the realm value is unspecified, it defaults to the TURN server hostname.
130-
# You probably want to configure it to a domain name that you control to
131-
# improve log output. There is no functional impact.
132-
realm=example.com
133-
134-
# Configure TLS support.
135-
# Adjust these paths to match the locations of your certificate files
136-
cert=/etc/letsencrypt/live/turn.example.com/fullchain.pem
137-
pkey=/etc/letsencrypt/live/turn.example.com/privkey.pem
138-
# Limit the allowed ciphers to improve security
139-
# Based on https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
140-
cipher-list="ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS"
141-
142-
# Enable longer DH TLS key to improve security
143-
dh2066
144-
145-
# All WebRTC-compatible web browsers support TLS 1.2 or later, so disable
146-
# older protocols
137+
static-auth-secret=<secret_value>
138+
realm=<example.com>
139+
140+
cert=/etc/turnserver/fullchain.pem
141+
pkey=/etc/turnserver/privkey.pem
142+
# From https://ssl-config.mozilla.org/ Intermediate, openssl 1.1.0g, 2020-01
143+
cipher-list="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
144+
dh-file=/etc/turnserver/dhp.pem
145+
146+
keep-address-family
147+
no-cli
147148
no-tlsv1
148149
no-tlsv1_1
150+
```
149151

150-
# Log to a single filename (rather than new log files each startup). You'll
151-
# want to install a logrotate configuration (see below)
152-
log-file=/var/log/coturn.log
152+
We need to create `dph.pem` file,
153153

154-
# To enable single filename logs you need to enable the simple-log flag
155-
simple-log
154+
```bash
155+
$ sudo mkdir -p /etc/turnserver
156+
$ sudo openssl dhparam -dsaparam -out /etc/turnserver/dhp.pem 2048
157+
```
156158

157-
# Lower and upper bounds of the UDP relay endpoints:
158-
# (default values are 49152 and 65535)
159-
#
160-
min-port=32768
161-
max-port=65535
159+
To increase the file handle limit for the TURN server and to give it the ability to bind to port 443, add the following systemd override file. First, create the directory.
160+
161+
```bash
162+
$ sudo mkdir -p /etc/systemd/system/coturn.service.d
162163
```
163164

164-
If the TURN server is used by many users concurrently, it might hit the open file-handles limit. Therefore it is recommended to increase this limit by adding `ulimit -n 49152` in `/etc/init.d/coturn` or editing the systemd service specification using `sudo systemctl edit --full coturn` and then adding `LimitNOFILE=49152`. Once this change is applied, restart the coturn service.
165+
and then then create `/etc/systemd/system/coturn.service.d/override.conf` with the following contents
166+
167+
```
168+
[Service]
169+
LimitNOFILE=1048576
170+
AmbientCapabilities=CAP_NET_BIND_SERVICE
171+
ExecStart=
172+
ExecStart=/usr/bin/turnserver --daemon -c /etc/turnserver.conf --pidfile /run/turnserver/turnserver.pid --no-stdout-log --simple-log --log-file /var/log/turnserver/turnserver.log
173+
Restart=always
174+
```
165175

166176
## Configure Log Rotation
167177

168178
To rotate the logs for `coturn`, install the following configuration file to `/etc/logrotate.d/coturn`
169179

170180
```
171-
/var/log/coturn.log
181+
/var/log/turnserver/*.log
172182
{
173-
rotate 30
174-
daily
175-
missingok
176-
notifempty
177-
delaycompress
178-
compress
179-
postrotate
180-
systemctl kill -sHUP coturn.service
181-
endscript
183+
rotate 7
184+
daily
185+
missingok
186+
notifempty
187+
compress
188+
postrotate
189+
/bin/systemctl kill -s HUP coturn.service
190+
endscript
182191
}
183192
```
184193

185-
## Enabling the coturn service
194+
And create the associated log directory
186195

187-
The ubuntu package for `coturn` requires that you edit a file to enable startup. Edit the file `/etc/default/coturn` and ensure the following line is uncommented:
188-
189-
```ini
190-
TURNSERVER_ENABLED=1
191196
```
197+
$ sudo mkdir -p /var/log/turnserver
198+
$ sudo chown turnserver:turnserver /var/log/turnserver
199+
```
200+
201+
## Restart coturn
192202

193-
You can then start the coturn service by running
203+
With the above steps completed, restart the TURN server
194204

195205
```bash
196-
$ systemctl start coturn
206+
$ sudo /etc/letsencrypt/renewal-hooks/deploy/coturn # Initial copy of certificates
207+
$ sudo systemctl daemon-reload # Ensure the override file is loaded
208+
$ sudo systemctl restart coturn # Restart
197209
```
198210

199-
## Configure BigBlueButton to use the coturn server
211+
Ensure that the `coturn` has binded to port 443 with `netstat -antp | grep 443`. Also restart your TURN server and ensure that `coturn` is running (and binding to port 443 after restart).
212+
213+
214+
# Configure BigBlueButton to use your TURN server
200215

201216
You must configure bbb-web so that it will provide the list of turn servers to the web browser. Edit the file `/usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml` using the contents below and make edits:
202217

203-
* replace both instances of `turn.example.com` with the hostname of the TURN server, and
204-
* replace `<random value>` with the secret you configured in `turnserver.conf`.
218+
* replace both instances of `<turn.example.com>` with the hostname of the TURN server, and
219+
* replace `<secret_value>` with the secret you configured in `turnserver.conf`.
205220

206221
```xml
207222
<?xml version="1.0" encoding="UTF-8"?>
@@ -211,19 +226,19 @@ You must configure bbb-web so that it will provide the list of turn servers to t
211226
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
212227

213228
<bean id="stun0" class="org.bigbluebutton.web.services.turn.StunServer">
214-
<constructor-arg index="0" value="stun:turn.example.com"/>
229+
<constructor-arg index="0" value="stun:<turn.example.com>"/>
215230
</bean>
216231

217232

218233
<bean id="turn0" class="org.bigbluebutton.web.services.turn.TurnServer">
219-
<constructor-arg index="0" value="<random value>"/>
220-
<constructor-arg index="1" value="turns:turn.example.com:443?transport=tcp"/>
234+
<constructor-arg index="0" value="<secret_value>"/>
235+
<constructor-arg index="1" value="turns:<turn.example.com>:443?transport=tcp"/>
221236
<constructor-arg index="2" value="86400"/>
222237
</bean>
223238

224239
<bean id="turn1" class="org.bigbluebutton.web.services.turn.TurnServer">
225-
<constructor-arg index="0" value="<random value>"/>
226-
<constructor-arg index="1" value="turn:turn.example.com:443?transport=tcp"/>
240+
<constructor-arg index="0" value="<secret_value>"/>
241+
<constructor-arg index="1" value="turn:<turn.example.com>:443?transport=tcp"/>
227242
<constructor-arg index="2" value="86400"/>
228243
</bean>
229244

@@ -288,16 +303,16 @@ Filtering test: success
288303
Nat filtering: Endpoint Independent Filtering
289304
```
290305

291-
If you get an error, check that `coturn` is running on the TURN server using `systemctl status coturn.service`. Check the logs by doing `tail -f /var/log/coturn.log`. You can get verbose logs by adding `verbose` to `/etc/turnserver.conf` and restarting the TURN server `systemctl restart coturn.service`
306+
If you get an error, check that `coturn` is running on the TURN server using `systemctl status coturn.service`. Check the logs by doing `tail -f /var/log/turnserver/coturn.log`. You can get verbose logs by adding `verbose` to `/etc/turnserver.conf` and restarting the TURN server `systemctl restart coturn.service`
292307

293308

294-
You can test your TURN server using the [trickle ICE](https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/) page. This gives you a log of the relay candidates as they are returned from ICE gathering. To test using this page, you need to generate some test credentials. Run the following BASH script and substitute `<host>` with the hostname of your TURN server and `<password>` with the password for your TURN server.
309+
You can test your TURN server using the [trickle ICE](https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/) page. This gives you a log of the relay candidates as they are returned from ICE gathering. To test using this page, you need to generate some test credentials. Run the following BASH script and substitute `<turn.example.com>` with the hostname of your TURN server and `<secret_value>` with the password for your TURN server.
295310

296311
```bash
297312
#!/bin/bash
298313

299-
HOST=<host>
300-
SECRET=<password>
314+
HOST=<turn.example.com>
315+
SECRET=<secret_value>
301316

302317
time=$(date +%s)
303318
expiry=8400
@@ -313,6 +328,6 @@ echo
313328

314329
```
315330

316-
Enter the values into URI, username, and password into the trickle ICE page and click 'Gather candidates'. You should see a list of relay candidates. If you don't, again check that your TURN server is running and tail the logs TURN server logs via `tail -f /var/log/coturn.log` or `journalctl -f -u coturn.service`.
331+
Enter the values into URI, username, and password into the trickle ICE page and click 'Gather candidates'. You should see a list of relay candidates. If you don't, again check that your TURN server is running and tail the logs TURN server logs via `tail -f /var/log/turnserver/coturn.log` or `journalctl -f -u coturn.service`.
317332

318333
You can get verbose logs by adding `verbose` to `/etc/turnserver.conf` and then restarting the TURN server `systemctl restart coturn.service`, and try testing again from FireFox or the above Tricke ICE page.

0 commit comments

Comments
 (0)