unvdb开启ident认证方式
一、概述
ident 认证方法通过从一个 ident 服务器获得客户端的操作系统用户名并且用它作为被允许的数据库用户名(和可选的用户名映射)来工作。它只在 TCP/IP 连接上支持。
当为一个本地(非 TCP/IP)连接指定 idnet 时,将实际使用 peer 认证。
二、配置方式
修改数据库配置文件
ud_ident.conf 文件
# MAPNAME SYSTEM-USERNAME UD-USERNAME
ss aaa test
ss syd dddd
ss unvdb unvdb
ud_hba.conf 文件
TYPE DATABASE USER ADDRESS METHOD
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all 0.0.0.0/0 ident map=ss
重启数据库
systemctl restart unvdb
MAPNAME:映射名,自定义配置在 ud_hba.conf 文件中。
SYSTEM-USERNAME:系统用户名。
PG-USERNAME :数据库用户名。
下载oidentd
yum -y install epel-release
yum clean all && yum makecache
yum install -y oidentd
systemctl start oidentd.service
systemctl status oidentd.service
#如果是编译安装的直接运行以下命令启动
oidentd
#如不方便关闭防火墙或者是在生产环境下执行以下放行端口命令
#开放防火墙端口或关闭防火墙
firewall-cmd --add-port=113/tcp
firewall-cmd --permanent --add-port=113/tcp
firewall-cmd --reload
firewall-cmd --list-ports | grep 113
systemctl stop firewalld.service
systemctl status firewalld.service
systemctl disable firewalld.service
连接数据库
# aaa 操作系统用户,使用 test 数据库用户,免密连入数据库。
[root@udb-49 ~]# su - aaa
[aaa@udb-49 ~]$ ud_sql -U test -d ew -h 192.168.4.98 -p 5679
ud_sql (24.2)
Type "help" for help.
ew=> select user;
user
------
test
(1 row)
#如果使用非允许用户连接则会报错
#异常
[root@udb-49 ~]# su aaa
[aaa@udb-49 ~]$ ud_sql -U unvdb -h 192.168.4.98 -p 5679
ud_sql: error: connection to server at "192.168.4.98", port 5679 failed: FATAL: Ident authentication failed for user "unvdb"
[aaa@udb-49 ~]$ exit
#正常
[root@udb-49 ~]# su unvdb
[unvdb@x98 udb-49]$ ud_sql -U unvdb -h 192.168.4.98 -p 5679
ud_sql (24.2)
Type "help" for help.
unvdb=#