2016-08-09 22:21:19 +02:00
|
|
|
# Authentication methods
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
Zulip supports a wide variety of authentication methods. Some of them
|
2018-01-19 02:43:23 +01:00
|
|
|
require configuration to set up.
|
2016-07-30 00:02:32 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
To configure or disable authentication methods on your Zulip server,
|
|
|
|
edit the `AUTHENTICATION_BACKENDS` setting in
|
|
|
|
`/etc/zulip/settings.py`, as well as any additional configuration your
|
|
|
|
chosen authentication methods require; then restart the Zulip server.
|
|
|
|
|
|
|
|
Details on each method below.
|
|
|
|
|
|
|
|
## Email and password
|
|
|
|
|
|
|
|
The `EmailAuthBackend` method is the one method enabled by default,
|
|
|
|
and it requires no additional configuration.
|
|
|
|
|
|
|
|
Users set a password with the Zulip server, and log in with their
|
|
|
|
email and password.
|
|
|
|
|
|
|
|
When first setting up your Zulip server, this method must be used for
|
2021-08-20 21:53:28 +02:00
|
|
|
creating the initial realm and user. You can disable it after that.
|
2018-01-19 02:43:23 +01:00
|
|
|
|
2020-02-11 23:13:09 +01:00
|
|
|
## Plug-and-play SSO (Google, GitHub, GitLab)
|
2018-01-19 02:43:23 +01:00
|
|
|
|
|
|
|
With just a few lines of configuration, your Zulip server can
|
|
|
|
authenticate users with any of several single-sign-on (SSO)
|
|
|
|
authentication providers:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Google accounts, with `GoogleAuthBackend`
|
|
|
|
- GitHub accounts, with `GitHubAuthBackend`
|
|
|
|
- GitLab accounts, with `GitLabAuthBackend`
|
|
|
|
- Microsoft Azure Active Directory, with `AzureADAuthBackend`
|
2018-01-19 02:43:23 +01:00
|
|
|
|
|
|
|
Each of these requires one to a handful of lines of configuration in
|
2021-08-20 21:53:28 +02:00
|
|
|
`settings.py`, as well as a secret in `zulip-secrets.conf`. Details
|
2018-01-19 02:43:23 +01:00
|
|
|
are documented in your `settings.py`.
|
|
|
|
|
2021-08-10 07:55:12 +02:00
|
|
|
(ldap)=
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2018-09-25 23:29:03 +02:00
|
|
|
## LDAP (including Active Directory)
|
|
|
|
|
|
|
|
Zulip supports retrieving information about users via LDAP, and
|
|
|
|
optionally using LDAP as an authentication mechanism.
|
|
|
|
|
|
|
|
In either configuration, you will need to do the following:
|
|
|
|
|
2019-10-29 01:55:37 +01:00
|
|
|
1. These instructions assume you have an installed Zulip server and
|
2021-08-20 21:53:28 +02:00
|
|
|
are logged into a shell there. You can have created an
|
2019-10-29 01:55:37 +01:00
|
|
|
organization already using EmailAuthBackend, or plan to create the
|
|
|
|
organization using LDAP authentication.
|
2018-09-27 22:37:14 +02:00
|
|
|
|
2019-10-29 01:55:37 +01:00
|
|
|
1. Tell Zulip how to connect to your LDAP server:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Fill out the section of your `/etc/zulip/settings.py` headed "LDAP
|
2018-09-25 23:29:03 +02:00
|
|
|
integration, part 1: Connecting to the LDAP server".
|
2021-08-20 21:45:39 +02:00
|
|
|
- If a password is required, put it in
|
2018-09-25 23:29:03 +02:00
|
|
|
`/etc/zulip/zulip-secrets.conf` by setting
|
2021-08-20 21:53:28 +02:00
|
|
|
`auth_ldap_bind_password`. For example:
|
2021-09-08 00:23:24 +02:00
|
|
|
`auth_ldap_bind_password = abcd1234`.
|
2018-09-25 23:29:03 +02:00
|
|
|
|
2019-10-29 01:55:37 +01:00
|
|
|
1. Decide how you want to map the information in your LDAP database to
|
2021-08-20 21:53:28 +02:00
|
|
|
users' account data in Zulip. For each Zulip user, two closely
|
2018-09-26 00:55:51 +02:00
|
|
|
related concepts are:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
- their **email address**. Zulip needs this in order to send, for
|
2018-09-26 00:55:51 +02:00
|
|
|
example, a notification when they're offline and another user
|
2023-06-16 00:55:22 +02:00
|
|
|
sends a direct message.
|
2021-08-20 21:53:28 +02:00
|
|
|
- their **Zulip username**. This means the name the user types into the
|
|
|
|
Zulip login form. You might choose for this to be the user's
|
2018-09-26 00:55:51 +02:00
|
|
|
email address (`sam@example.com`), or look like a traditional
|
|
|
|
"username" (`sam`), or be something else entirely, depending on
|
|
|
|
your environment.
|
|
|
|
|
|
|
|
Either or both of these might be an attribute of the user records
|
|
|
|
in your LDAP database.
|
|
|
|
|
2019-10-29 01:55:37 +01:00
|
|
|
1. Tell Zulip how to map the user information in your LDAP database to
|
2021-08-20 21:53:28 +02:00
|
|
|
the form it needs for authentication. There are three supported
|
2018-12-12 19:46:37 +01:00
|
|
|
ways to set up the username and/or email mapping:
|
2018-09-26 00:55:51 +02:00
|
|
|
|
2019-12-13 21:22:58 +01:00
|
|
|
(A) Using email addresses as Zulip usernames, if LDAP has each
|
2021-08-20 22:54:08 +02:00
|
|
|
user's email address:
|
|
|
|
|
|
|
|
- Make `AUTH_LDAP_USER_SEARCH` a query by email address.
|
|
|
|
- Set `AUTH_LDAP_REVERSE_EMAIL_SEARCH` to the same query with
|
|
|
|
`%(email)s` rather than `%(user)s` as the search parameter.
|
|
|
|
- Set `AUTH_LDAP_USERNAME_ATTR` to the name of the LDAP
|
|
|
|
attribute for the user's LDAP username in the search result
|
|
|
|
for `AUTH_LDAP_REVERSE_EMAIL_SEARCH`.
|
2018-09-26 00:55:51 +02:00
|
|
|
|
|
|
|
(B) Using LDAP usernames as Zulip usernames, with email addresses
|
2021-08-20 22:54:08 +02:00
|
|
|
formed consistently like `sam` -> `sam@example.com`:
|
|
|
|
|
|
|
|
- Set `AUTH_LDAP_USER_SEARCH` to query by LDAP username
|
|
|
|
- Set `LDAP_APPEND_DOMAIN = "example.com"`.
|
2018-09-26 00:55:51 +02:00
|
|
|
|
|
|
|
(C) Using LDAP usernames as Zulip usernames, with email addresses
|
2021-08-20 22:54:08 +02:00
|
|
|
taken from some other attribute in LDAP (for example, `mail`):
|
|
|
|
|
|
|
|
- Set `AUTH_LDAP_USER_SEARCH` to query by LDAP username
|
|
|
|
- Set `LDAP_EMAIL_ATTR = "mail"`.
|
|
|
|
- Set `AUTH_LDAP_REVERSE_EMAIL_SEARCH` to a query that will find
|
|
|
|
an LDAP user given their email address (i.e. a search by
|
|
|
|
`LDAP_EMAIL_ATTR`). For example:
|
|
|
|
```python
|
|
|
|
AUTH_LDAP_REVERSE_EMAIL_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE, "(mail=%(email)s)")
|
|
|
|
```
|
|
|
|
- Set `AUTH_LDAP_USERNAME_ATTR` to the name of the LDAP
|
|
|
|
attribute for the user's LDAP username in that search result.
|
2019-10-05 01:02:46 +02:00
|
|
|
|
2018-09-25 23:29:03 +02:00
|
|
|
You can quickly test whether your configuration works by running:
|
2018-09-27 22:37:14 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```bash
|
2018-12-13 23:58:26 +01:00
|
|
|
/home/zulip/deployments/current/manage.py query_ldap username
|
2018-09-25 23:29:03 +02:00
|
|
|
```
|
2018-09-27 22:37:14 +02:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
from the root of your Zulip installation. If your configuration is
|
2018-09-27 22:37:14 +02:00
|
|
|
working, that will output the full name for your user (and that user's
|
|
|
|
email address, if it isn't the same as the "Zulip username").
|
2018-09-25 23:29:03 +02:00
|
|
|
|
2019-12-13 21:22:58 +01:00
|
|
|
**Active Directory**: Most Active Directory installations will use one
|
|
|
|
of the following configurations:
|
2019-01-09 01:28:51 +01:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- To access by Active Directory username:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
|
|
|
```python
|
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")
|
|
|
|
AUTH_LDAP_REVERSE_EMAIL_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE, "(mail=%(email)s)")
|
|
|
|
AUTH_LDAP_USERNAME_ATTR = "sAMAccountName"
|
|
|
|
```
|
2019-12-13 21:22:58 +01:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- To access by Active Directory email address:
|
2021-08-20 22:54:08 +02:00
|
|
|
```python
|
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE, "(mail=%(user)s)")
|
|
|
|
AUTH_LDAP_REVERSE_EMAIL_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
|
|
|
|
ldap.SCOPE_SUBTREE, "(mail=%(email)s)")
|
|
|
|
AUTH_LDAP_USERNAME_ATTR = "mail"
|
|
|
|
```
|
2019-01-09 01:28:51 +01:00
|
|
|
|
2018-09-26 00:05:58 +02:00
|
|
|
**If you are using LDAP for authentication**: you will need to enable
|
|
|
|
the `zproject.backends.ZulipLDAPAuthBackend` auth backend, in
|
2021-08-20 21:53:28 +02:00
|
|
|
`AUTHENTICATION_BACKENDS` in `/etc/zulip/settings.py`. After doing so
|
2019-12-13 21:22:58 +01:00
|
|
|
(and as always [restarting the Zulip server](settings.md) to ensure
|
docs: Add missing space to compound verbs “log in”, “set up”, etc.
Noun: backup, checkout, cleanup, login, logout, setup, shutdown, signup,
timeout.
Verb: back up, check out, clean up, log in, log out, set up, shut
down, sign up, time out.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-25 23:05:38 +02:00
|
|
|
your settings changes take effect), you should be able to log in to
|
2018-09-26 00:05:58 +02:00
|
|
|
Zulip by entering your email address and LDAP password on the Zulip
|
|
|
|
login form.
|
2018-09-25 23:29:03 +02:00
|
|
|
|
2020-01-26 08:38:47 +01:00
|
|
|
You may also want to configure Zulip's settings for [inviting new
|
2021-08-20 21:53:28 +02:00
|
|
|
users](https://zulip.com/help/invite-new-users). If LDAP is the
|
2020-01-26 08:38:47 +01:00
|
|
|
only enabled authentication method, the main use case for Zulip's
|
|
|
|
invitation feature is selecting the initial streams for invited users
|
|
|
|
(invited users will still need to use their LDAP password to create an
|
|
|
|
account).
|
|
|
|
|
2018-12-13 23:58:26 +01:00
|
|
|
### Synchronizing data
|
|
|
|
|
|
|
|
Zulip can automatically synchronize data declared in
|
|
|
|
`AUTH_LDAP_USER_ATTR_MAP` from LDAP into Zulip, via the following
|
|
|
|
management command:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```bash
|
2018-12-13 23:58:26 +01:00
|
|
|
/home/zulip/deployments/current/manage.py sync_ldap_user_data
|
2018-09-25 23:29:03 +02:00
|
|
|
```
|
|
|
|
|
2018-12-13 23:58:26 +01:00
|
|
|
This will sync the fields declared in `AUTH_LDAP_USER_ATTR_MAP` for
|
2019-05-28 10:53:49 +02:00
|
|
|
all of your users.
|
2018-12-13 23:58:26 +01:00
|
|
|
|
2023-11-23 18:26:46 +01:00
|
|
|
We recommend running this command in a **regular cron job** at
|
|
|
|
whatever frequency your organization prefers for synchronizing changes
|
|
|
|
made on your LDAP server to Zulip.
|
2018-12-13 23:58:26 +01:00
|
|
|
|
2019-02-05 19:37:04 +01:00
|
|
|
All of these data synchronization options have the same model:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- New users will be populated automatically with the
|
2019-02-05 19:37:04 +01:00
|
|
|
name/avatar/etc. from LDAP (as configured) on account creation.
|
2023-11-23 18:26:46 +01:00
|
|
|
- `manage.py sync_ldap_user_data` will automatically update existing
|
|
|
|
users with any changes that were made in LDAP.
|
2021-08-20 21:45:39 +02:00
|
|
|
- You can easily test your configuration using `manage.py query_ldap`.
|
2019-02-05 19:37:04 +01:00
|
|
|
Once you're happy with the configuration, remember to restart the
|
|
|
|
Zulip server with
|
|
|
|
`/home/zulip/deployments/current/scripts/restart-server` so that
|
|
|
|
your configuration changes take effect.
|
2023-07-15 22:25:36 +02:00
|
|
|
- Logs are available in `/var/log/zulip/ldap.log`.
|
2019-02-05 19:37:04 +01:00
|
|
|
|
2018-12-13 23:58:26 +01:00
|
|
|
When using this feature, you may also want to
|
|
|
|
[prevent users from changing their display name in the Zulip UI][restrict-name-changes],
|
|
|
|
since any such changes would be automatically overwritten on the sync
|
|
|
|
run of `manage.py sync_ldap_user_data`.
|
|
|
|
|
2020-06-08 23:04:39 +02:00
|
|
|
[restrict-name-changes]: https://zulip.com/help/restrict-name-and-email-changes
|
2018-12-13 23:58:26 +01:00
|
|
|
|
|
|
|
#### Synchronizing avatars
|
2018-12-12 19:46:37 +01:00
|
|
|
|
2021-09-16 17:28:30 +02:00
|
|
|
Zulip supports syncing LDAP / Active
|
2018-12-12 19:46:37 +01:00
|
|
|
Directory profile pictures (usually available in the `thumbnailPhoto`
|
|
|
|
or `jpegPhoto` attribute in LDAP) by configuring the `avatar` key in
|
2019-02-05 19:37:04 +01:00
|
|
|
`AUTH_LDAP_USER_ATTR_MAP`.
|
2018-12-12 19:46:37 +01:00
|
|
|
|
2019-02-05 18:14:07 +01:00
|
|
|
#### Synchronizing custom profile fields
|
|
|
|
|
2021-09-16 17:28:30 +02:00
|
|
|
Zulip supports syncing
|
2019-02-05 19:37:04 +01:00
|
|
|
[custom profile fields][custom-profile-fields] from LDAP / Active
|
2021-08-20 21:53:28 +02:00
|
|
|
Directory. To configure this, you first need to
|
2019-02-05 19:37:04 +01:00
|
|
|
[configure some custom profile fields][custom-profile-fields] for your
|
2021-08-20 21:53:28 +02:00
|
|
|
Zulip organization. Then, define a mapping from the fields you'd like
|
|
|
|
to sync from LDAP to the corresponding LDAP attributes. For example,
|
2019-02-05 18:14:07 +01:00
|
|
|
if you have a custom profile field `LinkedIn Profile` and the
|
2019-02-05 19:37:04 +01:00
|
|
|
corresponding LDAP attribute is `linkedinProfile` then you just need
|
|
|
|
to add `'custom_profile_field__linkedin_profile': 'linkedinProfile'`
|
|
|
|
to the `AUTH_LDAP_USER_ATTR_MAP`.
|
|
|
|
|
2023-07-15 22:25:36 +02:00
|
|
|
#### Synchronizing groups
|
|
|
|
|
|
|
|
Zulip supports syncing [Zulip groups][zulip-groups] with LDAP
|
|
|
|
groups. To configure this feature:
|
|
|
|
|
|
|
|
1. Review the [django-auth-ldap
|
|
|
|
documentation](https://django-auth-ldap.readthedocs.io/en/latest/groups.html)
|
|
|
|
to determine which of its supported group type configurations
|
|
|
|
matches how your LDAP directory stores groups.
|
|
|
|
|
|
|
|
1. Set `AUTH_LDAP_GROUP_TYPE` to the appropriate class instance for
|
|
|
|
that LDAP group type:
|
|
|
|
|
|
|
|
```python
|
|
|
|
from django_auth_ldap.config import ActiveDirectoryGroupType
|
|
|
|
AUTH_LDAP_GROUP_TYPE = ActiveDirectoryGroupType()
|
|
|
|
```
|
|
|
|
|
|
|
|
The default is `GroupOfUniqueNamesType`.
|
|
|
|
|
|
|
|
1. Configure `AUTH_LDAP_GROUP_SEARCH` to specify how to find groups in
|
|
|
|
your LDAP directory:
|
|
|
|
|
|
|
|
```python
|
|
|
|
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
|
|
|
|
"ou=groups,dc=www,dc=example,dc=com", ldap.SCOPE_SUBTREE,
|
|
|
|
"(objectClass=groupOfUniqueNames)"
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
1. Configure which LDAP groups you want to sync into
|
|
|
|
Zulip. `LDAP_SYNCHRONIZED_GROUPS_BY_REALM` is a map where the keys
|
|
|
|
are subdomains of the realms being configured (use `""` for the
|
|
|
|
root domain), and the value corresponding to the key being a list
|
|
|
|
the names of groups to sync:
|
|
|
|
|
|
|
|
```python
|
|
|
|
LDAP_SYNCHRONIZED_GROUPS_BY_REALM = {
|
|
|
|
"subdomain1" : [
|
|
|
|
"group1",
|
|
|
|
"group2",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
In this example configuration, for the Zulip realm with subdomain
|
|
|
|
`subdomain1`, user membership in the Zulip groups named `group1`
|
|
|
|
and `group2` will match their membership in LDAP groups with those
|
|
|
|
names.
|
|
|
|
|
|
|
|
1. Test your configuration and restart the server into the new
|
|
|
|
configuration as [documented above](#synchronizing-data).
|
|
|
|
|
|
|
|
[zulip-groups]: https://zulip.com/help/user-groups
|
|
|
|
|
2023-02-03 15:44:14 +01:00
|
|
|
#### Synchronizing email addresses
|
|
|
|
|
|
|
|
User accounts in Zulip are uniquely identified by their email address,
|
|
|
|
and that's [currently](https://github.com/zulip/zulip/pull/16208) the
|
|
|
|
only way through which a Zulip account is associated with their LDAP
|
|
|
|
user account.
|
|
|
|
|
|
|
|
In particular, whenever a user attempts to log in to Zulip using LDAP,
|
|
|
|
Zulip will use the LDAP information to authenticate the access, and
|
|
|
|
determine the user's email address. It will then log in the user to
|
|
|
|
the Zulip account with that email address (or if none exists,
|
|
|
|
potentially prompt the user to create one). This model is convenient,
|
|
|
|
because it works well with any LDAP provider (and handles migrations
|
|
|
|
between LDAP providers transparently).
|
|
|
|
|
|
|
|
However, when a user's email address is changed in your LDAP
|
|
|
|
directory, manual action needs to be taken to tell Zulip that the
|
|
|
|
email address Zulip account with the new email address.
|
|
|
|
|
|
|
|
There are two ways to execute email address changes:
|
|
|
|
|
|
|
|
- Users changing their email address in LDAP can [change their email
|
|
|
|
address in Zulip](https://zulip.com/help/change-your-email-address)
|
|
|
|
before logging out of Zulip. The user will need to be able to
|
|
|
|
receive email at the new email address in order to complete this
|
|
|
|
flow.
|
|
|
|
|
|
|
|
- A server administrator can use the `manage.py change_user_email`
|
|
|
|
[management command][management-commands] to adjust a Zulip
|
|
|
|
account's email address directly.
|
|
|
|
|
|
|
|
If a user accidentally creates a duplicate account, the duplicate
|
|
|
|
account can be deactivated (and its email address changed) or deleted,
|
|
|
|
and then the real account adjusted using the management command above.
|
|
|
|
|
|
|
|
[management-commands]: ../production/management-commands.md
|
|
|
|
|
2021-09-16 20:04:19 +02:00
|
|
|
#### Automatically deactivating users
|
2018-12-13 23:58:26 +01:00
|
|
|
|
2021-09-16 17:28:30 +02:00
|
|
|
Zulip supports synchronizing the
|
2021-09-16 20:04:19 +02:00
|
|
|
disabled/deactivated status of users. If you're using Active Directory,
|
|
|
|
you can configure this by uncommenting the sample line
|
2021-09-08 00:23:24 +02:00
|
|
|
`"userAccountControl": "userAccountControl",` in
|
2021-08-20 21:53:28 +02:00
|
|
|
`AUTH_LDAP_USER_ATTR_MAP` (and restarting the Zulip server). Zulip
|
2021-09-08 00:23:24 +02:00
|
|
|
will then treat users that are disabled via the "Disable Account"
|
|
|
|
feature in Active Directory as deactivated in Zulip.
|
2018-12-13 23:58:26 +01:00
|
|
|
|
2021-09-16 20:04:19 +02:00
|
|
|
If you're using a different LDAP server which uses a boolean attribute
|
|
|
|
which is `TRUE` or `YES` for users that should be deactivated and `FALSE`
|
|
|
|
or `NO` otherwise. You can configure a mapping for `deactivated` in
|
|
|
|
`AUTH_LDAP_USER_ATTR_MAP`. For example, `"deactivated": "nsAccountLock",` is a correct mapping for a
|
|
|
|
[FreeIPA](https://www.freeipa.org/) LDAP database.
|
|
|
|
|
2023-11-23 18:26:46 +01:00
|
|
|
Users who are disabled in LDAP will be immediately unable to log in to
|
|
|
|
Zulip using LDAP authentication, since Zulip queries the LDAP/Active
|
|
|
|
Directory server on every login attempt. The user will be fully
|
|
|
|
deactivated the next time you run `manage.py sync_ldap_user_data` (at
|
|
|
|
which point they will be forcibly logged out from all active browser
|
|
|
|
sessions, appear as deactivated in the Zulip UI, etc.).
|
2018-12-13 23:58:26 +01:00
|
|
|
|
|
|
|
This feature works by checking for the `ACCOUNTDISABLE` flag on the
|
2021-08-20 21:53:28 +02:00
|
|
|
`userAccountControl` field in Active Directory. See
|
2018-12-13 23:58:26 +01:00
|
|
|
[this handy resource](https://jackstromberg.com/2013/01/useraccountcontrol-attributeflag-values/)
|
|
|
|
for details on the various `userAccountControl` flags.
|
|
|
|
|
2019-01-13 13:53:52 +01:00
|
|
|
#### Deactivating non-matching users
|
|
|
|
|
2023-11-23 18:26:46 +01:00
|
|
|
Zulip supports automatically deactivating users if they are not found
|
|
|
|
by the `AUTH_LDAP_USER_SEARCH` query (either because the user is no
|
|
|
|
longer in LDAP/Active Directory, or because the user no longer matches
|
|
|
|
the query). This feature is enabled by default if LDAP is the only
|
|
|
|
authentication backend configured on the Zulip server. Otherwise, you
|
|
|
|
can enable this feature by setting
|
|
|
|
`LDAP_DEACTIVATE_NON_MATCHING_USERS` to `True` in
|
2021-08-20 21:53:28 +02:00
|
|
|
`/etc/zulip/settings.py`. Nonmatching users will be fully deactivated
|
2023-11-23 18:26:46 +01:00
|
|
|
the next time you run `manage.py sync_ldap_user_data`.
|
2019-01-13 13:53:52 +01:00
|
|
|
|
2018-12-14 01:04:48 +01:00
|
|
|
#### Other fields
|
|
|
|
|
|
|
|
Other fields you may want to sync from LDAP include:
|
|
|
|
|
2021-10-06 17:43:24 +02:00
|
|
|
- Boolean flags describing the user's level of permission:
|
|
|
|
`is_realm_owner` (Organization owner), `is_realm_admin` (Organization administrator),
|
|
|
|
`is_guest` (Guest), `is_moderator` (Moderator). You can use the
|
2018-12-14 01:04:48 +01:00
|
|
|
[AUTH_LDAP_USER_FLAGS_BY_GROUP][django-auth-booleans] feature of
|
2021-10-06 17:43:24 +02:00
|
|
|
`django-auth-ldap` to configure a group to get any of these permissions.
|
|
|
|
(Don't use this to modify other boolean flags such as
|
|
|
|
`is_active` as that can introduce inconsistent state in the database;
|
|
|
|
see the above discussion of automatic deactivation for how to do that properly).
|
2021-08-20 21:45:39 +02:00
|
|
|
- String fields like `default_language` (e.g. `en`) or `timezone`, if
|
2018-12-14 01:04:48 +01:00
|
|
|
you have that data in the right format in your LDAP database.
|
|
|
|
|
|
|
|
You can look at the [full list of fields][models-py] in the Zulip user
|
|
|
|
model; search for `class UserProfile`, but the above should cover all
|
|
|
|
the fields that would be useful to sync from your LDAP databases.
|
|
|
|
|
2021-09-01 00:15:31 +02:00
|
|
|
[models-py]: https://github.com/zulip/zulip/blob/main/zerver/models.py
|
2018-12-14 01:04:48 +01:00
|
|
|
[django-auth-booleans]: https://django-auth-ldap.readthedocs.io/en/latest/users.html#easy-attributes
|
|
|
|
|
2018-09-26 00:05:58 +02:00
|
|
|
### Multiple LDAP searches
|
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
To do the union of multiple LDAP searches, use `LDAPSearchUnion`. For example:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```python
|
2018-09-26 00:05:58 +02:00
|
|
|
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(
|
|
|
|
LDAPSearch("ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"),
|
|
|
|
LDAPSearch("ou=otherusers,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"),
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
2019-02-11 20:40:57 +01:00
|
|
|
### Restricting access to an LDAP group
|
|
|
|
|
|
|
|
You can restrict access to your Zulip server to a set of LDAP groups
|
|
|
|
using the `AUTH_LDAP_REQUIRE_GROUP` and `AUTH_LDAP_DENY_GROUP`
|
2022-03-20 20:42:57 +01:00
|
|
|
settings in `/etc/zulip/settings.py`.
|
2019-02-11 20:40:57 +01:00
|
|
|
|
2023-10-09 20:41:12 +02:00
|
|
|
An example configuration for Active Directory group restriction can be:
|
2022-03-20 20:42:57 +01:00
|
|
|
|
2023-05-31 01:18:00 +02:00
|
|
|
```python
|
2022-03-20 20:42:57 +01:00
|
|
|
import django_auth_ldap
|
|
|
|
AUTH_LDAP_GROUP_TYPE = django_auth_ldap.config.ActiveDirectoryGroupType()
|
|
|
|
|
|
|
|
AUTH_LDAP_REQUIRE_GROUP = "cn=enabled,ou=groups,dc=example,dc=com"
|
|
|
|
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=groups,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(objectClass=groupOfNames)")
|
|
|
|
```
|
|
|
|
|
|
|
|
Please note that `AUTH_LDAP_GROUP_TYPE` needs to be set to the correct
|
|
|
|
group type for your LDAP server. See the [upstream django-auth-ldap
|
|
|
|
documentation][upstream-ldap-groups] for details.
|
|
|
|
|
|
|
|
[upstream-ldap-groups]: https://django-auth-ldap.readthedocs.io/en/latest/groups.html
|
2019-02-11 20:40:57 +01:00
|
|
|
|
2020-08-15 18:33:16 +02:00
|
|
|
### Restricting LDAP user access to specific organizations
|
|
|
|
|
|
|
|
If you're hosting multiple Zulip organizations, you can restrict which
|
|
|
|
users have access to which organizations.
|
|
|
|
This is done by setting `org_membership` in `AUTH_LDAP_USER_ATTR_MAP` to the name of
|
2021-08-20 21:53:28 +02:00
|
|
|
the LDAP attribute which will contain a list of subdomains that the
|
2020-08-15 18:33:16 +02:00
|
|
|
user should be allowed to access.
|
|
|
|
|
|
|
|
For the root subdomain, `www` in the list will work, or any other of
|
|
|
|
`settings.ROOT_SUBDOMAIN_ALIASES`.
|
|
|
|
|
|
|
|
For example, with `org_membership` set to `department`, a user with
|
|
|
|
the following attributes will have access to the root and `engineering` subdomains:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```text
|
2020-08-15 18:33:16 +02:00
|
|
|
...
|
|
|
|
department: engineering
|
|
|
|
department: www
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
2020-09-22 18:18:45 +02:00
|
|
|
More complex access control rules are possible via the
|
2021-08-20 21:53:28 +02:00
|
|
|
`AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL` setting. Note that
|
2020-09-22 18:18:45 +02:00
|
|
|
`org_membership` takes precedence over
|
|
|
|
`AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL`:
|
|
|
|
|
|
|
|
1. If `org_membership` is set and allows access, access will be granted
|
|
|
|
2. If `org_membership` is not set or does not allow access,
|
|
|
|
`AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL` will control access.
|
|
|
|
|
2023-02-03 13:01:03 +01:00
|
|
|
`AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL` is a dictionary keyed by the
|
|
|
|
organization's subdomain. The corresponding value is a list of
|
|
|
|
`attribute: value` pair sets such that a user is permitted to access
|
|
|
|
the organization if and only if the `attribute: value` pairs in at
|
|
|
|
least one of these sets match the user's LDAP attributes. If this
|
2023-10-08 22:53:54 +02:00
|
|
|
setting is enabled, organizations not explicitly configured in it
|
|
|
|
will not be affected - they'll allow normal LDAP login, unless restricted
|
|
|
|
by other settings.
|
2023-02-03 13:01:03 +01:00
|
|
|
This is better illustrated with an example:
|
|
|
|
|
|
|
|
```
|
|
|
|
AUTH_LDAP_ADVANCED_REALM_ACCESS_CONTROL = {
|
|
|
|
"zulip": [
|
|
|
|
{
|
|
|
|
"department": "main",
|
|
|
|
"employeeType": "staff"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"office": "Dallas"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
This means that the organization `"zulip"` will be accessible via ldap
|
|
|
|
authentication only for users whose ldap attributes either contain
|
|
|
|
both `department: main` `employeeType: staff` or just `office:
|
2023-10-08 22:53:54 +02:00
|
|
|
Dallas`. LDAP authentication will proceed normally for all other
|
|
|
|
organizations.
|
2020-09-22 18:18:45 +02:00
|
|
|
|
2021-08-10 07:55:12 +02:00
|
|
|
:::{warning}
|
|
|
|
Restricting access using these mechanisms only affects authentication via LDAP,
|
|
|
|
and won't prevent users from accessing the organization using any other
|
|
|
|
authentication backends that are enabled for the organization.
|
|
|
|
:::
|
2020-08-15 18:33:16 +02:00
|
|
|
|
2020-01-03 05:57:47 +01:00
|
|
|
### Troubleshooting
|
|
|
|
|
|
|
|
Most issues with LDAP authentication are caused by misconfigurations of
|
2021-08-20 21:53:28 +02:00
|
|
|
the user and email search settings. Some things you can try to get to
|
2020-01-03 05:57:47 +01:00
|
|
|
the bottom of the problem:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Review the instructions for the LDAP configuration type you're
|
2020-01-03 05:57:47 +01:00
|
|
|
using: (A), (B) or (C) (described above), and that you have
|
|
|
|
configured all of the required settings documented in the
|
|
|
|
instructions for that configuration type.
|
2021-08-20 21:45:39 +02:00
|
|
|
- Use the `manage.py query_ldap` tool to verify your configuration.
|
2020-01-03 05:57:47 +01:00
|
|
|
The output of the command will usually indicate the cause of any
|
2021-08-20 21:53:28 +02:00
|
|
|
configuration problem. For the LDAP integration to work, this
|
2020-01-03 05:57:47 +01:00
|
|
|
command should be able to successfully fetch a complete, correct set
|
|
|
|
of data for the queried user.
|
2021-08-20 21:45:39 +02:00
|
|
|
- You can find LDAP-specific logs in `/var/log/zulip/ldap.log`. If
|
2020-01-03 05:57:47 +01:00
|
|
|
you're asking for help with your setup, please provide logs from
|
|
|
|
this file (feel free to anonymize any email addresses to
|
|
|
|
`username@example.com`) in your report.
|
|
|
|
|
2021-02-05 08:15:56 +01:00
|
|
|
## SAML
|
|
|
|
|
|
|
|
Zulip 2.1 and later supports SAML authentication, used by Okta,
|
2021-08-20 21:53:28 +02:00
|
|
|
OneLogin, and many other IdPs (identity providers). You can configure
|
2021-02-05 08:15:56 +01:00
|
|
|
it as follows:
|
|
|
|
|
|
|
|
1. These instructions assume you have an installed Zulip server; if
|
|
|
|
you're using Zulip Cloud, see [this article][saml-help-center],
|
|
|
|
which also has IdP-side configuration advice for common IdPs.
|
|
|
|
|
|
|
|
You can have created a Zulip organization already using the default
|
|
|
|
EmailAuthBackend, or plan to create the organization using SAML
|
|
|
|
authentication.
|
|
|
|
|
|
|
|
1. Tell your IdP how to find your Zulip server:
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- **SP Entity ID**: `https://yourzulipdomain.example.com`.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
The `Entity ID` should match the value of
|
|
|
|
`SOCIAL_AUTH_SAML_SP_ENTITY_ID` computed in the Zulip settings.
|
|
|
|
You can get the correct value by running the following:
|
|
|
|
`/home/zulip/deployments/current/scripts/get-django-setting SOCIAL_AUTH_SAML_SP_ENTITY_ID`.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- **SSO URL**:
|
|
|
|
`https://yourzulipdomain.example.com/complete/saml/`. This is
|
|
|
|
the "SAML ACS url" in SAML terminology.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
If you're
|
2022-02-16 01:39:15 +01:00
|
|
|
[hosting multiple organizations](multiple-organizations.md#authentication),
|
2021-08-20 22:54:08 +02:00
|
|
|
you need to use `SOCIAL_AUTH_SUBDOMAIN`. For example,
|
|
|
|
if `SOCIAL_AUTH_SUBDOMAIN="auth"` and `EXTERNAL_HOST=zulip.example.com`,
|
|
|
|
this should be `https://auth.zulip.example.com/complete/saml/`.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-05-31 14:48:12 +02:00
|
|
|
1. Tell Zulip how to connect to your SAML provider(s) by filling
|
2021-02-05 08:15:56 +01:00
|
|
|
out the section of `/etc/zulip/settings.py` on your Zulip server
|
|
|
|
with the heading "SAML Authentication".
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- You will need to update `SOCIAL_AUTH_SAML_ORG_INFO` with your
|
2021-02-05 08:15:56 +01:00
|
|
|
organization name (`displayname` may appear in the IdP's
|
|
|
|
authentication flow; `name` won't be displayed to humans).
|
2021-08-20 21:45:39 +02:00
|
|
|
- Fill out `SOCIAL_AUTH_SAML_ENABLED_IDPS` with data provided by
|
2021-08-20 21:53:28 +02:00
|
|
|
your identity provider. You may find [the python-social-auth
|
2021-02-05 08:15:56 +01:00
|
|
|
SAML
|
|
|
|
docs](https://python-social-auth.readthedocs.io/en/latest/backends/saml.html)
|
2021-08-20 21:53:28 +02:00
|
|
|
helpful. You'll need to obtain several values from your IdP's
|
2021-02-05 08:15:56 +01:00
|
|
|
metadata and enter them on the right-hand side of this
|
|
|
|
Python dictionary:
|
|
|
|
1. Set the outer `idp_name` key to be an identifier for your IdP,
|
2021-08-20 21:53:28 +02:00
|
|
|
e.g. `testshib` or `okta`. This field appears in URLs for
|
2021-02-05 08:15:56 +01:00
|
|
|
parts of your Zulip server's SAML authentication flow.
|
|
|
|
2. The IdP should provide the `url` and `entity_id` values.
|
|
|
|
3. Save the `x509cert` value to a file; you'll use it in the
|
|
|
|
instructions below.
|
|
|
|
4. The values needed in the `attr_` fields are often configurable
|
|
|
|
in your IdP's interface when setting up SAML authentication
|
|
|
|
(referred to as "Attribute Statements" with Okta, or
|
2022-02-07 22:32:06 +01:00
|
|
|
"Attribute Mapping" with Google Workspace). You'll want to connect
|
2021-02-05 08:15:56 +01:00
|
|
|
these so that Zulip gets the email address (used as a unique
|
|
|
|
user ID) and name for the user.
|
|
|
|
5. The `display_name` and `display_icon` fields are used to
|
|
|
|
display the login/registration buttons for the IdP.
|
2021-06-13 14:18:28 +02:00
|
|
|
6. The `auto_signup` field determines how Zulip should handle
|
|
|
|
login attempts by users who don't have an account yet.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
1. Install the certificate(s) required for SAML authentication. You
|
2021-08-20 22:54:08 +02:00
|
|
|
will definitely need the public certificate of your IdP. Some IdP
|
|
|
|
providers also support the Zulip server (Service Provider) having
|
|
|
|
a certificate used for encryption and signing. We detail these
|
|
|
|
steps as optional below, because they aren't required for basic
|
|
|
|
setup, and some IdPs like Okta don't fully support Service
|
|
|
|
Provider certificates. You should install them as follows:
|
|
|
|
|
|
|
|
1. On your Zulip server, `mkdir -p /etc/zulip/saml/idps/`
|
|
|
|
2. Put the IDP public certificate in `/etc/zulip/saml/idps/{idp_name}.crt`
|
|
|
|
3. (Optional) Put the Zulip server public certificate in `/etc/zulip/saml/zulip-cert.crt`
|
|
|
|
and the corresponding private key in `/etc/zulip/saml/zulip-private-key.key`. Note that
|
|
|
|
the certificate should be the single X.509 certificate for the server, not a full chain of
|
|
|
|
trust, which consists of multiple certificates. The private key cannot be encrypted
|
|
|
|
with a password, as then Zulip will not be able to load it. An example pair can be
|
|
|
|
generated using:
|
|
|
|
```bash
|
|
|
|
openssl req -x509 -newkey rsa:2056 -keyout zulip-private-key.key -out zulip-cert.crt -days 365 -nodes
|
|
|
|
```
|
|
|
|
4. Set the proper permissions on these files and directories:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
chown -R zulip.zulip /etc/zulip/saml/
|
|
|
|
find /etc/zulip/saml/ -type f -exec chmod 644 -- {} +
|
|
|
|
chmod 640 /etc/zulip/saml/zulip-private-key.key
|
|
|
|
```
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-05-31 14:48:12 +02:00
|
|
|
1. (Optional) If you configured the optional public and private server
|
2021-02-05 08:15:56 +01:00
|
|
|
certificates above, you can enable the additional setting
|
|
|
|
`"authnRequestsSigned": True` in `SOCIAL_AUTH_SAML_SECURITY_CONFIG`
|
|
|
|
to have the SAMLRequests the server will be issuing to the IdP
|
2021-08-20 21:53:28 +02:00
|
|
|
signed using those certificates. Additionally, if the IdP supports
|
2021-02-05 08:15:56 +01:00
|
|
|
it, you can upload the public certificate to enable encryption of
|
|
|
|
assertions in the SAMLResponses the IdP will send about
|
|
|
|
authenticated users.
|
|
|
|
|
2021-05-31 14:48:12 +02:00
|
|
|
1. Enable the `zproject.backends.SAMLAuthBackend` auth backend, in
|
2021-08-20 22:54:08 +02:00
|
|
|
`AUTHENTICATION_BACKENDS` in `/etc/zulip/settings.py`.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-05-31 14:48:12 +02:00
|
|
|
1. (Optional) New in Zulip 5.0: Zulip can synchronize [custom profile
|
|
|
|
fields][custom-profile-fields] from the SAML provider. Just
|
|
|
|
configure the `SOCIAL_AUTH_SYNC_CUSTOM_ATTRS_DICT`; the
|
|
|
|
[LDAP](#synchronizing-custom-profile-fields) documentation for
|
|
|
|
synchronizing custom profile fields will be helpful. Servers
|
|
|
|
installed before Zulip 5.0 may want to [update inline comment
|
|
|
|
documentation][update-inline-comments] so they can take advantage
|
|
|
|
of the latest inline SAML documentation in
|
|
|
|
`/etc/zulip/settings.py`.
|
|
|
|
|
|
|
|
Note that in contrast with LDAP, Zulip can only query the SAML
|
|
|
|
database for a user's settings when the user authenticates to Zulip
|
|
|
|
using SAML, so custom profile fields are only synchronized when the
|
|
|
|
user logs in.
|
|
|
|
|
|
|
|
Note also that the SAML feature currently only synchronizes custom
|
|
|
|
profile fields during login, not during account creation; we
|
|
|
|
consider this [a bug](https://github.com/zulip/zulip/issues/18746).
|
|
|
|
|
2022-02-24 00:17:21 +01:00
|
|
|
1. [Restart the Zulip server](settings.md) to ensure
|
2021-08-20 22:54:08 +02:00
|
|
|
your settings changes take effect. The Zulip login page should now
|
|
|
|
have a button for SAML authentication that you can use to log in or
|
|
|
|
create an account (including when creating a new organization).
|
2021-02-05 08:15:56 +01:00
|
|
|
|
2021-05-31 14:48:12 +02:00
|
|
|
1. If the configuration was successful, the server's metadata can be
|
2021-08-20 22:54:08 +02:00
|
|
|
found at `https://yourzulipdomain.example.com/saml/metadata.xml`. You
|
|
|
|
can use this for verifying your configuration or provide it to your
|
|
|
|
IdP.
|
2021-02-05 08:15:56 +01:00
|
|
|
|
|
|
|
[saml-help-center]: https://zulip.com/help/saml-authentication
|
|
|
|
|
|
|
|
### IdP-initiated SSO
|
|
|
|
|
|
|
|
The above configuration is sufficient for Service Provider initialized
|
2021-05-14 00:16:30 +02:00
|
|
|
SSO, i.e. you can visit the Zulip web app and click "Sign in with
|
2021-08-20 21:53:28 +02:00
|
|
|
{IdP}" and it'll correctly start the authentication flow. If you are
|
2021-02-05 08:15:56 +01:00
|
|
|
not hosting multiple organizations, with Zulip 3.0+, the above
|
|
|
|
configuration is also sufficient for Identity Provider initiated SSO,
|
|
|
|
i.e. clicking a "Sign in to Zulip" button on the IdP's website can
|
|
|
|
correctly authenticate the user to Zulip.
|
|
|
|
|
|
|
|
If you're hosting multiple organizations and thus using the
|
|
|
|
`SOCIAL_AUTH_SUBDOMAIN` setting, you'll need to configure a custom
|
2021-09-08 00:23:24 +02:00
|
|
|
`RelayState` in your IdP of the form
|
|
|
|
`{"subdomain": "yourzuliporganization"}` to let Zulip know which
|
|
|
|
organization to authenticate the user to when they visit your SSO URL
|
2021-08-20 21:53:28 +02:00
|
|
|
from the IdP. (If the organization is on the root domain, use the
|
2021-09-08 00:23:24 +02:00
|
|
|
empty string: `{"subdomain": ""}`.).
|
2021-02-05 08:15:56 +01:00
|
|
|
|
|
|
|
### Restricting access to specific organizations
|
|
|
|
|
|
|
|
If you're hosting multiple Zulip organizations, you can restrict which
|
|
|
|
organizations can use a given IdP by setting `limit_to_subdomains`.
|
|
|
|
For example, `limit_to_subdomains = ["", "engineering"]` would
|
|
|
|
restrict an IdP the root domain and the `engineering` subdomain.
|
|
|
|
|
|
|
|
You can achieve the same goal with a SAML attribute; just declare
|
|
|
|
which attribute using `attr_org_membership` in the IdP configuration.
|
|
|
|
For the root subdomain, `www` in the list will work, or any other of
|
|
|
|
`settings.ROOT_SUBDOMAIN_ALIASES`.
|
|
|
|
|
|
|
|
For example, with `attr_org_membership` set to `member`, a user with
|
|
|
|
the following attribute in their `AttributeStatement` will have access
|
|
|
|
to the root and `engineering` subdomains:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```xml
|
2021-02-05 08:15:56 +01:00
|
|
|
<saml2:Attribute Name="member" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
|
|
|
|
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">
|
|
|
|
www
|
|
|
|
</saml2:AttributeValue>
|
|
|
|
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">
|
|
|
|
engineering
|
|
|
|
</saml2:AttributeValue>
|
|
|
|
</saml2:Attribute>
|
|
|
|
```
|
|
|
|
|
2023-04-02 13:15:57 +02:00
|
|
|
### SCIM
|
|
|
|
|
|
|
|
Many SAML IdPs also offer SCIM provisioning to manage automatically
|
|
|
|
deactivating accounts; consider configuring the [Zulip SCIM
|
|
|
|
integration](../production/scim.md).
|
|
|
|
|
2021-07-14 13:27:44 +02:00
|
|
|
### 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
|
2022-04-13 23:28:20 +02:00
|
|
|
as `{idp_name}.crt` in `/etc/zulip/saml/idps/`. You can obtain the
|
2021-09-10 22:23:09 +02:00
|
|
|
certificate from the Keycloak UI in the `Keys` tab. Click on the
|
2021-07-14 13:27:44 +02:00
|
|
|
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:
|
2021-09-10 22:23:09 +02:00
|
|
|
|
2023-05-31 01:18:00 +02:00
|
|
|
```text
|
2021-07-14 13:27:44 +02:00
|
|
|
-----BEGIN CERTIFICATE-----
|
|
|
|
{Paste the content here}
|
|
|
|
-----END CERTIFICATE-----
|
|
|
|
```
|
|
|
|
|
|
|
|
4. If you want to sign SAML requests, you have to do two things in Keycloak:
|
2021-09-10 22:23:09 +02:00
|
|
|
|
docs: Add missing space to compound verbs “back up”, “log in”, etc.
Noun: backup, login, logout, lookup, setup.
Verb: back up, log in, log out, look up, set up.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-02-07 20:41:10 +01:00
|
|
|
1. In the Keycloak client settings you set up previously, open the
|
2021-07-14 13:27:44 +02:00
|
|
|
`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
|
2021-09-10 22:23:09 +02:00
|
|
|
resulting certificates. Instead, you must generate the key and
|
2021-07-14 13:27:44 +02:00
|
|
|
certificate on the Zulip server and import them into Keycloak:
|
2021-09-10 22:23:09 +02:00
|
|
|
|
2021-07-14 13:27:44 +02:00
|
|
|
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):
|
2021-09-10 22:23:09 +02:00
|
|
|
|
2021-07-14 13:27:44 +02:00
|
|
|
```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)
|
2021-09-10 22:23:09 +02:00
|
|
|
|
2021-07-14 13:27:44 +02:00
|
|
|
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).
|
|
|
|
|
2022-01-19 10:29:35 +01:00
|
|
|
### Using Authentik as a SAML IdP
|
|
|
|
|
|
|
|
1. Make sure you reviewed [this article](https://goauthentik.io/integrations/services/zulip/), which
|
|
|
|
details how to integrate Zulip with Authentik.
|
|
|
|
1. 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://authentik.example.com/`, then `url`
|
|
|
|
should be
|
|
|
|
`https://authentik.company/application/saml/<application slug>/sso/binding/redirect/` where `<application slug>`
|
|
|
|
is the application slug you've assigned to this application in Authentik settings (e.g `zulip`).
|
|
|
|
1. Update the attribute mapping in your new entry in `SOCIAL_AUTH_SAML_ENABLED_IDPS` to match how
|
|
|
|
Authentik specifies attributes in its`SAMLResponse`:
|
|
|
|
|
|
|
|
```
|
|
|
|
"attr_user_permanent_id": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
|
|
|
|
"attr_first_name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
|
|
|
|
"attr_last_name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
|
|
|
|
"attr_username": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
|
|
|
|
"attr_email": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
|
|
|
|
```
|
|
|
|
|
|
|
|
1. Your Authentik public certificate must be saved on the Zulip server
|
|
|
|
as `/etc/zulip/saml/idps/{idp_name}.crt`. You can obtain the
|
|
|
|
certificate from the Authentik UI in the `Certificates` section or directly
|
|
|
|
from the provider's page.
|
|
|
|
|
|
|
|
(Alternatively, open the settings page of the provider you created and copy the certificate embedded in the
|
|
|
|
SAML Metadata's `<ds:X509Certificate>` field.).
|
|
|
|
|
|
|
|
Save the certificate in a new `{idp_name}.crt` file constructed as follows:
|
|
|
|
|
|
|
|
```
|
|
|
|
-----BEGIN CERTIFICATE-----
|
|
|
|
{Paste the content here}
|
|
|
|
-----END CERTIFICATE-----
|
|
|
|
```
|
|
|
|
|
2021-11-01 20:08:20 +01:00
|
|
|
### SAML Single Logout
|
2021-10-21 14:16:26 +02:00
|
|
|
|
2021-11-01 20:08:20 +01:00
|
|
|
Zulip supports both IdP-initiated and SP-initiated SAML Single
|
|
|
|
Logout. The implementation has primarily been tested with Keycloak and
|
|
|
|
these instructions are for that provider; please [contact
|
|
|
|
us](https://zulip.com/help/contact-support) if you need help using
|
|
|
|
this with another IdP.
|
|
|
|
|
2023-10-09 20:54:10 +02:00
|
|
|
#### IdP-initiated Single Logout
|
2021-10-21 14:16:26 +02:00
|
|
|
|
|
|
|
1. In the KeyCloak configuration for Zulip, enable `Force Name ID Format`
|
|
|
|
and set `Name ID Format` to `email`. Zulip needs to receive
|
|
|
|
the user's email address in the NameID to know which user's
|
|
|
|
sessions to terminate.
|
|
|
|
1. Make sure `Front Channel Logout` is enabled, which it should be by default.
|
2021-11-01 15:58:41 +01:00
|
|
|
Disable `Force POST Binding`, as Zulip only supports the Redirect binding.
|
2021-10-21 14:16:26 +02:00
|
|
|
1. In `Fine Grain SAML Endpoint Configuration`, set `Logout Service Redirect Binding URL`
|
|
|
|
to the same value you provided for `SSO URL` above.
|
|
|
|
1. Add the IdP's `Redirect Binding URL`for `SingleLogoutService` to
|
|
|
|
your IdP configuration dict in `SOCIAL_AUTH_SAML_ENABLED_IDPS` in
|
|
|
|
`/etc/zulip/settings.py` as `slo_url`. For example it may look like
|
|
|
|
this:
|
|
|
|
|
2023-05-31 01:18:00 +02:00
|
|
|
```text
|
2021-10-21 14:16:26 +02:00
|
|
|
"your_keycloak_idp_name": {
|
|
|
|
"entity_id": "https://keycloak.example.com/auth/realms/yourrealm",
|
|
|
|
"url": "https://keycloak.example.com/auth/realms/yourrealm/protocol/saml",
|
|
|
|
"slo_url": "https://keycloak.example.com/auth/realms/yourrealm/protocol/saml",
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
|
|
|
You can find these details in your `SAML 2.0 Identity Provider Metadata` (available
|
|
|
|
in your `Realm Settings`).
|
|
|
|
|
|
|
|
1. Because Keycloak uses the old `Name ID Format` format for
|
|
|
|
pre-existing sessions, each user needs to be logged out before SAML
|
|
|
|
Logout will work for them. Test SAML logout with your account by
|
|
|
|
logging out from Zulip, logging back in using SAML, and then using
|
|
|
|
the SAML logout feature from KeyCloak. Check
|
|
|
|
`/var/log/zulip/errors.log` for error output if it doesn't work.
|
docs: Add missing space to compound verbs “back up”, “log in”, etc.
Noun: backup, login, logout, lookup, setup.
Verb: back up, log in, log out, look up, set up.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-02-07 20:41:10 +01:00
|
|
|
1. Once SAML logout is working for you, you can use the `manage.py logout_all_users` management command to log out all users so that
|
2021-10-21 14:16:26 +02:00
|
|
|
SAML logout works for everyone.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
/home/zulip/deployments/current/manage.py logout_all_users
|
|
|
|
```
|
|
|
|
|
2021-11-01 20:08:20 +01:00
|
|
|
#### SP-initiated Single Logout
|
|
|
|
|
|
|
|
After configuring IdP-initiated Logout, you only need to set
|
2022-11-12 21:44:02 +01:00
|
|
|
`"sp_initiated_logout_enabled": True` in the appropriate IdP
|
|
|
|
configuration dict in `SOCIAL_AUTH_SAML_ENABLED_IDPS` in
|
2021-11-01 20:08:20 +01:00
|
|
|
`/etc/zulip/settings.py` to also enable SP-initiated Logout. When this
|
|
|
|
is active, a user who logged in to Zulip via SAML, upon clicking
|
|
|
|
"Logout" in the Zulip web app will be redirected to the IdP's Single
|
|
|
|
Logout endpoint with a `LogoutRequest`. If a successful
|
|
|
|
`LogoutResponse` is received back, their current Zulip session will be
|
|
|
|
terminated.
|
|
|
|
|
2022-11-16 18:31:10 +01:00
|
|
|
Note that this doesn't work when logging out of the mobile application
|
|
|
|
since the app doesn't use sessions and relies on just having the user's
|
|
|
|
API key.
|
2021-11-01 20:08:20 +01:00
|
|
|
|
2021-10-21 14:16:26 +02:00
|
|
|
#### Caveats
|
|
|
|
|
2021-11-01 20:08:20 +01:00
|
|
|
- This implementation doesn't support using `SessionIndex` to limit which
|
|
|
|
sessions are affected; in IdP-initiated Logout it always terminates
|
|
|
|
all logged-in sessions for the user identified in the `NameID`.
|
2021-10-21 14:16:26 +02:00
|
|
|
- SAML Logout in a configuration where your IdP handles authentication
|
|
|
|
for multiple organizations is not yet supported.
|
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
## Apache-based SSO with `REMOTE_USER`
|
|
|
|
|
|
|
|
If you have any existing SSO solution where a preferred way to deploy
|
|
|
|
it (a) runs inside Apache, and (b) sets the `REMOTE_USER` environment
|
|
|
|
variable, then the `ZulipRemoteUserBackend` method provides you with a
|
|
|
|
straightforward way to deploy that SSO solution with Zulip.
|
|
|
|
|
|
|
|
### Setup instructions for Apache-based SSO
|
2016-07-13 01:05:04 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
1. In `/etc/zulip/settings.py`, configure two settings:
|
2016-07-13 01:05:04 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `AUTHENTICATION_BACKENDS`: `'zproject.backends.ZulipRemoteUserBackend'`,
|
2018-01-19 02:43:23 +01:00
|
|
|
and no other entries.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `SSO_APPEND_DOMAIN`: see documentation in `settings.py`.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
Make sure that you've restarted the Zulip server since making this
|
|
|
|
configuration change.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
2. Edit `/etc/zulip/zulip.conf` and change the `puppet_classes` line to read:
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```ini
|
2020-10-20 03:49:23 +02:00
|
|
|
puppet_classes = zulip::profile::standalone, zulip::apache_sso
|
2018-01-19 02:43:23 +01:00
|
|
|
```
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
3. As root, run `/home/zulip/deployments/current/scripts/zulip-puppet-apply`
|
|
|
|
to install our SSO integration.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
4. To configure our SSO integration, edit a copy of
|
|
|
|
`/etc/apache2/sites-available/zulip-sso.example`, saving the result
|
2021-08-20 21:53:28 +02:00
|
|
|
as `/etc/apache2/sites-available/zulip-sso.conf`. The example sets
|
2018-01-19 02:43:23 +01:00
|
|
|
up HTTP basic auth, with an `htpasswd` file; you'll want to replace
|
|
|
|
that with configuration for your SSO solution to authenticate the
|
|
|
|
user and set `REMOTE_USER`.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
For testing, you may want to move ahead with the rest of the setup
|
|
|
|
using the `htpasswd` example configuration and demonstrate that
|
|
|
|
working end-to-end, before returning later to configure your SSO
|
2021-08-20 21:53:28 +02:00
|
|
|
solution. You can do that with the following steps:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```bash
|
2018-01-19 02:43:23 +01:00
|
|
|
/home/zulip/deployments/current/scripts/restart-server
|
|
|
|
cd /etc/apache2/sites-available/
|
|
|
|
cp zulip-sso.example zulip-sso.conf
|
|
|
|
htpasswd -c /home/zulip/zpasswd username@example.com # prompts for a password
|
|
|
|
```
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
5. Run `a2ensite zulip-sso` to enable the SSO integration within Apache.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
6. Run `service apache2 reload` to use your new configuration. If
|
2021-09-08 00:23:24 +02:00
|
|
|
Apache isn't already running, you may need to run
|
|
|
|
`service apache2 start` instead.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
Now you should be able to visit your Zulip server in a browser (e.g.,
|
|
|
|
at `https://zulip.example.com/`) and log in via the SSO solution.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
### Troubleshooting Apache-based SSO
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
Most issues with this setup tend to be subtle issues with the
|
2021-08-20 21:53:28 +02:00
|
|
|
hostname/DNS side of the configuration. Suggestions for how to
|
2018-01-19 02:43:23 +01:00
|
|
|
improve this SSO setup documentation are very welcome!
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- For example, common issues have to do with `/etc/hosts` not mapping
|
2018-01-19 02:43:23 +01:00
|
|
|
`settings.EXTERNAL_HOST` to the Apache listening on
|
|
|
|
`127.0.0.1`/`localhost`.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- While debugging, it can often help to temporarily change the Apache
|
2018-01-19 02:43:23 +01:00
|
|
|
config in `/etc/apache2/sites-available/zulip-sso` to listen on all
|
|
|
|
interfaces rather than just `127.0.0.1`.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- While debugging, it can also be helpful to change `proxy_pass` in
|
2018-01-19 02:43:23 +01:00
|
|
|
`/etc/nginx/zulip-include/app.d/external-sso.conf` to point to a
|
|
|
|
more explicit URL, possibly not over HTTPS.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The following log files can be helpful when debugging this setup:
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- `/var/log/zulip/{errors.log,server.log}` (the usual places)
|
|
|
|
- `/var/log/nginx/access.log` (nginx access logs)
|
|
|
|
- `/var/log/apache2/zulip_auth_access.log` (from the
|
|
|
|
`zulip-sso.conf` Apache config file; you may want to change
|
|
|
|
`LogLevel` in that file to "debug" to make this more verbose)
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
### Life of an Apache-based SSO login attempt
|
|
|
|
|
|
|
|
Here's a summary of how the Apache `REMOTE_USER` SSO system works,
|
|
|
|
assuming you're using the example configuration with HTTP basic auth.
|
|
|
|
This summary should help with understanding what's going on as you try
|
|
|
|
to debug.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Since you've configured `/etc/zulip/settings.py` to only define the
|
2020-08-19 21:55:28 +02:00
|
|
|
`zproject.backends.ZulipRemoteUserBackend`,
|
|
|
|
`zproject/computed_settings.py` configures `/accounts/login/sso/` as
|
2021-08-20 21:53:28 +02:00
|
|
|
`HOME_NOT_LOGGED_IN`. This makes `https://zulip.example.com/`
|
2020-08-19 21:55:28 +02:00
|
|
|
(a.k.a. the homepage for the main Zulip Django app running behind
|
|
|
|
nginx) redirect to `/accounts/login/sso/` for a user that isn't
|
|
|
|
logged in.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- nginx proxies requests to `/accounts/login/sso/` to an Apache
|
2018-01-19 02:43:23 +01:00
|
|
|
instance listening on `localhost:8888`, via the config in
|
|
|
|
`/etc/nginx/zulip-include/app.d/external-sso.conf` (using the
|
|
|
|
upstream `localhost_sso`, defined in `/etc/nginx/zulip-include/upstreams`).
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- The Apache `zulip-sso` site which you've enabled listens on
|
2018-01-19 02:43:23 +01:00
|
|
|
`localhost:8888` and (in the example config) presents the `htpasswd`
|
2021-08-20 21:53:28 +02:00
|
|
|
dialogue. (In a real configuration, it takes the user through
|
|
|
|
whatever more complex interaction your SSO solution performs.) The
|
2018-01-19 02:43:23 +01:00
|
|
|
user provides correct login information, and the request reaches a
|
|
|
|
second Zulip Django app instance, running behind Apache, with
|
2021-08-20 21:53:28 +02:00
|
|
|
`REMOTE_USER` set. That request is served by
|
2016-10-23 02:49:43 +02:00
|
|
|
`zerver.views.remote_user_sso`, which just checks the `REMOTE_USER`
|
2018-01-19 02:43:23 +01:00
|
|
|
variable and either logs the user in or, if they don't have an
|
2021-08-20 21:53:28 +02:00
|
|
|
account already, registers them. The login sets a cookie.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- After succeeding, that redirects the user back to `/` on port 443.
|
2018-01-19 02:43:23 +01:00
|
|
|
This request is sent by nginx to the main Zulip Django app, which
|
|
|
|
sees the cookie, treats them as logged in, and proceeds to serve
|
|
|
|
them the main app page normally.
|
2016-07-12 23:32:12 +02:00
|
|
|
|
2020-06-09 12:04:21 +02:00
|
|
|
## Sign in with Apple
|
|
|
|
|
|
|
|
Zulip supports using the web flow for Sign in with Apple on
|
2021-08-20 21:53:28 +02:00
|
|
|
self-hosted servers. To do so, you'll need to do the following:
|
2020-06-09 12:04:21 +02:00
|
|
|
|
|
|
|
1. Visit [the Apple Developer site][apple-developer] and [Create a
|
2021-08-20 22:54:08 +02:00
|
|
|
Services ID.][apple-create-services-id]. When prompted for a "Return
|
|
|
|
URL", enter `https://zulip.example.com/complete/apple/` (using the
|
|
|
|
domain for your server).
|
2020-06-09 12:04:21 +02:00
|
|
|
|
|
|
|
1. Create a [Sign in with Apple private key][apple-create-private-key].
|
|
|
|
|
|
|
|
1. Store the resulting private key at
|
2021-08-20 21:53:28 +02:00
|
|
|
`/etc/zulip/apple-auth-key.p8`. Be sure to set
|
2020-06-09 12:04:21 +02:00
|
|
|
permissions correctly:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```bash
|
2020-06-25 13:26:17 +02:00
|
|
|
chown zulip:zulip /etc/zulip/apple-auth-key.p8
|
|
|
|
chmod 640 /etc/zulip/apple-auth-key.p8
|
2020-06-09 12:04:21 +02:00
|
|
|
```
|
|
|
|
|
2020-06-24 03:38:08 +02:00
|
|
|
1. Configure Apple authentication in `/etc/zulip/settings.py`:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `SOCIAL_AUTH_APPLE_TEAM`: Your Team ID from Apple, which is a
|
2020-06-24 03:38:08 +02:00
|
|
|
string like "A1B2C3D4E5".
|
2021-08-20 21:45:39 +02:00
|
|
|
- `SOCIAL_AUTH_APPLE_SERVICES_ID`: The Services ID you created in
|
2020-06-24 03:38:08 +02:00
|
|
|
step 1, which might look like "com.example.services".
|
2021-08-20 21:45:39 +02:00
|
|
|
- `SOCIAL_AUTH_APPLE_APP_ID`: The App ID, or Bundle ID, of your
|
2020-06-24 03:38:08 +02:00
|
|
|
app that you used in step 1 to configure your Services ID.
|
|
|
|
This might look like "com.example.app".
|
2021-08-20 21:45:39 +02:00
|
|
|
- `SOCIAL_AUTH_APPLE_KEY`: Despite the name this is not a key, but
|
2021-08-20 21:53:28 +02:00
|
|
|
rather the Key ID of the key you created in step 2. This looks
|
2020-06-24 03:38:08 +02:00
|
|
|
like "F6G7H8I9J0".
|
2021-08-20 21:45:39 +02:00
|
|
|
- `AUTHENTICATION_BACKENDS`: Uncomment (or add) a line like
|
2020-06-24 03:38:08 +02:00
|
|
|
`'zproject.backends.AppleAuthBackend',` to enable Apple auth
|
|
|
|
using the created configuration.
|
2020-06-09 12:04:21 +02:00
|
|
|
|
2020-06-24 04:01:16 +02:00
|
|
|
1. Register with Apple the email addresses or domains your Zulip
|
2021-08-20 21:53:28 +02:00
|
|
|
server sends email to users from. For instructions and background,
|
2020-06-24 04:01:16 +02:00
|
|
|
see the "Email Relay Service" subsection of
|
2021-08-20 21:53:28 +02:00
|
|
|
[this page][apple-get-started]. For details on what email
|
2020-06-24 04:01:16 +02:00
|
|
|
addresses Zulip sends from, see our
|
|
|
|
[outgoing email documentation][outgoing-email].
|
2020-06-09 12:04:21 +02:00
|
|
|
|
|
|
|
[apple-create-services-id]: https://help.apple.com/developer-account/?lang=en#/dev1c0e25352
|
|
|
|
[apple-developer]: https://developer.apple.com/account/resources/
|
|
|
|
[apple-create-private-key]: https://help.apple.com/developer-account/?lang=en#/dev77c875b7e
|
|
|
|
[apple-get-started]: https://developer.apple.com/sign-in-with-apple/get-started/
|
2022-02-24 00:17:21 +01:00
|
|
|
[outgoing-email]: email.md
|
2020-06-09 12:04:21 +02:00
|
|
|
|
2021-05-21 16:45:43 +02:00
|
|
|
## OpenID Connect
|
|
|
|
|
|
|
|
Starting with Zulip 5.0, Zulip can be integrated with any OpenID
|
2021-08-20 21:53:28 +02:00
|
|
|
Connect (OIDC) authentication provider. You can configure it by
|
2021-05-21 16:45:43 +02:00
|
|
|
enabling `zproject.backends.GenericOpenIdConnectBackend` in
|
|
|
|
`AUTHENTICATION_BACKENDS` and following the steps outlined in the
|
|
|
|
comment documentation in `/etc/zulip/settings.py`.
|
|
|
|
|
2021-11-25 10:24:41 +01:00
|
|
|
If your server was originally installed from a release in the
|
|
|
|
`4.x` series or earlier, you will need to update your `settings.py`
|
|
|
|
file. You can find instructions on how to do that in a
|
|
|
|
[separate doc][update-inline-comments].
|
|
|
|
|
2021-07-21 13:28:54 +02:00
|
|
|
Note that `SOCIAL_AUTH_OIDC_ENABLED_IDPS` only supports a single IdP currently.
|
2021-05-21 16:45:43 +02:00
|
|
|
|
|
|
|
The Return URL to authorize with the provider is
|
|
|
|
`https://yourzulipdomain.example.com/complete/oidc/`.
|
|
|
|
|
docs: Add missing space to compound verbs “back up”, “log in”, etc.
Noun: backup, login, logout, lookup, setup.
Verb: back up, log in, log out, look up, set up.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-02-07 20:41:10 +01:00
|
|
|
By default, users who attempt to log in with OIDC using an email
|
2021-07-21 13:50:54 +02:00
|
|
|
address that does not have a current Zulip account will be prompted
|
docs: Add missing space to compound verbs “back up”, “log in”, etc.
Noun: backup, login, logout, lookup, setup.
Verb: back up, log in, log out, look up, set up.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-02-07 20:41:10 +01:00
|
|
|
for whether they intend to create a new account or would like to log in
|
2021-07-21 13:50:54 +02:00
|
|
|
using another authentication method. You can configure automatic
|
2021-09-08 00:23:24 +02:00
|
|
|
account creation on first login attempt by setting
|
|
|
|
`"auto_signup": True` in the IdP configuration dictionary.
|
2021-07-21 13:50:54 +02:00
|
|
|
|
2021-07-21 13:54:20 +02:00
|
|
|
The global setting `SOCIAL_AUTH_OIDC_FULL_NAME_VALIDATED` controls how
|
|
|
|
Zulip uses the Full Name provided by the IdP. By default, Zulip
|
|
|
|
prefills that value in the new account creation form, but gives the
|
|
|
|
user the opportunity to edit it before submitting. When `True`, Zulip
|
|
|
|
assumes the name is correct, and new users will not be presented with
|
|
|
|
a registration form unless they need to accept Terms of Service for
|
2021-11-03 21:36:54 +01:00
|
|
|
the server (i.e. `TERMS_OF_SERVICE_VERSION` is set).
|
2021-07-21 13:54:20 +02:00
|
|
|
|
2022-09-13 17:39:18 +02:00
|
|
|
## JWT
|
|
|
|
|
|
|
|
Zulip supports using JSON Web Tokens (JWT) authentication in two ways:
|
|
|
|
|
|
|
|
1. Obtaining a logged in session by making a POST request to
|
|
|
|
`/accounts/login/jwt/`. This allows a separate application to
|
|
|
|
integrate with Zulip via having a button that directly takes the user
|
|
|
|
to Zulip and logs them in.
|
|
|
|
2. Fetching a user's API key by making a POST request to
|
|
|
|
`/api/v1/jwt/fetch_api_key`. This allows a separate application to
|
|
|
|
integrate with Zulip by [making API
|
|
|
|
requests](https://zulip.com/api/) on behalf of any user in a Zulip
|
|
|
|
organization.
|
|
|
|
|
|
|
|
In both cases, the request should be made by sending an HTTP `POST`
|
|
|
|
request with the JWT in the `token` parameter, with the JWT payload
|
|
|
|
having the structure `{"email": "<target user email>"}`.
|
|
|
|
|
|
|
|
In order to use JWT authentication with Zulip, one must first
|
|
|
|
configure the JWT secret and algorithm via `JWT_AUTH_KEYS` in
|
|
|
|
`/etc/zulip/settings.py`; see the inline comment documentation in that
|
|
|
|
file for details.
|
|
|
|
|
2018-01-19 02:43:23 +01:00
|
|
|
## Adding more authentication backends
|
|
|
|
|
2018-12-19 01:45:57 +01:00
|
|
|
Adding an integration with any of the more than 100 authentication
|
|
|
|
providers supported by [python-social-auth][python-social-auth] (e.g.,
|
2018-01-19 02:43:23 +01:00
|
|
|
Facebook, Twitter, etc.) is easy to do if you're willing to write a
|
|
|
|
bit of code, and pull requests to add new backends are welcome.
|
|
|
|
|
2018-12-19 01:45:57 +01:00
|
|
|
For example, the
|
|
|
|
[Azure Active Directory integration](https://github.com/zulip/zulip/commit/49dbd85a8985b12666087f9ea36acb6f7da0aa4f)
|
|
|
|
was about 30 lines of code, plus some documentation and an
|
2021-08-20 21:53:28 +02:00
|
|
|
[automatically generated migration][schema-migrations]. We also have
|
2018-12-19 01:45:57 +01:00
|
|
|
helpful developer documentation on
|
2019-11-07 18:29:05 +01:00
|
|
|
[testing auth backends](../development/authentication.md).
|
2018-01-19 02:43:23 +01:00
|
|
|
|
2019-09-30 19:37:56 +02:00
|
|
|
[schema-migrations]: ../subsystems/schema-migrations.md
|
2018-01-19 02:43:23 +01:00
|
|
|
[python-social-auth]: https://python-social-auth.readthedocs.io/en/latest/
|
|
|
|
|
|
|
|
## Development only
|
|
|
|
|
|
|
|
The `DevAuthBackend` method is used only in development, to allow
|
2021-08-20 21:53:28 +02:00
|
|
|
passwordless login as any user in a development environment. It's
|
2018-01-19 02:43:23 +01:00
|
|
|
mentioned on this page only for completeness.
|
2021-05-31 14:48:12 +02:00
|
|
|
|
2022-11-28 15:40:51 +01:00
|
|
|
[custom-profile-fields]: https://zulip.com/help/custom-profile-fields
|
2023-01-17 04:33:42 +01:00
|
|
|
[update-inline-comments]: upgrade.md#updating-settingspy-inline-documentation
|