Use SSL with an external PostgreSQL database
4 minute read
This procedure applies to a distributed deployment in which the database runs outside the appliance. Every web server and job engine node needs outbound access to the database on TCP 5432. See Network connectivity.
The paths and commands below use PostgreSQL 14. If your database server runs another version, such as PostgreSQL 18, replace 14 with your version number.
PostgreSQL database configuration
Perform the following on the PostgreSQL server.
-
Add the following to the PostgreSQL data directory:
/var/lib/pgsql/14/data- Server SSL certificate:
server.crt - Private key:
server.key
- Server SSL certificate:
-
Update the SSL configuration to enable SSL:
- Edit
/var/lib/pgsql/14/data/postgresql.conf:- Uncomment
ssland set the value toon
- Uncomment
- If the filename for the server SSL certificate is not
server.crt, or the private key is notserver.key, do the following:- Uncomment
ssl_cert_fileand set the value to the server SSL certificate filename - Uncomment
ssl_key_fileand set the value to the private key filename
- Uncomment
Example
/var/lib/pgsql/14/data/postgresql.conf# - SSL - ssl = on #ssl_ca_file = '' #ssl_cert_file = 'server.crt' #ssl_crl_file = '' #ssl_crl_dir = '' #ssl_key_file = 'server.key' #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers #ssl_prefer_server_ciphers = on #ssl_ecdh_curve = 'prime256v1' #ssl_min_protocol_version = 'TLSv1.2' #ssl_max_protocol_version = '' #ssl_dh_params_file = '' #ssl_passphrase_command = '' #ssl_passphrase_command_supports_reload = off - Edit
-
Update the allowed hosts to use SSL by adding
hostsslentries for your IP addresses or IP ranges:-
Edit
/var/lib/pgsql/14/data/pg_hba.conf:Example
/var/lib/pgsql/14/data/pg_hba.conf# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 scram-sha-256 # IPv6 local connections: host all all ::1/128 scram-sha-256 # Allow replication connections from localhost, by a user with the # replication privilege. local replication all peer host replication all 127.0.0.1/32 scram-sha-256 host replication all ::1/128 scram-sha-256 hostssl all all 192.168.56.0/24 scram-sha-256
-
-
Restart the database
systemctl restart postgresql-14 -
Verify SSL is configured properly by connecting to the database using the
psqlcommand below:#Replace value for password in the psql command below psql "dbname=cloudbolt host=db.cloudbolt.vm user=cb_dba password=yourdbpassword sslmode=require"Example expected return after running the
psqlcommand above# Example of successful psql command return psql (14.2) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. cloudbolt=>
For more detailed information, refer to the PostgreSQL documentation: Secure TCP/IP Connections with SSL.
CMP database configuration
-
Add the following files to the CMP database directory:
/var/opt/cloudbolt/proserv/dbserver.crtserver.keyroot.crt
-
Change ownership of all three files to
cloudbolt:cloudboltwith the following commands:chown cloudbolt:cloudbolt /var/opt/cloudbolt/proserv/db/server.crt chown cloudbolt:cloudbolt /var/opt/cloudbolt/proserv/db/server.key chown cloudbolt:cloudbolt /var/opt/cloudbolt/proserv/db/root.crt -
On all web nodes and all job engine nodes, update your database settings:
-
Edit
/var/opt/cloudbolt/proserv/customer_settings.pyto add theOPTIONSfor SSL:Example
/var/opt/cloudbolt/proserv/customer_settings.pywithOPTIONS#Replace value for PASSWORD in the block below DATABASES = { 'default': { "ENGINE": "django.db.backends.postgresql", "NAME": "cloudbolt", "USER": "cb_dba", "PASSWORD": "yourpassword", "HOST": "db.cloudbolt.vm", "PORT": "5432", 'OPTIONS': { 'sslmode': "require", 'sslcert': "/var/opt/cloudbolt/proserv/db/server.crt", 'sslkey': "/var/opt/cloudbolt/proserv/db/server.key", 'sslrootcert': "/var/opt/cloudbolt/proserv/db/root.crt", }, } }
-
-
In a web browser, log in to the CMP UI and go to a couple of different pages.
-
On the database server, connect to the database using
psqland run the following query.#Replace value for password in the psql command below psql "dbname=cloudbolt host=db.cloudbolt.vm user=cb_dba password=yourdbpassword sslmode=require" psql (14.2) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. cloudbolt=> SELECT * FROM pg_stat_ssl;-
The ssl column should have the value
tfor all pids.#Example Expected Result pid | ssl | version | cipher | bits | client_dn | client_serial | issuer_dn ------+-----+---------+-----------------------------+------+-----------+---------------+----------- 2963 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | 2952 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | 2994 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | 2995 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | 2993 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | 2996 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | 2997 | t | TLSv1.2 | ECDHE-RSA-AES256-GCM-SHA384 | 256 | | | (7 rows)
-
Related
- Set up high availability: Point every node at the shared database.
- Network connectivity: Open TCP 5432 from each node to the database.
- Appliance security: Other transport encryption and hardening measures.