如何从本地连接到带SSL加密的AWS RDS?

问题描述 投票:0回答:3

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

postgresql amazon-web-services localhost amazon-rds ssh-tunnel
3个回答
1
投票

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


1
投票

在 PostgreSQL 中使用 SSL 加密和

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


0
投票

我在 AWS RDS (postgres 16) 上解决此问题的方法是设置一个参数组。将参数组分配给选择的数据库。您可以创建新的参数组或编辑现有的参数组。 enter image description here

enter image description here

enter image description here

点击编辑按钮可编辑参数组 enter image description here

在可修改参数的搜索框中,搜索 ssl 并单击 rds.force_ssl。将值更改为 0。单击“保存更改”以保存更改。 enter image description here 现在,转到 AWS RDS 仪表板上的数据库并修改数据库

enter image description here 在数据库的附加配置部分,将新创建的参数组(从下拉列表中选择)添加到数据库中。确保保存必要的更改。

enter image description here 重新启动数据库实例以传播这些更改。

N:B: 还要确保您的数据库是公开可用的或允许从您的 IP 访问。

enter image description here 按照此方法,您应该能够访问 AWS 上托管的 postgres 数据库。但是,请注意,这可能会存在一些安全问题,因为它仅建议用于测试目的。

© www.soinside.com 2019 - 2024. All rights reserved.