diff options
| author | Denshi <alex@denshi.org> | 2023-03-21 19:58:09 +0400 |
|---|---|---|
| committer | Denshi <alex@denshi.org> | 2023-03-21 19:58:09 +0400 |
| commit | 46a8ff50ef16904e1a5140550a11616c38f6cbcb (patch) | |
| tree | e3f6907d38a6c13974c8d2ddcfc8c43aeae57842 | |
| parent | 0d8a5922c1436f0b563fe59a720923b94f820ac5 (diff) | |
Added Dendrite guide, added voice and video calling guide to Prosody, fixed up ejabberd PostgreSQL so it applies to all modules
| -rw-r--r-- | content/coturn.md | 5 | ||||
| -rw-r--r-- | content/dendrite.md | 292 | ||||
| -rw-r--r-- | content/ejabberd.md | 78 | ||||
| -rw-r--r-- | content/matrix.md | 37 | ||||
| -rw-r--r-- | content/prosody.md | 29 |
5 files changed, 401 insertions, 40 deletions
diff --git a/content/coturn.md b/content/coturn.md index 614b87c..b49c47c 100644 --- a/content/coturn.md +++ b/content/coturn.md @@ -102,6 +102,11 @@ systemctl restart coturn At this stage, you should look in your application's own guide on how to set the TURN and STUN server settings. Configure it to point at **turn.example.org** and use either your **username and password pair** or your super-secure **authentication secret.** +- [How to configure TURN on ejabberd](/ejabberd#voice-and-video-calls) +- [How to configure TURN on Prosody](/prosody#voice-and-video-calls) +- [How to configure TURN on Matrix Synapse](/matrix#voice-and-video-calls) +- [How to configure TURN on Matrix Dendrite](/dendrite#voice-and-video-calls) + Congratulations! You've successfully setup a Coturn server! --- diff --git a/content/dendrite.md b/content/dendrite.md new file mode 100644 index 0000000..79d2417 --- /dev/null +++ b/content/dendrite.md @@ -0,0 +1,292 @@ +--- +title: "Matrix Dendrite" +date: 2023-03-21 +icon: 'element.svg' +tags: ['service'] +short_desc: "A faster server implementation of Matrix." +--- + +The Matrix protocol's default implementation, [Synapse,](/matrix) is very memory and processor hungry, mostly due to it being written in the *interpreted Python programming language.* This means that running Synapse on less powerful servers may **take a lot of resources away** from other services. If you need a more efficient and less memory-intensive but still fully functional Matrix server, then [Dendrite](https://github.com/matrix-org/dendrite) is for you. + +## Prerequisities + +### DNS Records and Delegation + +You are **not required** to run a Matrix server under a subdomain (like **matrix.example.org**), regardless of server software. You can run your server under **example.org** to ensure usernames and rooms look like `@user:example.org` and `#room:example.org` respectively. + +Because Matrix uses **HTTP** for transport over the SSL ports (443 and 8448), you'll have to configure NGINX for it to work. This can cause confusion, especially if you're running both a [static website](/basic/nginx/) and Matrix server under the same domain (like **example.org**). + +Depending on your setup, there are 2 different configurations to achieve this: + +1. Your *desired* domain (**example.org**) has an [A DNS record](http://localhost:1313/basic/dns/) that already poinst to your desired Matrix server, so you can configure this or add to your existing NGINX static site configuration to setup Matrix. + +2. You wish to use Matrix with your *desired* domain (**example.org**) but this domain's A record points to a different server, accessible through another domain (like **matrix.example.org**). In this case, look into [delegation.](https://matrix-org.github.io/synapse/latest/delegate.html) + + +### NGINX Configuration + +Here's an example configuration for a Matrix server running under **example.org:** + +```nginx +server { + server_name {{<hl>}}example.org{{</hl>}}; + + listen 80; + listen [::]:80; + + listen 443 ssl http2 default_server; + listen [::]:443 ssl http2 default_server; + + listen 8448 ssl http2 default_server; + listen [::]:8448 ssl http2 default_server; + + location ~* ^(\/_matrix|\/_synapse|\/_client) { + proxy_pass http://localhost:8008; + proxy_set_header X-Forwarded-For $remote_addr; + client_max_body_size {{<hl>}}50M{{</hl>}}; + } + + # These sections are required for client and federation discovery + # (AKA: Client Well-Known URI) + location /.well-known/matrix/client { + return 200 '{"m.homeserver": {"base_url": "https://{{<hl>}}example.org{{</hl>}}"}}'; + default_type application/json; + add_header Access-Control-Allow-Origin *; + } + + location /.well-known/matrix/server { + return 200 '{"m.server": "{{<hl>}}example.org{{</hl>}}:443"}'; + default_type application/json; + add_header Access-Control-Allow-Origin *; + } +} +``` + +Let's say you also want to run a **static website** under **example.org.** This can be achieved by adding these usual lines under the `server` section: + +```nginx + # Basic static site configuration, like any other site + root /var/www/{{<hl>}}example.org{{</hl>}}; + index index.html; + + location / { + try_files $uri $uri/ =404; + } +``` + +#### Certbot Certificates + +Finally, make sure to download and enable TLS certificates for this setup by using the `certbot` command: + +```sh +certbot --nginx -d {{<hl>}}example.org{{</hl>}} +``` + +## Installation + +Dendrite has no official distribution packages at the time of writing. To install and run it, you must first install *the Go programming language* and then compile the Dendrite software from source. + +### Installing Go + +First, download the latest Go tarball: +```sh +curl -fLO "https://dl.google.com/go/$(curl https://go.dev/VERSION?m=text).linux-amd64.tar.gz" +``` + +Then, extract the contents to `/usr/local`, which will create the directory `/usr/local/go`: +```sh +tar -C /usr/local -xzfv go*.tar.gz +``` + +Then finally, make sure the `/usr/local/go/bin/` path is accessible in the `$PATH` variable for every user by editing `/etc/profile` and adding the following line: + +```sh +export PATH=$PATH:/usr/local/go/bin +``` + +### Compiling and Installing Dendrite + +Besides Go, we also need the `build-essential` package to compile software: + +```sh +apt install build-essential +``` + +Now download the Dendrite repository using `git` and change directory to it: + +```sh +git clone https://github.com/matrix-org/dendrite +cd dendrite +``` +Finally, run the `./build.sh` script to compile Dendrite: + +```sh +./build.sh +``` + +*This might take a few minutes,* but once the process is finished you should find the final Dendrite programs populating the `bin/` directory. + +## Configuration + +To configure Dendrite, begin by coping the `dendrite-sample.yaml` configuration file to `dendrite.yaml`: + +```sh +cp dendrite-sample.yaml dendrite.yaml +``` + +To configure your domain, edit the following under the `global:` section: + +```yaml +server_name: {{<hl>}}example.org{{</hl>}} +``` + +### Server Signing Keys + +Generate the signing keys used by your homeserver with the following command, ran from the Dendrite repository: + +```sh +./bin/generate-keys --private-key matrix_key.pem +``` + +You can also import old keys from Synapse, by specifying their file path in the `old_private_keys:` variable in `dendrite.yaml`. + +### Database Configuration + +By default, Dendrite will create SQLite databases for all its various components. On most server deployments however, it is beneficial to run Dendrite with a more efficient database backend, like PostgreSQL. + +Begin by installing PostgreSQL: + +```sh +apt install postgresql +``` + +Then start the daemon: + +```sh +systemctl restart postgresql +``` + +Now create a user named `dendrite` to manage your database: + +```sh +su -c "createuser --pwprompt dendrite" postgres +``` + +And finally, create the actual database: + +```sh +su -c "psql -c 'CREATE DATABASE dendrite ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER dendrite;'" postgres +``` + +Now we can configure this in `dendrite.yaml` using the `connection_string:` option under the `database:` section: + +```yaml + database: + connection_string: postgres://dendrite:{{<hl>}}password{{</hl>}}@localhost/dendrite?sslmode=disable + max_open_conns: 90 + max_idle_conns: 5 + conn_max_lifetime: -1 +``` + +**Important:** If you find `database:` sub-sections under the individual Dendrite modules in `dendrite.yaml` (`app_service_api`, `federation_api`, `key_server`, `media_api`, `mscs`, `room_server`, `sync_api` and `user_api`), make sure to **comment these out** as these would override the global `database` configuration. + +### Voice and Video Calls + +Dendrite supports native voice and video calling by connecting to a compatible TURN and STUN server. + +Begin by setting up the [coturn](/coturn) TURN server using the guide provided, setting either a shared secret or a username-password pair for authentication. + +Then edit the `turn:` section in `dendrite.yaml`: + +```yaml + turn: + turn_user_lifetime: "5m" + turn_uris: + - turn:{{<hl>}}turn.example.org{{</hl>}}?transport=udp + - turn:{{<hl>}}turn.example.org{{</hl>}}?transport=tcp + + turn_shared_secret: "{{<hl>}}your_shared_secret{{</hl>}}" + + # If your TURN server requires static credentials, then you will need to enter + # them here instead of supplying a shared secret. Note that these credentials + # will be visible to clients! + # turn_username: "" + # turn_password: "" +``` + +### File Directory and Ownership + +Like [Synapse,](/matrix) it's recommended you place the Dendrite program files in `/opt` to keep your server organized: + +```sh +mv dendrite/ /opt/ +``` + +It's also recommended you create a `dendrite` user, who will own the `/opt/dendrite` directory, so it can be used to run Dendrite as a service: + +```sh +useradd dendrite -d /opt/dendrite +chown -R dendrite:dendrite /opt/dendrite +``` + +### Setting up a systemd Service + +Now setup a **systemd service** to run Dendrite automatically for you. Make sure to set the `WorkingDirectory` to the directory where your Dendrite repository is located! + +```systemd +[Unit] +Description=Dendrite (Matrix Homeserver) +After=syslog.target +After=network.target +After=postgresql.service ## Remove this if you're not using PostgreSQL + +[Service] +Environment=GODEBUG=madvdontneed=1 +RestartSec=2s +Type=simple +User={{<hl>}}dendrite{{</hl>}} +Group={{<hl>}}dendrite{{</hl>}} +WorkingDirectory={{<hl>}}/opt/dendrite/{{</hl>}} +ExecStart={{<hl>}}/opt/dendrite/bin/dendrite{{</hl>}} +Restart=always +LimitNOFILE=65535 + +[Install] +WantedBy=multi-user.target +``` + +Refresh the systemd daemon configuration by running: + +```sh +systemctl daemon-reload +``` + +And finally, **run Dendrite** by running: + +```sh +systemctl restart dendrite +``` + +## Using Dendrite + +### Creating Users + +To create users on the Dendrite server, first ensure it is running. Then, enter a secret value into the `registration_shared_secret:` field under the `client_api` section: + +```yaml +registration_shared_secret: "your_secret_string" +``` + + Then, use the `./bin/create-account` tool located in its repository: + +```sh +./bin/create-account -config dendrite.yaml -username {{<hl>}}user{{</hl>}} -admin +``` +This will automatically prompt you for a password. + +Congratulations! You've installed the Matrix Dendrite homeserver. Now you can login with any [Matrix client](https://matrix.org/clients/) you wish, and chat securely. + +--- +Written by [Denshi.](https://denshi.org) +Donate Monero at: +`48dnPpGgo8WernVJp5VhvhaX3u9e46NujdYA44u8zuMdETNC5jXiA9S7JoYMM6qRt1ZcKpt1J3RZ3JPuMyXetmbHH7Mnc9C` diff --git a/content/ejabberd.md b/content/ejabberd.md index b8579cd..c725465 100644 --- a/content/ejabberd.md +++ b/content/ejabberd.md @@ -17,10 +17,26 @@ Ejabberd presumes that you have already created all the **required and optional Depending on the usecase, you may need any or all of the following domains for XMPP functionality: - **example.org** - Your XMPP hostname -- **conference.example.org** - For Multi User Chats (MUCs) -- **upload.example.org** - For file upload support -- **proxy.example.org** - For SOCKS5 proxy support -- **pubsub.example.org** - For publish-subscribe support (A fancier RSS) +- **conference.example.org** - For `mod_muc`, Multi User Chats (MUCs) +- **upload.example.org** - For `mod_http_upload`, file upload support +- **proxy.example.org** - For `mod_proxy65`, SOCKS5 proxy support +- **pubsub.example.org** - For `mod_pubsub`, publish-subscribe support (A fancier RSS) + +Only the **example.org** domain is required for basic, private chat usage. +If you do **not** wish to use a certain domain, just disable it's associated module and ejabberd won't complain when it can't find it's associated certificate. +For example, if you don't want [Publish-Subscribe](https://xmpp.org/extensions/xep-0060.html) support, just comment out the `mod_pubsub` config in `/etc/ejabberd.yml`: + +```yml +## mod_pubsub: +## access_createnode: pubsub_createnode +## plugins: +## - flat +## - pep +## force_node_config: +## ## Avoid buggy clients to make their bookmarks public +## storage:bookmarks: +## access_model: whitelist +``` This guide will assume **all these subdomains** have been created. @@ -213,16 +229,37 @@ sql_server: "localhost" sql_database: "{{<hl>}}ejabberd{{</hl>}}" sql_username: "{{<hl>}}ejabberd{{</hl>}}" sql_password: "{{<hl>}}psql_password{{</hl>}}" + +default_db: sql ``` +That line at the end sets **every module's database** to default to the `sql` backend. This includes the `mod_mam` module, so all our data is being stored with PostgreSQL. + +### Voice and Video Calls -Once you've ensured your database name, username and password are all correct, enable SQL storage for `mod_mam`: +Ejabberd supports the **TURN** and **STUN** protocols to allow internet users behind NATs to perform voice and video calls with other XMPP users. **This is enabled by default using [ejabberd_stun](https://docs.ejabberd.im/admin/configuration/listen#ejabberd-stun-1).** + +**However,** if you plan on running ejabberd alongside **other applications** that require TURN and STUN, such as Matrix, then you'll have to setup your own external TURN server using Coturn. + +#### Setup with Coturn and `mod_stun_disco` + +Firstly, setup a TURN and STUN server with [Coturn,](/coturn) using an **authentication secret.** + +Then, edit `mod_stun_disco` to contain the appropriate information for +your turnserver: ```yml -mod_mam: - ## (Other parameters above) - db_type: sql + mod_stun_disco: + secret: "{{<hl>}}your_auth_secret{{</hl>}}" + services: + - + host: {{<hl>}}turn.example.org{{</hl>}} + type: stun + - + host: {{<hl>}}turn.example.org{{</hl>}} + type: turn ``` + ## Using ejabberd ### Registering the Admin User @@ -252,31 +289,6 @@ your ejabberd server from this web interface: {{< img src="/pix/ejabberd-admin.webp" >}} -## TURN & STUN for Calls - -Ejabberd supports the **TURN** and **STUN** protocols to allow internet users behind NATs to perform voice and video calls with other XMPP users. **This is enabled by default using [ejabberd_stun](https://docs.ejabberd.im/admin/configuration/listen#ejabberd-stun-1).** - -**However,** if you plan on running ejabberd alongside **other applications** that require TURN and STUN, such as Matrix, then you'll have to setup your own external TURN server using Coturn. - -### Setup with Coturn and `mod_stun_disco` - -Firstly, setup a TURN and STUN server with [Coturn,](/coturn) using an **authentication secret.** - -Then, edit `mod_stun_disco` to contain the appropriate information for -your turnserver: - -```yml - mod_stun_disco: - secret: "{{<hl>}}your_auth_secret{{</hl>}}" - services: - - - host: {{<hl>}}turn.example.org{{</hl>}} - type: stun - - - host: {{<hl>}}turn.example.org{{</hl>}} - type: turn -``` - ## Further Configuration For a deeper look into all the modules and options, have a look at the following ejabberd documentation: diff --git a/content/matrix.md b/content/matrix.md index 0b71d7b..76bb816 100644 --- a/content/matrix.md +++ b/content/matrix.md @@ -151,13 +151,42 @@ registration_shared_secret: {{<hl>}}???{{</hl>}} Then, run the following command to register a user: ```sh -cd /etc/matrix-synapse - -register_new_matrix_user -c homeserver.yaml http://localhost:8008 +register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml ``` This command will prompt you for a username, password and whether to make the user an admin or not. +### Voice and Video Calls + +For native voice and video call support, the Synapse homserver needs to interface with a working **TURN and STUN Server.** + +First, follow the guide on installing and setting up [coturn](/coturn), setting either a shared secret or username-password pair for authentication. + +Then, in `/etc/matrix-synapse/homeserver.yaml`, edit the configuration as follows: + +```yaml +turn_uris: [ "turn:{{<hl>}}turn.example.org{{</hl>}}?transport=udp", "turn:{{<hl>}}turn.example.org{{</hl>}}?transport=tcp" ] + +## This is how long call credentials are valid. Lessen to prevent abuse. +turn_user_lifetime: 86400000 + +## Keep this enabled unless for security reasons. +turn_allow_guests: True +``` + +If you're using a shared secret, add the following config: + +```yaml +turn_shared_secret: "{{<hl>}}your secret here{{</hl>}}" +``` + +Otherwise, add this config if you're using username-password pairs: + +```yaml +turn_username: "{{<hl>}}turnserver_username{{</hl>}}" +turn_password: "{{<hl>}}turnserver_password{{</hl>}}" +``` + ### URL Previews To enable server-generated previews of webpages, change this line to true in `/etc/matrix-synapse/homeserver.yaml`: @@ -166,7 +195,7 @@ To enable server-generated previews of webpages, change this line to true in `/e url_preview_enabled: true ``` -And make sure to uncomment the `url_preview_ip_range_blacklist:` section; Otherwise, Synapse will refuse to start up again! +And **make sure to uncomment** the `url_preview_ip_range_blacklist:` section; Otherwise, Synapse will refuse to start up again! ### Federation diff --git a/content/prosody.md b/content/prosody.md index 5c6bbc1..2797a8e 100644 --- a/content/prosody.md +++ b/content/prosody.md @@ -64,7 +64,7 @@ The second line is important because it prevents non-admins from creating and sq Read more about the `muc` plugin on the Prosody documentation page [here](https://prosody.im/doc/modules/mod_muc). -### Enabling chat histories +### Enabling Chat Histories By default, Prosody will send out messages received only to the first available clients. That means that if you have your desktop client turned off and your cell phone receives a message, @@ -104,8 +104,9 @@ As you will notice, you need another subdomain for this. We will add an ssl cert You will also need to go back to `modules_enabled` and uncomment the `http_files` module. This is used to actually serve the files to users. -And the last part of the setup is to enable the built in proxy server. -This helps with file transfers for devices behind a NAT, and unless you are using XMPP in a LAN, you probably need this. +### Proxy Support + +This helps with file transfers for devices behind a NAT, and unless you are using XMPP in a LAN, you **probably need this.** Enable the proxy by adding the following line to the config: ```cfg @@ -154,6 +155,28 @@ sql = { (This is assuming you've installed the `postgresql` package, and setup a database named `prosody` with a user named `prosody` as the owner.) +### Voice and Video Calling + +Prosody supports XMPP voice and video calls through an external TURN and STUN server. + +First, follow the guide on installing and setting up [coturn,](/coturn) setting **only a shared secret** for authentication. + +Then, uncomment the `turn_external` module in the modules section in `prosody.cfg.lua`. + +```cfg +"turn_external"; +``` + +Finally, specify the host and credentials lower in the config: + +```cfg +-- Specify the address of the TURN service (you may use the same domain as XMPP) +turn_external_host = "{{<hl>}}turn.example.org{{</hl>}}" + +-- This secret must be set to the same value in both Prosody and the TURN server +turn_external_secret = "{{<hl>}}your shared secret{{</hl>}}" +``` + ### Other things to check Check the config file for other settings you might want to change. For example, if you want to run a general public XMPP server, you can allow anyone to create an account by changing `allow_registration` to `true`. |
