背景
Openshift默认的用户认证是使用HTPasswd,之前的部署方式也都是使用了HTPasswd的方式。其实Openshift官方默认支持LDAP协议,可以很容易地将OpenLDAP与Openshift进行集成,使用OpenLDAP集中管理用户。
环境
- centos 7.4
- openshift 3.10
- openldap 2.4.44
openldap安装与使用介绍
Openshift集群3.9升级到3.10
用户账号配置及验证登录
Openshift中配置验证方式为LDAPPasswordIdentityProvider
LDAP URL说明
:
ldapurl = scheme "://" [hostport] ["/"[dn ["?" [attributes] ["?" [scope]["?" [filter] ["?" extensions]]]]]]
scheme = "ldap"
hostport = hostport from Section 5 of [RFC 1738]
dn = distinguishedName from Section 3 of [1]
attributes = attrdesc *("," attrdesc)
scope = "base" / "one" / "sub"
filter = filter from Section 4 of [4]
extensions = extension *("," extension)
extension = ["!"] extype ["=" exvalue]
extype = token / xtoken
exvalue = LDAPString from section 4.1.2 of [2]
token = oid from section 4.1 of [3]
xtoken = ("X-" / "x-") token</pre>
# 例子:
# ldap://host.com:6666/o=UniversityofMichigan,c=US??sub?(cn=BabsJensen)
# ldap://host.com:6666/o=UniversityofMichigan,c=US?mail??(sn=MBU)
使用person对象中的mail作为登录的用户名,同时使用dn作为用户的id,用户的显示名为person对象中的cn,同时只允许带有sn=MBC
的用户登录
# /etc/origin/master/master-config.yaml
oauthConfig:
identityProviders:
- challenge: true
login: true
mappingMethod: claim
name: my_ldap_provider
provider:
apiVersion: v1
attributes:
email:
- mail
id:
- dn
name:
- cn
preferredUsername:
- uid
bindDN: ''
bindPassword: ''
ca: ''
insecure: true
kind: LDAPPasswordIdentityProvider
url: ldap://192.168.0.2:389/ou=users,dc=example,dc=com?mail??(sn=MBC)
重启openshift服务
# master-restart controllers api
# master-restart controllers controllers
在openldap中创建对应的用户
创建用户密码
# slappasswd -s test
{SSHA}5rMM/3f8Ki13IyarGTtwzieoTu7KMgwc
使用创建的密码及用户信息添加openldap账号
$ cat users.ldif
dn: ou=users,dc=example,dc=com
objectClass: organizationalUnit
ou: users
dn: cn=Michael,ou=users,dc=example,dc=com
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Michael
sn: MBC
displayName: Michael MBC
mail: michael@example.com
userPassword: {SSHA}5rMM/3f8Ki13IyarGTtwzieoTu7KMgwc
至此就可以通过:用户名michael@example.com
,密码:test
进行登录openshift。登录成功后,openshift会自动创建一个普通用户,用户id为cn=Michael,ou=users,dc=example,dc=com
解决了登录,是否就完全OK了呢?openshift与openldap的集成就到此为止了吗?当然不是。
用户组配置及同步
在openldap中创建对应的组对象,并将用户Michael设置为组成员
$ cat groups.ldif
dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
ou: groups
dn: cn=admins,ou=groups,dc=example,dc=com
objectClass: groupOfNames
cn: admins
owner: cn=Manager,dc=example,dc=com
description: Administrators Group
member: cn=Michael,ou=users,dc=example,dc=com
openshift同步openldap上的组与用户信息
$ cat rfc2307_config.yaml
kind: LDAPSyncConfig
apiVersion: v1
url: ldap://192.168.0.2:389
insecure: true
rfc2307:
groupsQuery:
baseDN: "ou=groups,dc=example,dc=com"
scope: sub
derefAliases: never
filter: (objectclass=groupOfNames)
groupUIDAttribute: dn
groupNameAttributes: [ cn ]
groupMembershipAttributes: [ member ]
usersQuery:
baseDN: "ou=users,dc=example,dc=com"
scope: sub
derefAliases: never
pageSize: 0
userUIDAttribute: dn
userNameAttributes: [ dn ]
tolerateMemberNotFoundErrors: true
tolerateMemberOutOfScopeErrors: true
执行同步
oc adm groups sync --sync-config=rfc2307_config.yaml --confirm
结果展示
[root@allinone ~]# oc get group
NAME USERS
admins cn=Michael,ou=users,dc=example,dc=com
[root@allinone ~]#
[root@allinone ~]# oc get user
NAME UID FULL NAME IDENTITIES
cn=Michael,ou=users,dc=example,dc=com bf612e04-b592-11e8-8841-5254501db2dc Michael my_ldap_provider:cn=Michael,ou=users,dc=example,dc=com
通过给admins这个group授权,admins组下面的成员也都具有了对应的权限,实现了权限的管理。
网友评论