跳转到主要内容

Synapse的LDAP3认证提供者

项目描述

允许synapse使用LDAP作为密码提供者。

这允许用户使用来自LDAP服务器的用户名和密码登录到synapse。还有一个ma1sd (第三方) 提供更全面的集成。

安装

  • 作为matrix.org的标准部分包含在deb软件包Docker镜像中。

  • 如果您在虚拟环境中安装了
    • 请确保pip已更新: pip install -U pip

    • 安装LDAP密码提供者: pip install matrix-synapse-ldap3

  • 有关其他安装机制,请参阅维护者提供的文档。

使用方法

示例Synapse配置

modules:
 - module: "ldap_auth_provider.LdapAuthProviderModule"
   config:
     enabled: true
     uri: "ldap://ldap.example.com:389"
     start_tls: true
     base: "ou=users,dc=example,dc=com"
     attributes:
        uid: "cn"
        mail: "mail"
        name: "givenName"
     #bind_dn:
     #bind_password:
     #filter: "(objectClass=posixAccount)"
     # Additional options for TLS, can be any key from https://ldap3.readthedocs.io/en/latest/ssltls.html#the-tls-object
     #tls_options:
     #  validate: true
     #  local_certificate_file: foo.crt
     #  local_private_key_file: bar.pem
     #  local_private_key_password: secret

如果您想为高可用性指定多个LDAP服务器,您可以提供带有列表的uri参数。默认情况下,采用ldap3.ServerPool的高可用策略,因此使用第一个可用的服务器。

modules:
 - module: "ldap_auth_provider.LdapAuthProviderModule"
   config:
     enabled: true
     uri:
        - "ldap://ldap1.example.com:389"
        - "ldap://ldap2.example.com:389"
     start_tls: true
     base: "ou=users,dc=example,dc=com"
     attributes:
        uid: "cn"
        mail: "email"
        name: "givenName"
     #bind_dn:
     #bind_password:
     #filter: "(objectClass=posixAccount)"
     #tls_options:
     #  validate: true
     #  local_certificate_file: foo.crt
     #  local_private_key_file: bar.pem
     #  local_private_key_password: secret

如果您想启用通过电子邮件登录/注册或注册时的givenName/email绑定,则需要启用搜索模式。以下是一个搜索模式的示例配置

modules:
 - module: "ldap_auth_provider.LdapAuthProviderModule"
   config:
     enabled: true
     mode: "search"
     uri: "ldap://ldap.example.com:389"
     start_tls: true
     base: "ou=users,dc=example,dc=com"
     attributes:
        uid: "cn"
        mail: "mail"
        name: "givenName"
     # Search auth if anonymous search not enabled
     bind_dn: "cn=hacker,ou=svcaccts,dc=example,dc=com"
     bind_password: "ch33kym0nk3y"
     #filter: "(objectClass=posixAccount)"
     #tls_options:
     #  validate: true
     #  local_certificate_file: foo.crt
     #  local_private_key_file: bar.pem
     #  local_private_key_password: secret

或者,您也可以将服务用户的 bind_password 放入自己的文件中,以防止机密信息泄露到配置文件中

modules:
 - module: "ldap_auth_provider.LdapAuthProviderModule"
   config:
     enabled: true
     # all the other options you need
     bind_password_file: "/var/secrets/synapse-ldap-bind-password"

请注意,密码文件中每个末尾的 \n 都将被自动删除。

Active Directory森林支持

如果将 active_directory 标志设置为 true,将搜索Active Directory森林以查找登录详细信息。在此模式下,用户在以下表单之一中输入他们的登录信息

  • <login>/<domain>

  • <domain>\<login>

在任一情况下,这将被映射到Matrix UID <login>/<domain>(在Matrix用户标识符中不能使用正常的AD域分隔符 @\,因此使用 / 代替。)

假设您在 example.com 森林中有几个域名

modules:
 - module: "ldap_auth_provider.LdapAuthProviderModule"
   config:
     enabled: true
     mode: "search"
     uri: "ldap://main.example.com:389"
     base: "dc=example,dc=com"
     # Must be true for this feature to work
     active_directory: true
     # Optional. Users from this domain may log in without specifying the domain part
     default_domain: main.example.com
     attributes:
        uid: "userPrincipalName"
        mail: "mail"
        name: "givenName"
     bind_dn: "cn=hacker,ou=svcaccts,dc=example,dc=com"
     bind_password: "ch33kym0nk3y"

使用此配置,用户可以使用 main\someusermain.example.com\someusersomeuser/main.example.comsomeuser 登录。

example.com 森林中的其他域用户可以使用 domain\loginlogin/domain 登录。

请注意,当启用 active_directory 选项时,必须使用 userPrincipalName 或类似格式的LDAP属性,如 login@domain

故障排除和调试

matrix-synapse-ldap3 日志包含在Synapse homeserver日志中(通常是 homeserver.log)。通过修改Synapse服务器日志配置文件,可以将LDAP插件日志级别提高到 DEBUG 以进行故障排除和调试

  • handlers.file.level 的值设置为 DEBUG

handlers:
  file:
    # [...]
    level: DEBUG
  • loggers 部分添加以下内容

loggers:
   # [...]
   ldap3:
     level: DEBUG
   ldap_auth_provider:
     level: DEBUG

最后,重新启动您的Synapse服务器以使更改生效

synctl restart

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

matrix-synapse-ldap3-0.3.0.tar.gz (21.0 kB 查看哈希值)

上传时间

构建分布

matrix_synapse_ldap3-0.3.0-py3-none-any.whl (14.1 kB 查看哈希值)

上传时间: Python 3

支持者