How to configure External PostgreSQL Database Server to use SSL with Red Hat Satellite 6?
Environment
- Red Hat Satellite 6
Issue
- Is there any way to configure the External
PostgreSQLdatabase forRed Hat Satellite6 over SSL? - How to configure the External
PostgreSQLdatabase Server to useSSLto ConnectRed Hat Satellite6 securely?
Resolution
-
First Setup an external
PostgreSQLserver with dependencies and configure the user/role of databasePostgreSQLto connect withRed Hat Satellite6, Refer to our Installation documentation. -
Once the setup of the External Database is ready, create Certificates on a Database server to use SSL.
- Create a private key to sign the Certificate Signing Request (CSR) on the external
PostgreSQLserver.
# mkdir /root/postgres # openssl genrsa -out /root/postgres/`hostname -f`_cert_key.pem 4096- Generate the Certificate Signing Request (CSR) on the external
PostgreSQLserver.
# openssl req -new -key `hostname -f`_cert_key.pem -out `hostname -f`_cert_csr.pem Country Name (2 letter code) [XX]: State or Province Name (full name) []: Locality Name (eg, city) [Default City]: Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: NOTE: Above information will be according to your environment. - Create a private key to sign the Certificate Signing Request (CSR) on the external
-
Send the certificate signing request (CSR) to the Certificate Authority. When submitting the request, specify the lifespan of the certificate.
NOTE: The method for sending the certificate request varies, so consult the Certificate Authority for the preferred method. In response to the request, you can expect to receive a Certificate Authority bundle and a signed certificate, in separate files. -
Keep all the required SSL certificates inside
/var/opt/rh/rh-postgresql12/lib/pgsql/data/and change thePermissionandOwnershipcertificates as below.- Ensure that PostgreSQL has access to the files and set the private key file permissions to disallow access to the world or group.
# cp /root/postgres/*pem /var/opt/rh/rh-postgresql12/lib/pgsql/data/ # chown postgres:postgres /var/opt/rh/rh-postgresql12/lib/pgsql/data/*.pem # chmod 600 /var/opt/rh/rh-postgresql12/lib/pgsql/data/dbhost.example.com_cert_key.pem # ls -l -rw-r--r--. 1 postgres postgres 6120 Apr 28 16:58 CA-Bundle.pem -rw-------. 1 postgres postgres 3247 Apr 28 16:58 dbhost.example.com_cert_key.pem -rw-r--r--. 1 postgres postgres 1846 Apr 28 16:58 dbhost.example.com_cert.pem -
Edit
/var/opt/rh/rh-postgresql12/lib/pgsql/data/postgresql.confconfiguration file and add the certificates details with SSL flag On.ssl = on ssl_ca_file = '/var/opt/rh/rh-postgresql12/lib/pgsql/data/CA-Bundle.pem' ssl_cert_file = '/var/opt/rh/rh-postgresql12/lib/pgsql/data/dbhost.example.com_cert.pem' ssl_key_file = '/var/opt/rh/rh-postgresql12/lib/pgsql/data/dbhost.example.com_cert_key.pem' -
Modify
pg_hba.conffile, change all records for non-local connections fromhosttohostsslfor require clients to connect overTLS.# TYPE DATABASE USER ADDRESS METHOD # ... hostssl all all all md5 -
Restart the
PostgreSQLservice to reflect the changes.# systemctl restart rh-postgresql12-postgresql.service
From Red Hat Satellite side
-
To enable the Secure Sockets Layer (SSL) protocol for this external database, add the following options with
satellite-installer- Copy CA certificates from the
External Databaseserver to the Satellite server, the CA root certificate will be used to verify that the client can trust the certificate presented by the server.
# scp root@dbhost.example.com:/root/postgres/CA-Bundle.pem /root/# cp /root/CA-Bundle.pem /etc/pki/ca-trust/source/anchors/ # update-ca-trust-
Run
satellite-installerwith the below parameters to add Certificates details in satellite configuration.# satellite-installer --scenario satellite \ --foreman-db-sslmode verify-full \ --foreman-db-root-cert /root/CA-Bundle.pem \ --katello-candlepin-db-ssl true \ --katello-candlepin-db-ssl-verify true \ --foreman-proxy-content-pulpcore-postgresql-ssl true \ --foreman-proxy-content-pulpcore-postgresql-ssl-root-ca /root/CA-Bundle.pem
- Copy CA certificates from the
Diagnostic Steps
-
To verify the
SSLconnection from theRed Hat Satelliteserver to theExternal Postgresqldatabase server use below command.# psql -h dbhost.example.com -p 5432 -U pulp -d pulpcore Password for user pulp: psql (12.9) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. pulpcore=> # echo 0| openssl s_client -connect dbhost.example.com:5432 -starttls postgres -CAfile /root/CA-Bundle.pem CONNECTED(00000003)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.