Configuring mTLS on an external database
Prerequisites
Before configuring mTLS for an external database in a Kubernetes deployment, ensure the following:
-
Environment setup:
-
Kubernetes and Helm are installed and properly configured.
-
Persistent Volumes (PV) and Persistent Volume Claims (PVC) are set up in your environment.
-
-
Deployment preparation:
-
You have identified the correct deployment files to use and know where to download them.
-
You are familiar with setting up a Black Duck deployment using an external database.
-
You have the necessary commands ready for running a Black Duck deployment with an external database.
-
-
mTLS requirements:
-
The
openssl.cnffile is available on your server for generating certificates. -
Secrets are named using the default values provided in the deployment instructions.
-
Depending on your deployment, you may have up to five secrets for mTLS: root certificate, admin certificate & key, and user certificate & key. If you are not using one or more of these, update the corresponding entries in the
values.yamlfile to an empty string ( "" ).-
Example: To configure the root certificate, update the
postgres.customCerts.rootCAKeyNamefield in value.yaml. By default, this is set to "HUB_POSTGRES_CA". If you do not have a root certificate, set this value to "".
-
-
-
Namespace consistency:
-
Both the Black Duck and PostgreSQL deployments use the same namespace.
-
Changes to your Black Duck deployment
Updating values.yaml
To configure mTLS for your Black Duck deployment, you must
update the values.yaml file with the necessary settings secrets.
Follow these steps:
-
Configure
postgres.sslModeAdd the
postgres.sslModeconfiguration option tovalues.yaml. This option determines whether the deployment will include certificate ane key secrets. If this option is not configured, the setenv.sh script will exclude the cert/key secrets from the deployment. Ensure this value is set to enable mTLS. -
Set the secret name for custom certificates
Add the
postgres.customCerts.useCustomCertsoption tovalues.yaml. This specifies the name of the secret containing the necessary certificate and key data for connecting to the external database (e.g., root CA, admin cert/key, and user cert/key). -
Define custom certificate data
Under the
postgres.customCertssection invalues.yaml, configure the following five options to specify the data for the certificates and keys:-
rootCAKeyName: The key name for the root CA certificate. -
clientCertName: The key name for the user certificate. -
clientKeyName: The key name for the user private key. -
adminClientCertName: The key name for the admin certificate. -
adminClientKeyName: The key name for the admin private key.
Ensure these values match the names in your secrets configuration.
-
Updating postgres-init.yaml
To support mTLS, the following changes are required in the
postgres-init.yaml file:
-
Add volume and volume mount logic for the five new SSL secrets.
-
Include logic to set the
PGSSLMODEenvironment variable. -
Add logic to set the
PGSSLROOTCERTenvironment variable. -
Set the
PGSSLCERTenvironment variable first based onHUB_POSTGRES_CRTand then onHUB_ADMIN_POSTGRES_CRT. Separateifstatements should be used for clarity. -
Set the
PGSSLKEYenvironment variable first based onHUB_POSTGRES_KEYand then onHUB_ADMIN_POSTGRES_KEY. Separateifstatements should be used for clarity. -
Reorganize shell command logic by moving the logic for running
/tmp/postgres-init/init.pgsqland grouping it with other shell commands for improved readability.
Update environs
Add HUB_POSTGRES_ENABLE_SSL_CERT_AUTH: "true" to environs.
Update postgres.name
After starting the database pod, retrieve the host value for the pod and update the
postgres.host field in values.yaml.
Update postgres.customCerts.useCustomCerts
Update postgres.customCerts.useCustomCerts to
true.
Create the secret for certificates and keys
Use the following command to create the secret for certificates and keys:
kubectl create secret generic -n bdbd-blackduck-postgres-certificate --from-file=HUB_POSTGRES_CA=root.crt
--from-file=HUB_POSTGRES_CRT=blackduck_user.crt
--from-file=HUB_POSTGRES_KEY=blackduck_user.pk8
--from-file=HUB_ADMIN_POSTGRES_CRT=blackduck_admin.crt
--from-file=HUB_ADMIN_POSTGRES_KEY=blackduck_admin.pk8
