赞
踩
上一节安装了数据库,这节我们开启openssl,并开启密码复杂度检查模块
【没有开启ssl,使用wireshark工具对抓取的包解析,传输的sql会被解析到,开启ssl 抓包时sql会加密】
Server.key server.crt位置都处于$PGDATA下,为保证安全性,可以将其放置于不同的位置,权限为0600,对于postgres用户可读可写,其他用户都没有任何权限
目录
- [postgres@localhost ~]$ cd ~
- [postgres@localhost ~]$ mkdir openssl
- [postgres@localhost ~]$ cd openssl/
- [postgres@localhost openssl]$ openssl req -new -nodes -text -out root.csr -keyout root.key -subj "/CN=test1"
查看会生成两个文件(.key和.csr)
注意:-subj 参数内容 必须以/开头
删除其他用户的权限
[postgres@localhost openssl]$ chmod og-rwx root.key
修改openssl配置文件 修改默认路径如下
- [postgres@localhost openssl]$ cp /etc/pki/tls/openssl.cnf /home/postgres/openssl/
- [postgres@localhost openssl]$ vi openssl.cnf
生成CRT文件
[postgres@localhost openssl]$ openssl x509 -req -in root.csr -text -days 3650 -extfile /home/postgres/openssl/openssl.cnf -extensions v3_ca -signkey root.key -out root.crt
[postgres@localhost openssl]$ openssl req -new -nodes -text -out server.csr -keyout server.key -subj "/CN=test1"
删除其他用户的权限
[postgres@localhost openssl]$ chmod og-rwx server.key
[postgres@localhost openssl]$ openssl x509 -req -in server.csr -text -days 365 -CA root.crt -CAkey root.key -CAcreateserial -out server.crt
修改配置文件
[postgres@localhost openssl]$ vi $PGDATA/postgresql.conf
- ssl = on
- #ssl_ca_file = ''
- ssl_cert_file = '/home/postgres/openssl/server.crt'
- #ssl_crl_file = ''
- ssl_key_file = '/home/postgres/openssl/server.key'
说明:crt和key这些文件 默认路径是在$PGDATA,为了安全 我们新建了目录,在自定义的目录生成 ,所以这里密钥的路径要改一下。
对于密钥文件的处理,我们做了两步,一个是修改了密钥的默认路径,一个是修改了key的权限,都是为了安全考虑
- [postgres@localhost openssl]$ pg_ctl restart
- [postgres@localhost openssl]$ psql
-
- postgres=# show ssl;
- ssl
- -----
- on
- (1 row)
-
- postgres=# show ssl_key_file ;
- ssl_key_file
- -----------------------------------
- /home/postgres/openssl/server.key
- (1 row)
-
- postgres=# show ssl_cert_file;
- ssl_cert_file
- -----------------------------------
- /home/postgres/openssl/server.crt
- (1 row)
-
postgres=# create extension sslinfo;
[postgres@localhost openssl]$ psql "host=localhost user=postgres dbname=postgres password=123456 sslmode=require"
- postgres=# select ssl_is_used();
- ssl_is_used
- -------------
- t
- (1 row)
上一节已经编译过所有模块了,如果没有编译,需要先将模块编译出来并且放到lib库
- [postgres@bogon passwordcheck]$ cd /home/postgres/postgresql-12.0/contrib/passwordcheck
- [postgres@bogon passwordcheck]$ make
- [postgres@bogon passwordcheck]$ make install
- [postgres@bogon passwordcheck]$ cp passwordcheck.so /home/postgres/install/lib/
[postgres@localhost openssl]$ vi $PGDATA/postgresql.conf
- [postgres@localhost openssl]$ pg_ctl restart
- [postgres@localhost openssl]$ psql
- psql (12.0)
- Type "help" for help.
-
- postgres=# create user user1 with password '123456';
- 2022-07-05 12:11:49.250 EDT [23839] ERROR: password is too short
- 2022-07-05 12:11:49.250 EDT [23839] STATEMENT: create user user1 with password '123456';
- ERROR: password is too short
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。