Database 带有TLS/SSL客户端和服务器连接的pgbouncer 1.7

Database 带有TLS/SSL客户端和服务器连接的pgbouncer 1.7,database,postgresql,ssl,tls1.2,pgbouncer,Database,Postgresql,Ssl,Tls1.2,Pgbouncer,使用从运行Postgres 9.4.1和pgbouncer 1.6.1的类似服务器借用的设置,我有多个用户通过端口6543上的pgbouncer连接到数据库。我还有第二台运行PostgreSQL 9.4.5的服务器,在那里我验证了所有用户只能使用设置为verify full的TLS/SSL直接连接到数据库(在端口5432上) 但是,我需要创建一个结合这些配置的环境:其中所有用户通过TLS/SSL连接到数据库,并通过pgbouncer连接池。这意味着我需要在最近发布的(截至2015年12月18日)

使用从运行Postgres 9.4.1和pgbouncer 1.6.1的类似服务器借用的设置,我有多个用户通过端口6543上的pgbouncer连接到数据库。我还有第二台运行PostgreSQL 9.4.5的服务器,在那里我验证了所有用户只能使用设置为
verify full
的TLS/SSL直接连接到数据库(在端口5432上)

但是,我需要创建一个结合这些配置的环境:其中所有用户通过TLS/SSL连接到数据库,并通过pgbouncer连接池。这意味着我需要在最近发布的(截至2015年12月18日)pgbouncer 1.7中使用新的TLS/SSL功能,但除了的文档外,我还没有找到任何可以证明新功能的示例,也没有在我的第二台服务器上通过pgbouncer使用TLS/SSL成功建立有效连接

我已经从我的第二台服务器中收录了
postgresql.conf
pg_hba.conf
,&
pgbouncer.ini
的相关摘录

postgresql.conf:

ssl = on                                # (change requires restart)
ssl_cert_file = 'server.crt'            # (change requires restart)
ssl_key_file = 'server.key'             # (change requires restart)
ssl_ca_file = 'root.crt'                        # (change requires restart)
pg_hba.conf:

hostssl    all             all             10.10.5.0/24            cert
pgbouncer.ini:

;
; pgbouncer configuration
;
[databases]
mydatabase = host=localhost port=5432 dbname=mydatabase
;
[pgbouncer]
listen_port = 6543
listen_addr = *
admin_users = lalligood, postgres
logfile = /tmp/pgbouncer.log
pidfile = /tmp/pgbouncer.pid
ignore_startup_parameters = application_name
server_reset_query = DISCARD ALL;
pool_mode = session
max_client_conn = 1000
default_pool_size = 300
log_pooler_errors = 0
; Improve compatibility with Java/JDBC connections
ignore_startup_parameters = extra_float_digits
; USER AUTHENTICATION (old way commented out with new lines below)
;auth_type = md5
;auth_file = pgbouncer/users.txt
auth_type = hba
auth_hba_file = pg_hba.conf
; TLS SETTINGS (NEW STUFF!)
client_tls_sslmode = verify-full
client_tls_key_file = server.key
client_tls_cert_file = server.crt
client_tls_ca_file = root.crt
server_tls_sslmode = verify-full
server_tls_key_file = /tmp/pgb_user.key
server_tls_cert_file = /tmp/pgb_user.crt
server_tls_ca_file = root.crt
但是,当我尝试以用户“lalligood”的身份连接时,pgbouncer启动,出现以下错误:

ERROR: no such user: lalligood
pgbouncer.log包含每次尝试的以下行:

2016-01-13 16:00:36.971 2144 LOG C-0xcad410: 
(nodb)/(nouser)@10.10.5.194:54848 closing because: No such user: 
lalligood (age=0)
如有必要,我可以提供更多信息。如果有人对我可能忽略的工作有任何建议,我非常感谢您的帮助

我明白了。。。我(部分?)对试图在PGBouncer1.7中使用太多新功能感到内疚

有TLS/SSL设置,然后是HBA访问控制。(TLS/SSL不需要HBA访问控制,反之亦然)。此外,由于pgbouncer和数据库位于同一个框中,因此pgbouncer和数据库之间不需要额外的TLS/SSL开销

简化为只使用更常用的用户身份验证设置证明是解决方案

首先,
postgresql.conf
&
pg_hba.conf
保持不变,如上所示

然而,pgbouncer.ini是这样的:

;
; pgbouncer configuration
;
[databases]
mydatabase = host=localhost port=5432 dbname=mydatabase
;
[pgbouncer]
listen_port = 6543
listen_addr = *
admin_users = lalligood, postgres
auth_type = cert
auth_file = pgbouncer/users.txt
logfile = /var/lib/pgsql/pgbouncer.log
pidfile = /var/lib/pgsql/pgbouncer.pid
ignore_startup_parameters = application_name
server_reset_query = DISCARD ALL;
pool_mode = session
max_client_conn = 1000
default_pool_size = 300
log_pooler_errors = 0
; Improve compatibility with Java/JDBC connections
ignore_startup_parameters = extra_float_digits
; TLS settings
client_tls_sslmode = verify-full
client_tls_key_file = server.key
client_tls_cert_file = server.crt
client_tls_ca_file = root.crt
因此,具体的更改是
auth\u type=cert
auth\u file=pgbouncer/users.txt
(更改/删除HBA引用)&去掉末尾的4行
server\u tls…

用户使用SSL证书对pgbouncer和postgres数据库进行身份验证

这也意味着我必须在
/pgbouncer/users.txt
中列出要通过pgbouncer的用户列表。格式应如下所示(对于每个用户):

因为pgbouncer不会基于密码验证任何连接

因此,所有这一切意味着通过pgbouncer进行TLS/SSL身份验证/连接是可行的。但这也让我感到,
auth_type=hba
/
auth_hba_file=pg_hba.conf
充其量也值得怀疑;最坏的情况是不能正常工作

"lalligood" ""