0

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

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

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

4

1 回答 1

0

我想通了……我(部分?)因为试图在 pgbouncer 1.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_type = cert& auth_file = pgbouncer/users.txt(改变/删除 HBA 引用) & 去掉最后的 4server_tls_...行。

用户使用 SSL 证书对 pgbouncerpostgres 数据库进行身份验证。

意味着我必须汇总将通过 pgbouncer 的用户列表./pgbouncer/users.txt。格式应该是这样的(对于每个用户):

"lalligood" ""

因为 pgbouncer 不会根据密码验证任何连接。

所以这一切意味着通过 pgbouncer 的 TLS/SSL 身份验证/连接有效。但这也让我觉得auth_type = hba/auth_hba_file = pg_hba.conf充其量是可疑的;在最坏的情况下无法正常工作。

于 2016-01-15T16:59:35.100 回答