• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.ci/H03-May-2022-219103

.github/H24-Jan-2022-909779

changelog.d/H24-Jan-2022-21

contrib/H24-Jan-2022-15,24214,146

debian/H24-Jan-2022-2,8461,763

demo/H24-Jan-2022-233163

docker/H24-Jan-2022-1,8951,364

docs/H03-May-2022-18,32714,322

scripts/H24-Jan-2022-1,9131,363

scripts-dev/H24-Jan-2022-2,4831,671

snap/H24-Jan-2022-5855

stubs/H24-Jan-2022-567531

synapse/H03-May-2022-180,334126,499

synmark/H24-Jan-2022-347198

tests/H24-Jan-2022-81,45558,630

.codecov.ymlH A D24-Jan-2022264 1513

.coveragercH A D24-Jan-2022110 97

.dockerignoreH A D24-Jan-2022139 1411

.editorconfigH A D24-Jan-2022149 107

.git-blame-ignore-revsH A D24-Jan-2022229 96

.gitignoreH A D24-Jan-2022550 5348

AUTHORS.rstH A D24-Jan-20221.6 KiB5235

CHANGES.mdH A D24-Jan-2022687.7 KiB9,5376,917

CONTRIBUTING.mdH A D24-Jan-2022171 42

INSTALL.mdH A D24-Jan-2022283 85

LICENSEH A D24-Jan-20229.9 KiB178150

MANIFEST.inH A D24-Jan-20221.2 KiB5750

README.rstH A D24-Jan-202220 KiB481346

UPGRADE.rstH A D24-Jan-2022257 85

book.tomlH A D24-Jan-20221.3 KiB3932

mypy.iniH A D24-Jan-20229 KiB354277

pylint.cfgH A D24-Jan-20228.5 KiB281189

pyproject.tomlH A D24-Jan-20221.2 KiB5748

setup.cfgH A D24-Jan-2022827 3329

setup.pyH A D24-Jan-20225.8 KiB17299

synctlH A D24-Jan-202211.1 KiB353270

sytest-blacklistH A D24-Jan-20221.7 KiB3830

tox.iniH A D24-Jan-20225.8 KiB205178

README.rst

1=========================================================================
2Synapse |support| |development| |documentation| |license| |pypi| |python|
3=========================================================================
4
5.. contents::
6
7Introduction
8============
9
10Matrix is an ambitious new ecosystem for open federated Instant Messaging and
11VoIP.  The basics you need to know to get up and running are:
12
13- Everything in Matrix happens in a room.  Rooms are distributed and do not
14  exist on any single server.  Rooms can be located using convenience aliases
15  like ``#matrix:matrix.org`` or ``#test:localhost:8448``.
16
17- Matrix user IDs look like ``@matthew:matrix.org`` (although in the future
18  you will normally refer to yourself and others using a third party identifier
19  (3PID): email address, phone number, etc rather than manipulating Matrix user IDs)
20
21The overall architecture is::
22
23      client <----> homeserver <=====================> homeserver <----> client
24             https://somewhere.org/_matrix      https://elsewhere.net/_matrix
25
26``#matrix:matrix.org`` is the official support room for Matrix, and can be
27accessed by any client from https://matrix.org/docs/projects/try-matrix-now.html or
28via IRC bridge at irc://irc.libera.chat/matrix.
29
30Synapse is currently in rapid development, but as of version 0.5 we believe it
31is sufficiently stable to be run as an internet-facing service for real usage!
32
33About Matrix
34============
35
36Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard,
37which handle:
38
39- Creating and managing fully distributed chat rooms with no
40  single points of control or failure
41- Eventually-consistent cryptographically secure synchronisation of room
42  state across a global open network of federated servers and services
43- Sending and receiving extensible messages in a room with (optional)
44  end-to-end encryption
45- Inviting, joining, leaving, kicking, banning room members
46- Managing user accounts (registration, login, logout)
47- Using 3rd Party IDs (3PIDs) such as email addresses, phone numbers,
48  Facebook accounts to authenticate, identify and discover users on Matrix.
49- Placing 1:1 VoIP and Video calls
50
51These APIs are intended to be implemented on a wide range of servers, services
52and clients, letting developers build messaging and VoIP functionality on top
53of the entirely open Matrix ecosystem rather than using closed or proprietary
54solutions. The hope is for Matrix to act as the building blocks for a new
55generation of fully open and interoperable messaging and VoIP apps for the
56internet.
57
58Synapse is a Matrix "homeserver" implementation developed by the matrix.org core
59team, written in Python 3/Twisted.
60
61In Matrix, every user runs one or more Matrix clients, which connect through to
62a Matrix homeserver. The homeserver stores all their personal chat history and
63user account information - much as a mail client connects through to an
64IMAP/SMTP server. Just like email, you can either run your own Matrix
65homeserver and control and own your own communications and history or use one
66hosted by someone else (e.g. matrix.org) - there is no single point of control
67or mandatory service provider in Matrix, unlike WhatsApp, Facebook, Hangouts,
68etc.
69
70We'd like to invite you to join #matrix:matrix.org (via
71https://matrix.org/docs/projects/try-matrix-now.html), run a homeserver, take a look
72at the `Matrix spec <https://matrix.org/docs/spec>`_, and experiment with the
73`APIs <https://matrix.org/docs/api>`_ and `Client SDKs
74<https://matrix.org/docs/projects/try-matrix-now.html#client-sdks>`_.
75
76Thanks for using Matrix!
77
78Support
79=======
80
81For support installing or managing Synapse, please join |room|_ (from a matrix.org
82account if necessary) and ask questions there. We do not use GitHub issues for
83support requests, only for bug reports and feature requests.
84
85Synapse's documentation is `nicely rendered on GitHub Pages <https://matrix-org.github.io/synapse>`_,
86with its source available in |docs|_.
87
88.. |room| replace:: ``#synapse:matrix.org``
89.. _room: https://matrix.to/#/#synapse:matrix.org
90
91.. |docs| replace:: ``docs``
92.. _docs: docs
93
94Synapse Installation
95====================
96
97.. _federation:
98
99* For details on how to install synapse, see
100  `Installation Instructions <https://matrix-org.github.io/synapse/latest/setup/installation.html>`_.
101* For specific details on how to configure Synapse for federation see `docs/federate.md <docs/federate.md>`_
102
103
104Connecting to Synapse from a client
105===================================
106
107The easiest way to try out your new Synapse installation is by connecting to it
108from a web client.
109
110Unless you are running a test instance of Synapse on your local machine, in
111general, you will need to enable TLS support before you can successfully
112connect from a client: see
113`TLS certificates <https://matrix-org.github.io/synapse/latest/setup/installation.html#tls-certificates>`_.
114
115An easy way to get started is to login or register via Element at
116https://app.element.io/#/login or https://app.element.io/#/register respectively.
117You will need to change the server you are logging into from ``matrix.org``
118and instead specify a Homeserver URL of ``https://<server_name>:8448``
119(or just ``https://<server_name>`` if you are using a reverse proxy).
120If you prefer to use another client, refer to our
121`client breakdown <https://matrix.org/docs/projects/clients-matrix>`_.
122
123If all goes well you should at least be able to log in, create a room, and
124start sending messages.
125
126.. _`client-user-reg`:
127
128Registering a new user from a client
129------------------------------------
130
131By default, registration of new users via Matrix clients is disabled. To enable
132it, specify ``enable_registration: true`` in ``homeserver.yaml``. (It is then
133recommended to also set up CAPTCHA - see `<docs/CAPTCHA_SETUP.md>`_.)
134
135Once ``enable_registration`` is set to ``true``, it is possible to register a
136user via a Matrix client.
137
138Your new user name will be formed partly from the ``server_name``, and partly
139from a localpart you specify when you create the account. Your name will take
140the form of::
141
142    @localpart:my.domain.name
143
144(pronounced "at localpart on my dot domain dot name").
145
146As when logging in, you will need to specify a "Custom server".  Specify your
147desired ``localpart`` in the 'User name' box.
148
149Security note
150=============
151
152Matrix serves raw, user-supplied data in some APIs -- specifically the `content
153repository endpoints`_.
154
155.. _content repository endpoints: https://matrix.org/docs/spec/client_server/latest.html#get-matrix-media-r0-download-servername-mediaid
156
157Whilst we make a reasonable effort to mitigate against XSS attacks (for
158instance, by using `CSP`_), a Matrix homeserver should not be hosted on a
159domain hosting other web applications. This especially applies to sharing
160the domain with Matrix web clients and other sensitive applications like
161webmail. See
162https://developer.github.com/changes/2014-04-25-user-content-security for more
163information.
164
165.. _CSP: https://github.com/matrix-org/synapse/pull/1021
166
167Ideally, the homeserver should not simply be on a different subdomain, but on
168a completely different `registered domain`_ (also known as top-level site or
169eTLD+1). This is because `some attacks`_ are still possible as long as the two
170applications share the same registered domain.
171
172.. _registered domain: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-2.3
173
174.. _some attacks: https://en.wikipedia.org/wiki/Session_fixation#Attacks_using_cross-subdomain_cookie
175
176To illustrate this with an example, if your Element Web or other sensitive web
177application is hosted on ``A.example1.com``, you should ideally host Synapse on
178``example2.com``. Some amount of protection is offered by hosting on
179``B.example1.com`` instead, so this is also acceptable in some scenarios.
180However, you should *not* host your Synapse on ``A.example1.com``.
181
182Note that all of the above refers exclusively to the domain used in Synapse's
183``public_baseurl`` setting. In particular, it has no bearing on the domain
184mentioned in MXIDs hosted on that server.
185
186Following this advice ensures that even if an XSS is found in Synapse, the
187impact to other applications will be minimal.
188
189
190Upgrading an existing Synapse
191=============================
192
193The instructions for upgrading synapse are in `the upgrade notes`_.
194Please check these instructions as upgrading may require extra steps for some
195versions of synapse.
196
197.. _the upgrade notes: https://matrix-org.github.io/synapse/develop/upgrade.html
198
199.. _reverse-proxy:
200
201Using a reverse proxy with Synapse
202==================================
203
204It is recommended to put a reverse proxy such as
205`nginx <https://nginx.org/en/docs/http/ngx_http_proxy_module.html>`_,
206`Apache <https://httpd.apache.org/docs/current/mod/mod_proxy_http.html>`_,
207`Caddy <https://caddyserver.com/docs/quick-starts/reverse-proxy>`_,
208`HAProxy <https://www.haproxy.org/>`_ or
209`relayd <https://man.openbsd.org/relayd.8>`_ in front of Synapse. One advantage of
210doing so is that it means that you can expose the default https port (443) to
211Matrix clients without needing to run Synapse with root privileges.
212
213For information on configuring one, see `<docs/reverse_proxy.md>`_.
214
215Identity Servers
216================
217
218Identity servers have the job of mapping email addresses and other 3rd Party
219IDs (3PIDs) to Matrix user IDs, as well as verifying the ownership of 3PIDs
220before creating that mapping.
221
222**They are not where accounts or credentials are stored - these live on home
223servers. Identity Servers are just for mapping 3rd party IDs to matrix IDs.**
224
225This process is very security-sensitive, as there is obvious risk of spam if it
226is too easy to sign up for Matrix accounts or harvest 3PID data. In the longer
227term, we hope to create a decentralised system to manage it (`matrix-doc #712
228<https://github.com/matrix-org/matrix-doc/issues/712>`_), but in the meantime,
229the role of managing trusted identity in the Matrix ecosystem is farmed out to
230a cluster of known trusted ecosystem partners, who run 'Matrix Identity
231Servers' such as `Sydent <https://github.com/matrix-org/sydent>`_, whose role
232is purely to authenticate and track 3PID logins and publish end-user public
233keys.
234
235You can host your own copy of Sydent, but this will prevent you reaching other
236users in the Matrix ecosystem via their email address, and prevent them finding
237you. We therefore recommend that you use one of the centralised identity servers
238at ``https://matrix.org`` or ``https://vector.im`` for now.
239
240To reiterate: the Identity server will only be used if you choose to associate
241an email address with your account, or send an invite to another user via their
242email address.
243
244
245Password reset
246==============
247
248Users can reset their password through their client. Alternatively, a server admin
249can reset a users password using the `admin API <docs/admin_api/user_admin_api.rst#reset-password>`_
250or by directly editing the database as shown below.
251
252First calculate the hash of the new password::
253
254    $ ~/synapse/env/bin/hash_password
255    Password:
256    Confirm password:
257    $2a$12$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
258
259Then update the ``users`` table in the database::
260
261    UPDATE users SET password_hash='$2a$12$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
262        WHERE name='@test:test.com';
263
264
265Synapse Development
266===================
267
268The best place to get started is our
269`guide for contributors <https://matrix-org.github.io/synapse/latest/development/contributing_guide.html>`_.
270This is part of our larger `documentation <https://matrix-org.github.io/synapse/latest>`_, which includes
271information for synapse developers as well as synapse administrators.
272
273Developers might be particularly interested in:
274
275* `Synapse's database schema <https://matrix-org.github.io/synapse/latest/development/database_schema.html>`_,
276* `notes on Synapse's implementation details <https://matrix-org.github.io/synapse/latest/development/internal_documentation/index.html>`_, and
277* `how we use git <https://matrix-org.github.io/synapse/latest/development/git.html>`_.
278
279Alongside all that, join our developer community on Matrix:
280`#synapse-dev:matrix.org <https://matrix.to/#/#synapse-dev:matrix.org>`_, featuring real humans!
281
282
283Quick start
284-----------
285
286Before setting up a development environment for synapse, make sure you have the
287system dependencies (such as the python header files) installed - see
288`Platform-specific prerequisites <https://matrix-org.github.io/synapse/latest/setup/installation.html#platform-specific-prerequisites>`_.
289
290To check out a synapse for development, clone the git repo into a working
291directory of your choice::
292
293    git clone https://github.com/matrix-org/synapse.git
294    cd synapse
295
296Synapse has a number of external dependencies, that are easiest
297to install using pip and a virtualenv::
298
299    python3 -m venv ./env
300    source ./env/bin/activate
301    pip install -e ".[all,dev]"
302
303This will run a process of downloading and installing all the needed
304dependencies into a virtual env. If any dependencies fail to install,
305try installing the failing modules individually::
306
307    pip install -e "module-name"
308
309We recommend using the demo which starts 3 federated instances running on ports `8080` - `8082`
310
311    ./demo/start.sh
312
313(to stop, you can use `./demo/stop.sh`)
314
315If you just want to start a single instance of the app and run it directly::
316
317    # Create the homeserver.yaml config once
318    python -m synapse.app.homeserver \
319      --server-name my.domain.name \
320      --config-path homeserver.yaml \
321      --generate-config \
322      --report-stats=[yes|no]
323
324    # Start the app
325    python -m synapse.app.homeserver --config-path homeserver.yaml
326
327
328Running the unit tests
329----------------------
330
331After getting up and running, you may wish to run Synapse's unit tests to
332check that everything is installed correctly::
333
334    trial tests
335
336This should end with a 'PASSED' result (note that exact numbers will
337differ)::
338
339    Ran 1337 tests in 716.064s
340
341    PASSED (skips=15, successes=1322)
342
343For more tips on running the unit tests, like running a specific test or
344to see the logging output, see the `CONTRIBUTING doc <CONTRIBUTING.md#run-the-unit-tests>`_.
345
346
347Running the Integration Tests
348-----------------------------
349
350Synapse is accompanied by `SyTest <https://github.com/matrix-org/sytest>`_,
351a Matrix homeserver integration testing suite, which uses HTTP requests to
352access the API as a Matrix client would. It is able to run Synapse directly from
353the source tree, so installation of the server is not required.
354
355Testing with SyTest is recommended for verifying that changes related to the
356Client-Server API are functioning correctly. See the `SyTest installation
357instructions <https://github.com/matrix-org/sytest#installing>`_ for details.
358
359
360Platform dependencies
361=====================
362
363Synapse uses a number of platform dependencies such as Python and PostgreSQL,
364and aims to follow supported upstream versions. See the
365`<docs/deprecation_policy.md>`_ document for more details.
366
367
368Troubleshooting
369===============
370
371Need help? Join our community support room on Matrix:
372`#synapse:matrix.org <https://matrix.to/#/#synapse:matrix.org>`_
373
374Running out of File Handles
375---------------------------
376
377If synapse runs out of file handles, it typically fails badly - live-locking
378at 100% CPU, and/or failing to accept new TCP connections (blocking the
379connecting client).  Matrix currently can legitimately use a lot of file handles,
380thanks to busy rooms like #matrix:matrix.org containing hundreds of participating
381servers.  The first time a server talks in a room it will try to connect
382simultaneously to all participating servers, which could exhaust the available
383file descriptors between DNS queries & HTTPS sockets, especially if DNS is slow
384to respond. (We need to improve the routing algorithm used to be better than
385full mesh, but as of March 2019 this hasn't happened yet).
386
387If you hit this failure mode, we recommend increasing the maximum number of
388open file handles to be at least 4096 (assuming a default of 1024 or 256).
389This is typically done by editing ``/etc/security/limits.conf``
390
391Separately, Synapse may leak file handles if inbound HTTP requests get stuck
392during processing - e.g. blocked behind a lock or talking to a remote server etc.
393This is best diagnosed by matching up the 'Received request' and 'Processed request'
394log lines and looking for any 'Processed request' lines which take more than
395a few seconds to execute. Please let us know at #synapse:matrix.org if
396you see this failure mode so we can help debug it, however.
397
398Help!! Synapse is slow and eats all my RAM/CPU!
399-----------------------------------------------
400
401First, ensure you are running the latest version of Synapse, using Python 3
402with a PostgreSQL database.
403
404Synapse's architecture is quite RAM hungry currently - we deliberately
405cache a lot of recent room data and metadata in RAM in order to speed up
406common requests. We'll improve this in the future, but for now the easiest
407way to either reduce the RAM usage (at the risk of slowing things down)
408is to set the almost-undocumented ``SYNAPSE_CACHE_FACTOR`` environment
409variable. The default is 0.5, which can be decreased to reduce RAM usage
410in memory constrained enviroments, or increased if performance starts to
411degrade.
412
413However, degraded performance due to a low cache factor, common on
414machines with slow disks, often leads to explosions in memory use due
415backlogged requests. In this case, reducing the cache factor will make
416things worse. Instead, try increasing it drastically. 2.0 is a good
417starting value.
418
419Using `libjemalloc <http://jemalloc.net/>`_ can also yield a significant
420improvement in overall memory use, and especially in terms of giving back
421RAM to the OS. To use it, the library must simply be put in the
422LD_PRELOAD environment variable when launching Synapse. On Debian, this
423can be done by installing the ``libjemalloc1`` package and adding this
424line to ``/etc/default/matrix-synapse``::
425
426    LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1
427
428This can make a significant difference on Python 2.7 - it's unclear how
429much of an improvement it provides on Python 3.x.
430
431If you're encountering high CPU use by the Synapse process itself, you
432may be affected by a bug with presence tracking that leads to a
433massive excess of outgoing federation requests (see `discussion
434<https://github.com/matrix-org/synapse/issues/3971>`_). If metrics
435indicate that your server is also issuing far more outgoing federation
436requests than can be accounted for by your users' activity, this is a
437likely cause. The misbehavior can be worked around by setting
438the following in the Synapse config file:
439
440.. code-block:: yaml
441
442   presence:
443       enabled: false
444
445People can't accept room invitations from me
446--------------------------------------------
447
448The typical failure mode here is that you send an invitation to someone
449to join a room or direct chat, but when they go to accept it, they get an
450error (typically along the lines of "Invalid signature"). They might see
451something like the following in their logs::
452
453    2019-09-11 19:32:04,271 - synapse.federation.transport.server - 288 - WARNING - GET-11752 - authenticate_request failed: 401: Invalid signature for server <server> with key ed25519:a_EqML: Unable to verify signature for <server>
454
455This is normally caused by a misconfiguration in your reverse-proxy. See
456`<docs/reverse_proxy.md>`_ and double-check that your settings are correct.
457
458.. |support| image:: https://img.shields.io/matrix/synapse:matrix.org?label=support&logo=matrix
459  :alt: (get support on #synapse:matrix.org)
460  :target: https://matrix.to/#/#synapse:matrix.org
461
462.. |development| image:: https://img.shields.io/matrix/synapse-dev:matrix.org?label=development&logo=matrix
463  :alt: (discuss development on #synapse-dev:matrix.org)
464  :target: https://matrix.to/#/#synapse-dev:matrix.org
465
466.. |documentation| image:: https://img.shields.io/badge/documentation-%E2%9C%93-success
467  :alt: (Rendered documentation on GitHub Pages)
468  :target: https://matrix-org.github.io/synapse/latest/
469
470.. |license| image:: https://img.shields.io/github/license/matrix-org/synapse
471  :alt: (check license in LICENSE file)
472  :target: LICENSE
473
474.. |pypi| image:: https://img.shields.io/pypi/v/matrix-synapse
475  :alt: (latest version released on PyPi)
476  :target: https://pypi.org/project/matrix-synapse
477
478.. |python| image:: https://img.shields.io/pypi/pyversions/matrix-synapse
479  :alt: (supported python versions)
480  :target: https://pypi.org/project/matrix-synapse
481