Configure SAML with Microsoft ADFS for Windows Server 2012

The following process provides steps to configure SAML 2.0 with Microsoft ADFS for Mattermost.

Before you begin

Before you begin, you need generate encryption certificates for encrypting the SAML connection.

  1. You can use the Bash script from the mattermost/docs repository on GitHub, or any other suitable method.

  2. Save the two files that are generated. They are the private key and the public key. In the System Console, they are referred to as the Service Provider Private Key and the Service Provider Public Certificate respectively.

The following are basic requirements to use ADFS for Mattermost:
  • An Active Directory instance where all users have a specified email and username attributes. For Mattermost servers running 3.3 and earlier, users must also have their first name and last name attributes specified.

  • A Microsoft Server running. The screenshots used in this guide are from Microsoft Server 2012R2, but similar steps should work for other versions.

  • An SSL certificate to sign your ADFS login page.

  • ADFS installed on your Microsoft Server. You can find a detailed guide for deploying and configuring ADFS in this article.

On your ADFS installation, note down the value of the SAML 2.0/W-Federation URL in ADFS Endpoints section, also known as the SAML SSO URL Endpoint in this guide. If you chose the defaults for the installation, this will be /adfs/ls/.

Add a relying party trust

  1. In the ADFS management sidebar, go to AD FS > Trust Relationships > Relying Party Trusts, then select Add Relying Party Trust. A configuration wizard opens for adding a new relying party trust.

    ../_images/adfs_1_add_new_relying_party_trust.png
  2. On the Welcome screen, select Start.

    ../_images/adfs_2_start_wizard.png
  3. On the Select Data Source screen, select Enter data about the relying party manually.

    ../_images/adfs_3_select_data_source.png
  4. On the Specify Display Name screen, enter a Display Name to recognize the trust, such as Mattermost, then add any notes you want to make.

    ../_images/adfs_4_specify_display_name.png
  5. On the Choose Profile screen, select AD FS profile.

    ../_images/adfs_5_choose_profile.png
  6. On the Configure Certificate screen, leave the certificate settings at their default values.

    ../_images/adfs_6_configure_certificate_default.png

However, if you would like to set up encryption for your SAML connection, select Browse, then upload your Service Provider Public Certificate.

../_images/adfs_7_configure_certificate_encryption.png
  1. On the Configure URL screen, select Enable Support for the SAML 2.0 WebSSO protocol, then enter the SAML 2.0 SSO service URL, similar to https://<your-mattermost-url>/login/sso/saml where <your-mattermost-url> should typically match the Mattermost Site URL.

    ../_images/adfs_8_configure_url.png
  2. On the Configure Identifiers screen, enter the Relying party trust identifier (also known as the Identity Provider Issuer URL) of the form https://<your-idp-url>/adfs/services/trust, then click Add.

    ../_images/adfs_9_configure_identifiers.png
  3. On the Configure Multi-factor Authentication Now screen, you may enable multi-factor authentication. This is beyond the scope of this documentation.

    ../_images/adfs_10_configure_mfa.png
  4. On the Choose Issuance Authorization Rules screen, select Permit all users to access this relying party.

    ../_images/adfs_11_authorization.png
  5. On the Ready to Add Trust screen, review your settings.

    ../_images/adfs_12_ready_to_add_trust.png
  6. On the Finish screen, select Open the Edit Claim Rules dialog for this relying party trust when the wizard closes, then select Close. You exit the configuration wizard, and a Claim Rules editor opens.

    ../_images/adfs_13_finish_trust.png

Create claim rules

  1. In the Issuance Transform Rules section of the Claim Rules editor, select Add Rule… to open an Add Transform Claim Rule Wizard.

    ../_images/adfs_14_claim_rules_editor.png
  2. On the Choose Rule Type screen, select Send LDAP Attributes as Claims from the drop-down menu, then select Next.

    ../_images/adfs_15_choose_rule_type.png
  3. In the Configure Claim Rule screen, enter a Claim Rule Name of your choice, select Active Directory as the Attribute Store, then complete the following:

  • From the LDAP Attribute column, select E-Mail-Addresses. From the Outgoing Claim Type, type Email.

  • From the LDAP Attribute column, select E-Mail-Addresses. From the Outgoing Claim Type, type Name ID.

  • From the LDAP Attribute column, select Given-Name. From the Outgoing Claim Type, type FirstName.

  • From the LDAP Attribute column, select Surname. From the Outgoing Claim Type, type LastName.

  • From the LDAP Attribute column, select SAM-Account-Name. From the Outgoing Claim Type, type Username.

From Mattermost version 3.4, the FirstName and LastName attributes are optional.

Select Finish to add the rule.

Note that the entries in the Outgoing Claim Type column can be chosen to be something else. They can contain dashes but no spaces. They will be used to map the corresponding fields in Mattermost later.

../_images/adfs_16_configure_claim_rule.png
  1. Create another new rule by selecting Add Rule.

  2. On the Choose Rule Type screen, select Transform an Incoming Claim from the drop-down menu, then select Next.

    ../_images/adfs_17_transformation_of_incoming_claim.png
  3. On the Configure Claim Rule screen, enter a Claim Rule Name of your choice, then:

  • Select Name ID for the Incoming claim type.

  • Select Unspecified for the Incoming name ID format.

  • Select E-Mail Address for the Outgoing claim type.

Select Pass through all claim values, then select Finish.

../_images/adfs_18_configure_incoming_claim.png
  1. Select Finish to create the claim rule, then select OK to finish creating rules.

  2. Open Windows PowerShell as an administrator, then run the following command:

Set-ADFSRelyingPartyTrust -TargetName <display-name> -SamlResponseSignature "MessageAndAssertion"

where <display-name> is the name you specified in step 4 when adding a relying party trust. In this example, <display-name> would be mattermost.

This action adds the signature to SAML messages, making verification successful.

Export identity provider certificate

Next, export the identity provider certificate, which will be later uploaded to Mattermost to finish SAML configuration.

  1. In the ADFS management sidebar, go to AD FS > Service > Certificates, then double click on the certificate under Token-signing. Alternatively, you can right-click on the field, then select View Certificate.

    ../_images/adfs_19_export_idp_cert_start.png
  2. On the Certificate screen, go to the Details tab, then select Copy to File, followed by OK. This opens a Certificate Export Wizard.

    ../_images/adfs_20_export_idp_cert_copy.png
  3. On the Certificate Export Wizard screen, select Next, then, select the option Base-64 encoded X.509 (.CER), and select Next again.

    ../_images/adfs_21_export_idp_cert_wizard.png
  4. On the Certificate Export Wizard screen, select Browse to specify the location where you want the Identity Provider Certificate to be exported, then specify the file name.

    ../_images/adfs_21-2_export_idp_cert_wizard.png
  5. Select Save. In the Certificate Export Wizard screen, verify the file path is correct, then select Next.

  6. In the Completing the Certificate Export Wizard, select Finish, then select OK to confirm the export was successful.

    ../_images/adfs_21-3_export_idp_cert_wizard.png

Configure SAML Sign-On for Mattermost

Create a metadata URL by appending “FederationMetadata/2007-06/FederationMetadata.xml” to the root URL of the ADFS server, for example: https://<adfs.domain.com>/federationmetadata/2007-06/FederationMetadata.xml>.

Next, start the Mattermost server and log in to Mattermost as a System Administrator. Go to System Console > Authentication > SAML, paste the metadata URL in the Identity Provider Metadata URL field, then select Get SAML Metadata from IdP.

This populates the SAML SSO URL and the Identity Provider Issuer URL fields automatically. The Identity Provider Public Certificate is also downloaded from the server and set locally.

Alternatively you can enter the following fields manually:
  • SAML SSO URL: SAML 2.0/W-Federation URL ADFS Endpoint you copied earlier.

  • Identity Provider Issuer URL: Relying party trust identifier from ADFS you specified earlier.

  • Identity Provider Public Certificate: X.509 Public Certificate you downloaded earlier.

    ../_images/adfs_22_mattermost_basics.png
  1. Configure Mattermost to verify the signature. The Service Provider Login URL is the SAML 2.0 SSO service URL you specified in ADFS earlier.

    ../_images/adfs_23_mattermost_verification.png
  2. Enable encryption by uploading the Service Provider Private Key and Service Provider Public Certificate you generated earlier.

    ../_images/adfs_24_mattermost_encryption.png
  3. Configure Mattermost to sign SAML requests using the Service Provider Private Key.

  4. Set attributes for the SAML Assertions, which will be used to update user information in Mattermost. Attributes for email and username are required and should match the values you entered in ADFS earlier. See documentation on SAML configuration settings for more detail.

For Mattermost servers running 3.3 and earlier, the FirstName and LastName attributes are also required fields.

../_images/adfs_25_mattermost_attributes.png
  1. (Optional) Customize the login button text.

../_images/adfs_26_mattermost_login_button.png
  1. Select Save.

  2. (Optional) If you configured a FirstName and LastName Attribute, go to System Console > Site Configuration > Users and Teams, then set Teammate Name Display to Show first and last name. This is recommended for a better user experience.

If you’d like to confirm SAML SSO is successfully enabled, switch your System Administrator account from email to SAML-based authentication from your profile picture via Profile > Security > Sign-in Method > Switch to SAML SSO, then log in with your SAML credentials to complete the switch.

We recommend that you post an announcement about how the migration will work for your users.

You may also configure SAML for ADFS by editing the config.json file to enable SAML based on SAML configuration settings. You must restart the Mattermost server for the changes to take effect.

Configure SAML synchronization with AD/LDAP

In addition to configuring SAML sign-in, you can optionally configure synchronizing SAML accounts with AD/LDAP. When configured:

  • Mattermost queries AD/LDAP for relevant account information and updates SAML accounts based on changes to attributes (first name, last name, and nickname)

  • Accounts disabled in AD/LDAP are made inactive in Mattermost, and their active sessions are revoked once Mattermost synchronizes attributes.

To configure SAML synchronization with AD/LDAP:

  1. Go to System Console > Authentication > SAML 2.0, then set Enable Synchronizing SAML Accounts With AD/LDAP to true.

  2. Go to System Console > Authentication > AD/LDAP, then set Enable Synchronization with AD/LDAP to true.

  3. To ignore guest users when sychronizing, go to System Console > Authentication > SAML 2.0, then set Ignore Guest Users when Synchronizing with AD/LDAP to true.

  4. Set the rest of the AD/LDAP settings based on configuration settings documentation to connect Mattermost with your AD/LDAP server.

  • If you don’t want to enable AD/LDAP sign-in, go to System Console > Authentication > AD/LDAP, then set Enable sign-in with AD/LDAP to false.

  1. To specify how often Mattermost synchronizes SAML user accounts with AD/LDAP, go to System Console > Authentication > AD/LDAP, then set a Synchronization Interval in minutes. The default setting is 60 minutes. If you want to synchronize immediately after disabling an account, select AD/LDAP Synchronize Now.

  2. To confirm that Mattermost can successfully connect to your AD/LDAP server, go to System Console > Authentication > AD/LDAP, then select AD/LDAP Test.

Once the synchronization with AD/LDAP is enabled, user attributes are synchronized with AD/LDAP based on their email address. If a user with a given email address doesn’t have an AD/LDAP account, they will be deactivated in Mattermost on the next AD/LDAP sync.

To re-activate the account:

  1. Add the user to your AD/LDAP server.

  2. Purge all caches in Mattermost by going to System Console > Environment > Web Server, then select Purge All Caches.

  3. Run AD/LDAP synchronization by going to System Console > Authentication > AD/LDAP, then select AD/LDAP Synchronize Now.

  4. Purge all caches again in Mattermost by going to System Console > Environment > Web Server, then select Purge All Caches again. This re-activates the account in Mattermost.

Note

If a user is deactivated from AD/LDAP, they will be deactivated in Mattermost on the next sync. They will be shown as “Inactive” in the System Console users list, all of their sessions will expire and they won’t be able to log back in to Mattermost.

If a user is deactivated from SAML, their session won’t expire until they’re deactivated from AD/LDAP. However, they won’t be able to log back in to Mattermost.

Note

SAML synchronization with AD/LDAP is designed to pull user attributes such as first name and last name from your AD/LDAP, not to control authentication.

In particular, the user filter cannot be used to control who can log in to Mattermost, this should be controlled by your SAML service provider’s group permissions.

See technical description of SAML synchronization with AD/LDAP for more details.

Override SAML data with AD/LDAP data

Alternatively, you can choose to override SAML bind data with AD/LDAP information. For more information on binding a user with the SAML ID Attribute, please refer to this documentation.

This process overrides SAML email address with AD/LDAP email address data or SAML Id Attribute with AD/LDAP Id Attribute if configured. We recommend using this configuration with the SAML ID Attribute to help ensure new users are not created when the email address changes for a user.

To ensure existing user accounts do not get disabled in this process, ensure the SAML IDs match the LDAP IDs by exporting data from both systems and comparing the ID data. Mapping ID Attributes for both AD/LDAP and SAML within Mattermost to fields that hold the same data will ensure the IDs match as well.

  1. Set the SAML Id Attribute by going to System Console > Authentication > SAML 2.0 > Id Attribute.

  2. Set System Console > Authentication > SAML 2.0 > Override SAML bind data with AD/LDAP information to true.

  3. Set System Console > Authentication > SAML 2.0 > Enable Synchronizing SAML Accounts With AD/LDAP to true.

  4. Run AD/LDAP sync by going to System Console > Authentication > AD/LDAP, then select AD/LDAP Synchronize Now.

Frequently Asked Questions

How to bind authentication to Id attribute instead of email

Alternatively, you can use an Id attribute instead of email to bind the user. We recommend choosing an ID that is unique and will not change over time.

Configuring with an Id attribute allows you to reuse an email address for a new user without the old user’s information being exposed. For instance, if a user with an email address joe.smith@mattermost.com was once an employee, a new employee named Joe Smith can use the same email. This configuration is also useful when a user’s name changes and their email needs to be updated.

This process was designed with backwards compatibility to email binding. Here is the process applied to new account creations and to accounts logging in after the configuration:

  • A user authenticated with SAML is bound to the SAML service user using the Id Attribute (as long as it has been configured) or bound by email using the email received from SAML.

  • When the user tries to login and the SAML server responds with a valid authentication, then the server uses the “Id” field of the SAML authentication to search the user.

  • If a user bound to that ID already exists, it logs in as that user.

  • If a user bound to that ID does not exist, it will search base on the email.

  • If a user bound to the email exists, it logs in with email and updates the autentication data to the ID, instead of the email.

  • If a user bound to the ID or email does not exist, it will create a new Mattermost account bound to the SAML account by ID and will allow the user to log in.

Note

Existing accounts won’t update until they log in to the server.

Can SAML via Microsoft ADFS be configured with Integrated Windows Authentication (IWA)?

Yes. IWA is supported on the browser, with support added to iOS and Android mobile apps in Q2/2019 (mobile apps v1.18 and later).

However, IWA is not supported on the Mattermost Desktop Apps due to a limitation in Electron. As a workaround you may create a browser desktop shortcut for quick access to Mattermost, just like a Desktop App.

Can I provision and deprovision users who log in via SAML?

Yes, but this relies on AD/LDAP to do so. Currently, we do not support SCIM. See “How do I deactivate users?” for more information.

How is SAML different from OAuth 2.0 and OpenId Connect?

OAuth 2.0 was primarily intended for delegated authorization, where an app is authorized to access resources, such as Google contact list. It doesn’t deal with authentication.

OpenID Connect is built on top of OAuth 2.0, which supports authentication and thus direct SSO.

SAML is like OpenID Connect, except typically used in enterprise settings. OpenID Connect is more common in consumer websites and web/mobile apps.

Learn more at https://hackernoon.com/demystifying-oauth-2-0-and-openid-connect-and-saml-12aa4cf9fdba.