postgresql - JDBCPool 与 PgPool,对于 postgres 的 SSLMODE 无法解释的行为
问题描述
我们有一个rds.force_ssl设置为 true 的 RDS postgres 实例。使用 vert.x 连接到数据库并看到一些与 postgres 的 sslmode 文档相矛盾的无法解释的行为。
// Fails with SSL auth error as expected
PgConnectOptions connectOptions = new PgConnectOptions()
.setHost(host)
.setPort(port)
.setUser(username)
.setPassword(password)
.setDatabase(database);
PoolOptions poolOptions = new PoolOptions().setMaxSize(10);
PgPool pgPool = PgPool.pool(vertx, connectOptions, poolOptions);
pgPool.getConnection.onSuccess(...).onFailure(...);
// error (note the "SSL off" in the message)
{
"message": "no pg_hba.conf entry for host "x.x.x.x", user "...", database "...", SSL off",
"severity": "FATAL",
"code": "28000",
"file": "auth.c",
"line": "490",
"routine": "ClientAuthentication"
}
// Works but I expected this to fail since the postgres server is expecting SSL
// and I am not passing any certs info in connection string.
JsonObject cfg = new JsonObject()
.put("url", "jdbc:postgresql://host:port/database")
.put("user", username)
.put("password", password);
JDBCPool jdbcPool = JDBCPool.pool(vertx, cfg);
jdbcClient.getConnection.onSuccess(...).onFailure(...);
我得出的结论是,使用 jdbc 样式的 url 正在做一些神奇的事情,使其在不指定 sslmode 的情况下工作。所以有几个问题:
- 为什么 jdbc 样式的 url 在没有 sslmode 的情况下工作?预计这会引发异常,因为服务器正在强制 ssl 连接。
- 为什么不正确使用 jdbc 样式的 url 会引发 SSL 错误(如预期的那样)?PgPool 与 JDBCPool 有何不同?
谢谢。
更新:使用所有可用值进行测试sslmode
// ssl error
jdbc:postgresql://host:port/dbname?sslmode=disable
// works
jdbc:postgresql://host:port/dbname
jdbc:postgresql://host:port/dbname?sslmode=allow
jdbc:postgresql://host:port/dbname?sslmode=prefer
jdbc:postgresql://host:port/dbname?sslmode=require
jdbc:postgresql://host:port/dbname?sslmode=verify-ca
jdbc:postgresql://host:port/dbname?sslmode=verify-full