This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support for serving server well-known files #11211
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19a98b3
Support for serving server well-known files
richvdh f577249
update config
richvdh da179ff
Merge remote-tracking branch 'origin/develop' into rav/server_well_known
richvdh a089f51
fix unit test
richvdh 27ff1f2
Fix wording in sample config
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for serving `/.well-known/matrix/server` files, to redirect federation traffic to port 443. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# Delegation | ||
# Delegation of incoming federation traffic | ||
|
||
In the following documentation, we use the term `server_name` to refer to that setting | ||
in your homeserver configuration file. It appears at the ends of user ids, and tells | ||
other homeservers where they can find your server. | ||
|
||
By default, other homeservers will expect to be able to reach yours via | ||
your `server_name`, on port 8448. For example, if you set your `server_name` | ||
|
@@ -12,22 +16,31 @@ to a different server and/or port (e.g. `synapse.example.com:443`). | |
|
||
## .well-known delegation | ||
|
||
To use this method, you need to be able to alter the | ||
`server_name` 's https server to serve the `/.well-known/matrix/server` | ||
URL. Having an active server (with a valid TLS certificate) serving your | ||
`server_name` domain is out of the scope of this documentation. | ||
To use this method, you need to be able to configure the server at | ||
`https://<server_name>` to serve a file at | ||
`https://<server_name>/.well-known/matrix/server`. There are two ways to do this, shown below. | ||
|
||
Note that the `.well-known` file is hosted on the default port for `https` (port 443). | ||
|
||
### External server | ||
|
||
For maximum flexibility, you need to configure an external server such as nginx, Apache | ||
or HAProxy to serve the `https://<server_name>/.well-known/matrix/server` file. Setting | ||
up such a server is out of the scope of this documentation, but note that it is often | ||
possible to configure your [reverse proxy](reverse_proxy.md) for this. | ||
|
||
The URL `https://<server_name>/.well-known/matrix/server` should | ||
return a JSON structure containing the key `m.server` like so: | ||
The URL `https://<server_name>/.well-known/matrix/server` should be configured | ||
return a JSON structure containing the key `m.server` like this: | ||
|
||
```json | ||
{ | ||
"m.server": "<synapse.server.name>[:<yourport>]" | ||
} | ||
``` | ||
|
||
In our example, this would mean that URL `https://example.com/.well-known/matrix/server` | ||
should return: | ||
In our example (where we want federation traffic to be routed to | ||
`https://synapse.example.com`, on port 443), this would mean that | ||
`https://example.com/.well-known/matrix/server` should return: | ||
|
||
```json | ||
{ | ||
|
@@ -38,16 +51,29 @@ should return: | |
Note, specifying a port is optional. If no port is specified, then it defaults | ||
to 8448. | ||
|
||
With .well-known delegation, federating servers will check for a valid TLS | ||
certificate for the delegated hostname (in our example: `synapse.example.com`). | ||
### Serving a `.well-known/matrix/server` file with Synapse | ||
|
||
If you are able to set up your domain so that `https://<server_name>` is routed to | ||
Synapse (i.e., the only change needed is to direct federation traffic to port 443 | ||
instead of port 8448), then it is possible to configure Synapse to serve a suitable | ||
`.well-known/matrix/server` file. To do so, add the following to your `homeserver.yaml` | ||
file: | ||
|
||
```yaml | ||
serve_server_wellknown: true | ||
``` | ||
|
||
**Note**: this *only* works if `https://<server_name>` is routed to Synapse, so is | ||
generally not suitable if Synapse is hosted at a subdomain such as | ||
`https://synapse.example.com`. | ||
|
||
## SRV DNS record delegation | ||
|
||
It is also possible to do delegation using a SRV DNS record. However, that is | ||
considered an advanced topic since it's a bit complex to set up, and `.well-known` | ||
delegation is already enough in most cases. | ||
It is also possible to do delegation using a SRV DNS record. However, that is generally | ||
not recommended, as it can be difficult to configure the TLS certificates correctly in | ||
this case, and it offers little advantage over `.well-known` delegation. | ||
|
||
However, if you really need it, you can find some documentation on how such a | ||
However, if you really need it, you can find some documentation on what such a | ||
record should look like and how Synapse will use it in [the Matrix | ||
specification](https://matrix.org/docs/spec/server_server/latest#resolving-server-names). | ||
|
||
|
@@ -68,27 +94,9 @@ wouldn't need any delegation set up. | |
domain `server_name` points to, you will need to let other servers know how to | ||
find it using delegation. | ||
|
||
### Do you still recommend against using a reverse proxy on the federation port? | ||
|
||
We no longer actively recommend against using a reverse proxy. Many admins will | ||
find it easier to direct federation traffic to a reverse proxy and manage their | ||
own TLS certificates, and this is a supported configuration. | ||
### Should I use a reverse proxy for federation traffic? | ||
|
||
See [the reverse proxy documentation](reverse_proxy.md) for information on setting up a | ||
Generally, using a reverse proxy for both the federation and client traffic is a good | ||
idea, since it saves handling TLS traffic in Synapse. See | ||
[the reverse proxy documentation](reverse_proxy.md) for information on setting up a | ||
reverse proxy. | ||
|
||
### Do I still need to give my TLS certificates to Synapse if I am using a reverse proxy? | ||
|
||
This is no longer necessary. If you are using a reverse proxy for all of your | ||
TLS traffic, then you can set `no_tls: True` in the Synapse config. | ||
|
||
In that case, the only reason Synapse needs the certificate is to populate a legacy | ||
`tls_fingerprints` field in the federation API. This is ignored by Synapse 0.99.0 | ||
and later, and the only time pre-0.99 Synapses will check it is when attempting to | ||
fetch the server keys - and generally this is delegated via `matrix.org`, which | ||
is running a modern version of Synapse. | ||
|
||
### Do I need the same certificate for the client and federation port? | ||
|
||
No. There is nothing stopping you from using different certificates, | ||
particularly if you are using a reverse proxy. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Ah, this all reminds me of Synapse from a long time ago. Nostalgic.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's still there in https://matrix-org.github.io/synapse/latest/MSC1711_certificates_FAQ.html if you want the nostalgia hit :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to you, but I might have been tempted to put this section first since it's the 'easy' case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to put it second, because it's only useful in one very specific case. I thought it was clearer to put the more general solution first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's reasonable! I think the way you introduced it will give enough hint that there are more options too, so no problem there