Использование SSL соединения в PostgreSQL

  1. Сгенерируем сертификаты в папке data:

Вместо localhost укажите название хоста вашей базы

openssl genrsa -out root.key 2048
openssl req -new -x509 -days 365 -key root.key -subj "/C=CN/ST=GD/L=SZ/O=Bapps, Inc./CN=Bapps Root CA" -out root.crt
openssl req -newkey rsa:2048 -nodes -keyout server.key -subj "/C=CN/ST=GD/L=SZ/O=Bapps, Inc./CN=localhost" -out server.csr
openssl x509 -req -extfile <(printf "subjectAltName=DNS:localhost") -days 365 -in server.csr -CA root.crt -CAkey root.key -CAcreateserial -out server.crt
  1. Раскомментируем ssl = on в файле postgresql.conf

  2. Добавим строку в pg_hba.conf

hostssl    all             all             127.0.0.1/32         cert
  1. Перезапустим базу данных

systemctl restart postgresql-server
  1. В переменной окружения CRM_DB_CONN_STR прописать sslmode и sslrootcert:

"CRM_DB_CONN_STR":"postgres://bapps:bapps@localhost:5432/bapps?sslmode=verify-full&TimeZone=Asia/Almaty&sslrootcert=c:\\tmp\\root.crt"
  1. Перезапустим приклад

systemctl restart damu