docs/main/administration-guide/onboard/sso-saml-keycloak.mdx
import Inc0_sso_saml_ldapsync from './sso-saml-ldapsync.mdx'; import Inc1_sso_saml_faq from './sso-saml-faq.mdx';
<PlanAvailability slug="all-commercial" />The following process provides steps to configure SAML with Keycloak for Mattermost.
See the encryption options documentation for details on what encryption methods Mattermost supports for SAML.
This was tested with Keycloak v26.4.0. We recommend adding Mattermost as a client to your primary realm.
</Note>
- Client type:
SAML- Client ID:
mattermost
- Root URL:
http://your-mattermost-url.com- Home URL:
/login/sso/saml- Valid redirect URIs:
/login/sso/saml
- Enabled: On
- Name ID format:
- Force Name ID format: On
<div class="warning"> <div class="title">
- Sign Documents: Off
- Sign Assertions: On
- Signature Algorithm:
RSA_SHA1- SAML signature key name:
NONE- Canonicalization Method:
EXCLUSIVE- Encryption Algorithm:
AES_256_GCM- Key Transport Algorithm:
RSA_OAEP_MGF1P- Digest method for RSA-OAEP:
SHA1Warning
</div>Mattermost only supports
</div>RSA_SHA1for Keycloak SAML, because Keycloak is usingxmlencforRSA_SHA512andRSA_SHA256, wheras Mattermost currently only supportsxmldsig. So make sure to useRSA_SHA1as the Signature Algorithm and Digest Method as described in this section.
Client signature required: Off
Encrypt Assertions: On
<div class="warning"> <div class="title">
- Click Generate
- Download the private.key file.
- Click Confirm
Warning
</div>Mattermost does not support request signing with Keycloak so make sure to disable the Client signature setting as mentioned above.
</div>Next, click Export and update the following values and download the keystore.p12 file.
- Archive Format:
PKCS12- Key Alias:
mattermost- Key Password:
mattermost- Store Password:
mattermost
Navigate to the Client scopes tab.
First we add the predefined mappers for email, first name, and last name.
Next, we add the mappers for username and id.
Username.username (This is case sensitive and must be lowercase).username.id to create the ID Attribute.If you're planning to sync your SAML users with LDAP within Mattermost, the ID value used here must match with your Mattermost LDAP ID Attribute.
Once done your Mappers should look like this:
Get the metadata URL from Keycloak:
In the Mattermost System Console go to Authentication > SAML.
Set the Identity Provider Metadata URL to the value you copied from the step above and select Get SAML Metadata from IdP. The metadata import will populate fields related to your Keycloak configuration.
If you have any issues with this import, you can check the mattermost.log file for more information. Enable debug logging and try again.
Set the below fields:
http://your-mattermost-url.com/login/sso/samlmattermostThe Service Provider Identifier will match the Client ID that you configured in the second Keycloak step.
Configure the Encryption using the key you downloaded in step 6 of the Keycloak config.
.crt file from the .p12 file.openssl pkcs12 -password pass:mattermost -in keystore.p12 -out mattermost.crt -nodes -legacy
.key file from the .p12 file.openssl pkcs12 -password pass:mattermost -in keystore.p12 -out mattermost.key -nodes -nocerts -legacy
- Service Provider Private Key:
mattermost.key- Service Provider Private Certificate:
mattermost.crt- Sign Request: true
- Signature Algorithm:
RSAwithSHA256- Canonicalization Algorithm:
Exclusive XML Canonicalization 1.0 (omits comments)
Set attributes for the SAML Assertions, which will update user information in Mattermost.
The attributes below are from steps 7 and 8 above. These values must be the SAML Attribute Name within Keycloak. See documentation on SAML configuration settings for more details.
emailusernameidSelect Save.
To confirm SAML is working correctly, log out of Mattermost or open Mattermost in a new Incognito Browser Window and select Sign in with SAML on the login page and login with an existing Keycloak account.
If you have existing users in Mattermost that are going to be migrated to SAML login, make sure to plan for user migration and update your users accordingly.
You may also configure SAML for Keycloak by editing config.json. Before starting the Mattermost server, edit config.json to enable SAML based on SAML configuration settings. You must restart the Mattermost server for the changes to take effect.
In Mattermost, go to System Console > Authentication > SAML.
Set the Guest Attribute to designate which SAML users are guests.
In the Keycloak administration interface, add a user attribute mapper for guests.
Select Clients from the LHS menu.
Select mattermost from the list.
- Select the Client Scopes tab
- Select mattermost dedicated from the list of scopes
- Click the Add mapper drop down and select By configuration
- Select User Attribute on the model that opens
- Add values for Name, User Attribute and SAML Attribute Name as shown
Select Users from the LHS menu.
Select the username of the desired user.
Select the Attribute tab and select + add an attribute.
Add the key and value.
<Inc0_sso_saml_ldapsync />
<Inc1_sso_saml_faq /> :start-after: :nosearch: