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

Commit 7447f19

Browse files
authored
Prefix idp_id with "oidc-" (#9189)
... to avoid clashes with other SSO mechanisms
1 parent 937b849 commit 7447f19

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

changelog.d/9189.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add an `oidc-` prefix to any `idp_id`s which are given in the `oidc_providers` configuration.

docs/sample_config.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,9 @@ saml2_config:
17281728
#
17291729
# idp_icon: An optional icon for this identity provider, which is presented
17301730
# by identity picker pages. If given, must be an MXC URI of the format
1731-
# mxc://<server-name>/<media-id>
1731+
# mxc://<server-name>/<media-id>. (An easy way to obtain such an MXC URI
1732+
# is to upload an image to an (unencrypted) room and then copy the "url"
1733+
# from the source of the event.)
17321734
#
17331735
# discover: set to 'false' to disable the use of the OIDC discovery mechanism
17341736
# to discover endpoints. Defaults to true.
@@ -1814,13 +1816,16 @@ saml2_config:
18141816
#
18151817
# For backwards compatibility, it is also possible to configure a single OIDC
18161818
# provider via an 'oidc_config' setting. This is now deprecated and admins are
1817-
# advised to migrate to the 'oidc_providers' format.
1819+
# advised to migrate to the 'oidc_providers' format. (When doing that migration,
1820+
# use 'oidc' for the idp_id to ensure that existing users continue to be
1821+
# recognised.)
18181822
#
18191823
oidc_providers:
18201824
# Generic example
18211825
#
18221826
#- idp_id: my_idp
18231827
# idp_name: "My OpenID provider"
1828+
# idp_icon: "mxc://example.com/mediaid"
18241829
# discover: false
18251830
# issuer: "https://accounts.example.com/"
18261831
# client_id: "provided-by-your-issuer"
@@ -1844,8 +1849,8 @@ oidc_providers:
18441849

18451850
# For use with Github
18461851
#
1847-
#- idp_id: google
1848-
# idp_name: Google
1852+
#- idp_id: github
1853+
# idp_name: Github
18491854
# discover: false
18501855
# issuer: "https://github.com/"
18511856
# client_id: "your-client-id" # TO BE FILLED

synapse/config/oidc_config.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
6969
#
7070
# idp_icon: An optional icon for this identity provider, which is presented
7171
# by identity picker pages. If given, must be an MXC URI of the format
72-
# mxc://<server-name>/<media-id>
72+
# mxc://<server-name>/<media-id>. (An easy way to obtain such an MXC URI
73+
# is to upload an image to an (unencrypted) room and then copy the "url"
74+
# from the source of the event.)
7375
#
7476
# discover: set to 'false' to disable the use of the OIDC discovery mechanism
7577
# to discover endpoints. Defaults to true.
@@ -155,13 +157,16 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
155157
#
156158
# For backwards compatibility, it is also possible to configure a single OIDC
157159
# provider via an 'oidc_config' setting. This is now deprecated and admins are
158-
# advised to migrate to the 'oidc_providers' format.
160+
# advised to migrate to the 'oidc_providers' format. (When doing that migration,
161+
# use 'oidc' for the idp_id to ensure that existing users continue to be
162+
# recognised.)
159163
#
160164
oidc_providers:
161165
# Generic example
162166
#
163167
#- idp_id: my_idp
164168
# idp_name: "My OpenID provider"
169+
# idp_icon: "mxc://example.com/mediaid"
165170
# discover: false
166171
# issuer: "https://accounts.example.com/"
167172
# client_id: "provided-by-your-issuer"
@@ -185,8 +190,8 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
185190
186191
# For use with Github
187192
#
188-
#- idp_id: google
189-
# idp_name: Google
193+
#- idp_id: github
194+
# idp_name: Github
190195
# discover: false
191196
# issuer: "https://github.com/"
192197
# client_id: "your-client-id" # TO BE FILLED
@@ -210,6 +215,8 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
210215
"type": "object",
211216
"required": ["issuer", "client_id", "client_secret"],
212217
"properties": {
218+
# TODO: fix the maxLength here depending on what MSC2528 decides
219+
# remember that we prefix the ID given here with `oidc-`
213220
"idp_id": {"type": "string", "minLength": 1, "maxLength": 128},
214221
"idp_name": {"type": "string"},
215222
"idp_icon": {"type": "string"},
@@ -335,6 +342,8 @@ def _parse_oidc_config_dict(
335342
# enforce those limits now.
336343
# TODO: factor out this stuff to a generic function
337344
idp_id = oidc_config.get("idp_id", "oidc")
345+
346+
# TODO: update this validity check based on what MSC2858 decides.
338347
valid_idp_chars = set(string.ascii_lowercase + string.digits + "-._")
339348

340349
if any(c not in valid_idp_chars for c in idp_id):
@@ -348,6 +357,17 @@ def _parse_oidc_config_dict(
348357
"idp_id must start with a-z", config_path + ("idp_id",),
349358
)
350359

360+
# prefix the given IDP with a prefix specific to the SSO mechanism, to avoid
361+
# clashes with other mechs (such as SAML, CAS).
362+
#
363+
# We allow "oidc" as an exception so that people migrating from old-style
364+
# "oidc_config" format (which has long used "oidc" as its idp_id) can migrate to
365+
# a new-style "oidc_providers" entry without changing the idp_id for their provider
366+
# (and thereby invalidating their user_external_ids data).
367+
368+
if idp_id != "oidc":
369+
idp_id = "oidc-" + idp_id
370+
351371
# MSC2858 also specifies that the idp_icon must be a valid MXC uri
352372
idp_icon = oidc_config.get("idp_icon")
353373
if idp_icon is not None:

tests/rest/client/v1/test_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def test_multi_sso_redirect(self):
446446
p.feed(channel.result["body"].decode("utf-8"))
447447
p.close()
448448

449-
self.assertCountEqual(p.radios["idp"], ["cas", "oidc", "idp1", "saml"])
449+
self.assertCountEqual(p.radios["idp"], ["cas", "oidc", "oidc-idp1", "saml"])
450450

451451
self.assertEqual(p.hiddens["redirectUrl"], TEST_CLIENT_REDIRECT_URL)
452452

0 commit comments

Comments
 (0)