连接到 Amazon RDS 数据库时出现 pg-node 错误

pg-node error when connecting to amazon rds database

提问人:sorin182004 提问时间:7/29/2023 最后编辑:sorin182004 更新时间:7/29/2023 访问量:210

问:

我使用 Amazon RDS 控制台创建了一个数据库实例,为其分配了以下 VPC 安全组,授权任何 IPV4 地址连接到数据库(我知道这是不好的做法,但我迫切希望找到解决方案):vpc inbound rule

我已将公共访问设置为true:public access true

我还想指出,这场比赛!VPC security groups

我想使用库连接到此数据库:https://node-postgres.com,但我不断收到一个错误,上面写着:pg

error: no pg_hba.conf entry for host "**.***.***.**" (my IP), user "postgres", database "desk_booking", no encryption
    at Parser.parseErrorMessage (C:\apps\itec2022\node_modules\pg-protocol\src\parser.ts:369:69)
    at Parser.handlePacket (C:\apps\itec2022\node_modules\pg-protocol\src\parser.ts:188:21)
    at Parser.parse (C:\apps\itec2022\node_modules\pg-protocol\src\parser.ts:103:30)
    at Socket.<anonymous> (C:\apps\itec2022\node_modules\pg-protocol\src\index.ts:7:48)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Socket.Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 165,
  severity: 'FATAL',
  code: '28000',
  detail: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '543',
  routine: 'ClientAuthentication'
}

我读到无法更改通过 RDS 控制台创建的数据库。pg_hba.conf

当我尝试使用完全相同的凭据连接到数据库时,它起作用了:psqlpsql result

我认为软件包有问题,或者我如何设置它:local pg setup.pg

我知道有一种方法可以绕过这个问题,通过设置

ssl: {
  rejectUnauthorized: false,
}

但我觉得这很笨拙,不是最佳实践(尽管我不确定,因为它也用于官方 node-postgres 文档:https://node-postgres.com/features/ssl)。我想知道此选项是否可以在具有 Amazon RDS 的生产环境中使用。它会带来任何安全问题吗?与 、 参数结合使用是否更安全(如下所述:https://node-postgres.com/features/ssl)?如果是这样,我如何获取这些值?cakeycert

我也试过:

ssl: true

这会导致以下错误:

Error: self-signed certificate in certificate chain
    at TLSSocket.onConnectSecure (node:_tls_wrap:1540:34)
    at TLSSocket.emit (node:events:513:28)
    at TLSSocket.emit (node:domain:489:12)
    at TLSSocket._finishInit (node:_tls_wrap:959:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:743:12) {
  code: 'SELF_SIGNED_CERT_IN_CHAIN'
}

我不知道使用过任何 VPN:enter image description here

我想知道为什么允许访问终端,而我的申请被拒绝。此外,我该如何解决这个问题?

节点.js PostgreSQL 网络服务 亚马逊 RDS 节点 Postgres

评论

2赞 erik258 7/29/2023
“授权任何 IPV4 地址连接到数据库(我知道这是不好的做法,但我迫切希望找到解决方案)”是的,这是一个坏主意。Postgres 容易受到 DOS 攻击,很快就会有人找到 IP 地址。只允许您自己的 IP,而不是允许所有 IP(安全组规则编辑控制台页面将帮助您输入它)。当您的 IP 更改时,您必须更改它,但这仍然是正确的方法。您也可以在本地非常简单地运行 postgres,无论有没有 docker,这可能更简单(而且肯定会更便宜!
2赞 erik258 7/29/2023
docs.aws.amazon.com/AmazonRDS/latest/UserGuide/......介绍如何使用 RDS CA,以便正确验证证书。
0赞 sorin182004 7/29/2023
你是对的!我刚刚检查了文档,看起来 RDS Postgres 有一个设置,要求所有连接都是 SSL:(默认)。这确实引发了一个问题:虽然很明显该应用程序没有配置任何 SSL,但 shell 是如何连接的?默认情况下,所有 psql shell 连接都是 SSL 连接吗?rds.force_ssl = true

答: 暂无答案