简体   繁体   English

PostgreSQL SSL 配置

[英]PostgreSQL SSL Configuration

I have tried a lot but did't get exact knowledge to copy which files to client side我已经尝试了很多,但没有得到确切的知识来将哪些文件复制到客户端

Getting error " Valid authentication certificate required"出现错误“需要有效的身份验证证书”

Below is postgres DB server directory下面是 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

Below is postgresql.conf file content related to SSL configuration.以下是与 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)

Below is the pg_hba file.下面是 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

Below is the client side PostgreSQL user home directory from where psql will connect to server.下面是客户端 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

when i going to connect, getting below error.当我要连接时,出现以下错误。

[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

However, I can access without clientcert=1 in pg_hba file.但是,我可以在 pg_hba 文件中没有 clientcert=1 的情况下访问。

Ref:参考:

[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=#

In above successful connection, i think ssl checking only at server side not client side.在上面的成功连接中,我认为 ssl 只在服务器端而不是客户端检查。

but i want to know which files should i copy to PostgreSQL home directory @client side.但我想知道我应该将哪些文件复制到 PostgreSQL 主目录 @client 端。 to check certificate as per clientcert=1根据 clientcert=1 检查证书

Thanks for your help.谢谢你的帮助。

See https://www.postgresql.org/docs/current/libpq-ssl.htmlhttps://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 用户主目录,从这里 psql 将连接到服务器

They do not belong in the home directory, they belong in a subdirectory of the home directory named .postgresql .它们不属于主目录,它们属于名为.postgresql的主目录的子目录。 Or in Windows, in a directory named " %APPDATA% \\ postgresql ".或者在 Windows 中,在名为“ %APPDATA% \\ postgresql ”的目录中。 And file rootCA.crt has to be named root.crt , unless you have gone out of your way to change the name/location on the client side configuration, which it doesn't seem you have done (you have changed it on the server side, but that doesn't change it on the client side).并且文件rootCA.crt必须命名为root.crt ,除非您已经root.crt地更改客户端配置上的名称/位置,但您似乎没有这样做(您已在服务器上更改它)方面,但这不会在客户端改变它)。 And client.crt should be named postgresql.crt and you are missing the key file for it.并且client.crt应该命名为postgresql.crt并且您缺少它的密钥文件。 And the fact that you have a file named rootCA.key in the client's directory is frightening, no one but the CA should have access to that.并且您在客户端目录中有一个名为rootCA.key的文件这一事实令人恐惧,除了 CA 之外没有人可以访问该文件。

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

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