配置LDAP SSL访问

2022-07-30  本文已影响0人  CodingCode
  1. 配置证书信息
$ cat /usr/share/openldap-servers/slapd.ldif
...
#
# TLS settings
#
#olcTLSCACertificatePath: /etc/openldap/certs
#olcTLSCertificateFile: "OpenLDAP Server"
#olcTLSCertificateKeyFile: /etc/openldap/certs/password
olcTLSCACertificateFile: /path/to/cacert.pem
olcTLSCertificateFile: /path/to/server.pem
olcTLSCertificateKeyFile: /path/to/server.key
...

使用ldif配置

$ sudo ldapmodify -Y EXTERNAL -H ldapi:/// <<EOF
dn: cn=config
changetype: modify
add: olcTLSCACertificateFile
olcTLSCACertificateFile: /path/to/cacert.pem
-
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /path/to/server.key
-
replace: olcTLSCertificateFile
olcTLSCertificateFile: /path/to/server.pem
EOF

需要注意的是:

  1. 配置监听端口
$ cat /etc/sysconfig/slapd
...
# Where the server will run (-h option)
# - ldapi:/// is required for on-the-fly configuration using client tools
#   (use SASL with EXTERNAL mechanism for authentication)
# - default: ldapi:/// ldap:///
# - example: ldapi:/// ldap://127.0.0.1/ ldap://10.0.0.1:1389/ ldaps:///
SLAPD_URLS="ldapi:/// ldap:/// ldaps:///"
...

缺省的值为:
ldapi=/var/run/ldapi, ldap=389, ldaps=636

  1. 重启ldap
$ sudo systemctl stop slapd
$ sudo systemctl start slapd

验证证书信息:
$ openssl s_client -connect <hostname>:636
$ openssl s_client -showcerts -CAfile /path/to/ca.pem -connect <hostname>:636

  1. client配置

client的缺省配置文件

$ cat /etc/openldap/ldap.conf
...
TLS_CACERT  /path/to/certificate/cacert.pem
...

运行(假定SSL端口是636)

$ ldapsearch -x -b "dc=mydomain,dc=com" -H ldaps://:636

如果没有CA,也可以或略,则:

$ cat /etc/openldap/ldap.conf
...
TLS_REQCERT never
...

$ 
上一篇 下一篇

猜你喜欢

热点阅读