繁体   English   中英

PostgreSQL SSL 配置

[英]PostgreSQL SSL Configuration

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

出现错误“需要有效的身份验证证书”

下面是 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

下面是客户端 PostgreSQL 用户主目录,从这里 psql 将连接到服务器

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM