Openldap基于digest-md5方式的SASL认证配置
1. openldap编译
如果需要openldap支持SASL认证,需要在编译时加上–enable-spasswd选项
安装完cyrus-sasl,openssl(可选),BDB包后执行:
|
1
2
|
$ sudo ldconfig
$ export LD_LIBRARY_PATH="/usr/local/lib:/usr/local/BerkeleyDB.4.8/lib:/lib/i386-linux-gnu/"
|
注:
/usr/local/lib为 libsasl2.so.2所在目录
/usr/local/BerkeleyDB.4.8/lib为 libdb-4.8.so所在目录
/lib/i386-linux-gnu/为 libssl.so.1.0.0所在目录
|
1
|
$ ./configure CPPFLAGS=-I/usr/local/BerkeleyDB.4.8/include --enable-spasswd
|
安装完毕后
|
1
|
$ ldapsearch -x -s base -LLL supportedSASLMechanisms
|
输出:
|
1
2
3
4
|
dn:
supportedSASLMechanisms: DIGEST-MD5
supportedSASLMechanisms: CRAM-MD5
supportedSASLMechanisms: OTP
|
可以看到默认已经提供DIGEST-MD5方式 的SASL机制。
2. slapd.conf配置
|
1
|
$ cat /usr/local/etc/openldap/slapd.conf | grep -v ^#
|
配置输出:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/asterisk.schema
pidfile /usr/local/var/run/slapd.pid
argsfile /usr/local/var/run/slapd.args
database ldif
suffix "ou=accounts,dc=com"
rootdn "uid=manager,cn=digest-md5,cn=auth"
authz-regexp
uid=([^,]*),cn=digest-md5,cn=auth
AstAccountName=$1,ou=accounts,dc=com
password-hash {CLEARTEXT}
directory /usr/local/var/openldap-data
|
2.1 用户密码相关配置
参考http://www.openldap.org/doc/admin24/sasl.html#DIGEST-MD5
This section describes the use of the SASL DIGEST-MD5 mechanism using secrets stored either in the directory itself or in Cyrus SASL’s own database.
这里提到了两种管理用户密码的方式
a.对于第一种:
To use secrets stored in sasldb, simply add users with the saslpasswd2 command:
|
1
|
saslpasswd2 -c <username>
|
The passwords for such users must be managed with the saslpasswd2 command.
b.对于第二种:
To use secrets stored in the LDAP directory, place plaintext passwords in the userPassword attribute. It will be necessary to add an option to slapd.conf to make sure that passwords set using the LDAP Password Modify Operation are stored in plaintext:
|
1
|
password-hash {CLEARTEXT}
|
Passwords stored in this way can be managed either with ldappasswd(1) or by simply modifying the userPassword attribute. Regardless of where the passwords are stored, a mapping will be needed from authentication request DN to user’s DN.
在 这里,我采用了第二种。根据文档说明,这种方式的密码是存在userPassword属性中的,因此每个需要进行认证的用户都必须有一个 userPassword属性。并且通过在slapd.conf文件中通过指定password-hash {CLEARTEXT}来确保密码存储为明文的文本格式。
由于每个认证用户都必须有一个userPassword属性,因此对应的条目必须具有一个含有userPassword 属性的objectclass,我采用 simpleSecurityObject这个objectclass,这是一个辅助objectclass(区别于structual objectclass),仅包含一个必要属性userPassword.
参见core.schema:
|
1
2
3
4
|
objectclass ( 0.9.2342.19200300.100.4.19 NAME 'simpleSecurityObject'
DESC 'RFC1274: simple security object'
SUP top AUXILIARY
MUST userPassword )
|
因此可以将管理员用户的ldif数据文件配置为:
manager.ldif:
|
1
2
3
4
5
6
7
|
dn: ou=accounts,dc=com
ou: accounts
objectclass: organizationalUnit
dn: AstAccountName=manager,ou=accounts,dc=com
userPassword: grandstream
objectClass: AsteriskAccount
objectClass: simpleSecurityObject
|
2.2 认证ID与实际条目映射
参考http://www.openldap.org/doc/admin24/sasl.html#Mapping%20Authentication%20Identities
The DIGEST-MD5 mechanism produces authentication IDs of the form:
|
1
|
uid=<username>,cn=<realm>,cn=digest-md5,cn=auth
|
If the default realm is used,the realm name is omitted from the ID, giving:
|
1
|
uid=<username>,cn=digest-md5,cn=auth
|
对于我们的例子,配置管理员认证ID为:
|
1
|
rootdn "uid=manager,cn=digest-md5,cn=auth"
|
认证ID与实际的LDAP条目之间有两种映射方式:direct mapping和search-based mappings.
Where possible, direct mapping of the authentication request DN to the user’s DN is generally recommended. Aside from avoiding the expense of searching for the user’s DN, it allows mapping to DNs which refer to entries not held by this server.
基于以上原因,采用direct mapping方式。
The LDAP administrator will need to tell the slapd server how to map an authentication request DN to a user’s authentication DN. This is done by adding one or more authz-regexp directives to the slapd.conf(5) file. This directive takes two arguments:
|
1
|
authz-regexp <search pattern> <replacement pattern>
|
Suppose the authentication request DN is written as:
|
1
|
uid=adamson,cn=example.com,cn=gssapi,cn=auth
|
and the user’s actual LDAP entry is:
|
1
|
uid=adamson,ou=people,dc=example,dc=com
|
then the following authz-regexp directive in slapd.conf(5) would provide for direct mapping.
|
1
2
3
|
authz-regexp
uid=([^,]*),cn=example.com,cn=gssapi,cn=auth
uid=$1,ou=people,dc=example,dc=com
|
对于我们的例子则是:
|
1
2
3
|
authz-regexp
uid=([^,]*),cn=digest-md5,cn=auth
AstAccountName=$1,ou=accounts,dc=com
|
依据正则表达式的语法,([^,]*)匹配直到遇到逗号之前的字符,$1反向引用([^,]*)中的内容。
3 导入管理员用户信息
采 用这种方式时认证用户包括管理员的密码都是存储在ldap目录中的,也就是说,管理员本身的信息也是需要导入的,而在这种方式下rootdn的配置不满足 suffix的要求,不能设置rootpw选项,也就不能绑定管理员用户使用ldapadd命令进行管理员信息导入了,那管理员本身的信息如何导入呢?可 以通过以下命令:
|
1
|
$ slapadd -l manager.ldif
|
4 数据操作
开启openldap服务器
|
1
|
$ /usr/local/libexec/slapd&
|
导入ldif数据文件,添加数据
|
1
|
$ ldapadd -Y DIGEST-MD5 -U manager -f gs_phonebook.ldif -w grandstream
|
manager:管理员用户的DN为AstAccountName=manager,ou=accounts,dc=com,根据映射关系,对应的uid就是这里的AstAccountName属性的值manager。
grandstream:对应userPassword属性的值,即管理员密码。
gs_phonebook.ldif:要导入的ldif数据文件。
查询数据
|
1
|
$ ldapsearch -Y DiGEST-MD5 -U manager -w grandstream -b ou=accounts,dc=com
|
删除数据
|
1
|
$ ldapdelete -Y DiGEST-MD5 -U manager -w grandstream <DN1> <DN2> …<DNn>
|
或递归删除
|
1
|
$ ldapdelete -Y DiGEST-MD5 -U manager -w grandstream -r <BaseDN>
|
Openldap基于digest-md5方式的SASL认证配置的更多相关文章
- ASP.NET WebApi 基于分布式Session方式实现Token签名认证
一.课程介绍 明人不说暗话,跟着阿笨一起学玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NETWebSer ...
- ASP.NET WebApi 基于分布式Session方式实现Token签名认证(发布版)
一.课程介绍 明人不说暗话,跟着阿笨一起学玩WebApi!开发提供数据的WebApi服务,最重要的是数据的安全性.那么对于我们来说,如何确保数据的安全将会是需要思考的问题.在ASP.NETWebSer ...
- Kafka - SASL认证
kafka SASL认证配置 1.找到kafka安装根目录,在config文件夹下创建kafka_server_jaas.conf,写入 KafkaServer { org.apache.kafka. ...
- Spring Security认证配置(一)
学习本章之前,可以先了解下上篇 Spring Security基本配置. 本篇主要讲述Spring Security基于表单,自定义用户认证配置(上篇中的配置,本篇将不再阐述).一共分为三步: 1.处 ...
- svn使用openldap验证apache访问方式
启用svn服务器的sasl验证机制 1.安装cyrus-sasl认证包 # yum install -y *sasl* # rpm -qa|grep sasl cyrus-sasl-2.1.23-15 ...
- XEP-0078:非SASL认证
XEP-0078:非SASL认证 抽象: 这个文件规定了使用Jabber的Jabber的服务器和服务认证的协议:智商:AUTH命名空间.注意哦:本文规定的协议,取而代之的SASL认证的被取代,如RFC ...
- kafka SASL认证介绍及自定义SASL PLAIN认证功能
目录 kafka 2.x用户认证方式小结 SASL/PLAIN实例(配置及客户端) broker配置 客户端配置 自定义SASL/PLAIN认证(二次开发) kafka2新的callback接口介绍 ...
- 基于token的多平台身份认证架构设计
基于token的多平台身份认证架构设计 1 概述 在存在账号体系的信息系统中,对身份的鉴定是非常重要的事情. 随着移动互联网时代到来,客户端的类型越来越多, 逐渐出现了 一个服务器,N个客户端的格 ...
- 谈谈基于OAuth 2.0的第三方认证 [下篇]
从安全的角度来讲,<中篇>介绍的Implicit类型的Authorization Grant存在这样的两个问题:其一,授权服务器没有对客户端应用进行认证,因为获取Access Token的 ...
随机推荐
- executeQuery、executeUpdate 和 execute
Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 1. Resul ...
- [Java语言] HashMap,HashSet,Hashtable,Vector,ArrayList 的关系 <转>
这么几个比较常用的但是比较容易混淆的概念同出于 java.util 包.本文仅作几个类的浅度解析. (本文基于JDK1.7,源码来自openjdk1.7.) ├── Collection │ ├── ...
- 360全景图three.js与Photo-Sphere-Viewer-master 3D全景浏览开发
1.支持WebGL和canvas的浏览器 (IE10, IE11支持, 但在IE里移动图片时很卡, 不一定是全部人都有这情况) 2.Three.js (文件较大, 有官网demo, 可不下载, 下载p ...
- 【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树
[BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to ...
- 爬虫实战【3】Python-如何将html转化为pdf(PdfKit)
前言 前面我们对博客园的文章进行了爬取,结果比较令人满意,可以一下子下载某个博主的所有文章了.但是,我们获取的只有文章中的文本内容,并且是没有排版的,看起来也比较费劲... 咋么办的?一个比较好的方法 ...
- Linux定时对日志批量打包Shell脚本及定时任务crontab 详细用法
一.需求背景 因此次项目的生产环境中部署了多套系统,每天会产生大量的日志(数百GB的量),侵占了服务器宝贵的存储资源空间.为了有效缓解服务器存储压力,考虑通过Linux的Shell脚本结合cr ...
- Redis的简单了解以及主从复制
1.Redis的简单了解 Redis是一种高性能的分布式NoSql数据库,持久存储,高并发,数据类型丰富,通过现场申请内存空间,同时可以配置虚拟内存.五种数据类型:string(字符串,这种格式和me ...
- 持续集成之jenkins2
ip 什么是持续集成 没有持续集成 持续集成最佳实践 持续集成概览 什么是Jenkins Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开 ...
- vue - 计算属性、表单输入绑定
计算属性 computed:{} <!DOCTYPE html> <html> <head> <title></title> </he ...
- 设置UCHome注册登陆退出的跳转页自定义
UCHome 默认注册.登录成功后跳转到 http://www.xxx.com/home/space.php?do=home 退出后会跳转到站点的首页,即 http://www.xxx.com/hom ...