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

Commit cc3a52b

Browse files
authored
Support OIDC backchannel logouts (#11414)
If configured an OIDC IdP can log a user's session out of Synapse when they log out of the identity provider. The IdP sends a request directly to Synapse (and must be configured with an endpoint) when a user logs out.
1 parent 15bdb0d commit cc3a52b

File tree

13 files changed

+960
-66
lines changed

13 files changed

+960
-66
lines changed

changelog.d/11414.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support back-channel logouts from OpenID Connect providers.

docs/openid.md

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ setting in your configuration file.
4949
See the [configuration manual](usage/configuration/config_documentation.md#oidc_providers) for some sample settings, as well as
5050
the text below for example configurations for specific providers.
5151

52+
## OIDC Back-Channel Logout
53+
54+
Synapse supports receiving [OpenID Connect Back-Channel Logout](https://openid.net/specs/openid-connect-backchannel-1_0.html) notifications.
55+
56+
This lets the OpenID Connect Provider notify Synapse when a user logs out, so that Synapse can end that user session.
57+
This feature can be enabled by setting the `backchannel_logout_enabled` property to `true` in the provider configuration, and setting the following URL as destination for Back-Channel Logout notifications in your OpenID Connect Provider: `[synapse public baseurl]/_synapse/client/oidc/backchannel_logout`
58+
5259
## Sample configs
5360

5461
Here are a few configs for providers that should work with Synapse.
@@ -123,6 +130,9 @@ oidc_providers:
123130

124131
[Keycloak][keycloak-idp] is an opensource IdP maintained by Red Hat.
125132

133+
Keycloak supports OIDC Back-Channel Logout, which sends logout notification to Synapse, so that Synapse users get logged out when they log out from Keycloak.
134+
This can be optionally enabled by setting `backchannel_logout_enabled` to `true` in the Synapse configuration, and by setting the "Backchannel Logout URL" in Keycloak.
135+
126136
Follow the [Getting Started Guide](https://www.keycloak.org/getting-started) to install Keycloak and set up a realm.
127137

128138
1. Click `Clients` in the sidebar and click `Create`
@@ -144,6 +154,8 @@ Follow the [Getting Started Guide](https://www.keycloak.org/getting-started) to
144154
| Client Protocol | `openid-connect` |
145155
| Access Type | `confidential` |
146156
| Valid Redirect URIs | `[synapse public baseurl]/_synapse/client/oidc/callback` |
157+
| Backchannel Logout URL (optional) | `[synapse public baseurl]/_synapse/client/oidc/backchannel_logout` |
158+
| Backchannel Logout Session Required (optional) | `On` |
147159

148160
5. Click `Save`
149161
6. On the Credentials tab, update the fields:
@@ -167,7 +179,9 @@ oidc_providers:
167179
config:
168180
localpart_template: "{{ user.preferred_username }}"
169181
display_name_template: "{{ user.name }}"
182+
backchannel_logout_enabled: true # Optional
170183
```
184+
171185
### Auth0
172186

173187
[Auth0][auth0] is a hosted SaaS IdP solution.

docs/usage/configuration/config_documentation.md

+9
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,15 @@ Options for each entry include:
30213021
which is set to the claims returned by the UserInfo Endpoint and/or
30223022
in the ID Token.
30233023

3024+
* `backchannel_logout_enabled`: set to `true` to process OIDC Back-Channel Logout notifications.
3025+
Those notifications are expected to be received on `/_synapse/client/oidc/backchannel_logout`.
3026+
Defaults to `false`.
3027+
3028+
* `backchannel_logout_ignore_sub`: by default, the OIDC Back-Channel Logout feature checks that the
3029+
`sub` claim matches the subject claim received during login. This check can be disabled by setting
3030+
this to `true`. Defaults to `false`.
3031+
3032+
You might want to disable this if the `subject_claim` returned by the mapping provider is not `sub`.
30243033

30253034
It is possible to configure Synapse to only allow logins if certain attributes
30263035
match particular values in the OIDC userinfo. The requirements can be listed under

synapse/config/oidc.py

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def oidc_enabled(self) -> bool:
123123
"userinfo_endpoint": {"type": "string"},
124124
"jwks_uri": {"type": "string"},
125125
"skip_verification": {"type": "boolean"},
126+
"backchannel_logout_enabled": {"type": "boolean"},
127+
"backchannel_logout_ignore_sub": {"type": "boolean"},
126128
"user_profile_method": {
127129
"type": "string",
128130
"enum": ["auto", "userinfo_endpoint"],
@@ -292,6 +294,10 @@ def _parse_oidc_config_dict(
292294
token_endpoint=oidc_config.get("token_endpoint"),
293295
userinfo_endpoint=oidc_config.get("userinfo_endpoint"),
294296
jwks_uri=oidc_config.get("jwks_uri"),
297+
backchannel_logout_enabled=oidc_config.get("backchannel_logout_enabled", False),
298+
backchannel_logout_ignore_sub=oidc_config.get(
299+
"backchannel_logout_ignore_sub", False
300+
),
295301
skip_verification=oidc_config.get("skip_verification", False),
296302
user_profile_method=oidc_config.get("user_profile_method", "auto"),
297303
allow_existing_users=oidc_config.get("allow_existing_users", False),
@@ -368,6 +374,12 @@ class OidcProviderConfig:
368374
# "openid" scope is used.
369375
jwks_uri: Optional[str]
370376

377+
# Whether Synapse should react to backchannel logouts
378+
backchannel_logout_enabled: bool
379+
380+
# Whether Synapse should ignore the `sub` claim in backchannel logouts or not.
381+
backchannel_logout_ignore_sub: bool
382+
371383
# Whether to skip metadata verification
372384
skip_verification: bool
373385

0 commit comments

Comments
 (0)