无法在Postgres 14逻辑复制上启动GSSAPI安全上下文



我遵循这篇文章在Postgres 14上启用ssl进行逻辑复制。然后尝试在客户端建立连接:

CREATE SUBSCRIPTION my-sub
CONNECTION 'host=my-domain.com dbname=my-db user=my-username password=xxxxxx'
PUBLICATION my-pub;

抛出错误:

2022-05-12 13:51:36.047 PDT [37340] ERROR:  could not connect to the publisher: connection to server at "my_domain.com" (xxx.xxx.xxx.141), port 5432 failed: could not initiate GSSAPI security context:  The operation or option is not available: Credential for asked mech-type mech not found in the credential handle
connection to server at "my_domain.com" (xxx.xxx.xxx.141), port 5432 failed: FATAL:  connection requires a valid client certificate
connection to server at "my-domain.com" (xxx.xxx.xxx.141), port 5432 failed: FATAL:  no pg_hba.conf entry for host "xxx.xxx.xxx.199", user "my-username", database "my-db", no encryption

在my-pub服务器上,pg_hba.conf:

添加了一行
hostssl all             all             0.0.0.0/0               scram-sha-256 clientcert=verify-full

在子客户端上,ca文件的设置如下:

ssl_ca_file = '/usr/local/var/postgres/root.crt'. //<<==client cert copied from pub server. 

大多数人只是使用服务证书。使用客户机证书是不常见的,尤其是在逻辑复制订阅者的情况下。但是,如果您确实希望发布者要求客户端证书,它并没有被错误地配置为该目的(或者至少,我们不能从当前数据中看出)。发布者要求提供客户端证书,但订阅者没有提供。用户配置有问题。

注意,在这种情况下,订阅者将充当连接到发布者的客户端,而不是充当服务器角色。它使用libpq客户端库来做到这一点,因此它的配置不是基于postgresql.conf的内容。特别是,ssl_ca_file是一个服务器配置选项,而不是客户机配置。

这样做的方法是让CONNECTION看起来像

'host=my-domain.com dbname=my-db user=my-username password=xxxxxx sslcert=/foobar/my-username.crt sslkey=/foobar/my-username.key'

但是要使其工作,证书和密钥需要在订阅者计算机上,任何拥有postgres进程的人都可以读取。这已经使任何安全利益变得可疑。

最新更新