Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
help: Document how to configure Keycloak as the SAML IdP.
Philipp Seßnera8797b4d9f08
diff --git a/docs/production/authentication-methods.md b/docs/production/authentication-methods.mdindex 70b224ce969..ac2e1235071 100644--- a/docs/production/authentication-methods.md+++ b/docs/production/authentication-methods.md@@ -529,6 +529,64 @@ to the root and `engineering` subdomains:</saml2:Attribute>```+### Using Keycloak as a SAML IdP++1. Make sure you reviewed [this article][saml-help-center], which+ details how to configure Keycloak properly to use SAML with Zulip.+2. Verify that `SOCIAL_AUTH_SAML_ENABLED_IDPS[{idp_name}]['entity_id']` and+ `SOCIAL_AUTH_SAML_ENABLED_IDPS[{idp_name}]['url']` are correct in your Zulip+ configuration. Specifically, if `entity_id` is+ `https://keycloak.example.com/auth/realms/master`, then `url`+ should be+ `https://keycloak.example.com/auth/realms/master/protocol/saml`+3. Your Keycloak public certificate must be saved on the Zulip server+ as `{idp_name}.crt` in `/etc/zulip/idps/`. You can obtain the+ certificate from the Keycloak UI in the `Keys` tab. Click on the+ button `Certificate` and copy the content.++ (Alternatively, open the URL in your browser+ `https://keycloak.example.com/auth/realms/master/protocol/saml/descriptor`.+ Replace the domain (`keycloak.example.com`) as well as the realm+ name (`master`) in the url. The certificate is the content inside+ `<ds:X509Certificate>[...]</ds:X509Certificate>`).++ Save the certificate in a new `{idp_name}.crt` file constructed as follows:+ ```+ -----BEGIN CERTIFICATE-----+ {Paste the content here}+ -----END CERTIFICATE-----+ ```++4. If you want to sign SAML requests, you have to do two things in Keycloak:+ 1. In the Keycloak client settings you setup previously, open the+ `Settings` tab and **enable** `Client Signature Required`.+ 2. Keycloak can generate the Client private key and certificate+ automatically, but Zulip's SAML library does not support the+ resulting certificates. Instead, you must generate the key and+ certificate on the Zulip server and import them into Keycloak:+ 1. Generate **Zulip server public certificate** and the corresponding **private key**:+ ```bash+ openssl req -x509 -newkey rsa:2056 -keyout zulip-private-key.key \+ -out zulip-cert.crt -days 365 -nodes+ ```+ 2. Generate a JKS keystore (replace `{mypassword}` and+ `{myalias}` in the `keytool` invocation):+ ```bash+ openssl pkcs12 -export -out domainname.pfx -inkey zulip-private-key.key -in zulip-cert.crt+ keytool -importkeystore -srckeystore domainname.pfx -srcstoretype pkcs12 \+ -srcalias 1 -srcstorepass {mypassword} -destkeystore domainname.jks \+ -deststoretype jks -destalias {myalias}+ ```++ You can run the above on the Zulip server. If you instead run+ it on a Mac, you may want to use the keychain+ administration tool to generate the JKS keystore with a UI instead of+ using the `keytool` command. (see also: https://stackoverflow.com/a/41250334)+ 3. Then switch to the `SAML Keys` tab of your Keycloak+ client. Import `domainname.pfx` into Keycloak. After+ importing, only the certificate will be displayed (not the private+ key).+## Apache-based SSO with `REMOTE_USER`If you have any existing SSO solution where a preferred way to deploydiff --git a/templates/zerver/help/saml-authentication.md b/templates/zerver/help/saml-authentication.mdindex fd386515615..d4e8d07018c 100644--- a/templates/zerver/help/saml-authentication.md+++ b/templates/zerver/help/saml-authentication.md@@ -6,6 +6,9 @@ self-hosting or on the Zulip Cloud Plus plan.This page documents details on how to set up SAML authentication withZulip with various common SAML identity providers.+If you are self-hosting, this documentation is likely still useful for+how to configure these SAML providers to work with Zulip.+## Configure SAML with Okta1. Make sure you have created your organization.@@ -110,6 +113,45 @@ Zulip with various common SAML identity providers.1. We will take care of the server-side setup and let you know as soon as it's ready.+## Configure SAML with Keycloak++1. Make sure you have created your organization.+1. Make sure your Keycloak server is up and running. We assume the URL+ is `https://keycloak.example.com` and your Keycloak realm is `master` (which+ is the default name for a Keycloak realm).+1. In Keycloak, register a new Client for your Zulip organization:+ * Client-ID: `https://<subdomain>.zulipchat.com`+ * Client Protocol: `saml`+ * Client SAML Endpoint: leave this field empty+1. In the `Settings` tab for your new Keycloak client, set the following properties:+ - Valid Redirect URIs: `https://auth.zulipchat.com/*`+ - Base URL: `https://auth.zulipchat.com/complete/saml/`+ - Client Signature Required: `Disable`+1. In the `Mappers` tab for your new Keycloak client:+ 1. Create a Mapper for first name:+ * Property: `firstName`+ * Friendly Name: `first_name`+ * SAML Attribute Name: `first_name`+ * SAML Attribute Name Format: `Basic`+ 1. Create a Mapper for last name:+ * Property: `lastName`+ * Friendly Name: `last_name`+ * SAML Attribute Name: `last_name`+ * SAML Attribute Name Format: `Basic`+ 1. Create a Mapper for email address:+ * Property: `email`+ * Friendly Name: `email`+ * SAML Attribute Name: `email`+ * SAML Attribute Name Format: `Basic`++1. The Keycloak side of configuration should be ready! Send the+following information to Zulip Support at [email protected]:++ * The URL of your Zulip Cloud organization, i.e. `https://example.zulipchat.com`.+ * The URL of your Keycloak realm. If `master` is your Keycloak+ realm name, then the Keycloak realm URL should resemble+ `https://keycloak.example.com/auth/realms/master`.+## Related articlesdiff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.pyindex a7b7ed7b2a8..2d460c29d8b 100644--- a/tools/linter_lib/custom_check.py+++ b/tools/linter_lib/custom_check.py@@ -893,6 +893,8 @@ help_markdown_rules = RuleList("pattern": r"\b[rR]ealm[s]?\b","include_only": {"templates/zerver/help/"},"exclude": {"templates/zerver/help/change-organization-url.md"},+ # Keycloak uses the term realm as well.+ "exclude_pattern": "[Kk]eycloak","good_lines": ["Organization", "deactivate_realm", "realm_filter"],"bad_lines": ["Users are in a realm", "Realm is the best model"],"description": "Realms are referred to as Organizations in user-facing docs.",