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.
Configuring SSL secrets in setenv.sh
To enable mTLS for pods using an external database, modifications are required in the setenv.sh script for each pod. The following steps outline the changes and logic to handle SSL secrets:
Update logic for SSL secrets
Modify the
setenv.shscript for each pod that uses certificates to include logic for handling five new SSL secrets. The updated logic should include:For non-external databases:
Ignore all SSL secrets and use internally generated Black Duck keys and certificates.
Override
sslmodetoverify-cafor internal use.
For external databases:
If
enable sslis set tofalse, ignore SSL secrets.If
sslmodeis set to ignore, ignore SSL secrets.
Default configuration:
If none of the above conditions are met, configure the following environment variables based on the provided SSL secrets:
DB_SSL_CA: Root CA certificate.DB_SSL_CRTandDB_SSL_KEY: User certificate and private key.DB_ADMIN_SSL_CRTandDB_ADMIN_SSL_KEY: Admin certificate and private key.
Validate configuration
Ensure the modified
setenv.shscript is tested across all relevate pods to confirm it correctly applies the SSL secrets and exits cleanly for valid setups.
Updating _postgresql.tpl
To properly support mTLS with an external database, updates to the _postgresql.tpl file are required. These chagnes ensure the correct handling of SSL-related settings and secrets:
Correct logic for
HUB_POSTGRES_ENABLE_SSL_CERT_AUTHPreviously,
HUB_POSTGRES_ENABLE_SSL_CERT_AUTHwas hardcoded tofalsefor external databases. Update the logic to correctly determine whether SSL certificate authentication should be enabled based on deployment configuration.Add logic for
HUB_POSTGRES_SSL_MODEIntroduce logic to set the
HUB_POSTGRES_SSL_MODEenvironment variable. This ensures that the SSL mode is accurately configured for external database connections.Add conditional volume and volumemount logic
Add conditions to dynamically include volumes and volume mounts for five new SSL secrets: Root CA certificate, user certificate and private key, admin certificate and private key.
Set
PGSSLMODEenvironment variableInclude logic to set
PGSSLMODEas an environment variable withing the PostgreSQL init pod. This ensures the init pod respects the SSL mode configured in the deployment.
Updating configmap.yaml
Update the configmap.yaml file to include the HUB_POSTGRES_SSL_MODE configuration.
Updating postgres-config.yaml
Include logic for setting HUB_POSTGRES_ENABLE_SSL_CERT_AUTH.
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