借用运行Postgres 9.4.1&的类似服务器的设置。 pgbouncer 1.6.1,我有多个用户通过端口6543上的pgbouncer连接到数据库。我还有第二台运行PostgreSQL 9.4.5的服务器,我已经验证所有用户只能直接连接到数据库(在端口5432上) )使用TLS / SSL设置为verify-full
。
但是,我需要创建一个组合这些配置的环境:一个所有用户通过TLS / SSL通过pgbouncer与连接池连接到数据库的环境。这意味着我需要在最近发布的(截至2015年12月18日)pgbouncer 1.7中使用新的TLS / SSL功能,但除了the new TLS parameters的文档之外,我还没有找到任何可用的示例来演示新功能,也没有我自己在第二台服务器上使用TLS / SSL通过pgbouncer建立有效连接是否成功。
我添加了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 :(得分:0)
我想通了......我(部分?)因为试图在pgbouncer 1.7中使用太多新功能而感到内疚。
有TLS / SSL设置&然后是HBA访问控制。 (TLS / SSL不需要HBA访问控制,反之亦然)。另外,自从pgbouncer&数据库在同一个盒子里,不需要pgbouncer和amp;之间的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数据库进行身份验证。
此也意味着我必须将./pgbouncer/users.txt
中将通过pgbouncer的用户列表放在一起。格式应该是这样的(对于每个用户):
"lalligood" ""
因为pgbouncer不会根据密码验证任何连接。
所以这意味着通过pgbouncer进行TLS / SSL身份验证/连接是有效的。但它也让我觉得auth_type = hba
/ auth_hba_file = pg_hba.conf
充其量只是怀疑;在最坏的情况下不能正常工作。