Integrate with Mattermost Team Edition
Support level: Community
What is Mattermost Team Edition
Mattermost is an open source, real-time collaboration platform. It provides chat, audio/video calling, screen sharing, and a plugin architecture for extending its capabilities. Mattermost Team Edition is the free, open-source version of the product.
Preparation
The following placeholders are used in this guide:
mattermost.companyis the FQDN of the Mattermost installation.authentik.companyis the FQDN of the authentik installation.
This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application.
Configuration methods
You can configure Mattermost to use either OIDC or SAML, and this guide explains both options.
- Log in with OIDC
- Log in with SAML
Mattermost Team Edition does not natively support generic single sign-on. However, you can manually configure Mattermost to use its GitLab integration for authentication via authentik's OAuth2/OpenID Provider. This requires editing the config.json file directly, as the necessary settings are not available through the web interface. If you are using a hosted version of Mattermost without filesystem access, you will not be able to complete this setup.
Once configured, Mattermost will display a login button with the GitLab icon, but authentication will be handled entirely by authentik. GitLab itself is not required or used in any way.
authentik configuration
To support the integration of Mattermost Team Edition with authentik, you need to create property mappings and an application/provider pair in authentik.
Create property mappings
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to Customization > Property Mappings and click Create. Create a Scope Mapping with the following settings:
- Name:
mattermost-username - Scope Name:
username - Description:
Maps the user's authentik username to the username field for Mattermost authentication. - Expression:
return {
"username": request.user.username,
}
- Name:
The following id property mapping is optional. If omitted, Mattermost will generate user IDs based on email addresses, resulting in names such as person-example.com for person@example.com. Since these IDs serve as nicknames, this format may be undesirable.
- If desired, click Create again, and create another Scope Mapping with the following settings:
- Name:
mattermost-id - Scope Name:
id - Description:
Maps the user's Mattermost ID or primary key to the id field for Mattermost authentication. - Expression:
return {
"id": request.user.attributes.get("mattermostId", request.user.pk),
}
- Name:
Create an application and provider in authentik
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
- Application: provide a descriptive name, an optional group for the type of application, and the policy engine mode. Take note of the Slug value because it will be required later.
- Choose a Provider type: select OAuth2/OpenID Connect as the provider type.
- Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
- Note the Client ID and Client Secret values because they will be required later.
- Set a
Strictredirect URI tohttps://mattermost.company/signup/gitlab/complete. - Select any available signing key.
- Under Advanced protocol settings, add the scopes you just created to the list of selected scopes.
- Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
-
Click Submit to save the new application and provider.
Mattermost Team Edition configuration
To support the integration of Mattermost Team Edition with authentik, you'll need to update the config.json file of your Mattermost deployment:
- Modify the
GitLabSettingssection to look like the following:
"GitLabSettings": {
"Enable": true,
"Secret": "<client_secret>",
"Id": "<client_id>",
"Scope": "",
"AuthEndpoint": "https://authentik.company/application/o/authorize/",
"TokenEndpoint": "https://authentik.company/application/o/token/",
"UserAPIEndpoint": "https://authentik.company/application/o/userinfo/",
"DiscoveryEndpoint": "https://authentik.company/application/o/<application_slug>/.well-known/openid-configuration",
"ButtonText": "Log in with authentik",
"ButtonColor": "#000000"
},
- Log in to Mattermost as an administrator and navigate to the System Console. Go to Authentication > Signup options (
https://mattermost.company/admin_console/authentication/signup) and make sure that Enable Account Creation is set to true. - Restart Mattermost to apply the changes.
SAML authentication with encryption requires Mattermost Enterprise Edition or a licensed version. Mattermost Team Edition does not natively support SAML. If you are using Mattermost Team Edition, use OIDC instead.
Preparation
Before configuring SAML, you need to generate a certificate key pair for Mattermost to use for signing and decryption.
Generate a certificate key pair for Mattermost
Generate a public certificate and private key pair for Mattermost:
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
-keyout mattermost-private.key \
-out mattermost-public.crt \
-subj "/CN=mattermost.company"
Keep these files safe. You will upload the public certificate to authentik and both files to Mattermost.
authentik configuration
To support the integration of Mattermost with authentik via SAML, you need to upload the Mattermost certificate and create an application/provider pair in authentik.
Upload Mattermost's certificate to authentik
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to System > Certificates and click Import.
- Give it a name like
Mattermost Certificate. - Paste the contents of
mattermost-public.crtinto the Certificate field. - Leave the Private Key field empty (authentik only needs the public certificate for verification and encryption).
- Click Create.
Create an application and provider in authentik
-
Log in to authentik as an administrator and open the authentik Admin interface.
-
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair.
- Application: provide a descriptive name (e.g.,
Mattermost), an optional group for the type of application, and the policy engine mode. Take note of the slug as it will be required later. - Choose a Provider type: select SAML Provider as the provider type.
- Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations:
- Set the ACS URL to
https://mattermost.company/login/sso/saml. - Set the Issuer to
authentik. - Set the Service Provider Binding to
Post. - Under Advanced protocol settings:
- Set the Signing Certificate to any available authentik certificate (e.g., the default self-signed certificate).
- Enable Sign assertions.
- Enable Sign responses.
- Set the Verification Certificate to the Mattermost certificate you uploaded earlier.
- Set the Encryption Certificate to the Mattermost certificate you uploaded earlier.
- Set the ACS URL to
- Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
- Application: provide a descriptive name (e.g.,
-
Click Submit to save the new application and provider.
Download the authentik signing certificate
- Navigate to System > Certificates.
- Find the certificate you selected as the Signing Certificate for the SAML provider.
- Click the certificate name, then click Download Certificate to download the public certificate file.
Mattermost configuration
- Log in to Mattermost as an administrator.
- Navigate to Channels > System Console > Authentication > SAML 2.0.
- Configure the following settings:
- Enable Enable Login With SAML 2.0.
- Set SAML SSO URL to
https://authentik.company/application/saml/<application_slug>/sso/binding/redirect/. - Set Identity Provider Issuer URL to
authentik. - Set Identity Provider Public Certificate to the contents of the authentik signing certificate you downloaded.
- Enable Verify Signature.
- Set Service Provider Login URL to
https://mattermost.company/login/sso/saml. - Set Service Provider Identifier to
authentik. - Set Service Provider Private Key to
mattermost-private.key. - Set Service Provider Public Certificate to
mattermost-public.crt. - Enable Enable Encryption.
- Enable Sign Request.
- Set Signature Algorithm to
RSAwithSHA256. - Set Email Attribute to
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress. - Set Username Attribute to
http://schemas.goauthentik.io/2021/02/saml/username. - Set Id Attribute to
http://schemas.goauthentik.io/2021/02/saml/uid(optional).
- Click Save.
Configuration verification
To verify the integration of authentik with Mattermost, log out and attempt to log back in. You should see a login button for authentik on the login page, and a successful login should redirect you to Mattermost without any errors.
Troubleshooting
- Missing email or username error: If logging in with SAML, ensure that any users logging into Mattermost from authentik have both an email address and username set in their authentik profile.