Skip to content

Latest commit

 

History

History
111 lines (76 loc) · 5.42 KB

20210407_07.md

File metadata and controls

111 lines (76 loc) · 5.42 KB

PostgreSQL 14 preview - log_connections 支持打印更多内容, pg_hba第几行, 使用什么认证方法等, 方便判断客户通过什么方式在与数据库进行登陆认证

作者

digoal

日期

2021-04-07

标签

PostgreSQL , log_connections , 日志 , 认证方法


背景

PostgreSQL 14 preview - log_connections 支持打印更多内容, pg_hba第几行, 使用什么认证方法等, 方便判断客户通过什么方式在与数据库进行登陆认证

例如:

  LOG:  connection received: host=[local]  
  LOG:  connection authenticated: identity="foouser" method=peer (/data/pg_hba.conf:88)  
  LOG:  connection authorized: user=admin database=postgres application_name=psql  

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=9afffcb833d3c5e59a328a2af674fac7e7334fc1

Add some information about authenticated identity via log_connections master github/master  
author	Michael Paquier <michael@paquier.xyz>	  
Wed, 7 Apr 2021 01:16:39 +0000 (10:16 +0900)  
committer	Michael Paquier <michael@paquier.xyz>	  
Wed, 7 Apr 2021 01:16:39 +0000 (10:16 +0900)  
commit	9afffcb833d3c5e59a328a2af674fac7e7334fc1  
tree	48b3aff83fefc902317e30802abd453d5228a906	tree  
parent	8ee9b662daa6d51b54d21ec274f22a218462ad2d	commit | diff  
Add some information about authenticated identity via log_connections  
  
The "authenticated identity" is the string used by an authentication  
method to identify a particular user.  In many common cases, this is the  
same as the PostgreSQL username, but for some third-party authentication  
methods, the identifier in use may be shortened or otherwise translated  
(e.g. through pg_ident user mappings) before the server stores it.  
  
To help administrators see who has actually interacted with the system,  
this commit adds the capability to store the original identity when  
authentication succeeds within the backend's Port, and generates a log  
entry when log_connections is enabled.  The log entries generated look  
something like this (where a local user named "foouser" is connecting to  
the database as the database user called "admin"):  
  
  LOG:  connection received: host=[local]  
  LOG:  connection authenticated: identity="foouser" method=peer (/data/pg_hba.conf:88)  
  LOG:  connection authorized: user=admin database=postgres application_name=psql  
  
Port->authn_id is set according to the authentication method:  
  
  bsd: the PostgreSQL username (aka the local username)  
  cert: the client's Subject DN  
  gss: the user principal  
  ident: the remote username  
  ldap: the final bind DN  
  pam: the PostgreSQL username (aka PAM username)  
  password (and all pw-challenge methods): the PostgreSQL username  
  peer: the peer's pw_name  
  radius: the PostgreSQL username (aka the RADIUS username)  
  sspi: either the down-level (SAM-compatible) logon name, if  
        compat_realm=1, or the User Principal Name if compat_realm=0  
  
The trust auth method does not set an authenticated identity.  Neither  
does clientcert=verify-full.  
  
Port->authn_id could be used for other purposes, like a superuser-only  
extra column in pg_stat_activity, but this is left as future work.  
  
PostgresNode::connect_{ok,fails}() have been modified to let tests check  
the backend log files for required or prohibited patterns, using the  
new log_like and log_unlike parameters.  This uses a method based on a  
truncation of the existing server log file, like issues_sql_like().  
Tests are added to the ldap, kerberos, authentication and SSL test  
suites.  
  
Author: Jacob Champion  
Reviewed-by: Stephen Frost, Magnus Hagander, Tom Lane, Michael Paquier  
Discussion: https://postgr.es/m/c55788dd1773c521c862e8e0dddb367df51222be.camel@vmware.com  

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

digoal's wechat