PostgreSQL SSL 中客户端证书的要求

Requirement of Client certificates in PostgreSQL SSL

我是 DBA 角色的新手,也是第一次设置 SSL。在 this article 的帮助下,我创建了一个密钥并生成了一个用于使用 openssl 进行测试的证书。 This article说也要为客户端生成密钥和证书。我已经生成了它并针对本地服务器进行了测试。

我们有一个测试 aws rds 实例,我已经下载了此 link 提供的 RDS 证书。并且我可以使用以下命令连接到 rds 实例,而无需使用任何客户端 key/certificate。

psql -h somehost.rds.amazonaws.com -p 5432     "dbname=test user=testuser sslrootcert=rds-ca-2019-root.pem sslmode=verify-full"

但是,如果我不指定 sslrootcert,则会出现以下错误

psql: root certificate file "/root/.postgresql/root.crt" does not exist
Either provide the file or change sslmode to disable server certificate verification.

我想知道为什么在 AWS 的情况下我不需要客户端密钥和证书?

如果我们使用由证书颁发机构签署的证书,我们将不需要客户端密钥 和秘密?

如果我们想为所有客户端使用一个证书,我还需要做些什么才能在生产环境中启用 SSL?

我想使用 sslmode=verify-full

客户端证书是可选的,据我所知比服务器证书少得多。您可以通过将身份验证方法设置为 pg_hba.conf 中的 cert 或将 clientcert 选项添加到其他身份验证方法来要求客户端证书。如果您不执行其中任何一项,则不会使用客户端证书。

不要相信随机文章,请参阅the official documentation

如您所见,您需要使用连接字符串选项sslmode=verify-full(或将环境变量PGSSLMODE设置为verify-full)来验证服务器证书。

为此,您不需要客户端证书。您只需要客户端上的证书颁发机构 (CA) 证书,以便客户端可以验证服务器证书是否使用该证书签名。

仅当您希望服务器使用证书对客户端进行身份验证时才需要客户端证书。

如果您未使用 sslrootcert connection string option or the PGSSLROOTCERT environment variable, the client will search the CA certificate in ~/.postgresql/root.crt, as detailed in the documentation.

指定 CA 证书的路径