Skip to content

Commit e98b3f9

Browse files
committed
Use OS certificate bundle
We are getting away from storing configuration files in /root Now we are storing the ssl certificates in the standard linux location
1 parent 637835f commit e98b3f9

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

appliance_hardening_guide/_topics/db_ssl.md

+39-40
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,43 @@ The appliance image ships with a default SSL certificate and it is recommended t
1010

1111
For more information, see [Generating SSL Certificates for Your Appliance and Database](#generating-ssl-certificates-for-your-appliance-and-database).
1212

13-
1413
- `/var/www/miq/vmdb/certs/server.cer` - Signed or self-signed certificate for the database appliance.
15-
1614
- `/var/www/miq/vmdb/certs/server.cer.key` - Private key for server certificate.
1715

18-
- `/var/www/miq/vmdb/certs/root.crt` - The root CA certificate used to sign the CA certificate for the {{ site.data.product.title_short }} database. You can either use a self-signed certificate or a certificate that is signed by a trusted CA to generate your root certificate.
19-
2016
It is also recommended to stop all {{ site.data.product.title_short }} services before configuring the database to use SSL.
2117

18+
#### Configure SSL on the database appliance
19+
2220
To configure SSL on the database appliance:
2321

2422
1. Log in as `root` to the appliance where the database resides.
2523

2624
2. Stop the `evmserverd` and `postgresql` services:
2725

28-
[root@appliance2 ~]# systemctl stop evmserverd
29-
[root@appliance2 ~]# systemctl stop postgresql.service
26+
$ systemctl stop evmserverd
27+
$ systemctl stop postgresql.service
3028

3129
3. Install the server key file in the correct location and set the ownership and permissions for it:
3230

33-
[root@appliance2 ~]# install -m 600 -o postgres -g postgres \
34-
/var/www/miq/vmdb/certs/server.cer.key /var/www/miq/vmdb/certs/postgres.key
31+
$ install -m 600 -o postgres -g postgres \
32+
/var/www/miq/vmdb/certs/server.cer.key /var/lib/pgsql/data/postgres.key
3533

3634
4. Install the server certificate file in the correct location and set the ownership and permissions for it:
3735

38-
[root@appliance2 ~]# install -m 644 -o postgres -g postgres \
39-
/var/www/miq/vmdb/certs/server.cer /var/www/miq/vmdb/certs/postgres.crt
40-
41-
5. Install the database appliance certificate file as the root certificate in the correct location and set the ownership and
42-
permissions for it.
43-
44-
If you are using a self-signed certificate, run:
45-
46-
[root@appliance2 ~]# install -m 644 -o postgres -g postgres /var/www/miq/vmdb/certs/server.cer /var/www/miq/vmdb/certs/root.crt
47-
48-
If you are using a third-party certificate, edit this command to install your root certificate.
49-
50-
6. Make sure that the security context is set correctly for the files in `/var/www/miq/certs`:
36+
$ install -m 644 -o postgres -g postgres \
37+
/var/www/miq/vmdb/certs/server.cer /var/lib/pgsql/data/postgres.crt
5138

52-
[root@appliance2 ~]# restorecon -R -v /var/www/miq/vmdb/certs
53-
54-
7. Open the `/var/lib/pgsql/data/postgresql.conf` file and uncomment and edit the `ssl` option:
39+
5. Open the `/var/lib/pgsql/data/postgresql.conf` file and uncomment and edit the `ssl` option:
5540

5641
ssl=on
5742

58-
In the same file, locate the options `ssl_cert_file`, `ssl_key_file`, and `ssl_ca_file` that specify the location of SSL
43+
In the same file, locate the options `ssl_cert_file` and `ssl_key_file` that specify the location of SSL
5944
certificates and edit them so that they are uncommented and point to the correct certificate files:
6045

61-
ssl_cert_file = '/var/www/miq/vmdb/certs/postgres.crt' # (change requires restart)
62-
ssl_key_file = '/var/www/miq/vmdb/certs/postgres.key' # (change requires restart)
63-
ssl_ca_file = '/var/www/miq/vmdb/certs/root.crt' # (change requires restart)
46+
ssl_cert_file = 'postgres.crt' # (change requires restart)
47+
ssl_key_file = 'postgres.key' # (change requires restart)
6448

65-
8. Open the `/var/lib/pgsql/data/pg_hba.conf` file and locate the two lines that contain:
49+
6. Open the `/var/lib/pgsql/data/pg_hba.conf` file and locate the two lines that contain:
6650

6751
host all all all md5
6852
#hostssl all all all md5
@@ -74,30 +58,34 @@ To configure SSL on the database appliance:
7458

7559
This changes the incoming communication protocol to use SSL and refuse any unencrypted PostgreSQL connections.
7660

77-
9. Start the `postgresql` and `evmserverd` services so that the changes take effect:
61+
7. Start the `postgresql` and `evmserverd` services so that the changes take effect:
62+
63+
$ systemctl start postgresql.service
64+
$ systemctl start evmserverd
7865

79-
[root@{{ site.data.product.title_short_l }}1 ~]# systemctl start postgresql.service
80-
[root@{{ site.data.product.title_short_l }}1 ~]# systemctl start evmserverd
66+
#### Configure SSL on all connected appliances
8167

8268
The database appliance now accepts only connections from connecting appliances that use SSL. The following procedure sets up connecting appliances to communicate to the database by using SSL. Use this procedure for each connecting appliance:
8369

8470
1. Log in as `root` to the connecting appliance.
8571

86-
2. Create the `.postgresql` directory in your `root` user home directory.
72+
2. Copy the root certificate file from the database to the operating system's list of valid certificates:
8773

88-
[root@{{ site.data.product.title_short_l }}2 ~]# mkdir /root/.postgresql
74+
$ DATABASE=[database_appliance_fqdn]
75+
$ scp root@${DATABASE}:/var/www/miq/vmdb/certs/root.crt /etc/pki/ca-trust/source/anchors/${DATABASE}-postgres
76+
$ update-ca-trust extract
77+
$ export PGSSLROOTCERT=/etc/pki/tls/certs/ca-bundle.crt
8978

90-
The PostgreSQL client library, which {{ site.data.product.title_short }} also uses, looks to this directory for custom configuration files.
91-
92-
3. Copy the root certificate file from the database appliance to the `/root/.postgresql` directory on the connecting appliance:
79+
Where `[database_appliance_fqdn]` is the fully qualified domain name of the database appliance.
9380

94-
[root@{{ site.data.product.title_short_l }}2 ~]# scp root@[database_appliance_fqdn]:/var/www/miq/vmdb/certs/root.crt /root/.postgresql/root.crt
81+
3. Test the certificate got added to the certificate database:
9582

96-
Where `[database_appliance_fqdn]` is the fully qualified domain name of the database appliance.
83+
$ openssl x509 -in /etc/pki/tls/certs/ca-bundle.crt -text -noout
9784

9885
4. Test the connection between the connecting appliance and the database appliance by using the `psql`command:
9986

100-
[root@localhost ~]# psql -h [database_appliance_fqdn] -d vmdb_production
87+
$ PGSSLMODE=verify-full psql -h [database_appliance_fqdn] -d vmdb_production \
88+
-c "SELECT * from pg_stat_ssl WHERE pid=pg_backend_pid()"
10189
Password: ********
10290
psql (9.2.8)
10391
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
@@ -106,6 +94,17 @@ The database appliance now accepts only connections from connecting appliances t
10694
vmdb_production=#
10795

10896
The `psql` displays information about the SSL connection, which indicates that the configuration succeeded. Enter `\q` to leave `psql`.
97+
The `PGSSLMODE` variable forces a certain level of SSL. To learn more, please see [postgress sslmode documentation].
98+
99+
[postgress sslmode documentation]: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-SSLMODE
100+
101+
5. Ensure `/etc/default/manageiq.properties` has the proper ssl key file location defined:
102+
103+
$ grep PGSSLROOTCERT /etc/default/manageiq.properties || \
104+
echo PGSSLROOTCERT=/etc/pki/tls/certs/ca-bundle.crt >> /etc/default/manageiq.properties
105+
106+
The standard `manageiq.properties` should already have the `PGSSLROOTCERT` defined.
107+
The above command adds an entry to `manageiq.properties` if it is not already present.
109108

110109
Complete this procedure for each external appliance. This enhances the security of all database transactions in your {{ site.data.product.title_short }} infrastructure.
111110

0 commit comments

Comments
 (0)