18.5. LDAP 组同步示例
本节包含 RFC 2307、Active Directory 和增强 Active Directory 模式的示例。
这些示例假定所有用户都是其各自组的直接成员。具体而言,没有任何组的成员是其他组。如需有关如何同步嵌套组的信息,请参见嵌套成员资格同步示例。
18.5.1. 使用 RFC 2307 模式同步组 复制链接链接已复制到粘贴板!
对于 RFC 2307 模式,以下示例将同步名为 admins
的组,该组有两个成员 Jane
和 Jim
。这些示例阐述了:
- 如何将组和用户添加到 LDAP 服务器中。
- 同步之后 OpenShift Container Platform 中会生成什么组记录。
这些示例假定所有用户都是其各自组的直接成员。具体而言,没有任何组的成员是其他组。如需有关如何同步嵌套组的信息,请参见嵌套成员资格同步示例。
在 RFC 2307 模式中,用户(Jane 和 Jim)和组都作为第一类条目存在于 LDAP 服务器上,组成员资格则存储在组的属性中。以下 ldif
片段定义了这个模式的用户和组:
使用 RFC 2307 模式的 LDAP 条目:rfc2307.ldif
先决条件
- 创建配置文件。
流程
使用
rfc2307_config.yaml
文件运行同步:oc adm groups sync --sync-config=rfc2307_config.yaml --confirm
$ oc adm groups sync --sync-config=rfc2307_config.yaml --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:
使用
rfc2307_config.yaml
文件创建的 OpenShift Container Platform 组Copy to Clipboard Copied! Toggle word wrap Toggle overflow
18.5.2. 使用 RFC2307 模式及用户定义的名称映射来同步组 复制链接链接已复制到粘贴板!
使用用户定义的名称映射同步组时,配置文件会更改为包含这些映射,如下所示。
使用 RFC 2307 模式及用户定义的名称映射的 LDAP 同步配置:rfc2307_config_user_defined.yaml
先决条件
- 创建配置文件。
流程
使用
rfc2307_config_user_defined.yaml
文件运行同步:oc adm groups sync --sync-config=rfc2307_config_user_defined.yaml --confirm
$ oc adm groups sync --sync-config=rfc2307_config_user_defined.yaml --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:
使用
rfc2307_config_user_defined.yaml
文件创建的 OpenShift Container Platform 组Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 由用户定义的名称映射指定的组名称。
18.5.3. 使用 RFC 2307 及用户定义的容错来同步组 复制链接链接已复制到粘贴板!
默认情况下,如果要同步的组包含其条目在成员查询中定义范围之外的成员,组同步会失败并显示以下错误:
Error determining LDAP group membership for "<group>": membership lookup for user "<user>" in group "<group>" failed because of "search for entry with dn="<user-dn>" would search outside of the base dn specified (dn="<base-dn>")".
Error determining LDAP group membership for "<group>": membership lookup for user "<user>" in group "<group>" failed because of "search for entry with dn="<user-dn>" would search outside of the base dn specified (dn="<base-dn>")".
这通常表示 usersQuery
字段中的 baseDN
配置错误。不过,如果 baseDN
有意不含有组中的部分成员,那么设置 tolerateMemberOutOfScopeErrors: true
可以让组同步继续进行。范围之外的成员将被忽略。
同样,当组同步过程未能找到某个组的某一成员时,它会彻底失败并显示错误:
Error determining LDAP group membership for "<group>": membership lookup for user "<user>" in group "<group>" failed because of "search for entry with base dn="<user-dn>" refers to a non-existent entry". Error determining LDAP group membership for "<group>": membership lookup for user "<user>" in group "<group>" failed because of "search for entry with base dn="<user-dn>" and filter "<filter>" did not return any results".
Error determining LDAP group membership for "<group>": membership lookup for user "<user>" in group "<group>" failed because of "search for entry with base dn="<user-dn>" refers to a non-existent entry".
Error determining LDAP group membership for "<group>": membership lookup for user "<user>" in group "<group>" failed because of "search for entry with base dn="<user-dn>" and filter "<filter>" did not return any results".
这通常表示 usersQuery
字段配置错误。不过,如果组中包含已知缺失的成员条目,那么设置 tolerateMemberNotFoundErrors: true
可以让组同步继续进行。有问题的成员将被忽略。
为 LDAP 组同步启用容错会导致同步过程忽略有问题的成员条目。如果 LDAP 组同步配置不正确,这可能会导致同步的 OpenShift Container Platform 组中缺少成员。
使用 RFC 2307 模式并且组成员资格有问题的 LDAP 条目:rfc2307_problematic_users.ldif
要容许以上示例中的错误,您必须在同步配置文件中添加以下内容:
使用 RFC 2307 模式且容许错误的 LDAP 同步配置:rfc2307_config_tolerating.yaml
先决条件
- 创建配置文件。
流程
使用
rfc2307_config_tolerating.yaml
文件运行同步:oc adm groups sync --sync-config=rfc2307_config_tolerating.yaml --confirm
$ oc adm groups sync --sync-config=rfc2307_config_tolerating.yaml --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:
使用
rfc2307_config.yaml
文件创建的 OpenShift Container Platform 组Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- 属于组的成员的用户,根据同步文件指定。缺少查询遇到容许错误的成员。
18.5.4. 使用 Active Directory 模式同步组 复制链接链接已复制到粘贴板!
在 Active Directory 模式中,两个用户(Jane 和 Jim)都作为第一类条目存在于 LDAP 服务器中,组成员资格则存储在用户的属性中。以下 ldif
片段定义了这个模式的用户和组:
使用 Active Directory 模式的 LDAP 条目: active_directory.ldif
- 1
- 用户的组成员资格列为用户的属性,组没有作为条目存在于服务器中。
memberOf
属性不一定是用户的字面量属性;在一些 LDAP 服务器中,它在搜索过程中创建并返回给客户端,但不提交给数据库。
先决条件
- 创建配置文件。
流程
使用
active_directory_config.yaml
文件运行同步:oc adm groups sync --sync-config=active_directory_config.yaml --confirm
$ oc adm groups sync --sync-config=active_directory_config.yaml --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:
使用
active_directory_config.yaml
文件创建的 OpenShift Container Platform 组Copy to Clipboard Copied! Toggle word wrap Toggle overflow
18.5.5. 使用增强 Active Directory 模式同步组 复制链接链接已复制到粘贴板!
在增强 Active Directory 模式中,用户(Jane 和 Jim)和组都作为第一类条目存在于 LDAP 服务器中,组成员资格则存储在用户的属性中。以下 ldif
片段定义了这个模式的用户和组:
使用增强 Active Directory 模式的 LDAP 条目: increaseded_active_directory.ldif
先决条件
- 创建配置文件。
流程
使用
augmented_active_directory_config.yaml
文件运行同步:oc adm groups sync --sync-config=augmented_active_directory_config.yaml --confirm
$ oc adm groups sync --sync-config=augmented_active_directory_config.yaml --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:
使用
augmented_active_directory_config.yaml
文件创建的 OpenShift Container Platform 组Copy to Clipboard Copied! Toggle word wrap Toggle overflow
18.5.5.1. LDAP 嵌套成员资格同步示例 复制链接链接已复制到粘贴板!
OpenShift Container Platform 中的组不嵌套。在消耗数据之前,LDAP 服务器必须平展组成员资格。Microsoft 的 Active Directory Server 通过 LDAP_MATCHING_RULE_IN_CHAIN
规则支持这一功能,其 OID 为 1.2.840.113556.1.4.1941
。另外,使用此匹配规则时只能同步明确列在白名单中的组。
本节中的示例使用了增强 Active Directory 模式,它将同步一个名为 admins
的组,该组有一个用户 Jane
和一个组 otheradmins
。otheradmins
组具有一个用户成员:Jim
。这个示例阐述了:
- 如何将组和用户添加到 LDAP 服务器中。
- LDAP 同步配置文件的概貌。
- 同步之后 OpenShift Container Platform 中会生成什么组记录。
在增强 Active Directory 模式中,用户(Jane
和 Jim
)和组都作为第一类条目存在于 LDAP 服务器中,组成员资格则存储在用户或组的属性中。以下 ldif
片段定义了这个模式的用户和组:
使用增强 Active Directory 模式和嵌套成员的 LDAP 条目: increaseded_active_directory_nested.ldif
与 Active Directory 同步嵌套的组时,您必须提供用户条目和组条目的 LDAP 查询定义,以及在内部 OpenShift Container Platform 组记录中代表它们的属性。另外,此配置也需要进行某些修改:
-
oc adm groups sync
命令必须明确将组列在白名单中。 -
用户的
groupMembershipAttributes
必须包含"memberOf:1.2.840.113556.1.4.1941:"
,以遵守LDAP_MATCHING_RULE_IN_CHAIN
规则。 -
groupUIDAttribute
必须设为dn
。 groupsQuery
:-
不得设置
filter
。 -
必须设置有效的
derefAliases
。 -
不应设置
basedn
,因为此值将被忽略。 -
不应设置
scope
,因为此值将被忽略。
-
不得设置
为明确起见,您在 OpenShift Container Platform 中创建的组应尽可能将可分辨名称以外的属性用于面向用户或管理员的字段。例如,通过电子邮件标识 OpenShift Container Platform 组的用户,并将该组的名称用作通用名称。以下配置文件创建了这些关系:
使用增强 Active Directory 模式和嵌套成员的 LDAP 同步配置: increaseded_active_directory_config_nested.yaml
先决条件
- 创建配置文件。
流程
使用
augmented_active_directory_config_nested.yaml
文件运行同步:oc adm groups sync \ 'cn=admins,ou=groups,dc=example,dc=com' \ --sync-config=augmented_active_directory_config_nested.yaml \ --confirm
$ oc adm groups sync \ 'cn=admins,ou=groups,dc=example,dc=com' \ --sync-config=augmented_active_directory_config_nested.yaml \ --confirm
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意必须明确将
cn=admins,ou=groups,dc=example,dc=com
组列在白名单中。OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:
使用
augmented_active_directory_config_nested.yaml
文件创建的 OpenShift Container Platform 组Copy to Clipboard Copied! Toggle word wrap Toggle overflow