【问题标题】:pgbouncer 1.7 with TLS/SSL client and server connections带有 TLS/SSL 客户端和服务器连接的 pgbouncer 1.7
【发布时间】:2023-04-11 08:07:01
【问题描述】:

使用从运行 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 功能,但除了 the new TLS parameters 的文档之外,我还没有找到任何可用的示例来演示新功能,也没有任何可用的示例我自己成功通过 pgbouncer 在我的第二台服务器上使用 TLS/SSL 建立了有效连接。

我已经包含了来自我的第二个服务器的postgresql.confpg_hba.confpgbouncer.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)

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

【问题讨论】:

    标签: database postgresql ssl tls1.2 pgbouncer


    【解决方案1】:

    我想通了...我(部分?)因为试图在 pgbouncer 1.7 中使用太多新功能而感到内疚。

    有 TLS/SSL 设置和 HBA 访问控制。 (TLS/SSL 不需要 HBA 访问控制,反之亦然)。此外,由于 pgbouncer 和数据库在同一个盒子上,所以 pgbouncer 和数据库之间不需要额外的 TLS/SSL 开销。

    简化为仅使用更常用的用户身份验证设置已被证明是解决方法。

    首先,postgresql.confpg_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 = certauth_file = pgbouncer/users.txt(更改/删除 HBA 引用)并在末尾删除 4 个 server_tls_... 行。

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

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

    "lalligood" ""
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 2019-07-20
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多