use Windows AD (Active Directory) manage PostgreSQL auth

之前写过关于使用LDAP来认证PostgreSQL用户的文章, 有兴趣的朋友可以参考 : 
但是以前没有测试过windows AD是否可用.
其实方法和LDAP一样, 
首先我们要测试一下在linux下, 使用ldapsearch是否可以正常访问WINDOWS AD 服务.
例如 : 
# ldapsearch -H ldap://xxx.xxx.1.133:389  -x
# extended LDIF
#
# LDAPv3
# base <> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# search result
search: 2
result: 1 Operations error
text: 000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this ope
 ration a successful bind must be completed on the connection., data 0, v1db1

# numResponses: 1

检查使用域账号bind 是否正常 : 
# ldapsearch -H ldap://xxx.xxx.1.133:389  -x  -D "cn=德哥,ou=digoal,ou=SKYMOBI,dc=sky-mobi,dc=com" -W 
输入密码后可以正常返回.
Enter LDAP Password: 
# extended LDIF
#
# LDAPv3
# base <> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# search result
search: 2
result: 10 Referral
text: 0000202B: RefErr: DSID-031007EF, data 0, 1 access points
        ref 1: 'examp
 le.com'

ref: ldap://example.com/dc=example,dc=com

# numResponses: 1

接下来就可以配置postgresql的域认证了.
首先要在域中创建账号, 并获取账号的Distinguished Name 即binddn.
例如 : 

cn=德哥,ou=digoal,ou=SKYMOBI,dc=sky-mobi,dc=com

在数据库中创建对应的用户.
$ psql postgres postgres
# create role "德哥" login;

配置pg_hba.conf, 使用如下条目 : 
host all all 0.0.0.0/0 ldap ldapserver=xxx.xxx.1.133 ldapport=389 ldapprefix="cn=" ldapsuffix=",ou=digoal,ou=SKYMOBI,dc=sky-mobi,dc=com"


测试 : 
psql -h 172.16.3.150 -p 1921 -U 德哥
Password for user 德哥: 如果密码错误则
psql: FATAL:  LDAP authentication failed for user "德哥"
密码正确可以登录
Password for user 德哥: 
psql (9.3.5)
Type "help" for help.

postgres=> \q

[参考]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值