PostgreSQL SSL 配置

标签 postgresql ssl openssl ssl-certificate postgresql-9.4

我已经尝试了很多,但没有得到确切的知识来将哪些文件复制到客户端

收到错误“需要有效的身份验证证书”

下面是 postgres DB 服务器目录

total 80
skipping unwanted directory
-rw-------. 1 postgres postgres  1285 Feb 13 20:16 rootCA.crt
-rw-------. 1 postgres postgres  1168 Feb 13 20:16 server.crt
-rw-------. 1 postgres postgres  1679 Feb 13 20:17 server.key

下面是与 SSL 配置相关的 postgresql.conf 文件内容。
[postgres@munmvs2951 raj]$ cat postgresql.conf | grep ssl
ssl = on                                # (change requires restart)
ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on         # (change requires restart)
#ssl_ecdh_curve = 'prime256v1'          # (change requires restart)
#ssl_renegotiation_limit = 512MB        # amount of data between renegotiations
ssl_cert_file = 'server.crt'            # (change requires restart)
ssl_key_file = 'server.key'             # (change requires restart)
ssl_ca_file = 'rootCA.crt'                      # (change requires restart)
#ssl_crl_file = ''                      # (change requires restart)

下面是 pg_hba 文件。
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust
#secure client
hostssl  postgres       postgres        clientip/32               md5 clientcert=1

下面是客户端 PostgreSQL 用户主目录,psql 将从该目录连接到服务器。
[postgres@clinet ~]$ ll
total 32
-rw------- 1 postgres postgres 1168 Feb 15 10:27 client.crt
-rw------- 1 postgres postgres  989 Feb 15 10:27 client.csr
-rw------- 1 postgres postgres 1285 Feb 15 11:47 rootCA.crt
-rw------- 1 postgres postgres 1675 Feb 15 11:47 rootCA.key
-rw------- 1 postgres postgres   17 Feb 15 11:47 rootCA.srl
-rw------- 1 postgres postgres 1168 Feb 15 11:47 server.crt
-rw------- 1 postgres postgres  989 Feb 15 11:47 server.csr
-rw------- 1 postgres postgres 1679 Feb 15 11:47 server.key
[postgres@client ~]$ pwd
/home/postgres

当我要连接时,出现以下错误。
[postgres@client ~]$ /opt/PostgresPlus/9.4AS/bin/psql -U postgres -p5443 -hserverip
psql.bin: FATAL:  connection requires a valid client certificate
FATAL:  no pg_hba.conf entry for host "10.80.x.x", user "postgres", database "postgres", SSL off

但是,我可以在没有 pg_hba 文件中的 clientcert=1 的情况下访问。

引用:
[postgres@client ~]$ /opt/PostgresPlus/9.4AS/bin/psql -U postgres -p5443 -hserverip
psql.bin (9.4.1.3)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=#

在上述成功连接中,我认为 ssl 检查只在服务器端而不是客户端。

但我想知道我应该将哪些文件复制到 PostgreSQL 主目录@client 端。根据 clientcert=1 检查证书

谢谢你的帮助。

最佳答案

https://www.postgresql.org/docs/current/libpq-ssl.html

Below is the client side PostgreSQL user home directory from where psql will connect to server



它们不属于主目录,它们属于名为 .postgresql 的主目录的子目录。 .或者在 Windows 中,在名为“%APPDATA%\postgresql ”的目录中。和文件rootCA.crt必须命名为 root.crt , 除非您已经竭尽全力更改客户端配置上的名称/位置,但您似乎没有这样做(您已经在服务器端更改了它,但这并没有在客户端更改它边)。和client.crt应命名为 postgresql.crt并且您缺少它的 key 文件。事实上,您有一个名为 rootCA.key 的文件在客户端的目录中是可怕的,除了 CA 之外没有人可以访问它。

关于PostgreSQL SSL 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60236816/

相关文章:

c - OpenSSL如何加载DER格式的CA证书

c - openssl 没有正确验证签名

sql - 如何将单个选择插入到两个不同的表中?

sql - 错误 : syntax error at or near "AS" - What am I doing wrong?

redirect - 强制 HTTP 到 HTTPS 重定向

ssl - 台式机浏览器和平板电脑浏览器之间的 SSL 证书链是否不同?

javascript - 如何在 Chrome 中自动接受 SSL 证书?

ruby-on-rails - Windows 替代 zeus 和 spring for rails

python - 让 Django 忘记一个不正确的 'makemigration'

postgresql - 将 postgres DB 转储导入空数据库时出错