Ir para o conteúdo

Installation

Security hardening of the appliance

The appliance applies part of the recommendations of the advanced security hardening guide when it is built; the state of each recommendation, and what remains to be done after deployment, is given in Security hardening of the PostgreSQL database appliance.

Note

As a reminder, switching to root on Debian machines must be done with the following command:

1
su -

The instructions provided on this page should be followed for the installation of all nodes in the PostgreSQL cluster.

Systems settings

Connection to the machine

By default, there are two accounts on virtual appliances: a user account and a super-user account.

  • User account
    • Login : systancia
    • Password: systnci
  • Super-user account
    • Login : root
    • Password: systnci

Connect to the machine in console mode with the systancia account, then switch to the root account with the following command and the root password:

1
su -

Connecting as root

The root account is not accepted directly, neither in console mode nor over SSH.

Note

The default keyboard layout is QWERTY.

Modification of the keyboard layout

You can change the keyboard layout with the following command line:

1
dpkg-reconfigure keyboard-configuration

A menu appears to allow you to choose another keyboard layout.

Then use the following command line to apply and save the settings:

1
setupcon -k --save

The settings will take effect immediately after this command is executed.

Configuration of the network

The virtual appliance may not receive a network configuration when it starts up for the following reasons:

  • The network interface name is not ens192: the appliance is configured for DHCP only on the ens192 interface
  • No DHCP server is available

To check the network interface name, its status, and the assigned IP addresses, run the following command as root:

1
ip -br a | grep -ve "^lo"
Example

After executing the command, the following response is displayed:

1
ens192      UP      10.100.0.51/24

The name of the network interface in the example is ens192, the interface is active and has the IP address 10.100.0.51/24.

If the name is different from ens192 or if the command does not return any network settings, you will need to configure the network manually using the following commands:

1
2
ip address add IP_ADDRESS/SUBNET dev DEV_NAME
ip route add default via GATEWAY

Replace:

  • IP_ADDRESS by the machine's IP address
  • SUBNET by the subnetwork
  • DEV_NAME name of the previously retrieved network interface
  • GATEWAY by the network gateway
Example

To configure the PostgreSQL node with the following information:

  • IP address: 10.100.0.51
  • Sub-network: /24 or 255.255.255.0
  • Network interface name: eth0
  • Network gateway: 10.100.0.254

The commands are as follows:

1
2
ip address add 10.100.0.51/24 dev eth0
ip route add default via 10.100.0.254

Note

This network configuration is temporary, therefore any server restart will reset the manual settings made with the ip address and ip route commands.
Permanent configuration will be performed by the PostgreSQL cluster configuration utility.

However, thanks to this network configuration, you can now access the PostgreSQL node via SSH.

Modification of the time zone

By default, the virtual appliance is set to the Europe/Paris time zone.

To change this time zone, first use the following command to retrieve the syntax of available time zones:

1
timedatectl list-timezones

Then use the following command line:

1
timedatectl set-timezone your_time_zone
Example

To set the time zone to London, the following command must be executed:

1
timedatectl set-timezone Europe/London

Check the server's time zone using the following command line:

1
timedatectl

Configuration of an NTP time server

Danger

It is strongly recommended that you configure a time server to keep the system clock up to date: any time difference between PostgreSQL nodes may cause instability or even cause the cluster to stop working.

The necessary steps are described on the NTP configuration page (the configuration is equivalent to that of CyberElements Bastion Mediation Controller servers).

Creating a PKI to generate PostgreSQL node certificates

Information

This section is optional if you already have a PKI from which you have been able to generate the certificates indicated in the prerequisites.
This section will present the various steps for creating a PKI and the certificates required for the PostgreSQL cluster. Note that it will not be indicated how to renew them, as the renewal of a certificate involves its re-creation.

Skip this step

Attention!

The procedure described has been validated on a Debian 13 machine with the openssl package. However, any machine with a recent version of OpenSSL (3.0 or later) will be able to complete the procedure. Except for Windows or MacOS where the system commands will have to be adapted.

Definition of variables and customisations

This section provides various commands and configuration files that use variables that can be modified.
The table below summarises all the values and allows you to define them so that you can modify them directly in the commands displayed on this page.

Value Variable Definition
PSQL_IP Virtual IP address of the PostgreSQL cluster.
PSQL_NAME Short name (not the FQDN) associated with the virtual IP address of the PostgreSQL cluster.
PSQL_1_IP IP address of the PostgreSQL cluster node n°1.
PSQL_1_NAME Short name (not the FQDN) of the PostgreSQL cluster node n°1.
PSQL_2_IP IP address of the PostgreSQL cluster node n°2.
PSQL_2_NAME Short name (not the FQDN) of the PostgreSQL cluster node n°2.
PSQL_3_IP IP address of the PostgreSQL cluster node n°3.
PSQL_3_NAME Short name (not the FQDN) of the PostgreSQL cluster node n°3.
CA_ROOT_NAME Name assigned to the root certification authority (CA) of the PKI.

Preparation

The following actions will be performed in a new directory in order to gather all the new files in a single directory. Any directory can be used, but its access must be limited as much as possible. Log in to PostgreSQL node n°1 as root and run the following commands:

1
2
3
mkdir /root/psql-certificates/
chmod 600 /root/psql-certificates/
cd /root/psql-certificates/

Creation of the root certification authority

Run the following command to create a new root CA. You will be prompted for a password to protect the CA:

1
openssl req -x509 -newkey rsa:4096 -days 3650 -sha512 -keyout CA_ROOT_NAME.key -out CA_ROOT_NAME.crt -subj "/CN=CA_ROOT_NAME" -extensions v3_ca -addext "subjectKeyIdentifier=hash" -addext "authorityKeyIdentifier=keyid:always,issuer:always" -addext "basicConstraints=critical,CA:true" -addext "keyUsage=critical,digitalSignature,cRLSign,keyCertSign"

Replace CA_ROOT_NAME with the name of the root CA if you haven't customised it here.

Creation of certificates

The commands required to generate certificates for PostgreSQL nodes are as follows:

1
2
3
openssl genrsa -out PSQL_1_NAME.key 4096
openssl req -new -key PSQL_1_NAME.key -out PSQL_1_NAME.csr -subj "/CN=PSQL_1_NAME"
openssl x509 -req -in PSQL_1_NAME.csr -CA CA_ROOT_NAME.crt -CAkey CA_ROOT_NAME.key -CAcreateserial -out PSQL_1_NAME.crt -days 1825 -sha512 -extfile <(printf "subjectKeyIdentifier=hash\nauthorityKeyIdentifier=keyid,issuer\nbasicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth,clientAuth\nsubjectAltName=DNS:PSQL_NAME,DNS:PSQL_1_NAME,IP:PSQL_IP,IP:PSQL_1_IP")
1
2
3
openssl genrsa -out PSQL_2_NAME.key 4096
openssl req -new -key PSQL_2_NAME.key -out PSQL_2_NAME.csr -subj "/CN=PSQL_2_NAME"
openssl x509 -req -in PSQL_2_NAME.csr -CA CA_ROOT_NAME.crt -CAkey CA_ROOT_NAME.key -CAcreateserial -out PSQL_2_NAME.crt -days 1825 -sha512 -extfile <(printf "subjectKeyIdentifier=hash\nauthorityKeyIdentifier=keyid,issuer\nbasicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth,clientAuth\nsubjectAltName=DNS:PSQL_NAME,DNS:PSQL_2_NAME,IP:PSQL_IP,IP:PSQL_2_IP")
1
2
3
openssl genrsa -out PSQL_3_NAME.key 4096
openssl req -new -key PSQL_3_NAME.key -out PSQL_3_NAME.csr -subj "/CN=PSQL_3_NAME"
openssl x509 -req -in PSQL_3_NAME.csr -CA CA_ROOT_NAME.crt -CAkey CA_ROOT_NAME.key -CAcreateserial -out PSQL_3_NAME.crt -days 1825 -sha512 -extfile <(printf "subjectKeyIdentifier=hash\nauthorityKeyIdentifier=keyid,issuer\nbasicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth,clientAuth\nsubjectAltName=DNS:PSQL_NAME,DNS:PSQL_3_NAME,IP:PSQL_IP,IP:PSQL_3_IP")

The first command creates a new key, the second generates a certificate signing request CSR file, and the third creates the certificate itself.

The certificate still needs to be converted to P12, which will require you to set a password:

1
openssl pkcs12 -chain -CAfile CA_ROOT_NAME.crt -export -inkey PSQL_1_NAME.key -in PSQL_1_NAME.crt -out PSQL_1_NAME.p12
1
openssl pkcs12 -chain -CAfile CA_ROOT_NAME.crt -export -inkey PSQL_2_NAME.key -in PSQL_2_NAME.crt -out PSQL_2_NAME.p12
1
openssl pkcs12 -chain -CAfile CA_ROOT_NAME.crt -export -inkey PSQL_3_NAME.key -in PSQL_3_NAME.crt -out PSQL_3_NAME.p12

The files required to install the PostgreSQL cluster can be found here (please replace the variables CA_ROOT_NAME, PSQL_1_NAME, PSQL_2_NAME, and PSQL_3_NAME with the values you selected earlier):

  • /root/psql-certificates/CA_ROOT_NAME.crt: certificate of the root CA
  • /root/psql-certificates/PSQL_1_NAME.p12: certificate for the PostgreSQL node n°1
  • /root/psql-certificates/PSQL_2_NAME.p12: certificate for the PostgreSQL node n°2
  • /root/psql-certificates/PSQL_3_NAME.p12: certificate for the PostgreSQL node n°3

Installation of a PostgreSQL cluster

Information

The following steps must be performed on all three PostgreSQL nodes.

Preparation for the configuration of the PostgreSQL cluster

It is necessary to establish an SFTP or SCP connection in order to send to the appliance:

  • The certificate from the certification authority that signed the certificates for the PostgreSQL nodes
  • The PostgreSQL node certificate in P12 format

Please note that SFTP or SCP connections cannot be initialised using the root account. In addition, files can simply be placed in /home/systancia/.

It is necessary to move these files to a new directory:

1
2
3
mkdir /etc/ssl/certs/cleanroom/
mv /home/systancia/PSQL_?_NAME.p12 /etc/ssl/certs/cleanroom/
mv /home/systancia/ROOT_CA_NAME.crt /etc/ssl/certs/cleanroom/

Replace:

  • PSQL_?_NAME with the name of the certificate intended for the PostgreSQL node being installed
  • ROOT_CA_NAME with the name of the root certificate authority's certificate
1
2
3
mkdir /etc/ssl/certs/cleanroom/
cp /root/psql-certificates/PSQL_1_NAME.p12 /etc/ssl/certs/cleanroom/
cp /root/psql-certificates/CA_ROOT_NAME.crt /etc/ssl/certs/cleanroom/

The commands above must have been customised according to the customisation settings.

1
2
3
mkdir /etc/ssl/certs/cleanroom/
mv /home/systancia/PSQL_2_NAME.p12 /etc/ssl/certs/cleanroom/
mv /home/systancia/CA_ROOT_NAME.crt /etc/ssl/certs/cleanroom/

The commands above must have been customised according to the customisation settings.

1
2
3
mkdir /etc/ssl/certs/cleanroom/
mv /home/systancia/PSQL_3_NAME.p12 /etc/ssl/certs/cleanroom/
mv /home/systancia/CA_ROOT_NAME.crt /etc/ssl/certs/cleanroom/

The commands above must have been customised according to the customisation settings.

The P12 file contains the private key of the node: restrict its access to the root account:

1
2
chown root:root /etc/ssl/certs/cleanroom/*.p12
chmod 600 /etc/ssl/certs/cleanroom/*.p12

Configuration of the PostgreSQL node

To start initialising the node configuration, the following commands must be executed:

1
2
cd /etc/ssl/certs/cleanroom/
ConfigureSystanciaVault.py

The second command will launch a utility that will require the following information:

Passwords entered in the utility

The passwords entered in the utility must contain neither the % character nor the $ character. If the utility stops before the end, delete the /etc/cleanroom-vault.ini file before running it again:

1
rm /etc/cleanroom-vault.ini
  1. New passwords for the root and systancia local users
  2. Name of the PostgreSQL node (not the FQDN)
  3. The IP address of the PostgreSQL node, the name of its network interface, the default network gateway to use, as well as the DNS servers and DNS suffix
  4. The version of PostgreSQL: the appliance provides version 17, proposed by default
  5. The access port to the PostgreSQL cluster; we recommend using port 5432
  6. Password for the PostgreSQL account used for replication and for pg_rewind
  7. Name and IP address of a second PostgreSQL node
  8. Name and IP address of the last PostgreSQL node
  9. Virtual IP address of the PostgreSQL cluster
  10. The IP addresses (separated by commas) of the CyberElements Bastion Edge Gateways or any other machines that need to connect to the cluster
  11. Name and password of the PostgreSQL user account
  12. The IP addresses or networks (separated by commas) authorised to connect via SSH to PostgreSQL nodes
  13. Certificate information for the PostgreSQL node (node certificate in P12 format + root CA certificate)

After entering this information, a summary of all your entries will be provided before validation.
Once the configuration is applied, restrict the access to the private key of the node written by the utility:

1
chmod 600 /etc/cleanroomvault.key

In order to apply the configuration, a restart is required:

1
reboot
Tip for speeding up the installation of PostgreSQL nodes n°2 and n°3

After installing PostgreSQL node n°1, you can retrieve the configuration settings used to set it up from the /etc/cleanroom-vault.ini file.

Example of the /etc/cleanroom-vault.ini file

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[local]
name = PSQL-1
ip = 172.16.10.51

[cluster]
server1 = PSQL-2,172.16.10.52
server2 = PSQL-3,172.16.10.53

[ssl]
ca = MY-ROOT-CA.crt
client_cert = /etc/cleanroomvault.crt
client_key = /etc/cleanroomvault.key
peer_cert = /etc/cleanroomvault.crt
peer_key = /etc/cleanroomvault.key

[postgresql]
port = 5432
cluster = cleanroomvault5
version = 17

[patroni]
api_port = 8008
replication_password = R3pl1cationP@SSw0rd
rewind_password = Rew1ndP@SSw0rd

[vip]
interface = ens192
ip = 172.16.10.50

[cleanroom]
gw_ips = 172.16.10.10, 172.16.10.11
db_user = DbUser
db_password = DbP@SSw0rd

[networking]
interface = ens192
ip = 172.16.10.51/24
gateway = 172.16.10.254
dns = 172.16.10.100
dnssuffix = domain.local

[ssh]
allow = 10.0.20.0/24

Simply modify the highlighted lines with the values of the PostgreSQL node being installed, based on the file you retrieved from PostgreSQL node n°1.

Danger

If you reuse the example file, you will need to modify all of the following highlighted values according to your environment:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[local]
name = PSQL-1
ip = 172.16.10.51

[cluster]
server1 = PSQL-2,172.16.10.52
server2 = PSQL-3,172.16.10.53

[ssl]
ca = MY-ROOT-CA.crt
client_cert = /etc/cleanroomvault.crt
client_key = /etc/cleanroomvault.key
peer_cert = /etc/cleanroomvault.crt
peer_key = /etc/cleanroomvault.key

[postgresql]
port = 5432
cluster = cleanroomvault5
version = 17

[patroni]
api_port = 8008
replication_password = R3pl1cationP@SSw0rd
rewind_password = Rew1ndP@SSw0rd

[vip]
interface = ens192
ip = 172.16.10.50

[cleanroom]
gw_ips = 172.16.10.10, 172.16.10.11
db_user = DbUser
db_password = DbP@SSw0rd

[networking]
interface = ens192
ip = 172.16.10.51/24
gateway = 172.16.10.254
dns = 172.16.10.100
dnssuffix = domain.local

[ssh]
allow = 10.0.20.0/24

Once all the PostgreSQL nodes are installed, delete the /etc/cleanroom-vault.ini file from each node, as it contains the passwords entered during the configuration in plain text:

1
rm /etc/cleanroom-vault.ini

Opening the Patroni port and enabling the local firewall

The configuration utility writes the rules of the local firewall in the /etc/nftables.conf file. To enable the use of the PostgreSQL cluster management commands with patronictl, open the Patroni port 8008 in these rules, then enable the firewall. Run the following commands as root on each PostgreSQL node:

1
2
sed -i "s/2380/2380, 8008/g" /etc/nftables.conf
systemctl enable --now nftables

Information

When the firewall is enabled, the connections between the nodes are reset: etcd elects its leader again, which takes a few seconds. The state of the cluster can then be checked by obtaining the cluster LEADER node.

So that patronictl trusts the certificate of the Patroni API (port 8008), add the certification authority of the cluster to the settings of patronictl in the /etc/patroni/config.yml file, then reload Patroni. Run the following commands as root on each PostgreSQL node:

1
2
printf "\nctl:\n  cacert: /etc/patroni/ca.crt\n" >> /etc/patroni/config.yml
systemctl reload patroni

Information

Without this setting, the patronictl commands that go through the Patroni API fail with the certificate verify failed error, for example when switching the LEADER node or reinitialising a node.

Virtual IP address and VRRP identifier

VRRP identifier

The virtual IP address of the cluster is carried through keepalived with the VRRP identifier (VRID) 100 by default, which must be unique on the local network of the nodes (see the prerequisites). To use another identifier, see Changing the VRRP identifier; if the virtual IP address is carried by no node, see Troubleshooting keepalived.

Creation of the default database required for installing CyberElements Bastion

When installing CyberElements Bastion, you must first create a database named default.
To do this, fill out the following table to customise the command you will need to run from a node of the PostgreSQL cluster other than the LEADER node:

Value Variable Definition
DB_USERNAME The database username specified during PostgreSQL node configuration

Command to be executed from a node of the PostgreSQL cluster other than the LEADER node (see how to obtain the cluster LEADER node):

1
createdb -h PSQL_IP -U DB_USERNAME default