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

Commit df948d1

Browse files
committed
Merge branch 'rav/default_public_base_url' into rav/idp_icon
2 parents aeb9706 + 8d78ca9 commit df948d1

File tree

14 files changed

+48
-83
lines changed

14 files changed

+48
-83
lines changed

changelog.d/9159.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Give the `public_baseurl` a default value, if it is not explicitly set in the configuration file.

docs/sample_config.yaml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ pid_file: DATADIR/homeserver.pid
6767
#
6868
#web_client_location: https://riot.example.com/
6969

70-
# The public-facing base URL that clients use to access this HS
71-
# (not including _matrix/...). This is the same URL a user would
72-
# enter into the 'custom HS URL' field on their client. If you
73-
# use synapse with a reverse proxy, this should be the URL to reach
74-
# synapse via the proxy.
70+
# The public-facing base URL that clients use to access this Homeserver (not
71+
# including _matrix/...). This is the same URL a user might enter into the
72+
# 'Custom Homeserver URL' field on their client. If you use Synapse with a
73+
# reverse proxy, this should be the URL to reach Synapse via the proxy.
74+
# Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
75+
# 'listeners' below).
76+
#
77+
# If this is left unset, it defaults to 'https://<server_name>/'. (Note that
78+
# that will not work unless you configure Synapse or a reverse-proxy to listen
79+
# on port 443.)
7580
#
7681
#public_baseurl: https://example.com/
7782

@@ -1150,8 +1155,9 @@ account_validity:
11501155
# send an email to the account's email address with a renewal link. By
11511156
# default, no such emails are sent.
11521157
#
1153-
# If you enable this setting, you will also need to fill out the 'email' and
1154-
# 'public_baseurl' configuration sections.
1158+
# If you enable this setting, you will also need to fill out the 'email'
1159+
# configuration section. You should also check that 'public_baseurl' is set
1160+
# correctly.
11551161
#
11561162
#renew_at: 1w
11571163

@@ -1242,8 +1248,7 @@ account_validity:
12421248
# The identity server which we suggest that clients should use when users log
12431249
# in on this server.
12441250
#
1245-
# (By default, no suggestion is made, so it is left up to the client.
1246-
# This setting is ignored unless public_baseurl is also set.)
1251+
# (By default, no suggestion is made, so it is left up to the client.)
12471252
#
12481253
#default_identity_server: https://matrix.org
12491254

@@ -1268,8 +1273,6 @@ account_validity:
12681273
# by the Matrix Identity Service API specification:
12691274
# https://matrix.org/docs/spec/identity_service/latest
12701275
#
1271-
# If a delegate is specified, the config option public_baseurl must also be filled out.
1272-
#
12731276
account_threepid_delegates:
12741277
#email: https://example.com # Delegate email sending to example.com
12751278
#msisdn: http://localhost:8090 # Delegate SMS sending to this local process
@@ -1905,9 +1908,9 @@ sso:
19051908
# phishing attacks from evil.site. To avoid this, include a slash after the
19061909
# hostname: "https://my.client/".
19071910
#
1908-
# If public_baseurl is set, then the login fallback page (used by clients
1909-
# that don't natively support the required login flows) is whitelisted in
1910-
# addition to any URLs in this list.
1911+
# The login fallback page (used by clients that don't natively support the
1912+
# required login flows) is automatically whitelisted in addition to any URLs
1913+
# in this list.
19111914
#
19121915
# By default, this list is empty.
19131916
#

synapse/api/urls.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def __init__(self, hs_config):
4242
"""
4343
if hs_config.form_secret is None:
4444
raise ConfigError("form_secret not set in config")
45-
if hs_config.public_baseurl is None:
46-
raise ConfigError("public_baseurl not set in config")
4745

4846
self._hmac_secret = hs_config.form_secret.encode("utf-8")
4947
self._public_baseurl = hs_config.public_baseurl

synapse/config/_base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ def read_templates(
252252
env = jinja2.Environment(loader=loader, autoescape=autoescape)
253253

254254
# Update the environment with our custom filters
255-
env.filters.update({"format_ts": _format_ts_filter})
256-
if self.public_baseurl:
257-
env.filters.update(
258-
{"mxc_to_http": _create_mxc_to_http_filter(self.public_baseurl)}
259-
)
255+
env.filters.update(
256+
{
257+
"format_ts": _format_ts_filter,
258+
"mxc_to_http": _create_mxc_to_http_filter(self.public_baseurl),
259+
}
260+
)
260261

261262
for filename in filenames:
262263
# Load the template

synapse/config/emailconfig.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ def read_config(self, config, **kwargs):
166166
if not self.email_notif_from:
167167
missing.append("email.notif_from")
168168

169-
# public_baseurl is required to build password reset and validation links that
170-
# will be emailed to users
171-
if config.get("public_baseurl") is None:
172-
missing.append("public_baseurl")
173-
174169
if missing:
175170
raise ConfigError(
176171
MISSING_PASSWORD_RESET_CONFIG_ERROR % (", ".join(missing),)
@@ -269,9 +264,6 @@ def read_config(self, config, **kwargs):
269264
if not self.email_notif_from:
270265
missing.append("email.notif_from")
271266

272-
if config.get("public_baseurl") is None:
273-
missing.append("public_baseurl")
274-
275267
if missing:
276268
raise ConfigError(
277269
"email.enable_notifs is True but required keys are missing: %s"

synapse/config/oidc_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def read_config(self, config, **kwargs):
4444
raise ConfigError(e.message) from e
4545

4646
public_baseurl = self.public_baseurl
47-
if public_baseurl is None:
48-
raise ConfigError("oidc_config requires a public_baseurl to be set")
4947
self.oidc_callback_url = public_baseurl + "_synapse/oidc/callback"
5048

5149
@property

synapse/config/registration.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ def __init__(self, config, synapse_config):
4949

5050
self.startup_job_max_delta = self.period * 10.0 / 100.0
5151

52-
if self.renew_by_email_enabled:
53-
if "public_baseurl" not in synapse_config:
54-
raise ConfigError("Can't send renewal emails without 'public_baseurl'")
55-
5652
template_dir = config.get("template_dir")
5753

5854
if not template_dir:
@@ -109,13 +105,6 @@ def read_config(self, config, **kwargs):
109105
account_threepid_delegates = config.get("account_threepid_delegates") or {}
110106
self.account_threepid_delegate_email = account_threepid_delegates.get("email")
111107
self.account_threepid_delegate_msisdn = account_threepid_delegates.get("msisdn")
112-
if self.account_threepid_delegate_msisdn and not self.public_baseurl:
113-
raise ConfigError(
114-
"The configuration option `public_baseurl` is required if "
115-
"`account_threepid_delegate.msisdn` is set, such that "
116-
"clients know where to submit validation tokens to. Please "
117-
"configure `public_baseurl`."
118-
)
119108

120109
self.default_identity_server = config.get("default_identity_server")
121110
self.allow_guest_access = config.get("allow_guest_access", False)
@@ -240,8 +229,9 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
240229
# send an email to the account's email address with a renewal link. By
241230
# default, no such emails are sent.
242231
#
243-
# If you enable this setting, you will also need to fill out the 'email' and
244-
# 'public_baseurl' configuration sections.
232+
# If you enable this setting, you will also need to fill out the 'email'
233+
# configuration section. You should also check that 'public_baseurl' is set
234+
# correctly.
245235
#
246236
#renew_at: 1w
247237
@@ -332,8 +322,7 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
332322
# The identity server which we suggest that clients should use when users log
333323
# in on this server.
334324
#
335-
# (By default, no suggestion is made, so it is left up to the client.
336-
# This setting is ignored unless public_baseurl is also set.)
325+
# (By default, no suggestion is made, so it is left up to the client.)
337326
#
338327
#default_identity_server: https://matrix.org
339328
@@ -358,8 +347,6 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
358347
# by the Matrix Identity Service API specification:
359348
# https://matrix.org/docs/spec/identity_service/latest
360349
#
361-
# If a delegate is specified, the config option public_baseurl must also be filled out.
362-
#
363350
account_threepid_delegates:
364351
#email: https://example.com # Delegate email sending to example.com
365352
#msisdn: http://localhost:8090 # Delegate SMS sending to this local process

synapse/config/saml2_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ def _default_saml_config_dict(
189189
import saml2
190190

191191
public_baseurl = self.public_baseurl
192-
if public_baseurl is None:
193-
raise ConfigError("saml2_config requires a public_baseurl to be set")
194192

195193
if self.saml2_grandfathered_mxid_source_attribute:
196194
optional_attributes.add(self.saml2_grandfathered_mxid_source_attribute)

synapse/config/server.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ def read_config(self, config, **kwargs):
161161
self.print_pidfile = config.get("print_pidfile")
162162
self.user_agent_suffix = config.get("user_agent_suffix")
163163
self.use_frozen_dicts = config.get("use_frozen_dicts", False)
164-
self.public_baseurl = config.get("public_baseurl")
164+
self.public_baseurl = config.get("public_baseurl") or "https://%s/" % (
165+
self.server_name,
166+
)
167+
if self.public_baseurl[-1] != "/":
168+
self.public_baseurl += "/"
165169

166170
# Whether to enable user presence.
167171
self.use_presence = config.get("use_presence", True)
@@ -317,9 +321,6 @@ def read_config(self, config, **kwargs):
317321
# Always blacklist 0.0.0.0, ::
318322
self.federation_ip_range_blacklist.update(["0.0.0.0", "::"])
319323

320-
if self.public_baseurl is not None:
321-
if self.public_baseurl[-1] != "/":
322-
self.public_baseurl += "/"
323324
self.start_pushers = config.get("start_pushers", True)
324325

325326
# (undocumented) option for torturing the worker-mode replication a bit,
@@ -740,11 +741,16 @@ def generate_config_section(
740741
#
741742
#web_client_location: https://riot.example.com/
742743
743-
# The public-facing base URL that clients use to access this HS
744-
# (not including _matrix/...). This is the same URL a user would
745-
# enter into the 'custom HS URL' field on their client. If you
746-
# use synapse with a reverse proxy, this should be the URL to reach
747-
# synapse via the proxy.
744+
# The public-facing base URL that clients use to access this Homeserver (not
745+
# including _matrix/...). This is the same URL a user might enter into the
746+
# 'Custom Homeserver URL' field on their client. If you use Synapse with a
747+
# reverse proxy, this should be the URL to reach Synapse via the proxy.
748+
# Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
749+
# 'listeners' below).
750+
#
751+
# If this is left unset, it defaults to 'https://<server_name>/'. (Note that
752+
# that will not work unless you configure Synapse or a reverse-proxy to listen
753+
# on port 443.)
748754
#
749755
#public_baseurl: https://example.com/
750756

synapse/config/sso.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ def read_config(self, config, **kwargs):
6464
# gracefully to the client). This would make it pointless to ask the user for
6565
# confirmation, since the URL the confirmation page would be showing wouldn't be
6666
# the client's.
67-
# public_baseurl is an optional setting, so we only add the fallback's URL to the
68-
# list if it's provided (because we can't figure out what that URL is otherwise).
69-
if self.public_baseurl:
70-
login_fallback_url = self.public_baseurl + "_matrix/static/client/login"
71-
self.sso_client_whitelist.append(login_fallback_url)
67+
login_fallback_url = self.public_baseurl + "_matrix/static/client/login"
68+
self.sso_client_whitelist.append(login_fallback_url)
7269

7370
def generate_config_section(self, **kwargs):
7471
return """\
@@ -86,9 +83,9 @@ def generate_config_section(self, **kwargs):
8683
# phishing attacks from evil.site. To avoid this, include a slash after the
8784
# hostname: "https://my.client/".
8885
#
89-
# If public_baseurl is set, then the login fallback page (used by clients
90-
# that don't natively support the required login flows) is whitelisted in
91-
# addition to any URLs in this list.
86+
# The login fallback page (used by clients that don't natively support the
87+
# required login flows) is automatically whitelisted in addition to any URLs
88+
# in this list.
9289
#
9390
# By default, this list is empty.
9491
#

0 commit comments

Comments
 (0)