Skip to content

Commit 7ed5566

Browse files
sandhosereivilibre
andauthored
Stabilise MAS integration (#18759)
This can be reviewed commit by commit There are a few improvements over the experimental support: - authorisation of Synapse <-> MAS requests is simplified, with a single shared secret, removing the need for provisioning a client on the MAS side - the tests actually spawn a real server, allowing us to test the rust introspection layer - we now check that the device advertised in introspection actually exist, making it so that when a user logs out, the tokens are immediately invalidated, even if the cache doesn't expire - it doesn't rely on discovery anymore, rather on a static endpoint base. This means users don't have to override the introspection endpoint to avoid internet roundtrips - it doesn't depend on `authlib` anymore, as we simplified a lot the calls done from Synapse to MAS We still have to update the MAS documentation about the Synapse setup, but that can be done later. --------- Co-authored-by: reivilibre <[email protected]>
1 parent 8c71875 commit 7ed5566

32 files changed

+1608
-223
lines changed

changelog.d/18759.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stable support for delegating authentication to [Matrix Authentication Service](https://github.com/element-hq/matrix-authentication-service/).

docs/upgrade.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,29 @@ The Grafana dashboard JSON in `contrib/grafana/synapse.json` has been updated to
164164
this change but you will need to manually update your own existing Grafana dashboards
165165
using these metrics.
166166
167+
## Stable integration with Matrix Authentication Service
167168
169+
Support for [Matrix Authentication Service (MAS)](https://github.com/element-hq/matrix-authentication-service) is now stable, with a simplified configuration.
170+
This stable integration requires MAS 0.20.0 or later.
171+
172+
The existing `experimental_features.msc3861` configuration option is now deprecated and will be removed in Synapse v1.137.0.
173+
174+
Synapse deployments already using MAS should now use the new configuration options:
175+
176+
```yaml
177+
matrix_authentication_service:
178+
# Enable the MAS integration
179+
enabled: true
180+
# The base URL where Synapse will contact MAS
181+
endpoint: http://localhost:8080
182+
# The shared secret used to authenticate MAS requests, must be the same as `matrix.secret` in the MAS configuration
183+
# See https://element-hq.github.io/matrix-authentication-service/reference/configuration.html#matrix
184+
secret: "asecurerandomsecretstring"
185+
```
186+
187+
They must remove the `experimental_features.msc3861` configuration option from their configuration.
188+
189+
They can also remove the client previously used by Synapse [in the MAS configuration](https://element-hq.github.io/matrix-authentication-service/reference/configuration.html#clients) as it is no longer in use.
168190
169191
# Upgrading to v1.135.0
170192
@@ -186,10 +208,10 @@ native ICU library on your system is no longer required.
186208
## Documented endpoint which can be delegated to a federation worker
187209
188210
The endpoint `^/_matrix/federation/v1/version$` can be delegated to a federation
189-
worker. This is not new behaviour, but had not been documented yet. The
190-
[list of delegatable endpoints](workers.md#synapseappgeneric_worker) has
211+
worker. This is not new behaviour, but had not been documented yet. The
212+
[list of delegatable endpoints](workers.md#synapseappgeneric_worker) has
191213
been updated to include it. Make sure to check your reverse proxy rules if you
192-
are using workers.
214+
are using workers.
193215
194216
# Upgrading to v1.126.0
195217

docs/usage/configuration/config_documentation.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,28 @@ no_proxy_hosts:
643643
- 172.30.0.0/16
644644
```
645645
---
646+
### `matrix_authentication_service`
647+
648+
*(object)* The `matrix_authentication_service` setting configures integration with [Matrix Authentication Service (MAS)](https://github.com/element-hq/matrix-authentication-service).
649+
650+
This setting has the following sub-options:
651+
652+
* `enabled` (boolean): Whether or not to enable the MAS integration. If this is set to `false`, Synapse will use its legacy internal authentication API. Defaults to `false`.
653+
654+
* `endpoint` (string): The URL where Synapse can reach MAS. This *must* have the `discovery` and `oauth` resources mounted. Defaults to `"http://localhost:8080"`.
655+
656+
* `secret` (string|null): A shared secret that will be used to authenticate requests from and to MAS.
657+
658+
* `secret_path` (string|null): Alternative to `secret`, reading the shared secret from a file. The file should be a plain text file, containing only the secret. Synapse reads the secret from the given file once at startup.
659+
660+
Example configuration:
661+
```yaml
662+
matrix_authentication_service:
663+
enabled: true
664+
secret: someverysecuresecret
665+
endpoint: http://localhost:8080
666+
```
667+
---
646668
### `dummy_events_threshold`
647669

648670
*(integer)* Forward extremities can build up in a room due to networking delays between homeservers. Once this happens in a large room, calculation of the state of that room can become quite expensive. To mitigate this, once the number of forward extremities reaches a given threshold, Synapse will send an `org.matrix.dummy_event` event, which will reduce the forward extremities in the room.

schema/synapse-config.schema.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,43 @@ properties:
656656
- - master.hostname.example.com
657657
- 10.1.0.0/16
658658
- 172.30.0.0/16
659+
matrix_authentication_service:
660+
type: object
661+
description: >-
662+
The `matrix_authentication_service` setting configures integration with
663+
[Matrix Authentication Service (MAS)](https://github.com/element-hq/matrix-authentication-service).
664+
properties:
665+
enabled:
666+
type: boolean
667+
description: >-
668+
Whether or not to enable the MAS integration. If this is set to
669+
`false`, Synapse will use its legacy internal authentication API.
670+
default: false
671+
672+
endpoint:
673+
type: string
674+
format: uri
675+
description: >-
676+
The URL where Synapse can reach MAS. This *must* have the `discovery`
677+
and `oauth` resources mounted.
678+
default: http://localhost:8080
679+
680+
secret:
681+
type: ["string", "null"]
682+
description: >-
683+
A shared secret that will be used to authenticate requests from and to MAS.
684+
685+
secret_path:
686+
type: ["string", "null"]
687+
description: >-
688+
Alternative to `secret`, reading the shared secret from a file.
689+
The file should be a plain text file, containing only the secret.
690+
Synapse reads the secret from the given file once at startup.
691+
692+
examples:
693+
- enabled: true
694+
secret: someverysecuresecret
695+
endpoint: http://localhost:8080
659696
dummy_events_threshold:
660697
type: integer
661698
description: >-

synapse/_pydantic_compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434

3535
if TYPE_CHECKING or HAS_PYDANTIC_V2:
3636
from pydantic.v1 import (
37+
AnyHttpUrl,
3738
BaseModel,
3839
Extra,
3940
Field,
41+
FilePath,
4042
MissingError,
4143
PydanticValueError,
4244
StrictBool,
@@ -55,9 +57,11 @@
5557
from pydantic.v1.typing import get_args
5658
else:
5759
from pydantic import (
60+
AnyHttpUrl,
5861
BaseModel,
5962
Extra,
6063
Field,
64+
FilePath,
6165
MissingError,
6266
PydanticValueError,
6367
StrictBool,
@@ -77,6 +81,7 @@
7781

7882
__all__ = (
7983
"HAS_PYDANTIC_V2",
84+
"AnyHttpUrl",
8085
"BaseModel",
8186
"constr",
8287
"conbytes",
@@ -85,6 +90,7 @@
8590
"ErrorWrapper",
8691
"Extra",
8792
"Field",
93+
"FilePath",
8894
"get_args",
8995
"MissingError",
9096
"parse_obj_as",

synapse/api/auth/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
#
2121
from typing import TYPE_CHECKING, Optional, Protocol, Tuple
2222

23+
from prometheus_client import Histogram
24+
2325
from twisted.web.server import Request
2426

2527
from synapse.appservice import ApplicationService
2628
from synapse.http.site import SynapseRequest
29+
from synapse.metrics import SERVER_NAME_LABEL
2730
from synapse.types import Requester
2831

2932
if TYPE_CHECKING:
@@ -33,6 +36,13 @@
3336
GUEST_DEVICE_ID = "guest_device"
3437

3538

39+
introspection_response_timer = Histogram(
40+
"synapse_api_auth_delegated_introspection_response",
41+
"Time taken to get a response for an introspection request",
42+
labelnames=["code", SERVER_NAME_LABEL],
43+
)
44+
45+
3646
class Auth(Protocol):
3747
"""The interface that an auth provider must implement."""
3848

0 commit comments

Comments
 (0)