2016-01-13 133 views
0

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

但是,我需要创建一个组合这些配置的环境:其中所有用户都通过TLS/SSL通过pgbouncer连接池连接到数据库。这意味着我需要在最近发布的(截至2015年12月18日)pgbouncer 1.7中使用新的TLS/SSL功能,但除了文档the new TLS parameters之外,我还没有发现任何可用的示例来演示新功能,也没有取得任何成功我自己通过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 

pgbouncer开始,但是,当我尝试连接的用户“ lalligood',我得到以下错误:

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) 

如果必要的话,我可以提供更多的信息。如果任何人有任何意见/建议,我可能会忽略这个工作,我非常感谢帮助!

回答

0

我想通了......我(部分?)有罪,试图在pgbouncer 1.7中使用太多新功能。

有TLS/SSL设置&然后有HBA访问控制。 (TLS/SSL不需要HBA访问控制&反之亦然)。此外,由于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_type = cert & auth_file = pgbouncer/users.txt(改变/卸下HBA的参考文献)&剥出4条server_tls_...线在末端。

用户使用SSL证书向pgbouncer 验证postgres数据库。

This 意味着我必须把在./pgbouncer/users.txt将要通过pgbouncer的用户列表。格式应该像这样(针对每个用户):

"lalligood" "" 

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

所以这意味着通过pgbouncer的TLS/SSL认证/连接起作用。但它也让我感觉最好是怀疑auth_type = hba/auth_hba_file = pg_hba.conf;最坏的情况下工作不正常。