大网数据广告活动
服务器运维问答

Unable to connect to Postgres with client certificate

· 52CE 我爱测

I've installed Postgres 10.1 on a Windows server, and it's running as a Windows service. It's installed into %APPDATA% for the Local System user, which is the user account the Window service is running with: C:\Windows\System32\c…

问题原文

原帖链接 · Cocowalla · CC BY-SA 3.0

I've installed Postgres 10.1 on a Windows server, and it's running as a Windows service. It's installed into %APPDATA% for the Local System user, which is the user account the Window service is running with:

C:\Windows\System32\config\systemprofile\AppData\Roaming\My App Database

My server-side SSL certs are in this same directory, and my postgresql.conf is configured to find them:

ssl_cert_file = 'db.crt'
ssl_key_file = 'db.key'
ssl_ca_file = 'ca.crt'

My pg_hba.conf file seems to be configured correctly:

hostssl     my-database         my-username         0.0.0.0/0               cert clientcert=1 map=my-username

I'm trying to connect with the psql command line tool:

psql "postgresql://my-username@localhost/my-database?sslmode=verify-full&sslkey=C:\MyDir\MyClientCert.key&sslcert=C:\MyDir\MyClientCert.crt"

but I get this error:

psql: root certificate file "C:\Users\Administrator\AppData\Roaming/postgresql/root.crt" does not exist Either provide the file or change sslmode to disable server certificate verification.

I can't find any reference to root.crt in my config, and I've no idea why it's looking in %APPDATA%\postgresql, rather than the configured PGDATA directory, %APPDATA%\My App Database.

已采纳解答

原帖链接 · Michael Jameson · CC BY-SA 4.0

Connecting with sslmode=verify-full implies that you want the client to verify the server's certificate which requires specifying a "root certificate" using "sslrootcert" connection parameter or "PGSSLROOTCERT" environment variable. I would hazard to guess that it is supplying %APPDATA%\postgres\root.crt as the default.

The error message supplies your solution, but I suspect you misunderstood -- this is a client error not a server error, the server configuration is immaterial.

Either provide the file or change sslmode to disable server certificate verification.

You can change sslmode to "require" or provide a root cert.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-12-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。