如何从本地使用 SSL 加密连接到 AWS RDS?

How to connect to AWS RDS with SSL encryption from local?

我想从本地通过 EC2 连接到 AWS RDS。

我在我的本地机器上创建了一个隧道:

ssh -i ~/.ssh/id_rsa -f -N -L 5432:RDS-Endpoint:5432 EC2-User@EC2-IP -v

这种方式可行:

psql -hlocalhost -Upostgres -p5432 -d postgres

它确实连接到 RDS 数据库。

但是如果使用另一个经过 SSL 认证的 postgres 用户

psql -hlocalhost -p5432 "sslmode=verify-full sslrootcert=rds-ca-2019-root.pem user=another_user dbname=my_db"

导致此错误:

psql: error: server certificate for "tf-xxx.rds.amazonaws.com" (and 2 other names) does not match host name "localhost"

如果在EC2服务器上做,效果很好。在本地,证书似乎与 localhost 不匹配。那么如何正确设置呢?

在带有 sslmode=verify-full 的 PostgreSQL 中使用 SSL 加密与使用 SSL 隧道是互斥的,因为端点实际上是一个“中间人”。

我认为您可以通过将 'hostaddr' 指定为 127.0.0.1,但将 'host' 指定为真实主机名来实现。