第 18 章 同步 LDAP 组

作为管理员,您可以使用组来管理用户、更改其权限,并加强协作。您的组织可能已创建了用户组,并将其存储在 LDAP 服务器中。OpenShift Container Platform 可以将这些 LDAP 记录与 OpenShift Container Platform 内部记录同步,让您能够集中在一个位置管理您的组。OpenShift Container Platform 目前支持与使用以下三种通用模式定义组成员资格的 LDAP 服务器进行组同步:RFC 2307、Active Directory 和增强 Active Directory。

如需有关配置 LDAP 的更多信息,请参阅配置 LDAP 身份提供程序

注意

您必须具有 cluster-admin 特权才能同步组。

18.1. 关于配置 LDAP 同步

在运行 LDAP 同步之前,您需要有一个同步配置文件。此文件包含以下 LDAP 客户端配置详情:

  • 用于连接 LDAP 服务器的配置。
  • 依赖于您的 LDAP 服务器中所用模式的同步配置选项。
  • 管理员定义的名称映射列表,用于将 OpenShift Container Platform 组名称映射到 LDAP 服务器中的组。

配置文件的格式取决于您使用的模式,即 RFC 2307、Active Directory 或增强 Active Directory。

LDAP 客户端配置
配置中的 LDAP 客户端配置部分定义与 LDAP 服务器的连接。

配置中的 LDAP 客户端配置部分定义与 LDAP 服务器的连接。

LDAP 客户端配置

url: ldap://10.0.0.0:389 1
bindDN: cn=admin,dc=example,dc=com 2
bindPassword: <password> 3
insecure: false 4
ca: my-ldap-ca-bundle.crt 5

1
连接协议、托管数据库的 LDAP 服务器的 IP 地址以及要连接的端口,格式为 scheme://host:port
2
可选的可分辨名称 (DN),用作绑定 DN。如果需要升级特权才能检索同步操作的条目,OpenShift Container Platform 会使用此项。
3
用于绑定的可选密码。如果需要升级特权才能检索同步操作的条目,OpenShift Container Platform 会使用此项。此值也可在环境变量、外部文件或加密文件中提供。
4
false 时,安全 LDAP ldaps:// URL 使用 TLS 进行连接,并且不安全 LDAP ldap:// URL 会被升级到 TLS。为 true 时,不会对服务器进行 TLS 连接,您不能使用 ldaps:// URL。
5
用于验证所配置 URL 的服务器证书的证书捆绑包。如果为空,OpenShift Container Platform 将使用系统信任的根证书。只有 insecure 设为 false 时才会应用此项。
LDAP 查询定义
同步配置由用于同步所需条目的 LDAP 查询定义组成。LDAP 查询的具体定义取决于用来在 LDAP 服务器中存储成员资格信息的模式。

LDAP 查询定义

baseDN: ou=users,dc=example,dc=com 1
scope: sub 2
derefAliases: never 3
timeout: 0 4
filter: (objectClass=person) 5
pageSize: 0 6

1
所有搜索都应从其中开始的目录分支的可分辨名称 (DN)。您需要指定目录树的顶端,但也可以指定目录中的子树。
2
搜索的范围。有效值为 baseonesub。如果未定义,则假定为 sub 范围。下表中可找到范围选项的描述。
3
与 LDAP 树中别名相关的搜索行为。有效值是 neversearchbasealways。如果未定义,则默认为 always 解引用别名。下表中可找到有关解引用行为的描述。
4
客户端可进行搜索的时间限值(以秒为单位)。0 代表不实施客户端限制。
5
有效的 LDAP 搜索过滤器。如果未定义,则默认为 (objectClass=*)
6
服务器响应页面大小的可选最大值,以 LDAP 条目数衡量。如果设为 0,则不对响应页面实施大小限制。当查询返回的条目数量多于客户端或服务器默认允许的数量时,需要设置分页大小。

表 18.2. LDAP 解引用行为

解引用行为描述

never

从不解引用 LDAP 树中找到的任何别名。

search

仅解引用搜索时找到的别名。

base

仅在查找基本对象时解引用别名。

always

始终解引用 LDAP 树中找到的所有别名。

用户定义的名称映射
用户定义的名称映射明确将 OpenShift Container Platform 组的名称映射到可在 LDAP 服务器上找到组的唯一标识符。映射使用普通 YAML 语法。用户定义的映射可为 LDAP 服务器中每个组包含一个条目,或者仅包含这些组的一个子集。如果 LDAP 服务器上的组没有用户定义的名称映射,同步过程中的默认行为是使用指定为 OpenShift Container Platform 组名称的属性。

用户定义的名称映射

groupUIDNameMapping:
  "cn=group1,ou=groups,dc=example,dc=com": firstgroup
  "cn=group2,ou=groups,dc=example,dc=com": secondgroup
  "cn=group3,ou=groups,dc=example,dc=com": thirdgroup

18.1.1. 关于 RFC 2307 配置文件

RFC 2307 模式要求您提供用户和组条目的 LDAP 查询定义,以及在 OpenShift Container Platform 内部记录中代表它们的属性。

为明确起见,您在 OpenShift Container Platform 中创建的组应尽可能将可分辨名称以外的属性用于面向用户或管理员的字段。例如,通过电子邮件标识 OpenShift Container Platform 组的用户,并将该组的名称用作通用名称。以下配置文件创建了这些关系:

注意

如果使用用户定义的名称映射,您的配置文件会有所不同。

使用 RFC 2307 模式的 LDAP 同步配置:rfc2307_config.yaml

kind: LDAPSyncConfig
apiVersion: v1
url: ldap://LDAP_SERVICE_IP:389 1
insecure: false 2
rfc2307:
    groupsQuery:
        baseDN: "ou=groups,dc=example,dc=com"
        scope: sub
        derefAliases: never
        pageSize: 0
    groupUIDAttribute: dn 3
    groupNameAttributes: [ cn ] 4
    groupMembershipAttributes: [ member ] 5
    usersQuery:
        baseDN: "ou=users,dc=example,dc=com"
        scope: sub
        derefAliases: never
        pageSize: 0
    userUIDAttribute: dn 6
    userNameAttributes: [ mail ] 7
    tolerateMemberNotFoundErrors: false
    tolerateMemberOutOfScopeErrors: false

1
存储该组记录的 LDAP 服务器的 IP 地址和主机。
2
false 时,安全 LDAP ldaps:// URL 使用 TLS 进行连接,并且不安全 LDAP ldap:// URL 会被升级到 TLS。为 true 时,不会对服务器进行 TLS 连接,您不能使用 ldaps:// URL。
3
唯一标识 LDAP 服务器上组的属性。将 DN 用于 groupUIDAttribute 时,您无法指定 groupsQuery 过滤器。若要进行精细过滤,请使用白名单/黑名单方法。
4
要用作组名称的属性。
5
存储成员资格信息的组属性。
6
唯一标识 LDAP 服务器上用户的属性。将 DN 用于 userUIDAttribute 时,您无法指定usersQuery 过滤器。若要进行精细过滤,请使用白名单/黑名单方法。
7
OpenShift Container Platform 组记录中用作用户名称的属性。

18.1.2. 关于 Active Directory 配置文件

Active Directory 模式要求您提供用户条目的 LDAP 查询定义,以及在内部 OpenShift Container Platform 组记录中代表它们的属性。

为明确起见,您在 OpenShift Container Platform 中创建的组应尽可能将可分辨名称以外的属性用于面向用户或管理员的字段。例如,通过电子邮件标识 OpenShift Container Platform 组的用户,但通过 LDAP 服务器上的组名称来定义组名称。以下配置文件创建了这些关系:

使用 Active Directory 模式的 LDAP 同步配置:active_directory_config.yaml

kind: LDAPSyncConfig
apiVersion: v1
url: ldap://LDAP_SERVICE_IP:389
activeDirectory:
    usersQuery:
        baseDN: "ou=users,dc=example,dc=com"
        scope: sub
        derefAliases: never
        filter: (objectclass=person)
        pageSize: 0
    userNameAttributes: [ mail ] 1
    groupMembershipAttributes: [ memberOf ] 2

1
OpenShift Container Platform 组记录中用作用户名称的属性。
2
存储成员资格信息的用户属性。

18.1.3. 关于增强 Active Directory 配置文件

增强 Active Directory(augmented Active Directory) 模式要求您提供用户条目和组条目的 LDAP 查询定义,以及在内部 OpenShift Container Platform 组记录中代表它们的属性。

为明确起见,您在 OpenShift Container Platform 中创建的组应尽可能将可分辨名称以外的属性用于面向用户或管理员的字段。例如,通过电子邮件标识 OpenShift Container Platform 组的用户,并将该组的名称用作通用名称。以下配置文件创建了这些关系。

使用增强 Active Directory 模式的 LDAP 同步配置:increaseded_active_directory_config.yaml

kind: LDAPSyncConfig
apiVersion: v1
url: ldap://LDAP_SERVICE_IP:389
augmentedActiveDirectory:
    groupsQuery:
        baseDN: "ou=groups,dc=example,dc=com"
        scope: sub
        derefAliases: never
        pageSize: 0
    groupUIDAttribute: dn 1
    groupNameAttributes: [ cn ] 2
    usersQuery:
        baseDN: "ou=users,dc=example,dc=com"
        scope: sub
        derefAliases: never
        filter: (objectclass=person)
        pageSize: 0
    userNameAttributes: [ mail ] 3
    groupMembershipAttributes: [ memberOf ] 4

1
唯一标识 LDAP 服务器上组的属性。将 DN 用于 groupUIDAttribute 时,您无法指定 groupsQuery 过滤器。若要进行精细过滤,请使用白名单/黑名单方法。
2
要用作组名称的属性。
3
OpenShift Container Platform 组记录中用作用户名称的属性。
4
存储成员资格信息的用户属性。