OpenLDAP主配置文件slapd.conf介绍

本文介绍了slapd.conf配置文件的关键设置,包括安全性、访问控制策略、后端模块加载及数据库定义等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安全起见,slapd.conf文件应该只让运行此进程的用户可读写。下面是安装完毕后的一个slapd.conf示例。
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include /etc/openldap/openldap/schema/core.schema
# Define global ACLs to disable default read access.
# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral ldap://root.openldap.org
pidfile /usr/local/openldap/var/run/slapd.pid
argsfile /usr/local/openldap/var/run/slapd.args
# Load dynamic backend modules:
# modulepath /usr/local/openldap/libexec/openldap
# moduleload back_bdb.la
# moduleload back_ldap.la
# moduleload back_ldbm.la
# moduleload back_passwd.la
# moduleload back_shell.la
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64
# Sample access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
# Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!
####################################################
# BDB database definitions
####################################################
database bdb
suffix "dc=my-domain,dc=org"
rootdn "cn=Manager,dc=mydomain,dc=org"
# Cleartext passwords, especially for the rootdn, should
# be avoid. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw secret
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 reorgmended.
directory /usr/local/openldap/var/openldap-data
# Indices to maintain
index objectClass eq
接下来我们对上述部分进行一些介绍:
include /etc/openldap/openldap/schema/core.schema
此 句是用来将目录所用到的schema文件包含进来;openldap一般默认带有几个schema,在我们的配置文件安装目录下的schema目录中存 放。本句中的core.schema是LDAP V3中必须的,它给出了LDAP V3中最基本的attribute和objects的定义。其它的还有:corba.schema、dyngroup.schema、 java.schema nis.schema、openldap.schema、cosine.schema、 inetorgperson.schema、misc.schema、ppolicy.schema
pidfile /usr/local/openldap/var/run/slapd.pid
此句用来定义slapd进程运行时的pid文件,需要使用绝对路径。
argsfile /usr/local/openldap/var/run/slapd.args
此句用来定义包含当前正在运行的slapd进程所用到的命令行参数的文件,需要使用绝对路径。
# Load dynamic backend modules:
# modulepath /usr/local/openldap/libexec/openldap
# moduleload back_bdb.la
# moduleload back_ldap.la
# moduleload back_ldbm.la
# moduleload back_passwd.la
# moduleload back_shell.la
以上用来指定动态加载的后端模块。
# Sample security restrictions
# Require integrity protection (prevent hijacking)
# Require 112-bit (3DES or better) encryption for updates
# Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64
以上是安全相关的声明语句。常用到的参数有五类,除了Require和security外还有Allow、Disallow和password-hash等。
Require参数用来使管理员指定访问目录时必须遵循的规则和条件;这种指定可以是全局的,也可以仅用来限制对某个后端数据库的访问限制。
security参数用来让管理员指定加强安全性的一般规则。
# Sample access control policy:
# Root DSE: allow anyone to read it
# Subschema (sub)entry DSE: allow anyone to read it
# Other DSEs:
# Allow self write access
# Allow authenticated users read access
# Allow anonymous users to authenticate
# Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn. (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!
以上主要是用来定义访问控制列表。
#######################################################################
# BDB database definitions
#######################################################################
database bdb
定义使用的后端数据存储方式。其后可以跟的值有bdb、ldbm、passwd和shell。bdb指使用Berkley DB 4数据库。
suffix "dc=my-domain,dc=org"
定义suffix,以上部分可以改作你的域名中相关的部分,如"dc=example,dc=com"。
rootdn "cn=Manager,dc=mydomain,dc=org"
定义此目录的超级管理员帐号,类同于系统中的root。由于访问控制对此用户是不生效的,因此存在很大的安全隐患。建议安装配置及调试完成以后移除此帐号。
rootpw secret
定 义超级管理员帐号的密码,这里使用的是明文存储(secret即是其密码)的方式。这是极不安全的,建议使用加密方式存储,可以使用的加密方式有: CRYPT、MD5、SMD5、SHA和SSHA。产生加密密码散列的方法是使用slappasswd命令,用-h选项指明加密时使用的方式。示例如下:
# /usr/local/openldap/sbin/slappasswd -h {SSHA}
New password:
Re-enter new password:
{SSHA}k2H1GPM/95VfgsKg2jZv9hV+2GCH04hC
directory /usr/local/openldap/var/openldap-data
这一句用来指定目录相关数据的存放位置。此目录最好只能由运行slapd进程的用户所有,推荐权限为700
index objectClass eq
此 句用来指定slapd索引时用到的attribute,eq指索引时的匹配规则。主要是用来优化查询的。常用到的匹配规则有:approx(模糊匹配, approximate)、eq(精确匹配,equality)、pres(现值匹配,若某记录的此attribute没有值则不进行匹配, presence)和sub (子串匹配,substring)。

在CentOS上为OpenLDAP添加自签名SSL/TLS支持的步骤如下: ### 1. 安装必要工具 ```bash yum install openldap-servers openssl ``` ### 2. 生成自签名证书 ```bash # 创建证书存放目录 mkdir -p /etc/openldap/certs # 生成私钥(无密码) openssl genrsa -out /etc/openldap/certs/ldap.key 2048 # 生成自签名证书(CommonName填写服务器主机名/IP) openssl req -new -x509 \ -key /etc/openldap/certs/ldap.key \ -out /etc/openldap/certs/ldap.crt \ -days 365 \ -subj "/CN=your_server_hostname_or_ip" # 设置权限 chmod 400 /etc/openldap/certs/ldap.key chmod 444 /etc/openldap/certs/ldap.crt ``` ### 3. 配置OpenLDAP #### 对于使用动态配置(cn=config)的情况: ```bash # 创建LDIF文件 tls.ldif cat > tls.ldif << EOF dn: cn=config changetype: modify add: olcTLSCACertificateFile olcTLSCACertificateFile: /etc/openldap/certs/ldap.crt - add: olcTLSCertificateFile olcTLSCertificateFile: /etc/openldap/certs/ldap.crt - add: olcTLSCertificateKeyFile olcTLSCertificateKeyFile: /etc/openldap/certs/ldap.key EOF # 应用配置 ldapmodify -Y EXTERNAL -H ldapi:/// -f tls.ldif ``` #### 对于传统配置(slapd.conf): ```bash vim /etc/openldap/slapd.conf # 添加以下内容 TLSCACertificateFile /etc/openldap/certs/ldap.crt TLSCertificateFile /etc/openldap/certs/ldap.crt TLSCertificateKeyFile /etc/openldap/certs/ldap.key ``` ### 4. 修改监听配置 ```bash vim /etc/sysconfig/slapd # 修改SLAPD_URLS行 SLAPD_URLS="ldapi:/// ldap:/// ldaps:///" ``` ### 5. 配置防火墙 ```bash firewall-cmd --permanent --add-service=ldaps firewall-cmd --reload ``` ### 6. 重启服务 ```bash systemctl restart slapd systemctl enable slapd ``` ### 7. 验证连接 ```bash # 使用StartTLS方式验证 ldapsearch -ZZ -H ldap://localhost -x -b "" -s base # 使用LDAPS方式验证 ldapsearch -H ldaps://localhost -x -b "" -s base ``` ### 可能遇到的问题及解决: 1. **证书验证失败**: ```bash # 客户端临时关闭验证(仅测试用) vim /etc/openldap/ldap.conf ``` 添加: ```ini TLS_REQCERT allow ``` 2. **SELinux阻止访问**: ```bash semanage fcontext -a -t cert_t '/etc/openldap/certs(/.*)?' restorecon -Rv /etc/openldap/certs ``` 3. **端口未监听**: ```bash netstat -tulnp | grep 636 ``` > 注意:生产环境应使用正式CA签名的证书,并保持TLS验证严格模式。测试环境完成后建议恢复`TLS_REQCERT`为默认值。
05-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值