This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow SAML username provider plugins #6411
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b31adc6
Allow SAML username provider plugins
anoadragon453 11805ba
Add changelog
anoadragon453 82b81c0
Apply suggestions from code review
anoadragon453 f3a3eb4
typo
anoadragon453 da849c4
Provide a defeault mapping provider class
anoadragon453 b1a0a5b
wip saml mapping provider documentation
anoadragon453 466b28b
Add SAML mapping provider docs
anoadragon453 0985eb6
Pass the whole saml response object to the provider
anoadragon453 ce22034
Merge branch 'anoa/saml_username_provider' of github.com:matrix-org/s…
anoadragon453 595e947
Keep saml2_mxid_source_attribute object for SamlHandler
anoadragon453 6fec3a4
Fix if statement logic
anoadragon453 7eecd6c
Load module before doing most of the rest of the saml config
anoadragon453 fcb31ef
Properly pull in backwards compatible options
anoadragon453 0a42261
Fix argument to load_module
anoadragon453 5f03ec0
nostatic
anoadragon453 81688f4
Remove parse_config method
anoadragon453 e7cb32e
Fix reference to user mapping provider config
anoadragon453 e892842
Pull user mapping provider module from the right place
anoadragon453 169d369
Create an instance of the module's class first
anoadragon453 c0c75e5
Cleanup and fix var names
anoadragon453 27b5f0f
Remove comma
anoadragon453 aac1ab5
Deprecation warning, module config, cleanup and processing reordering
anoadragon453 1d0f2b2
Small fixes. Remove hs.config.saml2_mxid_source_attribute
anoadragon453 ba07fc2
Non-functional logging change. Doc update
anoadragon453 22a6b3c
Provider returns req/opt attrs, pass config to the provider, logging …
anoadragon453 9b85d7c
Remove modifications to load_module
anoadragon453 dcc6fe9
Address review comments
anoadragon453 e15fc6a
Fix typing statement
anoadragon453 f5dcbf5
lint
anoadragon453 22ead4f
Ensure parse_config doesn't fail if config: is None
anoadragon453 b8dd5ab
Fix attribute-retrieving method name
anoadragon453 e9bedc5
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/sam…
anoadragon453 87c9e7c
Add logging for what's returned by the provider
anoadragon453 9f01563
Add debug logging and fix config values being None
anoadragon453 e918990
Polish
anoadragon453 5b2281e
Comment cleanup
anoadragon453 8a2e617
Simplify pulling default from module config
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow custom SAML username mapping functinality through an external provider plugin. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # SAML Mapping Providers | ||
|
|
||
| A SAML mapping provider is a Python class (loaded via a Python module) that | ||
| works out how to map attributes of a SAML response object to Matrix-specific | ||
| user attributes. Details such as user ID localpart, displayname, and even avatar | ||
| URLs are all things that can be mapped from talking to a SSO service. | ||
|
|
||
| As an example, a SSO service may return the email address | ||
| "john.smith@example.com" for a user, whereas Synapse will need to figure out how | ||
| to turn that into a displayname when creating a Matrix user for this individual. | ||
| It may choose `John Smith`, or `Smith, John [Example.com]` or any number of | ||
| variations. As each Synapse configuration may want something different, this is | ||
| where SAML mapping providers come into play. | ||
|
|
||
| ## Enabling Providers | ||
|
|
||
| External mapping providers are provided to Synapse in the form of an external | ||
| Python module. Retrieve this module from [PyPi](https://pypi.org) or elsewhere, | ||
| then tell Synapse where to look for the handler class by editing the | ||
| `saml2_config.user_mapping_provider.module` config option. | ||
|
|
||
| `saml2_config.user_mapping_provider.config` allows you to provide custom | ||
| configuration options to the module. Check with the module's documentation for | ||
| what options it provides (if any). The options listed by default are for the | ||
| user mapping provider built in to Synapse. If using a custom module, you should | ||
| comment these options out and use those specified by the module instead. | ||
|
|
||
| ## Building a Custom Mapping Provider | ||
|
|
||
| A custom mapping provider must specify the following methods: | ||
|
|
||
| * `__init__(self, parsed_config)` | ||
| - Arguments: | ||
| - `parsed_config` - A configuration object that is the return value of the | ||
| `parse_config` method. You should set any configuration options needed by | ||
| the module here. | ||
| * `saml_response_to_user_attributes(self, saml_response, failures)` | ||
| - Arguments: | ||
| - `saml_response` - A `saml2.response.AuthnResponse` object to extract user | ||
| information from. | ||
| - `failures` - An `int` that represents the amount of times the returned | ||
| mxid localpart mapping has failed. This should be used | ||
| to create a deduplicated mxid localpart which should be | ||
| returned instead. For example, if this method returns | ||
| `john.doe` as the value of `mxid_localpart` in the returned | ||
| dict, and that is already taken on the homeserver, this | ||
| method will be called again with the same parameters but | ||
| with failures=1. The method should then return a different | ||
| `mxid_localpart` value, such as `john.doe1`. | ||
| - This method must return a dictionary, which will then be used by Synapse | ||
| to build a new user. The following keys are allowed: | ||
| * `mxid_localpart` - Required. The mxid localpart of the new user. | ||
| * `displayname` - The displayname of the new user. If not provided, will default to | ||
| the value of `mxid_localpart`. | ||
| * `parse_config(config)` | ||
| - This method should have the `@staticmethod` decoration. | ||
| - Arguments: | ||
| - `config` - A `dict` representing the parsed content of the | ||
| `saml2_config.user_mapping_provider.config` homeserver config option. | ||
| Runs on homeserver startup. Providers should extract any option values | ||
| they need here. | ||
| - Whatever is returned will be passed back to the user mapping provider module's | ||
| `__init__` method during construction. | ||
| * `get_saml_attributes(config)` | ||
| - This method should have the `@staticmethod` decoration. | ||
| - Arguments: | ||
| - `config` - A object resulting from a call to `parse_config`. | ||
| - Returns a tuple of two sets. The first set equates to the saml auth | ||
| response attributes that are required for the module to function, whereas | ||
| the second set consists of those attributes which can be used if available, | ||
| but are not necessary. | ||
|
|
||
| ## Synapse's Default Provider | ||
|
|
||
| Synapse has a built-in SAML mapping provider if a custom provider isn't | ||
| specified in the config. It is located at | ||
| [`synapse.handlers.saml_handler.DefaultSamlMappingProvider`](../synapse/handlers/saml_handler.py). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.