![](/img/trans.png)
[英]postgres logical replication not working. Error says "could not connect to the publisher"
[英]could not initiate GSSAPI security context on Postgres 14 logical replication
我正在關注這篇文章以在 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 進程的任何人都可讀。 這已經使任何安全利益變得可疑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.