Documentation

21. 设置 LDAP 身份验证

注解

If the LDAP server you want to connect to has a certificate that is self-signed or signed by a corporate internal certificate authority (CA), the CA certificate must be added to the system's trusted CAs. Otherwise, connection to the LDAP server will result in an error that the certificate issuer is not recognized. Refer to Knowledge Base article, How Do I Import CA Certificate (openldap, AD, IDM, FreeIPA) Required for LDAPS Integration?. If prompted, use your Red Hat customer credentials to login.

管理员使用 LDAP 作为控制器用户的帐户身份验证信息来源。它提供了用户身份验证,而未提供用户权限和凭证的同步功能。机构成员资格(以及机构管理员)和团队成员资格可以同步。

当这样配置时,使用 LDAP 用户名和密码登录的用户会自动获得为其创建的控制器帐户,并可作为常规用户或机构管理员自动将其放置到机构中。

通过 LDAP 登录创建的用户无法为自己更改用户名、名、姓或设置本地密码。也可以调整此项来限制其他字段名称的编辑。

为控制器配置 LDAP 集成:

  1. 首先,在 LDAP 中创建有权读取整个 LDAP 结构的用户。

  2. 如果您能够成功查询 LDAP 服务器,请使用 ldapsearch 命令,这是一个命令行工具,可以安装在控制器系统的命令行上,也可以安装在其他 Linux 和 OSX 系统上。使用以下命令查询 ldap 服务器,其中 josieJosie4Cloud 由适用于您的设置的属性替代:

ldapsearch -x  -H ldap://win -D "CN=josie,CN=Users,DC=website,DC=com" -b "dc=website,dc=com" -w Josie4Cloud

此处 CN=josie,CN=users,DC=website,DC=com 是连接的用户的可辨识名称。

注解

automation controller 不会自动预安装 ldapsearch 工具程序,您可以从 openldap-clients 软件包中安装它。

  1. 在 automation controller 用户界面中,从左面导航中点 Settings,点 Authentication 选项列表中的 LDAP settings

Multiple LDAP configurations are not needed per LDAP server, but you can configure multiple LDAP servers from this page, otherwise, leave the server at Default:

_images/configure-tower-auth-ldap-servers.png

等同的 API 端点将显示 AUTH_LDAP_* 重复:AUTH_LDAP_1_*AUTH_LDAP_2_*、......、AUTH_LDAP_5_* 用于表示服务器的名称。

  1. To enter or modify the LDAP server address to connect to, click Edit and enter in the LDAP Server URI field using the same format as the one prepopulated in the text field:

_images/configure-tower-auth-ldap-server-uri.png

注解

Multiple LDAP servers may be specified by separating each with spaces or commas. Click the help icon to comply with proper syntax and rules.

  1. LDAP Bind Password 文本字段中输入用于绑定用户的密码。在本例中,密码是“passme”:

_images/configure-tower-auth-ldap-bind-pwd.png
  1. 点击以从 LDAP Group Type 下拉菜单中选择组类型。

LDAP 组类型包括:

  • PosixGroupType

  • GroupOfNamesType

  • GroupOfUniqueNamesType

  • ActiveDirectoryGroupType

  • OrganizationalRoleGroupType

  • MemberDNGroupType

  • NISGroupType

  • NestedGroupOfNamesType

  • NestedGroupOfUniqueNamesType

  • NestedActiveDirectoryGroupType

  • NestedOrganizationalRoleGroupType

  • NestedMemberDNGroupType

  • PosixUIDGroupType

The LDAP Group Types that are supported by the controller leverage the underlying django-auth-ldap library. To specify the parameters for the selected group type, see Step 15 below.

  1. LDAP Start TLS 默认禁用。当 LDAP 连接未使用 SSL 时,若要启用 TLS,请点击切换到 ON

_images/configure-tower-auth-ldap-start-tls.png
  1. LDAP Bind DN 文本字段中输入可辨识的名称,以指定控制器用来连接(绑定)LDAP 服务器的用户。以下使用了示例 CN=josie,CN=users,DC=website,DC=com

_images/configure-tower-auth-ldap-bind-dn.png
  1. 如果该名称存储在键 sAMAccountName 中,则**LDAP User DN Template** 使用 (sAMAccountName=%(user)s) 填充。Active Directory 将用户名保存到 sAMAccountName。同样,对于 OpenLDAP,键是 uid,行变为 (uid=%(user)s)

  2. Enter the group distinguish name to allow users within that group to access the controller in the LDAP Require Group field, using the same format as the one shown in the text field, CN=controller Users,OU=Users,DC=website,DC=com.

_images/configure-tower-auth-ldap-req-group.png
  1. LDAP Deny Group 字段中输入组可辨识名称以防止该组中的用户访问控制器,使用的格式与文本字段中显示的格式相同。在本例中,将该字段留空。

  2. Enter where to search for users while authenticating in the LDAP User Search field using the same format as the one shown in the text field. In this example, use:

[
"OU=Users,DC=website,DC=com",
"SCOPE_SUBTREE",
"(cn=%(user)s)"
]

第一行指定在 LDAP 树中搜索用户的位置。在上例中,从 DC=website,DC=com 开始以递归方式搜索用户。

第二行指定搜索用户的范围:

  • SCOPE_BASE:此值只用于指定仅搜索基本 DN 处的条目,从而只返回该条目

  • SCOPE_ONELEVEL:此值用于指定搜索基本 DN 下某一个级别的所有条目,但不包括基本 DN,且不包括基本 DN 下某一级别下的条目。

  • SCOPE_SUBTREE:此值用于指定搜索所有级别的全部条目,且包括指定的基本 DN。

第三行指定存储用户名的键名。

_images/configure-tower-authen-ldap-user-search.png

注解

对于多个搜索查询,正确的语法是:

[
  [
  "OU=Users,DC=northamerica,DC=acme,DC=com",
  "SCOPE_SUBTREE",
  "(sAMAccountName=%(user)s)"
  ],
  [
  "OU=Users,DC=apac,DC=corp,DC=com",
  "SCOPE_SUBTREE",
  "(sAMAccountName=%(user)s)"
  ],
  [
  "OU=Users,DC=emea,DC=corp,DC=com",
  "SCOPE_SUBTREE",
  "(sAMAccountName=%(user)s)"
  ]
]
  1. LDAP Group Search 文本字段中,指定应当搜索哪些组以及如何搜索它们。在本例中,使用:

 [
"dc=example,dc=com",
"SCOPE_SUBTREE",
"(objectClass=group)"
 ]
  • 第一行指定应当搜索组的基本 DN。

  • 第二行指定范围,与用户指令的范围相同。

  • 第三行指定在您使用的 LDAP 中组对象的 objectclass 是什么。

_images/configure-tower-authen-ldap-group-search.png
  1. LDAP User Attribute Map 文本字段中输入用户属性。在本例中,使用:

{
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}

上面的示例按姓从键 sn 中检索用户。您可以对用户使用相同的 LDAP 查询,以找出他们存储在哪些键下。

_images/configure-tower-auth-ldap-user-attrb-map.png
  1. Depending on the selected LDAP Group Type, different parameters are available in the LDAP Group Type Parameters field to account for this. LDAP_GROUP_TYPE_PARAMS is a dictionary, which will be converted by the controller to kwargs and passed to the LDAP Group Type class selected. There are two common parameters used by any of the LDAP Group Type; name_attr and member_attr. Where name_attr defaults to cn and member_attr defaults to member:

{"name_attr": "cn", "member_attr": "member"}

要确定特定 LDAP 组类型所需的参数,请参阅有关类 init 参数的 django_auth_ldap 文档。

  1. LDAP User Flags by Group 文本字段中输入用户配置集标志。在本例中,使用以下语法将 LDAP 用户设置为“Superusers”和“Auditors”:

{
"is_superuser": "cn=superusers,ou=groups,dc=website,dc=com",
"is_system_auditor": "cn=auditors,ou=groups,dc=website,dc=com"
}

上例检索在其配置集中标记为 superusers 或 auditor 的用户。

_images/configure-tower-auth-ldap-user-flags.png
  1. 如需完成映射字段的详情,请参阅 LDAP 机构和团队映射

_images/configure-ldap-orgs-teams-mapping.png
  1. 完成后请点击 Save

使用此表单上输入的这些值,您现在可以通过 LDAP 进行成功身份验证。

注解

The controller does not actively sync users, but they are created during their initial login. To improve performance associated with LDAP authentication, see LDAP authentication performance tips at the end of this chapter.

21.1. LDAP 机构和团队映射

You can control which users are placed into which controller organizations based on LDAP attributes (mapping out between your organization admins/users and LDAP groups).

键是机构的名称。如果机构不存在,则会创建机构。值是字典,用于定义每个机构成员资格的选项。对于每个机构来说,可以指定哪些组自动成为机构的用户,以及哪些组可以管理机构。

admins:None、True/False、字符串或字符串的列表/元组。
  • 如果为 None,则机构管理员不会根据 LDAP 值进行更新。

  • 如果为 True,则 LDAP 中的所有用户将自动添加为机构管理员。

  • If False, no LDAP users will be automatically added as admins of the organization.

  • 如果为字符串或字符串列表,则指定在与任何指定组匹配时将添加到机构的组 DN。

remove_admins:True/False。默认为 False
  • 当为 True 时,不属于指定组的成员将从机构的管理列表中删除。

users:None、True/False、字符串或字符串列表/元组。应用的规则与 admins 相同。

remove_users:True/False。默认为 False。应用的规则与 remove_admins 相同。

{
"LDAP Organization": {
  "admins": "cn=engineering_admins,ou=groups,dc=example,dc=com",
  "remove_admins": false,
  "users": [
    "cn=engineering,ou=groups,dc=example,dc=com",
    "cn=sales,ou=groups,dc=example,dc=com",
    "cn=it,ou=groups,dc=example,dc=com"
  ],
  "remove_users": false
},
"LDAP Organization 2": {
  "admins": [
    "cn=Administrators,cn=Builtin,dc=example,dc=com"
  ],
  "remove_admins": false,
  "users": true,
  "remove_users": false
}
}

组成员(用户)和 LDAP 组之间的映射。键是团队名称(如果不存在就会创建)。值是每个团队成员资格选项的字典,其中每项可以包含以下参数:

organization:字符串。团队所属机构的名称。

如果机构和团队名称的组合不存在,将会创建团队。如果机构不存在,则会首先创建机构。

users:None、True/False、字符串或字符串列表/元组。

  • 如果为 None,则不会更新团队成员。

  • 如果为 True/False,则所有 LDAP 用户将作为团队成员添加/删除。

  • 如果为字符串或字符串列表,则指定组 DN。如果用户是这些组中任意组的成员,则用户将添加为团队成员。

remove:True/False。默认为 False。当为 True 时,不是给定组成员的用户将从团队中删除。

{
"LDAP Engineering": {
  "organization": "LDAP Organization",
  "users": "cn=engineering,ou=groups,dc=example,dc=com",
  "remove": true
},
"LDAP IT": {
  "organization": "LDAP Organization",
  "users": "cn=it,ou=groups,dc=example,dc=com",
  "remove": true
},
"LDAP Sales": {
  "organization": "LDAP Organization",
  "users": "cn=sales,ou=groups,dc=example,dc=com",
  "remove": true
}
}

21.2. 为 LDAP 启用日志记录

要为 LDAP 启用日志记录,您必须在 Settings 配置窗口中将级别设置为 DEBUG

  1. 从左侧导航窗格中点 Settings,再点系统选项列表中的 Logging settings

  2. Edit

  3. Logging Aggregator Level Threshold 字段设置为 Debug

_images/settings-system-logging-debug.png
  1. 点击 Save 保存您的更改。

21.3. 引用

当查询对象不存在于数据库中时,Active Directory 将使用“引用(referral)”。此项不适用于 django LDAP 客户端,大部分时间最好禁用引用。将以下行添加到您的 /etc/tower/conf.d/custom.py 文件来禁用 LDAP 引用。

AUTH_LDAP_GLOBAL_OPTIONS = {
    ldap.OPT_REFERRALS: False,
}

21.4. LDAP authentication performance tips

When an LDAP user authenticates, by default, all user-related attributes will be updated in the database on each log in. In some environments, this operation can be skipped due to performance issues. To avoid it, you can disable the option AUTH_LDAP_ALWAYS_UPDATE_USER. Refer to the Knowledge Base Article 5823061 for its configuration and usage instructions. Please note that new users will still be created and get their attributes pushed to the database on their first login.

警告

With this option set to False, no changes to LDAP user's attributes will be updated. Attributes will only be updated the first time the user is created.