【问题标题】:How to connect to AWS RDS with SSL encryption from local?如何从本地使用 SSL 加密连接到 AWS RDS?
【发布时间】:2021-09-05 19:34:25
【问题描述】:

我想从本地通过 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 db。

但是如果使用另一个具有 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


    【解决方案1】:

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

    【讨论】:

    • psql -hostaddr127.0.0.1 -h[RDS-Endpoint] -p5432 "sslmode=verify-full sslrootcert=rds-ca-2019-root.pem user=another_user dbname=my_db" - 错误:psql: error: could not connect to server: Operation timed out RDS 不允许本地 IP。
    • 您刚刚指定了两个 -h 开关,其中第二个覆盖了第一个。 hostaddr 必须在连接字符串中指定。它没有开关。
    • 所以不能和psql一起使用?我试了还是不行:psql -h[RDS-Endpoint] -d "port=5432 hostaddr=127.0.0.1 sslmode=prefer sslrootcert=rds-ca-2019-root.pem user=another_user dbname=my_db" Got psql: error: FATAL: role "another_user" does not exist.
    • 您现在遇到了一个完全不同的错误,所以实际上它确实有效。现在解决新的错误。你为什么要更改用户名,而不是你已经知道的用户名?
    • 其实我已经按照 PgAdmin 的建议连接了远程 RDS。用不同的数据设置hosthostaddr。现在只想弄清楚我是否可以通过psql 命令连接。 another_user 是远程数据库中的真实用户。
    【解决方案2】:

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

    【讨论】:

    • 谢谢。那么在这种情况下,没有办法为受 SSL 加密的用户执行此操作。唯一的方法是为用户创建一个密码才能使用 SSH 隧道,对吧?
    • 我不确定我是否理解。您可以在不使用 SSL 隧道的情况下进行 SSL 加密。另一方面,如果你使用隧道,你无论如何都会被加密。
    猜你喜欢
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2014-06-24
    相关资源
    最近更新 更多