Open×××的认证方式有多种,一般而言证书的安全性比较好,但是操作起来稍显麻烦,所以就衍生出很多使用本地密码、数据库、pam、ldap等认证方式的需求,网上对于open***使用ldap认证的教程有很多,大体上分为两类,一类是使用open***-auth-ldap,一类是使用老男孩发布的Python脚本,当然了也可以使用pam,然后通过pam_ldap调用ldap进行验证,不过这好像是使用pam,Python脚本的话不理解语法,担心出了问题无法进行排错,所以就使用open***-auth-ldap进行配置。网上对于open***-auth-ldap的教程不多,而且基本上都是open***和openldap部署到一台服务器上,当然我的一贯做法是独立部署,然后进行服务的整合。

1、准备环境

主机名角色IP地址
open***.contoso.comOpen××× Servereth0: 192.168.49.135  eth1:192.168.140.135
ldapsrv01.contoso.comOpenldap Servereth0:192.168.49.138

这里说明一下,open***是我重新部署的,就按照之前的open***部署来做就行,ldapsrv01是上一篇中做完双主复制的一个节点,如果不清楚ldapsrv01的配置看上一篇就行了。整个环境要保证,open***是可以正常运行的,客户端使用证书能正常连接×××;openldap服务处于运行状态,且ldap中存在用户数据。

wKioL1fiBgiS9PwEAAK2_nYAC88072.jpg-wh_50

这里我在windows客户端新创建一个eva的连接,客户端配置如图所示。

wKioL1fiBmGQVikCAAA3ZCwn4RE319.jpg-wh_50

wKiom1fiBmLQeAkAAAFRqbzT6Pk445.jpg-wh_50

成功使用eva证书连接之后,如上图所示,说明open***没有问题。

2、yum安装open***-auth-ldap

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 
sed -i 's@#b@b@g' /etc/yum.repos.d/epel.repo
sed  -i 's@mirrorlist@#mirrorlist@g' /etc/yum.repos.d/epel.repo
yum -y install open***-auth-ldap

3、修改open***-auth-ldap配置

cp /etc/open***/auth/ldap.conf /etc/open***/auth/ldap.conf.bak
vi /etc/open***/auth/ldap.conf

[root@open*** ~]# diff /etc/open***/auth/ldap.conf.bak /etc/open***/auth/ldap.conf

3c3

< URL ldap://ldap1.example.org

---

> URL ldap://192.168.49.138:389

6c6

< # BindDN uid=Manager,ou=People,dc=example,dc=com

---

>  BindDN cn=admin,dc=contoso,dc=com

9c9

< # Password SecretPassword

---

>  Password 123456

15c15

< TLSEnable yes

---

> TLSEnable no

18c18

< FollowReferrals yes

---

> FollowReferrals no

38c38

< BaseDN "ou=People,dc=example,dc=com"

---

> BaseDN "dc=contoso,dc=com"

41c41

< SearchFilter "(&(uid=%u)(accountStatus=active))"

---

> SearchFilter "(uid=%u)"

cp /usr/share/doc/open***-auth-ldap-2.0.3/auth-ldap.conf /usr/share/doc/open***-auth-ldap-2.0.3/auth-ldap.conf.bak
vi /usr/share/doc/open***-auth-ldap-2.0.3/auth-ldap.conf

[root@open*** ~]# diff /usr/share/doc/open***-auth-ldap-2.0.3/auth-ldap.conf.bak /usr/share/doc/open***-auth-ldap-2.0.3/auth-ldap.conf

3c3

< URL ldap://ldap1.example.org

---

> URL ldap://192.168.49.138:389

6c6

< # BindDN uid=Manager,ou=People,dc=example,dc=com

---

>  BindDN cn=admin,dc=contoso,dc=com

9c9

< # Password SecretPassword

---

>  Password 123456

15c15

< TLSEnable yes

---

> TLSEnable no

18c18

< FollowReferrals yes

---

> FollowReferrals no

21c21

< TLSCACertFile /usr/local/etc/ssl/ca.pem

---

> # TLSCACertFile /usr/local/etc/ssl/ca.pem

24c24

< TLSCACertDir /etc/ssl/certs

---

> # TLSCACertDir /etc/ssl/certs

28,29c28,29

< TLSCertFile /usr/local/etc/ssl/client-cert.pem

< TLSKeyFile /usr/local/etc/ssl/client-key.pem

---

> # TLSCertFile /usr/local/etc/ssl/client-cert.pem

> # TLSKeyFile /usr/local/etc/ssl/client-key.pem

38c38

< BaseDN "ou=People,dc=example,dc=com"

---

> BaseDN "dc=contoso,dc=com"

41c41

< SearchFilter "(&(uid=%u)(accountStatus=active))"

---

> SearchFilter "(uid=%u)"

50,52c50,52

< BaseDN "ou=Groups,dc=example,dc=com"

< SearchFilter "(|(cn=developers)(cn=artists))"

< MemberAttribute uniqueMember

---

> BaseDN "ou=Group,dc=contoso,dc=com"

> SearchFilter "(|(cn=*)(cn=artists))"

> #MemberAttribute uniqueMember

#下面贴上auth-ldap.conf文件内容,其实/etc/open***/auth/ldap.conf和这个文件的内容是一样的,可以配置一个,然后拷贝另一个就行了。

[root@open*** ~]# cat /usr/share/doc/open***-auth-ldap-2.0.3/auth-ldap.conf

<LDAP>

# LDAP server URL

URL ldap://192.168.49.138:389


# Bind DN (If your LDAP server doesn't support anonymous binds)

 BindDN cn=admin,dc=contoso,dc=com


# Bind Password

 Password 123456


# Network timeout (in seconds)

Timeout 15


# Enable Start TLS

TLSEnable no


# Follow LDAP Referrals (anonymously)

FollowReferrals no


# TLS CA Certificate File

# TLSCACertFile /usr/local/etc/ssl/ca.pem


# TLS CA Certificate Directory

# TLSCACertDir /etc/ssl/certs


# Client Certificate and key

# If TLS client authentication is required

# TLSCertFile /usr/local/etc/ssl/client-cert.pem

# TLSKeyFile /usr/local/etc/ssl/client-key.pem


# Cipher Suite

# The defaults are usually fine here

# TLSCipherSuite ALL:!ADH:@STRENGTH

</LDAP>


<Authorization>

# Base DN

BaseDN "dc=contoso,dc=com"


# User Search Filter

SearchFilter "(uid=%u)"


# Require Group Membership

RequireGroup false


# Add non-group members to a PF table (disabled)

#PFTable ips_***_users


<Group>

BaseDN "ou=Group,dc=contoso,dc=com"

SearchFilter "(|(cn=*)(cn=artists))"

#MemberAttribute uniqueMember

# Add group members to a PF table (disabled)

#PFTable ips_***_eng

</Group>

</Authorization>

4、修改open***的配置文件

[root@open*** ~]# ps -ef|grep ***

root      23727   1553  0 Sep20 pts/0    00:00:00 /usr/local/sbin/open*** --config /etc/server.conf

root      23811  23513  0 00:19 pts/1    00:00:00 grep ***

# 如果你不清楚配置文件是什么(比如你刚进入一家公司,open***的环境并不是你搭建的,但是你需要维护时),可以使用上面的命令查看,open***使用的配置文件,这里是/etc/server.conf。

编辑/etc/server.conf,在最下面添加以下几行内容:

plugin /usr/lib64/open***/plugin/lib/open***-auth-ldap.so "/etc/open***/auth/ldap.conf cn=%u"

client-cert-not-required

username-as-common-name

# 贴上这里的/etc/server.conf内容

[root@open*** ~]# cat /etc/server.conf 

port 1194

proto tcp

dev tun

ca   /opt/tools/open***-2.0.9/easy-rsa/2.0/keys/ca.crt

cert /opt/tools/open***-2.0.9/easy-rsa/2.0/keys/server.crt

key  /opt/tools/open***-2.0.9/easy-rsa/2.0/keys/server.key

dh   /opt/tools/open***-2.0.9/easy-rsa/2.0/keys/dh1024.pem

server 10.8.0.0 255.255.255.0

push "route 192.168.140.0 255.255.255.0"

ifconfig-pool-persist ipp.txt

keepalive 10 120

comp-lzo

persist-key

persist-tun

status open***-status.log

verb 5

plugin /usr/lib64/open***/plugin/lib/open***-auth-ldap.so "/etc/open***/auth/ldap.conf cn=%u"

client-cert-not-required

username-as-common-name

5、修改客户端配置文件

这里我先以eva.o***为例,需要将cert和key注释或者删掉(这个时候可以删除在eva目录下的crt和key文件),然后添加下面两行:

ns-cert-type server

auth-user-pass

#下面是eva.o***的配置(仅作示例,需要根据实际情况配置):

client

dev tun

proto tcp

remote 192.168.49.135 1194

resolv-retry infinite

nobind

persist-key

persist-tun

ca ca.crt

;cert eva.crt

;key eva.key

ns-cert-type server

auth-user-pass

comp-lzo

verb 3

因为上面的是在eva的客户单配置文件的基础上修改的,所以目录名依然是eva,里面的证书文件也没有删除,配置和连接的名字也都保留的eva,其实我们可以新创建一个ldap的连接。创建一个目录,名字随便起,然后里面只需要放CA.crt文件(open***上的CA证书文件)和.o***文件,然后根据需要参考上面eva的配置进行修改就可以了。

6、客户端进行连接测试

wKioL1fiDYqwtcOvAAFd8o0f5yo649.jpg-wh_50

点击连接之后,需要输入用户名密码,这里输入openldap中的用户user3.

[root@open*** ~]# id user3

id: user3: No such user

[root@open*** ~]# grep user3 /etc/passwd

[root@open*** ~]# 

open***服务器本地没有user3用户。

[root@ldapsrv01 ~]# ldapsearch -x -b "dc=contoso,dc=com"|grep uid=user3

dn: uid=user3,ou=People,dc=contoso,dc=com

ldapsrv01中的ldap中可以查询到user3用户。

wKioL1fiDYuhsTP4AAIIdW9c00o500.jpg-wh_50

验证通过,连接成功。

wKiom1fiDYzhdxR_AABabRGMpuk416.jpg-wh_50

wKioL1fiDY2QReGsAAFJtZnC_N0627.jpg-wh_50

最后获取IP地址,并可以ping通内网网段,说明open***使用openldap认证成功。