Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 956e015

Browse files
author
David Robertson
authored
Drop support for delegating email validation, round 2 (#13596)
1 parent 79281f5 commit 956e015

File tree

13 files changed

+108
-245
lines changed

13 files changed

+108
-245
lines changed

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Synapse 1.66.0rc1 (2022-08-23)
22
==============================
33

4+
This release removes the ability for homeservers to delegate email ownership
5+
verification and password reset confirmation to identity servers. This removal
6+
was originally planned for Synapse 1.64, but was later deferred until now.
7+
8+
See the [upgrade notes](https://matrix-org.github.io/synapse/v1.66/upgrade.html#upgrading-to-v1660) for more details.
9+
410
Features
511
--------
612

@@ -33,6 +39,12 @@ Improved Documentation
3339
- Fix the doc and some warnings that were referring to the nonexistent `custom_templates_directory` setting (instead of `custom_template_directory`). ([\#13538](https://github.com/matrix-org/synapse/issues/13538))
3440

3541

42+
Deprecations and Removals
43+
-------------------------
44+
45+
- Remove the ability for homeservers to delegate email ownership verification
46+
and password reset confirmation to identity servers. See [upgrade notes](https://matrix-org.github.io/synapse/v1.66/upgrade.html#upgrading-to-v1660) for more details.
47+
3648
Internal Changes
3749
----------------
3850

changelog.d/13596.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the ability for homeservers to delegate email ownership verification and password reset confirmation to identity servers. See [upgrade notes](https://github.com/matrix-org/synapse/blob/release-v1.66/docs/upgrade.md#upgrading-to-v1660) for more details.

docs/upgrade.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ process, for example:
8989
dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
9090
```
9191
92+
# Upgrading to v1.66.0
93+
94+
## Delegation of email validation no longer supported
95+
96+
As of this version, Synapse no longer allows the tasks of verifying email address
97+
ownership, and password reset confirmation, to be delegated to an identity server.
98+
This removal was previously planned for Synapse 1.64.0, but was
99+
[delayed](https://github.com/matrix-org/synapse/issues/13421) until now to give
100+
homeserver administrators more notice of the change.
101+
102+
To continue to allow users to add email addresses to their homeserver accounts,
103+
and perform password resets, make sure that Synapse is configured with a working
104+
email server in the [`email` configuration
105+
section](https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#email)
106+
(including, at a minimum, a `notif_from` setting.)
107+
108+
Specifying an `email` setting under `account_threepid_delegates` will now cause
109+
an error at startup.
110+
92111
# Upgrading to v1.64.0
93112
94113
## Deprecation of the ability to delegate e-mail verification to identity servers

docs/usage/configuration/config_documentation.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,10 @@ their account.
21822182
by the Matrix Identity Service API
21832183
[specification](https://matrix.org/docs/spec/identity_service/latest).)
21842184

2185-
*Updated in Synapse 1.64.0*: The `email` option is deprecated.
2185+
*Deprecated in Synapse 1.64.0*: The `email` option is deprecated.
2186+
2187+
*Removed in Synapse 1.66.0*: The `email` option has been removed.
2188+
If present, Synapse will report a configuration error on startup.
21862189

21872190
Example configuration:
21882191
```yaml

synapse/app/homeserver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
register_start,
4545
)
4646
from synapse.config._base import ConfigError, format_config_error
47-
from synapse.config.emailconfig import ThreepidBehaviour
4847
from synapse.config.homeserver import HomeServerConfig
4948
from synapse.config.server import ListenerConfig
5049
from synapse.federation.transport.server import TransportLayerServer
@@ -202,7 +201,7 @@ def _configure_named_resource(
202201
}
203202
)
204203

205-
if self.config.email.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
204+
if self.config.email.can_verify_email:
206205
from synapse.rest.synapse.client.password_reset import (
207206
PasswordResetSubmitTokenResource,
208207
)

synapse/config/emailconfig.py

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import email.utils
1919
import logging
2020
import os
21-
from enum import Enum
2221
from typing import Any
2322

2423
import attr
@@ -136,40 +135,22 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
136135

137136
self.email_enable_notifs = email_config.get("enable_notifs", False)
138137

139-
self.threepid_behaviour_email = (
140-
# Have Synapse handle the email sending if account_threepid_delegates.email
141-
# is not defined
142-
# msisdn is currently always remote while Synapse does not support any method of
143-
# sending SMS messages
144-
ThreepidBehaviour.REMOTE
145-
if self.root.registration.account_threepid_delegate_email
146-
else ThreepidBehaviour.LOCAL
147-
)
148-
149138
if config.get("trust_identity_server_for_password_resets"):
150139
raise ConfigError(
151-
'The config option "trust_identity_server_for_password_resets" has been removed.'
152-
"Please consult the configuration manual at docs/usage/configuration/config_documentation.md for "
153-
"details and update your config file."
140+
'The config option "trust_identity_server_for_password_resets" '
141+
"is no longer supported. Please remove it from the config file."
154142
)
155143

156-
self.local_threepid_handling_disabled_due_to_email_config = False
157-
if (
158-
self.threepid_behaviour_email == ThreepidBehaviour.LOCAL
159-
and email_config == {}
160-
):
161-
# We cannot warn the user this has happened here
162-
# Instead do so when a user attempts to reset their password
163-
self.local_threepid_handling_disabled_due_to_email_config = True
164-
165-
self.threepid_behaviour_email = ThreepidBehaviour.OFF
144+
# If we have email config settings, assume that we can verify ownership of
145+
# email addresses.
146+
self.can_verify_email = email_config != {}
166147

167148
# Get lifetime of a validation token in milliseconds
168149
self.email_validation_token_lifetime = self.parse_duration(
169150
email_config.get("validation_token_lifetime", "1h")
170151
)
171152

172-
if self.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
153+
if self.can_verify_email:
173154
missing = []
174155
if not self.email_notif_from:
175156
missing.append("email.notif_from")
@@ -360,18 +341,3 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
360341
"Config option email.invite_client_location must be a http or https URL",
361342
path=("email", "invite_client_location"),
362343
)
363-
364-
365-
class ThreepidBehaviour(Enum):
366-
"""
367-
Enum to define the behaviour of Synapse with regards to when it contacts an identity
368-
server for 3pid registration and password resets
369-
370-
REMOTE = use an external server to send tokens
371-
LOCAL = send tokens ourselves
372-
OFF = disable registration via 3pid and password resets
373-
"""
374-
375-
REMOTE = "remote"
376-
LOCAL = "local"
377-
OFF = "off"

synapse/config/registration.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,18 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
import argparse
16-
import logging
1716
from typing import Any, Optional
1817

1918
from synapse.api.constants import RoomCreationPreset
2019
from synapse.config._base import Config, ConfigError
2120
from synapse.types import JsonDict, RoomAlias, UserID
2221
from synapse.util.stringutils import random_string_with_symbols, strtobool
2322

24-
logger = logging.getLogger(__name__)
25-
26-
LEGACY_EMAIL_DELEGATE_WARNING = """\
27-
Delegation of email verification to an identity server is now deprecated. To
23+
NO_EMAIL_DELEGATE_ERROR = """\
24+
Delegation of email verification to an identity server is no longer supported. To
2825
continue to allow users to add email addresses to their accounts, and use them for
2926
password resets, configure Synapse with an SMTP server via the `email` setting, and
3027
remove `account_threepid_delegates.email`.
31-
32-
This will be an error in a future version.
3328
"""
3429

3530

@@ -64,9 +59,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
6459

6560
account_threepid_delegates = config.get("account_threepid_delegates") or {}
6661
if "email" in account_threepid_delegates:
67-
logger.warning(LEGACY_EMAIL_DELEGATE_WARNING)
68-
69-
self.account_threepid_delegate_email = account_threepid_delegates.get("email")
62+
raise ConfigError(NO_EMAIL_DELEGATE_ERROR)
7063
self.account_threepid_delegate_msisdn = account_threepid_delegates.get("msisdn")
7164
self.default_identity_server = config.get("default_identity_server")
7265
self.allow_guest_access = config.get("allow_guest_access", False)

synapse/handlers/identity.py

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
SynapseError,
2727
)
2828
from synapse.api.ratelimiting import Ratelimiter
29-
from synapse.config.emailconfig import ThreepidBehaviour
3029
from synapse.http import RequestTimedOutError
3130
from synapse.http.client import SimpleHttpClient
3231
from synapse.http.site import SynapseRequest
@@ -416,48 +415,6 @@ async def send_threepid_validation(
416415

417416
return session_id
418417

419-
async def request_email_token(
420-
self,
421-
id_server: str,
422-
email: str,
423-
client_secret: str,
424-
send_attempt: int,
425-
next_link: Optional[str] = None,
426-
) -> JsonDict:
427-
"""
428-
Request an external server send an email on our behalf for the purposes of threepid
429-
validation.
430-
431-
Args:
432-
id_server: The identity server to proxy to
433-
email: The email to send the message to
434-
client_secret: The unique client_secret sends by the user
435-
send_attempt: Which attempt this is
436-
next_link: A link to redirect the user to once they submit the token
437-
438-
Returns:
439-
The json response body from the server
440-
"""
441-
params = {
442-
"email": email,
443-
"client_secret": client_secret,
444-
"send_attempt": send_attempt,
445-
}
446-
if next_link:
447-
params["next_link"] = next_link
448-
449-
try:
450-
data = await self.http_client.post_json_get_json(
451-
id_server + "/_matrix/identity/api/v1/validate/email/requestToken",
452-
params,
453-
)
454-
return data
455-
except HttpResponseException as e:
456-
logger.info("Proxied requestToken failed: %r", e)
457-
raise e.to_synapse_error()
458-
except RequestTimedOutError:
459-
raise SynapseError(500, "Timed out contacting identity server")
460-
461418
async def requestMsisdnToken(
462419
self,
463420
id_server: str,
@@ -531,18 +488,7 @@ async def validate_threepid_session(
531488
validation_session = None
532489

533490
# Try to validate as email
534-
if self.hs.config.email.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
535-
# Remote emails will only be used if a valid identity server is provided.
536-
assert (
537-
self.hs.config.registration.account_threepid_delegate_email is not None
538-
)
539-
540-
# Ask our delegated email identity server
541-
validation_session = await self.threepid_from_creds(
542-
self.hs.config.registration.account_threepid_delegate_email,
543-
threepid_creds,
544-
)
545-
elif self.hs.config.email.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
491+
if self.hs.config.email.can_verify_email:
546492
# Get a validated session matching these details
547493
validation_session = await self.store.get_threepid_validation_session(
548494
"email", client_secret, sid=sid, validated=True

synapse/handlers/ui_auth/checkers.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from synapse.api.constants import LoginType
2121
from synapse.api.errors import Codes, LoginError, SynapseError
22-
from synapse.config.emailconfig import ThreepidBehaviour
2322
from synapse.util import json_decoder
2423

2524
if TYPE_CHECKING:
@@ -153,7 +152,7 @@ async def _check_threepid(self, medium: str, authdict: dict) -> dict:
153152

154153
logger.info("Getting validated threepid. threepidcreds: %r", (threepid_creds,))
155154

156-
# msisdns are currently always ThreepidBehaviour.REMOTE
155+
# msisdns are currently always verified via the IS
157156
if medium == "msisdn":
158157
if not self.hs.config.registration.account_threepid_delegate_msisdn:
159158
raise SynapseError(
@@ -164,18 +163,7 @@ async def _check_threepid(self, medium: str, authdict: dict) -> dict:
164163
threepid_creds,
165164
)
166165
elif medium == "email":
167-
if (
168-
self.hs.config.email.threepid_behaviour_email
169-
== ThreepidBehaviour.REMOTE
170-
):
171-
assert self.hs.config.registration.account_threepid_delegate_email
172-
threepid = await identity_handler.threepid_from_creds(
173-
self.hs.config.registration.account_threepid_delegate_email,
174-
threepid_creds,
175-
)
176-
elif (
177-
self.hs.config.email.threepid_behaviour_email == ThreepidBehaviour.LOCAL
178-
):
166+
if self.hs.config.email.can_verify_email:
179167
threepid = None
180168
row = await self.store.get_threepid_validation_session(
181169
medium,
@@ -227,10 +215,7 @@ def __init__(self, hs: "HomeServer"):
227215
_BaseThreepidAuthChecker.__init__(self, hs)
228216

229217
def is_enabled(self) -> bool:
230-
return self.hs.config.email.threepid_behaviour_email in (
231-
ThreepidBehaviour.REMOTE,
232-
ThreepidBehaviour.LOCAL,
233-
)
218+
return self.hs.config.email.can_verify_email
234219

235220
async def check_auth(self, authdict: dict, clientip: str) -> Any:
236221
return await self._check_threepid("email", authdict)

0 commit comments

Comments
 (0)