首页 > 解决方案 > 如何从本地使用 SSL 加密连接到 AWS RDS?

问题描述

我想通过本地的 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。那么如何正确设置呢?

标签: postgresqlamazon-web-serviceslocalhostamazon-rdsssh-tunnel

解决方案


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


推荐阅读