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

Commit 8f1aefa

Browse files
authored
Improve the sample config for SSO (OIDC, SAML, and CAS). (#8635)
1 parent cbc82aa commit 8f1aefa

File tree

5 files changed

+157
-104
lines changed

5 files changed

+157
-104
lines changed

changelog.d/8635.doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve the sample configuration for single sign-on providers.

docs/sample_config.yaml

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,10 +1505,8 @@ trusted_key_servers:
15051505

15061506
## Single sign-on integration ##
15071507

1508-
# Enable SAML2 for registration and login. Uses pysaml2.
1509-
#
1510-
# At least one of `sp_config` or `config_path` must be set in this section to
1511-
# enable SAML login.
1508+
# The following settings can be used to make Synapse use a single sign-on
1509+
# provider for authentication, instead of its internal password database.
15121510
#
15131511
# You will probably also want to set the following options to `false` to
15141512
# disable the regular login/registration flows:
@@ -1517,6 +1515,11 @@ trusted_key_servers:
15171515
#
15181516
# You will also want to investigate the settings under the "sso" configuration
15191517
# section below.
1518+
1519+
# Enable SAML2 for registration and login. Uses pysaml2.
1520+
#
1521+
# At least one of `sp_config` or `config_path` must be set in this section to
1522+
# enable SAML login.
15201523
#
15211524
# Once SAML support is enabled, a metadata file will be exposed at
15221525
# https://<server>:<port>/_matrix/saml2/metadata.xml, which you may be able to
@@ -1532,40 +1535,42 @@ saml2_config:
15321535
# so it is not normally necessary to specify them unless you need to
15331536
# override them.
15341537
#
1535-
#sp_config:
1536-
# # point this to the IdP's metadata. You can use either a local file or
1537-
# # (preferably) a URL.
1538-
# metadata:
1539-
# #local: ["saml2/idp.xml"]
1540-
# remote:
1541-
# - url: https://our_idp/metadata.xml
1542-
#
1543-
# # By default, the user has to go to our login page first. If you'd like
1544-
# # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
1545-
# # 'service.sp' section:
1546-
# #
1547-
# #service:
1548-
# # sp:
1549-
# # allow_unsolicited: true
1550-
#
1551-
# # The examples below are just used to generate our metadata xml, and you
1552-
# # may well not need them, depending on your setup. Alternatively you
1553-
# # may need a whole lot more detail - see the pysaml2 docs!
1554-
#
1555-
# description: ["My awesome SP", "en"]
1556-
# name: ["Test SP", "en"]
1557-
#
1558-
# organization:
1559-
# name: Example com
1560-
# display_name:
1561-
# - ["Example co", "en"]
1562-
# url: "http://example.com"
1563-
#
1564-
# contact_person:
1565-
# - given_name: Bob
1566-
# sur_name: "the Sysadmin"
1567-
# email_address": ["[email protected]"]
1568-
# contact_type": technical
1538+
sp_config:
1539+
# Point this to the IdP's metadata. You must provide either a local
1540+
# file via the `local` attribute or (preferably) a URL via the
1541+
# `remote` attribute.
1542+
#
1543+
#metadata:
1544+
# local: ["saml2/idp.xml"]
1545+
# remote:
1546+
# - url: https://our_idp/metadata.xml
1547+
1548+
# By default, the user has to go to our login page first. If you'd like
1549+
# to allow IdP-initiated login, set 'allow_unsolicited: true' in a
1550+
# 'service.sp' section:
1551+
#
1552+
#service:
1553+
# sp:
1554+
# allow_unsolicited: true
1555+
1556+
# The examples below are just used to generate our metadata xml, and you
1557+
# may well not need them, depending on your setup. Alternatively you
1558+
# may need a whole lot more detail - see the pysaml2 docs!
1559+
1560+
#description: ["My awesome SP", "en"]
1561+
#name: ["Test SP", "en"]
1562+
1563+
#organization:
1564+
# name: Example com
1565+
# display_name:
1566+
# - ["Example co", "en"]
1567+
# url: "http://example.com"
1568+
1569+
#contact_person:
1570+
# - given_name: Bob
1571+
# sur_name: "the Sysadmin"
1572+
# email_address": ["[email protected]"]
1573+
# contact_type": technical
15691574

15701575
# Instead of putting the config inline as above, you can specify a
15711576
# separate pysaml2 configuration file:
@@ -1641,11 +1646,10 @@ saml2_config:
16411646
# value: "sales"
16421647

16431648

1644-
# OpenID Connect integration. The following settings can be used to make Synapse
1645-
# use an OpenID Connect Provider for authentication, instead of its internal
1646-
# password database.
1649+
# Enable OpenID Connect (OIDC) / OAuth 2.0 for registration and login.
16471650
#
1648-
# See https://github.com/matrix-org/synapse/blob/master/docs/openid.md.
1651+
# See https://github.com/matrix-org/synapse/blob/master/docs/openid.md
1652+
# for some example configurations.
16491653
#
16501654
oidc_config:
16511655
# Uncomment the following to enable authorization against an OpenID Connect
@@ -1778,15 +1782,37 @@ oidc_config:
17781782

17791783

17801784

1781-
# Enable CAS for registration and login.
1785+
# Enable Central Authentication Service (CAS) for registration and login.
17821786
#
1783-
#cas_config:
1784-
# enabled: true
1785-
# server_url: "https://cas-server.com"
1786-
# service_url: "https://homeserver.domain.com:8448"
1787-
# #displayname_attribute: name
1788-
# #required_attributes:
1789-
# # name: value
1787+
cas_config:
1788+
# Uncomment the following to enable authorization against a CAS server.
1789+
# Defaults to false.
1790+
#
1791+
#enabled: true
1792+
1793+
# The URL of the CAS authorization endpoint.
1794+
#
1795+
#server_url: "https://cas-server.com"
1796+
1797+
# The public URL of the homeserver.
1798+
#
1799+
#service_url: "https://homeserver.domain.com:8448"
1800+
1801+
# The attribute of the CAS response to use as the display name.
1802+
#
1803+
# If unset, no displayname will be set.
1804+
#
1805+
#displayname_attribute: name
1806+
1807+
# It is possible to configure Synapse to only allow logins if CAS attributes
1808+
# match particular values. All of the keys in the mapping below must exist
1809+
# and the values must match the given value. Alternately if the given value
1810+
# is None then any value is allowed (the attribute just must exist).
1811+
# All of the listed attributes must match for the login to be permitted.
1812+
#
1813+
#required_attributes:
1814+
# userGroup: "staff"
1815+
# department: None
17901816

17911817

17921818
# Additional settings to use with single-sign on systems such as OpenID Connect,

synapse/config/cas.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,50 @@ class CasConfig(Config):
2626

2727
def read_config(self, config, **kwargs):
2828
cas_config = config.get("cas_config", None)
29-
if cas_config:
30-
self.cas_enabled = cas_config.get("enabled", True)
29+
self.cas_enabled = cas_config and cas_config.get("enabled", True)
30+
31+
if self.cas_enabled:
3132
self.cas_server_url = cas_config["server_url"]
3233
self.cas_service_url = cas_config["service_url"]
3334
self.cas_displayname_attribute = cas_config.get("displayname_attribute")
34-
self.cas_required_attributes = cas_config.get("required_attributes", {})
35+
self.cas_required_attributes = cas_config.get("required_attributes") or {}
3536
else:
36-
self.cas_enabled = False
3737
self.cas_server_url = None
3838
self.cas_service_url = None
3939
self.cas_displayname_attribute = None
4040
self.cas_required_attributes = {}
4141

4242
def generate_config_section(self, config_dir_path, server_name, **kwargs):
4343
return """
44-
# Enable CAS for registration and login.
44+
# Enable Central Authentication Service (CAS) for registration and login.
4545
#
46-
#cas_config:
47-
# enabled: true
48-
# server_url: "https://cas-server.com"
49-
# service_url: "https://homeserver.domain.com:8448"
50-
# #displayname_attribute: name
51-
# #required_attributes:
52-
# # name: value
46+
cas_config:
47+
# Uncomment the following to enable authorization against a CAS server.
48+
# Defaults to false.
49+
#
50+
#enabled: true
51+
52+
# The URL of the CAS authorization endpoint.
53+
#
54+
#server_url: "https://cas-server.com"
55+
56+
# The public URL of the homeserver.
57+
#
58+
#service_url: "https://homeserver.domain.com:8448"
59+
60+
# The attribute of the CAS response to use as the display name.
61+
#
62+
# If unset, no displayname will be set.
63+
#
64+
#displayname_attribute: name
65+
66+
# It is possible to configure Synapse to only allow logins if CAS attributes
67+
# match particular values. All of the keys in the mapping below must exist
68+
# and the values must match the given value. Alternately if the given value
69+
# is None then any value is allowed (the attribute just must exist).
70+
# All of the listed attributes must match for the login to be permitted.
71+
#
72+
#required_attributes:
73+
# userGroup: "staff"
74+
# department: None
5375
"""

synapse/config/oidc_config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ def read_config(self, config, **kwargs):
8787

8888
def generate_config_section(self, config_dir_path, server_name, **kwargs):
8989
return """\
90-
# OpenID Connect integration. The following settings can be used to make Synapse
91-
# use an OpenID Connect Provider for authentication, instead of its internal
92-
# password database.
90+
# Enable OpenID Connect (OIDC) / OAuth 2.0 for registration and login.
9391
#
94-
# See https://github.com/matrix-org/synapse/blob/master/docs/openid.md.
92+
# See https://github.com/matrix-org/synapse/blob/master/docs/openid.md
93+
# for some example configurations.
9594
#
9695
oidc_config:
9796
# Uncomment the following to enable authorization against an OpenID Connect

synapse/config/saml2_config.py

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,8 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
216216
return """\
217217
## Single sign-on integration ##
218218
219-
# Enable SAML2 for registration and login. Uses pysaml2.
220-
#
221-
# At least one of `sp_config` or `config_path` must be set in this section to
222-
# enable SAML login.
219+
# The following settings can be used to make Synapse use a single sign-on
220+
# provider for authentication, instead of its internal password database.
223221
#
224222
# You will probably also want to set the following options to `false` to
225223
# disable the regular login/registration flows:
@@ -228,6 +226,11 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
228226
#
229227
# You will also want to investigate the settings under the "sso" configuration
230228
# section below.
229+
230+
# Enable SAML2 for registration and login. Uses pysaml2.
231+
#
232+
# At least one of `sp_config` or `config_path` must be set in this section to
233+
# enable SAML login.
231234
#
232235
# Once SAML support is enabled, a metadata file will be exposed at
233236
# https://<server>:<port>/_matrix/saml2/metadata.xml, which you may be able to
@@ -243,40 +246,42 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
243246
# so it is not normally necessary to specify them unless you need to
244247
# override them.
245248
#
246-
#sp_config:
247-
# # point this to the IdP's metadata. You can use either a local file or
248-
# # (preferably) a URL.
249-
# metadata:
250-
# #local: ["saml2/idp.xml"]
251-
# remote:
252-
# - url: https://our_idp/metadata.xml
253-
#
254-
# # By default, the user has to go to our login page first. If you'd like
255-
# # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
256-
# # 'service.sp' section:
257-
# #
258-
# #service:
259-
# # sp:
260-
# # allow_unsolicited: true
261-
#
262-
# # The examples below are just used to generate our metadata xml, and you
263-
# # may well not need them, depending on your setup. Alternatively you
264-
# # may need a whole lot more detail - see the pysaml2 docs!
265-
#
266-
# description: ["My awesome SP", "en"]
267-
# name: ["Test SP", "en"]
268-
#
269-
# organization:
270-
# name: Example com
271-
# display_name:
272-
# - ["Example co", "en"]
273-
# url: "http://example.com"
274-
#
275-
# contact_person:
276-
# - given_name: Bob
277-
# sur_name: "the Sysadmin"
278-
# email_address": ["[email protected]"]
279-
# contact_type": technical
249+
sp_config:
250+
# Point this to the IdP's metadata. You must provide either a local
251+
# file via the `local` attribute or (preferably) a URL via the
252+
# `remote` attribute.
253+
#
254+
#metadata:
255+
# local: ["saml2/idp.xml"]
256+
# remote:
257+
# - url: https://our_idp/metadata.xml
258+
259+
# By default, the user has to go to our login page first. If you'd like
260+
# to allow IdP-initiated login, set 'allow_unsolicited: true' in a
261+
# 'service.sp' section:
262+
#
263+
#service:
264+
# sp:
265+
# allow_unsolicited: true
266+
267+
# The examples below are just used to generate our metadata xml, and you
268+
# may well not need them, depending on your setup. Alternatively you
269+
# may need a whole lot more detail - see the pysaml2 docs!
270+
271+
#description: ["My awesome SP", "en"]
272+
#name: ["Test SP", "en"]
273+
274+
#organization:
275+
# name: Example com
276+
# display_name:
277+
# - ["Example co", "en"]
278+
# url: "http://example.com"
279+
280+
#contact_person:
281+
# - given_name: Bob
282+
# sur_name: "the Sysadmin"
283+
# email_address": ["[email protected]"]
284+
# contact_type": technical
280285
281286
# Instead of putting the config inline as above, you can specify a
282287
# separate pysaml2 configuration file:

0 commit comments

Comments
 (0)