-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this change, it is possible to apply the required
SSL configuration to enable SSL in the PG database. Specifically, by mounting the appropriate certificates in the pgconf directory, it is possible to configure the 'ssl_key_file', 'ssl_cert_file', 'ssl_ca_file' and 'ssl_crl_file' postgresql.conf settings for the cluster via the DCS, effectively enabling the use of SSL and client certificates when connecting to and authenticating into the database. In support of configuring the DCS for SSL, the mechanism for detecting that the local node has been initialized has been updated. Now, in addition to verifying that the node is in a running state, a check is performed to first determine whether the local node has the primary or replica role, and then whether or not the primary or replica endpoint (depending on the role identified) is returning status code 200. This ensures that all initial configuration has been applied to the node prior to updating the DCS with the SSL configuration using a JSON patch. And finally, it is now possible to specify the certificates needed to allow the replication user to authenticate via client certificate in lieu of using a replication password.
- Loading branch information
1 parent
cc4a798
commit 128011f
Showing
3 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
source /opt/cpm/bin/common_lib.sh | ||
enable_debugging | ||
|
||
PGHA_SSL_CONFIG="" | ||
|
||
custom_config() { | ||
src=${1?} | ||
dest=${2?} | ||
mode=${3?} | ||
if [[ -f ${src?} ]] | ||
then | ||
echo_info "Custom ${src?} detected. Applying custom configuration.." | ||
|
||
cp ${src?} ${dest?} | ||
err_check "$?" "Applying custom configuration" "Could not copy ${src?} to ${dest?}" | ||
|
||
chmod ${mode?} ${dest?} | ||
err_check "$?" "Applying custom configuration" "Could not set mode ${mode?} on ${dest?}" | ||
|
||
case "${src?}" in | ||
"/pgconf/server.key") | ||
PGHA_SSL_CONFIG+=",\"ssl_key_file\":\"server.key\"" | ||
;; | ||
"/pgconf/server.crt") | ||
PGHA_SSL_CONFIG+=",\"ssl_cert_file\":\"server.crt\"" | ||
;; | ||
"/pgconf/ca.crt") | ||
PGHA_SSL_CONFIG+=",\"ssl_ca_file\":\"ca.crt\"" | ||
;; | ||
"/pgconf/ca.crl") | ||
PGHA_SSL_CONFIG+=",\"ssl_crl_file\":\"ca.crl\"" | ||
;; | ||
esac | ||
fi | ||
} | ||
|
||
# Call the custom-config function in order to configure any certificates available in the | ||
# '/pgconf' directory as needed to enable SSL | ||
custom_config "/pgconf/server.key" "${PATRONI_POSTGRESQL_DATA_DIR}/server.key" 600 | ||
custom_config "/pgconf/server.crt" "${PATRONI_POSTGRESQL_DATA_DIR}/server.crt" 600 | ||
custom_config "/pgconf/ca.crt" "${PATRONI_POSTGRESQL_DATA_DIR}/ca.crt" 600 | ||
custom_config "/pgconf/ca.crl" "${PATRONI_POSTGRESQL_DATA_DIR}/ca.crl" 600 | ||
custom_config "/pgconf/replicator.crt" "${PATRONI_POSTGRESQL_DATA_DIR}/replicator.crt" 600 | ||
custom_config "/pgconf/replicator.key" "${PATRONI_POSTGRESQL_DATA_DIR}/replicator.key" 600 | ||
|
||
export PGHA_SSL_CONFIG |