Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

14.5. 同步示例

本节包含 RFC 2307Active Directory 和增强 Active Directory 模式的示例。以下示例中两个成员同步了名为 admins 的组:JaneJim.每个示例都解释了:

  • 如何将组和用户添加到 LDAP 服务器中。
  • LDAP 同步配置文件的概貌。
  • 同步之后 OpenShift Container Platform 中会生成什么组记录。
注意

这些示例假定所有用户都是其各自组的直接成员。具体而言,没有任何组的成员是其他组。如需有关如何 同步嵌套组 的信息,请参阅嵌套成员资格同步示例。

14.5.1. 使用 RFC 2307 模式同步组

在 RFC 2307 模式中,用户(Jane 和 Jim)和组都作为第一类条目存在于 LDAP 服务器上,组成员资格则存储在组的属性中。以下 ldif 片段定义了这个模式的用户和组:

使用 RFC 2307 模式的 LDAP 条目:rfc2307.ldif

  dn: ou=users,dc=example,dc=com
  objectClass: organizationalUnit
  ou: users

  dn: cn=Jane,ou=users,dc=example,dc=com
  objectClass: person
  objectClass: organizationalPerson
  objectClass: inetOrgPerson
  cn: Jane
  sn: Smith
  displayName: Jane Smith
  mail: jane.smith@example.com

  dn: cn=Jim,ou=users,dc=example,dc=com
  objectClass: person
  objectClass: organizationalPerson
  objectClass: inetOrgPerson
  cn: Jim
  sn: Adams
  displayName: Jim Adams
  mail: jim.adams@example.com

  dn: ou=groups,dc=example,dc=com
  objectClass: organizationalUnit
  ou: groups

  dn: cn=admins,ou=groups,dc=example,dc=com 1
  objectClass: groupOfNames
  cn: admins
  owner: cn=admin,dc=example,dc=com
  description: System Administrators
  member: cn=Jane,ou=users,dc=example,dc=com 2
  member: cn=Jim,ou=users,dc=example,dc=com

1
组是 LDAP 服务器中的第一类条目。
2
组成员使用作为组属性的标识引用来列出。

要同步此组,您必须首先创建配置文件。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: [ uid ] 7
    tolerateMemberNotFoundErrors: false
    tolerateMemberOutOfScopeErrors: false

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

使用 rfc2307_config.yaml 文件运行同步:

$ oc adm groups sync --sync-config=rfc2307_config.yaml --confirm

OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:

使用 rfc2307_config.yaml 文件创建的 OpenShift Container Platform 组

apiVersion: user.openshift.io/v1
kind: Group
metadata:
  annotations:
    openshift.io/ldap.sync-time: 2015-10-13T10:08:38-0400 1
    openshift.io/ldap.uid: cn=admins,ou=groups,dc=example,dc=com 2
    openshift.io/ldap.url: LDAP_SERVER_IP:389 3
  creationTimestamp:
  name: admins 4
users: 5
- jane.smith@example.com
- jim.adams@example.com

1
此 OpenShift Container Platform 组与 LDAP 服务器最后一次同步的时间,采用 ISO 6801 格式。
2
LDAP 服务器上组的唯一标识符。
3
存储该组记录的 LDAP 服务器的 IP 地址和主机。
4
根据同步文件指定的组的名称。
5
属于组的成员的用户,名称由同步文件指定。

14.5.1.1. RFC2307,带有用户定义的名称映射

使用用户定义的名称映射同步组时,配置文件会更改为包含这些映射,如下所示。

使用 RFC 2307 模式及用户定义的名称映射的 LDAP 同步配置: rfc2307_config_user_defined.yaml

kind: LDAPSyncConfig
apiVersion: v1
groupUIDNameMapping:
  "cn=admins,ou=groups,dc=example,dc=com": Administrators 1
rfc2307:
    groupsQuery:
        baseDN: "ou=groups,dc=example,dc=com"
        scope: sub
        derefAliases: never
        pageSize: 0
    groupUIDAttribute: dn 2
    groupNameAttributes: [ cn ] 3
    groupMembershipAttributes: [ member ]
    usersQuery:
        baseDN: "ou=users,dc=example,dc=com"
        scope: sub
        derefAliases: never
        pageSize: 0
    userUIDAttribute: dn 4
    userNameAttributes: [ uid ]
    tolerateMemberNotFoundErrors: false
    tolerateMemberOutOfScopeErrors: false

1
用户定义的名称映射。
2
唯一标识符属性,用于用户定义的名称映射中的键。将 DN 用于 groupUIDAttribute 时,您无法指定 groupsQuery 过滤器。要进行精细过滤,请使用 白名单/黑名单方法
3
如果其唯一标识符不在用户定义的名称映射中,用于指定 OpenShift Container Platform 组的属性。
4
唯一标识 LDAP 服务器上用户的属性。将 DN 用于 userUIDAttribute 时,您无法指定usersQuery 过滤器。要进行精细过滤,请使用 白名单/黑名单方法

使用 rfc2307_config_user_defined.yaml 文件运行同步:

$ oc adm groups sync --sync-config=rfc2307_config_user_defined.yaml --confirm

OpenShift Container Platform 创建以下组记录作为上述同步操作的结果:

使用 rfc2307_config_user_defined.yaml 文件创建的 OpenShift Container Platform 组

apiVersion: user.openshift.io/v1
kind: Group
metadata:
  annotations:
    openshift.io/ldap.sync-time: 2015-10-13T10:08:38-0400
    openshift.io/ldap.uid: cn=admins,ou=groups,dc=example,dc=com
    openshift.io/ldap.url: LDAP_SERVER_IP:389
  creationTimestamp:
  name: Administrators 1
users:
- jane.smith@example.com
- jim.adams@example.com

1
由用户定义的名称映射指定的组名称。