免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 19261 | 回复: 5
打印 上一主题 下一主题

问问PostgreSQL的登录过程。 [复制链接]

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-08-28 21:56 |只看该作者 |倒序浏览
本帖最后由 fender0107401 于 2013-08-28 22:01 编辑

首先有个疑问就是pg_hba.conf这个文件。

我的理解是这个文件基本上算是一个PostgreSQL自带的防火墙,可以对ip、用户名、数据库以及认证方式进行限制。

如果一个用户连接数据库,那么 这个用户的客户端程序应该是先通过pg_hba.conf这个文件。

如果数据库的管理员创建role的时候,设定了用户的密码,那么这个密码应该是md5(我猜测的,没找到具体文档)存在数据库内部。

如果一个用户连接数据库,并且通过了pg_hba.conf文件的认证

问题1:假设pg_hba.conf文件里面设定的是password,那么会发生什么?用户的用户名和密码直接交给数据库服务器进程?然后校验?

问题2:假设pg_hba.conf文件里面设定的是md5,那么会发生什么?难道直接就把密码给翻译成md5之后的密文了吗?然后交给数据库服务器进程进行校验?

问题3:pg_hba.conf文件里面的password和md5选项应该不会影响到数据库里面保存密码的具体方式吧(我猜是md5加密后的密文)。

先问这么多,开始认真学PostgreSQL了。

之前发现PostgreSQL支持好多数据类型,感觉很牛逼,现在仔细学学,感觉更牛逼了。

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
2 [报告]
发表于 2013-08-29 08:16 |只看该作者
本帖最后由 fender0107401 于 2013-08-29 08:16 编辑

如果使用其他认证方式,不使用password和md5,那么是如何确认用户身份的呢?

谁来指点一下大致的流程,感激不尽。

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
3 [报告]
发表于 2013-08-29 12:09 来自手机 |只看该作者
3336901加群

论坛徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龙
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥猪
日期:2014-04-01 08:56:02亥猪
日期:2014-04-08 08:38:58程序设计版块每日发帖之星
日期:2016-01-05 06:20:00程序设计版块每日发帖之星
日期:2016-01-07 06:20:00
4 [报告]
发表于 2013-08-29 13:19 |只看该作者
本帖最后由 fender0107401 于 2013-08-29 13:19 编辑

回复 3# gvim

QQ群?好,我有空试试。


   

论坛徽章:
0
5 [报告]
发表于 2013-12-17 16:00 |只看该作者
gvim 发表于 2013-08-29 12:09
3336901加群


已加。

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
6 [报告]
发表于 2014-03-28 22:40 |只看该作者
Start-up
To begin a session, a frontend opens a connection to the server and sends a startup message. This message includes the names of the user and of the database the user wants to connect to; it also identifies the particular protocol version to be used. (Optionally, the startup message can include additional settings for run-time parameters.)

连接一开始只发送了用户名和数据库名,并没有发送密码。
client不能选择认证方式,也不知道密码是否被需要(比如trust,peer,ident等等)。

The server then uses this information and the contents of its configuration files (such as pg_hba.conf) to determine whether the connection is provisionally acceptable, and what additional authentication is required (if any).

server根据这些信息以及配置来选择是否需要认证,以及应该使用哪种认证方式。

AuthenticationCleartextPassword
    The frontend must now send a PasswordMessage containing the password in clear-text form. If this is the correct password, the server responds with an AuthenticationOk, otherwise it responds with an ErrorResponse.
AuthenticationMD5Password
    The frontend must now send a PasswordMessage containing the password encrypted via MD5, using the 4-character salt specified in the AuthenticationMD5Password message. If this is the correct password, the server responds with an AuthenticationOk, otherwise it responds with an ErrorResponse.

于是server就可以查询hba并根据md5或password发送不同的认证请求(或者根本就不需要认证请求)。
这时候client再选择密码传输的方式。

相关资料:
Password Authentication
Message Formats
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP